Skip to content

Commit

Permalink
[#1] Lots of things:
Browse files Browse the repository at this point in the history
- Did a major cleanup pass on the whole project.
  - Added nullable/not-nullable annotations just about everywhere.
  - Extracted each screen into its own FXML file with corresponding controllers.
  - Resolved a zillion issues IDEA and SonarLint were bugging me about.
- Added the option to install mods into the user folder. Pending UI support, this can only be enabled via config editing.
- Added the option to uninstall the currently active mod. (TODO: Maybe disable if the mod doesn't seem to be installed?)
- Should have replaced all references to SR2MM with the OpenSR Launchpad. Also removed the Patreon link for the same reason.
- Possibly fixed some bugs. It's been ages since I first did most of this commit, and I never committed it because it wasn't finished at the time. (And arguably still isn't, since I'm pretty sure I intended to commit working versions of the new screens!)
  • Loading branch information
DaloLorn committed Aug 5, 2021
1 parent 260a2c5 commit a7290c7
Show file tree
Hide file tree
Showing 26 changed files with 851 additions and 484 deletions.
6 changes: 6 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ repositories {
dependencies {
implementation("org.eclipse.jgit:org.eclipse.jgit:5.11.1.202105131744-r")
implementation("com.google.code.gson:gson:2.8.6")
implementation("org.jetbrains:annotations:20.1.0")
}

java {
Expand Down
2 changes: 1 addition & 1 deletion history.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"history":["git://github.com/OpenStarRuler/OpenStarRuler-Modpack.git","git://github.com/DaloLorn/Rising-Stars.git","git://github.com/Skeletonxf/star-ruler-2-mod-ce.git","git://github.com/sol-oriens/Shores-of-Infinity.git","git://github.com/Vandaria/SR2-Lost-Sector.git"]}
{"history":["github.com/DaloLorn/Rising-Stars","github.com/OpenSRProject/OpenStarRuler-Modpack","github.com/Skeletonxf/star-ruler-2-mod-ce","github.com/sol-oriens/Shores-of-Infinity","github.com/Vandaria/SR2-Lost-Sector"]}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dalolorn.sr2modmanager.adapter;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
Expand All @@ -8,15 +11,19 @@
import java.nio.file.attribute.BasicFileAttributes;

public class CopyFileVisitor extends SimpleFileVisitor<Path> {
private final Path targetPath;
private Path sourcePath = null;
public CopyFileVisitor(Path targetPath) {
@NotNull private final Path targetPath;
@Nullable private Path sourcePath = null;

public CopyFileVisitor(@NotNull Path targetPath) {
this.targetPath = targetPath;
}

@Override
public FileVisitResult preVisitDirectory(final Path dir,
final BasicFileAttributes attrs) throws IOException {
@NotNull
public FileVisitResult preVisitDirectory(
@NotNull final Path dir,
@NotNull final BasicFileAttributes attrs
) throws IOException {
if (sourcePath == null) {
sourcePath = dir;
} else {
Expand All @@ -27,8 +34,12 @@ public FileVisitResult preVisitDirectory(final Path dir,
}

@Override
public FileVisitResult visitFile(final Path file,
final BasicFileAttributes attrs) throws IOException {
@NotNull
public FileVisitResult visitFile(
@NotNull final Path file,
@NotNull final BasicFileAttributes attrs
) throws IOException {
//noinspection ConstantConditions
Files.copy(file,
targetPath.resolve(sourcePath.relativize(file)));
return FileVisitResult.CONTINUE;
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/com/dalolorn/sr2modmanager/adapter/Finder.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
package com.dalolorn.sr2modmanager.adapter;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

import static java.nio.file.FileVisitResult.CONTINUE;

public abstract class Finder<T> extends SimpleFileVisitor<Path> {
protected final PathMatcher matcher;
@NotNull protected final PathMatcher matcher;

Finder(String pattern) {
Finder(@NotNull String pattern) {
matcher = FileSystems.getDefault()
.getPathMatcher("glob:" + pattern);
}

@Nullable
protected abstract T find(Path file);

@Nullable
public abstract T getResult();

// Invoke the pattern matching
// method on each file.
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
@NotNull
public FileVisitResult visitFile(
@NotNull Path file,
@NotNull BasicFileAttributes attrs
) {
if(find(file) != null)
return FileVisitResult.TERMINATE;
return CONTINUE;
Expand All @@ -30,14 +39,22 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
// Invoke the pattern matching
// method on each directory.
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
@NotNull
public FileVisitResult preVisitDirectory(
@NotNull Path dir,
@NotNull BasicFileAttributes attrs
) {
if(find(dir) != null)
return FileVisitResult.TERMINATE;
return CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
@NotNull
public FileVisitResult visitFileFailed(
@NotNull Path file,
@NotNull IOException exc
) {
System.err.println(exc);
return CONTINUE;
}
Expand Down
Loading

0 comments on commit a7290c7

Please sign in to comment.