diff --git a/.idea/misc.xml b/.idea/misc.xml index 08d187b..d39d11a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,10 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/link/infra/packwiz/installer/UpdateManager.java b/src/main/java/link/infra/packwiz/installer/UpdateManager.java index fcde616..cffb55c 100644 --- a/src/main/java/link/infra/packwiz/installer/UpdateManager.java +++ b/src/main/java/link/infra/packwiz/installer/UpdateManager.java @@ -32,6 +32,7 @@ public class UpdateManager { private final Options opts; public final IUserInterface ui; private boolean cancelled; + private boolean cancelledStartGame = false; public static class Options { URI downloadURI = null; @@ -41,8 +42,10 @@ public class UpdateManager { public enum Side { @SerializedName("client") - CLIENT("client"), @SerializedName("server") - SERVER("server"), @SerializedName("both") + CLIENT("client"), + @SerializedName("server") + SERVER("server"), + @SerializedName("both") BOTH("both", new Side[] { CLIENT, SERVER }); private final String sideName; @@ -176,6 +179,10 @@ public class UpdateManager { System.out.println("Update cancelled by user!"); System.exit(1); return; + } else if (cancelledStartGame) { + System.out.println("Update cancelled by user! Continuing to start game..."); + System.exit(0); + return; } // TODO: update MMC params, java args etc @@ -286,11 +293,30 @@ public class UpdateManager { }); tasks.forEach(f -> f.downloadMetadata(indexFile, indexUri)); - // TODO: collect all exceptions, present in one dialog - // TODO: quit if there are exceptions or just remove failed tasks before presenting options List failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList()); + if (failedTasks.size() > 0) { + IExceptionDetails.ExceptionListResult exceptionListResult; + try { + exceptionListResult = ui.showExceptions(failedTasks, tasks.size(), true).get(); + } catch (InterruptedException | ExecutionException e) { + // Interrupted means cancelled??? + ui.handleExceptionAndExit(e); + return; + } + switch (exceptionListResult) { + case CONTINUE: + break; + case CANCEL: + cancelled = true; + return; + case IGNORE: + cancelledStartGame = true; + return; + } + } - List optionTasks = tasks.stream().filter(t -> t.getException() == null).filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList()); + List nonFailedFirstTasks = tasks.stream().filter(t -> t.getException() == null).collect(Collectors.toList()); + List optionTasks = nonFailedFirstTasks.stream().filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList()); // If options changed, present all options again if (optionTasks.stream().anyMatch(DownloadTask::isNewOptional)) { // new ArrayList is requires so it's an IOptionDetails rather than a DownloadTask list @@ -321,7 +347,6 @@ public class UpdateManager { try { task = completionService.take().get(); } catch (InterruptedException | ExecutionException e) { - // TODO: collect all exceptions, present in one dialog ui.handleException(e); task = null; } @@ -337,13 +362,14 @@ public class UpdateManager { manifest.cachedFiles.putIfAbsent(task.metadata.file, task.cachedFile); } } - // TODO: show errors properly? + String progress; if (task != null) { if (task.getException() != null) { progress = "Failed to download " + task.metadata.getName() + ": " + task.getException().getMessage(); task.getException().printStackTrace(); } else { + // TODO: should this be revised for tasks that didn't actually download it? progress = "Downloaded " + task.metadata.getName(); } } else { @@ -351,5 +377,26 @@ public class UpdateManager { } ui.submitProgress(new InstallProgress(progress, i + 1, tasks.size())); } + + List failedTasks2ElectricBoogaloo = nonFailedFirstTasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList()); + if (failedTasks2ElectricBoogaloo.size() > 0) { + IExceptionDetails.ExceptionListResult exceptionListResult; + try { + exceptionListResult = ui.showExceptions(failedTasks2ElectricBoogaloo, tasks.size(), false).get(); + } catch (InterruptedException | ExecutionException e) { + // Interrupted means cancelled??? + ui.handleExceptionAndExit(e); + return; + } + switch (exceptionListResult) { + case CONTINUE: + break; + case CANCEL: + cancelled = true; + return; + case IGNORE: + cancelledStartGame = true; + } + } } } diff --git a/src/main/java/link/infra/packwiz/installer/ui/CLIHandler.java b/src/main/java/link/infra/packwiz/installer/ui/CLIHandler.java index 6954da3..72f4195 100644 --- a/src/main/java/link/infra/packwiz/installer/ui/CLIHandler.java +++ b/src/main/java/link/infra/packwiz/installer/ui/CLIHandler.java @@ -40,7 +40,7 @@ public class CLIHandler implements IUserInterface { } @Override - public Future showExceptions(List opts, int numTotal) { + public Future showExceptions(List opts, int numTotal, boolean allowsIgnore) { CompletableFuture future = new CompletableFuture<>(); future.complete(IExceptionDetails.ExceptionListResult.CANCEL); return future; diff --git a/src/main/java/link/infra/packwiz/installer/ui/ExceptionListWindow.java b/src/main/java/link/infra/packwiz/installer/ui/ExceptionListWindow.java index 16e7927..126e5a1 100644 --- a/src/main/java/link/infra/packwiz/installer/ui/ExceptionListWindow.java +++ b/src/main/java/link/infra/packwiz/installer/ui/ExceptionListWindow.java @@ -23,7 +23,7 @@ class ExceptionListWindow extends JDialog { /** * Create the dialog. */ - ExceptionListWindow(List eList, CompletableFuture future, int numTotal, JFrame parentWindow) { + ExceptionListWindow(List eList, CompletableFuture future, int numTotal, boolean allowsIgnore, JFrame parentWindow) { super(parentWindow, "Failed file downloads", true); setBounds(100, 100, 540, 340); @@ -110,6 +110,7 @@ class ExceptionListWindow extends JDialog { } { JButton btnIgnoreUpdate = new JButton("Ignore update"); + btnIgnoreUpdate.setEnabled(allowsIgnore); btnIgnoreUpdate.setToolTipText("Start the game without attempting to update"); btnIgnoreUpdate.addActionListener(e -> { future.complete(ExceptionListResult.IGNORE); diff --git a/src/main/java/link/infra/packwiz/installer/ui/IUserInterface.java b/src/main/java/link/infra/packwiz/installer/ui/IUserInterface.java index ae09b6a..b933380 100644 --- a/src/main/java/link/infra/packwiz/installer/ui/IUserInterface.java +++ b/src/main/java/link/infra/packwiz/installer/ui/IUserInterface.java @@ -23,6 +23,6 @@ public interface IUserInterface { // Return true if the installation was cancelled! Future showOptions(List option); - Future showExceptions(List opts, int numTotal); + Future showExceptions(List opts, int numTotal, boolean allowsIgnore); } diff --git a/src/main/java/link/infra/packwiz/installer/ui/InstallWindow.java b/src/main/java/link/infra/packwiz/installer/ui/InstallWindow.java index 903cd68..f7fcfb1 100644 --- a/src/main/java/link/infra/packwiz/installer/ui/InstallWindow.java +++ b/src/main/java/link/infra/packwiz/installer/ui/InstallWindow.java @@ -180,10 +180,10 @@ public class InstallWindow implements IUserInterface { } @Override - public Future showExceptions(List opts, int numTotal) { + public Future showExceptions(List opts, int numTotal, boolean allowsIgnore) { CompletableFuture future = new CompletableFuture<>(); EventQueue.invokeLater(() -> { - ExceptionListWindow dialog = new ExceptionListWindow(opts, future, numTotal, frmPackwizlauncher); + ExceptionListWindow dialog = new ExceptionListWindow(opts, future, numTotal, allowsIgnore, frmPackwizlauncher); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setVisible(true); });