Use ExceptionListWindow to present errors

This commit is contained in:
comp500 2019-08-11 01:45:39 +01:00
parent ea60175514
commit 465e4973ba
6 changed files with 65 additions and 12 deletions

5
.idea/misc.xml generated
View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="com.google.gson.annotations.SerializedName" />
</list>
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK" /> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK" />
</project> </project>

View File

@ -32,6 +32,7 @@ public class UpdateManager {
private final Options opts; private final Options opts;
public final IUserInterface ui; public final IUserInterface ui;
private boolean cancelled; private boolean cancelled;
private boolean cancelledStartGame = false;
public static class Options { public static class Options {
URI downloadURI = null; URI downloadURI = null;
@ -41,8 +42,10 @@ public class UpdateManager {
public enum Side { public enum Side {
@SerializedName("client") @SerializedName("client")
CLIENT("client"), @SerializedName("server") CLIENT("client"),
SERVER("server"), @SerializedName("both") @SerializedName("server")
SERVER("server"),
@SerializedName("both")
BOTH("both", new Side[] { CLIENT, SERVER }); BOTH("both", new Side[] { CLIENT, SERVER });
private final String sideName; private final String sideName;
@ -176,6 +179,10 @@ public class UpdateManager {
System.out.println("Update cancelled by user!"); System.out.println("Update cancelled by user!");
System.exit(1); System.exit(1);
return; 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 // TODO: update MMC params, java args etc
@ -286,11 +293,30 @@ public class UpdateManager {
}); });
tasks.forEach(f -> f.downloadMetadata(indexFile, indexUri)); 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<IExceptionDetails> failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList()); List<IExceptionDetails> 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<DownloadTask> optionTasks = tasks.stream().filter(t -> t.getException() == null).filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList()); List<DownloadTask> nonFailedFirstTasks = tasks.stream().filter(t -> t.getException() == null).collect(Collectors.toList());
List<DownloadTask> optionTasks = nonFailedFirstTasks.stream().filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList());
// If options changed, present all options again // If options changed, present all options again
if (optionTasks.stream().anyMatch(DownloadTask::isNewOptional)) { if (optionTasks.stream().anyMatch(DownloadTask::isNewOptional)) {
// new ArrayList is requires so it's an IOptionDetails rather than a DownloadTask list // new ArrayList is requires so it's an IOptionDetails rather than a DownloadTask list
@ -321,7 +347,6 @@ public class UpdateManager {
try { try {
task = completionService.take().get(); task = completionService.take().get();
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
// TODO: collect all exceptions, present in one dialog
ui.handleException(e); ui.handleException(e);
task = null; task = null;
} }
@ -337,13 +362,14 @@ public class UpdateManager {
manifest.cachedFiles.putIfAbsent(task.metadata.file, task.cachedFile); manifest.cachedFiles.putIfAbsent(task.metadata.file, task.cachedFile);
} }
} }
// TODO: show errors properly?
String progress; String progress;
if (task != null) { if (task != null) {
if (task.getException() != null) { if (task.getException() != null) {
progress = "Failed to download " + task.metadata.getName() + ": " + task.getException().getMessage(); progress = "Failed to download " + task.metadata.getName() + ": " + task.getException().getMessage();
task.getException().printStackTrace(); task.getException().printStackTrace();
} else { } else {
// TODO: should this be revised for tasks that didn't actually download it?
progress = "Downloaded " + task.metadata.getName(); progress = "Downloaded " + task.metadata.getName();
} }
} else { } else {
@ -351,5 +377,26 @@ public class UpdateManager {
} }
ui.submitProgress(new InstallProgress(progress, i + 1, tasks.size())); ui.submitProgress(new InstallProgress(progress, i + 1, tasks.size()));
} }
List<IExceptionDetails> 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;
}
}
} }
} }

View File

@ -40,7 +40,7 @@ public class CLIHandler implements IUserInterface {
} }
@Override @Override
public Future<IExceptionDetails.ExceptionListResult> showExceptions(List<IExceptionDetails> opts, int numTotal) { public Future<IExceptionDetails.ExceptionListResult> showExceptions(List<IExceptionDetails> opts, int numTotal, boolean allowsIgnore) {
CompletableFuture<IExceptionDetails.ExceptionListResult> future = new CompletableFuture<>(); CompletableFuture<IExceptionDetails.ExceptionListResult> future = new CompletableFuture<>();
future.complete(IExceptionDetails.ExceptionListResult.CANCEL); future.complete(IExceptionDetails.ExceptionListResult.CANCEL);
return future; return future;

View File

@ -23,7 +23,7 @@ class ExceptionListWindow extends JDialog {
/** /**
* Create the dialog. * Create the dialog.
*/ */
ExceptionListWindow(List<IExceptionDetails> eList, CompletableFuture<ExceptionListResult> future, int numTotal, JFrame parentWindow) { ExceptionListWindow(List<IExceptionDetails> eList, CompletableFuture<ExceptionListResult> future, int numTotal, boolean allowsIgnore, JFrame parentWindow) {
super(parentWindow, "Failed file downloads", true); super(parentWindow, "Failed file downloads", true);
setBounds(100, 100, 540, 340); setBounds(100, 100, 540, 340);
@ -110,6 +110,7 @@ class ExceptionListWindow extends JDialog {
} }
{ {
JButton btnIgnoreUpdate = new JButton("Ignore update"); JButton btnIgnoreUpdate = new JButton("Ignore update");
btnIgnoreUpdate.setEnabled(allowsIgnore);
btnIgnoreUpdate.setToolTipText("Start the game without attempting to update"); btnIgnoreUpdate.setToolTipText("Start the game without attempting to update");
btnIgnoreUpdate.addActionListener(e -> { btnIgnoreUpdate.addActionListener(e -> {
future.complete(ExceptionListResult.IGNORE); future.complete(ExceptionListResult.IGNORE);

View File

@ -23,6 +23,6 @@ public interface IUserInterface {
// Return true if the installation was cancelled! // Return true if the installation was cancelled!
Future<Boolean> showOptions(List<IOptionDetails> option); Future<Boolean> showOptions(List<IOptionDetails> option);
Future<IExceptionDetails.ExceptionListResult> showExceptions(List<IExceptionDetails> opts, int numTotal); Future<IExceptionDetails.ExceptionListResult> showExceptions(List<IExceptionDetails> opts, int numTotal, boolean allowsIgnore);
} }

View File

@ -180,10 +180,10 @@ public class InstallWindow implements IUserInterface {
} }
@Override @Override
public Future<IExceptionDetails.ExceptionListResult> showExceptions(List<IExceptionDetails> opts, int numTotal) { public Future<IExceptionDetails.ExceptionListResult> showExceptions(List<IExceptionDetails> opts, int numTotal, boolean allowsIgnore) {
CompletableFuture<IExceptionDetails.ExceptionListResult> future = new CompletableFuture<>(); CompletableFuture<IExceptionDetails.ExceptionListResult> future = new CompletableFuture<>();
EventQueue.invokeLater(() -> { 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.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true); dialog.setVisible(true);
}); });