mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 21:16:30 +02:00
Use ExceptionListWindow to present errors
This commit is contained in:
parent
ea60175514
commit
465e4973ba
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -1,5 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK" />
|
||||
</project>
|
@ -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<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 (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<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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class CLIHandler implements IUserInterface {
|
||||
}
|
||||
|
||||
@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<>();
|
||||
future.complete(IExceptionDetails.ExceptionListResult.CANCEL);
|
||||
return future;
|
||||
|
@ -23,7 +23,7 @@ class ExceptionListWindow extends JDialog {
|
||||
/**
|
||||
* 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);
|
||||
|
||||
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);
|
||||
|
@ -23,6 +23,6 @@ public interface IUserInterface {
|
||||
// Return true if the installation was cancelled!
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -180,10 +180,10 @@ public class InstallWindow implements IUserInterface {
|
||||
}
|
||||
|
||||
@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<>();
|
||||
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);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user