Skip to content

Commit fe19491

Browse files
committed
More unjank (tm)
1 parent a25d9c7 commit fe19491

36 files changed

Lines changed: 315 additions & 293 deletions

src/main/java/com/lx862/pwgui/PWGUI.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static void init(CommandLine commandLine) {
3535
LOGGER.error("Failed to read config file!", e);
3636
}
3737

38-
String packFilePath = Config.getInstance().openLastModpackOnLaunch.getValue() ? Config.getInstance().lastModpackPath.getValue() == null ? null : Config.getInstance().lastModpackPath.getValue().toString() : null;
38+
String packFilePath = Config.getInstance().openLastModpackOnLaunch.value() ? Config.getInstance().lastModpackPath.value() == null ? null : Config.getInstance().lastModpackPath.value().toString() : null;
3939
boolean packwizLocated;
4040

4141
if(commandLine != null) {
@@ -53,8 +53,8 @@ public static void init(CommandLine commandLine) {
5353

5454
private static void launchGUI(String packFilePath, boolean packwizLocated) {
5555
Config config = Config.getInstance();
56-
GUIConfiguration.setupGUI(config.applicationTheme.getValue(), config.useWindowDecoration.getValue(), null); // Initialize FlatLaf and it's config
57-
UIScale.setZoomFactor(config.zoomFactor.getValue());
56+
GUIConfiguration.setupGUI(config.applicationTheme.value(), config.useWindowDecoration.value(), null); // Initialize FlatLaf and it's config
57+
UIScale.setZoomFactor(config.zoomFactor.value());
5858

5959
if(!packwizLocated) { // No packwiz, show setup wizard
6060
SwingUtilities.invokeLater(() -> {

src/main/java/com/lx862/pwgui/core/Config.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,19 @@ public void write(String reason) throws IOException {
9292
}
9393
jsonObject.add("lastPickedFiles", lastPickedFilesJsonArray);
9494
if(lastModpackPath.valueNotNull()) {
95-
jsonObject.addProperty(lastModpackPath.getKey(), lastModpackPath.getValue().toString());
95+
jsonObject.addProperty(lastModpackPath.getKey(), lastModpackPath.value().toString());
9696
}
97-
jsonObject.addProperty(applicationTheme.getKey(), applicationTheme.getValue().name());
98-
jsonObject.addProperty(authorName.getKey(), authorName.getValue());
99-
jsonObject.addProperty(openLastModpackOnLaunch.getKey(), openLastModpackOnLaunch.getValue());
100-
jsonObject.addProperty(debugMode.getKey(), debugMode.getValue());
101-
jsonObject.addProperty(useWindowDecoration.getKey(), useWindowDecoration.getValue());
102-
jsonObject.addProperty(showMetaFileName.getKey(), showMetaFileName.getValue());
103-
jsonObject.addProperty(zoomFactor.getKey(), zoomFactor.getValue());
97+
jsonObject.addProperty(applicationTheme.getKey(), applicationTheme.value().name());
98+
jsonObject.addProperty(authorName.getKey(), authorName.value());
99+
jsonObject.addProperty(openLastModpackOnLaunch.getKey(), openLastModpackOnLaunch.value());
100+
jsonObject.addProperty(debugMode.getKey(), debugMode.value());
101+
jsonObject.addProperty(useWindowDecoration.getKey(), useWindowDecoration.value());
102+
jsonObject.addProperty(showMetaFileName.getKey(), showMetaFileName.value());
103+
jsonObject.addProperty(zoomFactor.getKey(), zoomFactor.value());
104104

105105
JsonObject executableJsonObject = new JsonObject();
106106
if(packwizExecutablePath.valueNotNull()) {
107-
executableJsonObject.addProperty(packwizExecutablePath.getKey(), packwizExecutablePath.getValue().toString());
107+
executableJsonObject.addProperty(packwizExecutablePath.getKey(), packwizExecutablePath.value().toString());
108108
}
109109
jsonObject.add("executables", executableJsonObject);
110110

@@ -115,7 +115,7 @@ public void write(String reason) throws IOException {
115115
}
116116

117117
public void setLastModpackPath(Path newValue) {
118-
if(!Objects.equals(newValue, this.lastModpackPath.getValue())) {
118+
if(!Objects.equals(newValue, this.lastModpackPath.value())) {
119119
this.lastModpackPath.setValue(newValue);
120120
try { // Write if changed
121121
write("Save last opened modpack path");
@@ -150,10 +150,14 @@ public String getKey() {
150150
return this.configName;
151151
}
152152

153-
public T getValue() {
153+
public T value() {
154154
return this.value;
155155
}
156156

157+
public T valueOr(T defaultValue) {
158+
return this.value == null ? defaultValue : value;
159+
}
160+
157161
public void setValue(T newValue) {
158162
this.value = newValue;
159163
}

src/main/java/com/lx862/pwgui/core/data/Caches.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
import java.util.HashMap;
77
import java.util.List;
88
import java.util.Map;
9-
import java.util.function.Consumer;
9+
import java.util.concurrent.CompletableFuture;
1010

1111
public class Caches {
1212
public static final Map<PackComponent, List<VersionMetadata>> componentCaches = new HashMap<>();
1313
public static final Map<String, byte[]> resourceCaches = new HashMap<>();
1414

15-
public static void getVersionMetadata(PackComponent component, Consumer<List<VersionMetadata>> callback) {
15+
public static CompletableFuture<List<VersionMetadata>> fetchVersionMetadata(PackComponent component) {
1616
if(componentCaches.containsKey(component)) {
17-
callback.accept(componentCaches.get(component));
17+
return CompletableFuture.completedFuture(componentCaches.get(component));
1818
} else {
1919
try {
20-
component.versionGetter.get((versionList) -> {
21-
Caches.componentCaches.put(PackComponent.MINECRAFT, versionList);
22-
callback.accept(versionList);
20+
return component.versionGetter.get().thenApply(versionList -> {
21+
Caches.componentCaches.put(component, versionList);
22+
return versionList;
2323
});
2424
} catch (Exception e) {
2525
Caches.componentCaches.put(component, null);
26+
return CompletableFuture.completedFuture(null);
2627
}
2728
}
2829
}

src/main/java/com/lx862/pwgui/core/data/model/file/PackMetadataFileModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public PackMetadataFileModel(File file) {
1515

1616
@Override
1717
public String getDisplayName() {
18-
return Config.getInstance().showMetaFileName.getValue() ? name : packwizMetaFile.name;
18+
return Config.getInstance().showMetaFileName.value() ? name : packwizMetaFile.name;
1919
}
2020

2121
@Override
2222
public boolean isUserFriendlyName() {
23-
return !Config.getInstance().showMetaFileName.getValue();
23+
return !Config.getInstance().showMetaFileName.value();
2424
}
2525

2626
public PackwizMetaFile getPackMetadata() {

src/main/java/com/lx862/pwgui/core/log/Logger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private static void appendStdoutLogger() {
9696
addListener(((entry, isRealtime) -> {
9797
if(entry.logLevel() == LogEntry.LogLevel.ERROR) {
9898
System.err.println(entry.message());
99-
} else if(entry.logLevel() != LogEntry.LogLevel.DEBUG || Config.getInstance().debugMode.getValue()) {
99+
} else if(entry.logLevel() != LogEntry.LogLevel.DEBUG || Config.getInstance().debugMode.value()) {
100100
System.out.println(entry.message());
101101
}
102102
}));

src/main/java/com/lx862/pwgui/executable/Executable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lx862.pwgui.executable;
22

33
import com.lx862.pwgui.core.log.Logger;
4+
import com.lx862.pwgui.task.RunProgramTask;
45

56
import java.io.BufferedReader;
67
import java.io.InputStreamReader;
@@ -126,13 +127,13 @@ public ProgramArgumentBuilder append(List<String> strs) {
126127
return this;
127128
}
128129

129-
public ProgramExecution build() {
130+
public RunProgramTask build() {
130131
ensureExecutorActive();
131132
args.add(0, executableLocation);
132133
ProcessBuilder processBuilder = new ProcessBuilder(args.toArray(new String[0]));
133134
processBuilder.directory(workingDirectory.toFile());
134135

135-
return new ProgramExecution(logger, programName, processBuilder, executor);
136+
return new RunProgramTask(logger, programName, processBuilder, executor);
136137
}
137138
}
138139
}

src/main/java/com/lx862/pwgui/gui/action/DownloadPackwizAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.lx862.pwgui.core.Config;
66
import com.lx862.pwgui.gui.prompt.TaskDialog;
77
import com.lx862.pwgui.support.packwiz.executable.PackwizExecutable;
8-
import com.lx862.pwgui.util.DownloadTask;
8+
import com.lx862.pwgui.task.DownloadTask;
99
import com.lx862.pwgui.util.Strings;
1010
import com.lx862.pwgui.util.Util;
1111
import org.apache.commons.io.FileUtils;

src/main/java/com/lx862/pwgui/gui/action/FullUpdateAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.lx862.pwgui.support.packwiz.PackIndexFile;
77
import com.lx862.pwgui.support.packwiz.PackwizMetaFile;
88
import com.lx862.pwgui.util.Strings;
9-
import com.lx862.pwgui.executable.BatchedTask;
10-
import com.lx862.pwgui.executable.ProgramExecution;
9+
import com.lx862.pwgui.task.BatchedTask;
10+
import com.lx862.pwgui.task.RunProgramTask;
1111
import com.lx862.pwgui.gui.prompt.TaskDialog;
1212
import com.lx862.pwgui.gui.prompt.IncompatibleSummaryDialog;
1313
import com.lx862.pwgui.util.Util;
@@ -39,7 +39,7 @@ public FullUpdateAction(Supplier<Window> getParent, PackFile packFile) {
3939
@Override
4040
public void actionPerformed(ActionEvent event) {
4141
Window parent = getParent.get();
42-
ProgramExecution regularUpdateExecution = getProgramExecution(parent);
42+
RunProgramTask regularUpdateExecution = getProgramExecution(parent);
4343

4444
PackIndexFile packIndex = packFile.packIndexFile.get();
4545
List<PackIndexFile.FileEntry> originalEntries = packIndex.getFileEntries().stream().filter(f -> f.metafile).toList();
@@ -79,7 +79,7 @@ public void actionPerformed(ActionEvent event) {
7979
if(packwizMetaFile.updateGhSlug != null) continue;
8080

8181
String prefix = packwizMetaFile.updateMrVersion != null ? "mr" : "cf";
82-
ProgramExecution execution;
82+
RunProgramTask execution;
8383
if(prefix.equals("mr")) {
8484
execution = PackwizExecutable.INSTANCE.buildCommand("mr", "add", packwizMetaFile.updateMrModId).metaFolder(tempDirectory.getFileName().toString()).build();
8585
} else {

src/main/java/com/lx862/pwgui/gui/action/ReinstallAction.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.lx862.pwgui.gui.action;
22

33
import com.lx862.pwgui.PWGUI;
4-
import com.lx862.pwgui.executable.BatchedTask;
4+
import com.lx862.pwgui.task.BatchedTask;
55
import com.lx862.pwgui.gui.prompt.TaskDialog;
66
import com.lx862.pwgui.support.packwiz.executable.PackwizExecutable;
7-
import com.lx862.pwgui.executable.ProgramExecution;
7+
import com.lx862.pwgui.task.RunProgramTask;
88
import com.lx862.pwgui.support.packwiz.Modpack;
99
import com.lx862.pwgui.support.packwiz.PackFile;
1010
import com.lx862.pwgui.support.packwiz.PackIndexFile;
@@ -53,8 +53,8 @@ public void actionPerformed(ActionEvent actionEvent) {
5353
// Remove
5454
BatchedTask removeExecution = new BatchedTask("Removing meta files");
5555
for(PackwizMetaFile packwizMetaFile : metas) {
56-
ProgramExecution programExecution = PackwizExecutable.INSTANCE.remove(packwizMetaFile.getSlug()).build();
57-
removeExecution.add(programExecution);
56+
RunProgramTask runProgramTask = PackwizExecutable.INSTANCE.remove(packwizMetaFile.getSlug()).build();
57+
removeExecution.add(runProgramTask);
5858
}
5959
removeExecution.run("Re-installation requested by user");
6060

@@ -66,7 +66,7 @@ public void actionPerformed(ActionEvent actionEvent) {
6666

6767
String metaFolder = modpack.getRootPath().relativize(packwizMetaFile.getPath().getParent()).toString();
6868

69-
ProgramExecution execution;
69+
RunProgramTask execution;
7070
if(prefix.equals("mr")) {
7171
execution = PackwizExecutable.INSTANCE.buildCommand("mr", "add", packwizMetaFile.updateMrModId).metaFolder(metaFolder).yes().build();
7272
} else if(prefix.equals("cf")) {

src/main/java/com/lx862/pwgui/gui/action/UpdateAction.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.lx862.pwgui.support.packwiz.executable.PackwizExecutable;
44
import com.lx862.pwgui.util.Strings;
5-
import com.lx862.pwgui.executable.ProgramExecution;
5+
import com.lx862.pwgui.task.RunProgramTask;
66
import com.lx862.pwgui.gui.prompt.TaskDialog;
77
import com.lx862.pwgui.gui.prompt.UpdateSummaryDialog;
88
import com.lx862.pwgui.util.Util;
@@ -30,9 +30,9 @@ public UpdateAction(Supplier<Window> getParent) {
3030
@Override
3131
public void actionPerformed(ActionEvent e) {
3232
Window parent = getParent.get();
33-
ProgramExecution programExecution = getProgramExecution(parent);
33+
RunProgramTask runProgramTask = getProgramExecution(parent);
3434

35-
programExecution.onExit(exitResult -> {
35+
runProgramTask.onExit(exitResult -> {
3636
if(exitResult.success()) {
3737
if(alreadyUpToDate.get()) {
3838
JOptionPane.showMessageDialog(parent, "All files are already up to date!", Util.withTitlePrefix("Up to Date!"), JOptionPane.INFORMATION_MESSAGE);
@@ -43,19 +43,19 @@ public void actionPerformed(ActionEvent e) {
4343
}
4444
}
4545
});
46-
TaskDialog taskDialog = new TaskDialog(parent, "Checking for update...", programExecution);
47-
programExecution.run(Strings.REASON_TRIGGERED_BY_USER);
46+
TaskDialog taskDialog = new TaskDialog(parent, "Checking for update...", runProgramTask);
47+
runProgramTask.run(Strings.REASON_TRIGGERED_BY_USER);
4848
taskDialog.setVisible(true);
4949
}
5050

51-
public ProgramExecution getProgramExecution(Window parent) {
52-
ProgramExecution programExecution = PackwizExecutable.INSTANCE.updateAll().build();
51+
public RunProgramTask getProgramExecution(Window parent) {
52+
RunProgramTask runProgramTask = PackwizExecutable.INSTANCE.updateAll().build();
5353
List<String> updateMods = new ArrayList<>();
5454
List<String> skippedMods = new ArrayList<>();
5555
List<String> unsupportedMods = new ArrayList<>();
5656
AtomicBoolean startLogMods = new AtomicBoolean();
5757

58-
programExecution.onOutput(stdout -> {
58+
runProgramTask.onOutput(stdout -> {
5959
String line = stdout.content();
6060
if(line.startsWith("Updates found:")) {
6161
startLogMods.set(true);
@@ -71,8 +71,8 @@ public ProgramExecution getProgramExecution(Window parent) {
7171

7272
if(line.equals("Do you want to update? [Y/n]: ")) {
7373
new UpdateSummaryDialog(parent, updateMods, skippedMods, unsupportedMods, (update) -> {
74-
if(update) programExecution.enterInput("Y");
75-
else programExecution.enterInput("N");
74+
if(update) runProgramTask.enterInput("Y");
75+
else runProgramTask.enterInput("N");
7676
}).setVisible(true);
7777
}
7878

@@ -88,6 +88,6 @@ public ProgramExecution getProgramExecution(Window parent) {
8888
updateMods.add(line);
8989
}
9090
});
91-
return programExecution;
91+
return runProgramTask;
9292
}
9393
}

0 commit comments

Comments
 (0)