Skip to content

Commit f311b06

Browse files
committed
feat: Add better GUI feedback to deploader errors and restarts
1 parent a075dd6 commit f311b06

File tree

2 files changed

+55
-20
lines changed

2 files changed

+55
-20
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
group = "com.falsepattern"
66

77
//bump this after ANY change to the deploader!
8-
val deploaderVersion = 3
8+
val deploaderVersion = 4
99

1010
minecraft_fp {
1111
java {

src/deploader/java/com/falsepattern/deploader/DependencyLoaderImpl.java

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public class DependencyLoaderImpl {
117117
private static final Path tempDir;
118118
private static final Field metadataCollectionModListAccessor;
119119

120+
private static final AtomicBoolean needReboot = new AtomicBoolean(false);
121+
private static final Set<String> downloadedMods = new ConcurrentSet<>();
122+
private static final Set<String> downloadFailed = new ConcurrentSet<>();
123+
120124
static {
121125
try {
122126
metadataCollectionModListAccessor = MetadataCollection.class.getDeclaredField("modList");
@@ -126,8 +130,6 @@ public class DependencyLoaderImpl {
126130
metadataCollectionModListAccessor.setAccessible(true);
127131
}
128132

129-
private static AtomicBoolean needReboot = new AtomicBoolean(false);
130-
131133
private static void ensureExists(Path directory) {
132134
if (!Files.exists(directory)) {
133135
try {
@@ -468,13 +470,20 @@ public static void executeDependencyLoading() {
468470
tasks = executeArtifactLoading(baseTasks, false);
469471
}
470472
if (needReboot.get()) {
471-
val msg = "One or more minecraft mods which have been loaded by the FP DepLoader require a game restart to fully install.";
473+
var msgBuilder = new StringBuilder("One or more minecraft mods which have been loaded by the FP DepLoader require a game restart to fully install.");
474+
if (!downloadedMods.isEmpty()) {
475+
msgBuilder.append("\nDownloaded mods:");
476+
for (var mod : downloadedMods) {
477+
msgBuilder.append('\n').append(mod);
478+
}
479+
}
480+
val msg = msgBuilder.toString();
472481
if (!SystemUtils.IS_OS_MAC) {
473482
try {
474-
JOptionPane.showMessageDialog(null, msg + "\nThe game will exit when you close this prompt.", "Mod Dependency Download notice", JOptionPane.WARNING_MESSAGE);
483+
JOptionPane.showMessageDialog(null, msg + "\n\nThe game will exit when you close this prompt.", "Mod Dependency Download notice", JOptionPane.WARNING_MESSAGE);
475484
} catch (Exception ignored) {}
476485
}
477-
for (int i = 0; i < 16; i++) {
486+
for (int i = 0; i < 8; i++) {
478487
LOG.warn(msg);
479488
}
480489
SystemExitBypassHelper.exit();
@@ -805,29 +814,52 @@ static ScopeSide current() {
805814
futures.add(CompletableFuture.supplyAsync(task::load, executor));
806815
}
807816
}
808-
val theFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
809-
.thenApply(ignored ->
810-
futures.stream()
811-
.map(it -> it.getNow(null))
812-
.collect(Collectors.toList())
813-
);
814817
AtomicBoolean doViz = new AtomicBoolean(true);
815818
if (theFrame != null) {
816819
final var vizThread = getVizThread(doViz, progresses, theFrame);
817820
vizThread.start();
818821
}
819-
List<URL> res;
822+
List<URL> res = new ArrayList<>();
823+
Error err = null;
820824
try {
821-
res = theFuture.join();
822-
} catch (Error e) {
823-
throw e;
824-
} catch (Throwable t) {
825-
throw new Error(t);
825+
for (val future: futures) {
826+
try {
827+
res.add(future.get());
828+
} catch (Error e) {
829+
if (err != null) {
830+
err.addSuppressed(e);
831+
} else {
832+
err = e;
833+
}
834+
} catch (Throwable t) {
835+
if (err != null) {
836+
err.addSuppressed(t);
837+
} else {
838+
err = new Error(t);
839+
}
840+
}
841+
}
826842
} finally {
827843
if (theFrame != null) {
828844
doViz.set(false);
829845
}
830846
}
847+
if (err != null) {
848+
if (downloadFailed.isEmpty()) {
849+
JOptionPane.showMessageDialog(null, "FP DepLoader has encountered an error while trying to download libraries.\nSee the log for more details.", "Dependency download error", JOptionPane.ERROR_MESSAGE);
850+
} else {
851+
var msgBuilder = new StringBuilder("FP DepLoader has encountered an error while trying to download the following libraries:");
852+
for (val f: downloadFailed) {
853+
msgBuilder.append('\n').append(f);
854+
}
855+
msgBuilder.append("\n\nSee the log for more details.");
856+
JOptionPane.showMessageDialog(null, msgBuilder.toString(), "Dependency download error", JOptionPane.ERROR_MESSAGE);
857+
}
858+
throw err;
859+
}
860+
if (res.isEmpty()) {
861+
return null;
862+
}
831863
return scanDeps(res.stream());
832864
}
833865

@@ -956,9 +988,11 @@ private static class DependencyLoadTask {
956988
}
957989

958990
private IllegalStateException crashCouldNotDownload() {
959-
val errorMessage = "Failed to download library " + groupId + ":" + artifactId + ":" + preferredVersion + (
960-
(suffix != null) ? ":" + suffix : "") + " from any repository! Requested by mod: " + loadingModId;
991+
val lib = groupId + ":" + artifactId + ":" + preferredVersion + (
992+
(suffix != null) ? ":" + suffix : "");
993+
val errorMessage = "Failed to download library " + lib + " from any repository! Requested by mod: " + loadingModId;
961994
LOG.fatal(errorMessage);
995+
downloadFailed.add(lib);
962996
return new IllegalStateException(errorMessage);
963997
}
964998

@@ -1117,6 +1151,7 @@ private void validateDownloadsAllowed() {
11171151
} else {
11181152
if (isMod) {
11191153
detectModReloadRequirement(tmpFile);
1154+
downloadedMods.add(file.getFileName().toString());
11201155
}
11211156
try {
11221157
Files.move(tmpFile, file, StandardCopyOption.ATOMIC_MOVE);

0 commit comments

Comments
 (0)