mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 13:06:30 +02:00
Make handleExceptionAndExit better, fix some stuff
This commit is contained in:
parent
78f5d76fe9
commit
ea60175514
@ -5,6 +5,7 @@ import link.infra.packwiz.installer.metadata.ManifestFile;
|
|||||||
import link.infra.packwiz.installer.metadata.hash.GeneralHashingSource;
|
import link.infra.packwiz.installer.metadata.hash.GeneralHashingSource;
|
||||||
import link.infra.packwiz.installer.metadata.hash.Hash;
|
import link.infra.packwiz.installer.metadata.hash.Hash;
|
||||||
import link.infra.packwiz.installer.metadata.hash.HashUtils;
|
import link.infra.packwiz.installer.metadata.hash.HashUtils;
|
||||||
|
import link.infra.packwiz.installer.ui.IExceptionDetails;
|
||||||
import link.infra.packwiz.installer.ui.IOptionDetails;
|
import link.infra.packwiz.installer.ui.IOptionDetails;
|
||||||
import okio.Buffer;
|
import okio.Buffer;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
@ -19,7 +20,7 @@ import java.nio.file.StandardCopyOption;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
class DownloadTask implements IOptionDetails {
|
class DownloadTask implements IOptionDetails, IExceptionDetails {
|
||||||
final IndexFile.File metadata;
|
final IndexFile.File metadata;
|
||||||
ManifestFile.File cachedFile = null;
|
ManifestFile.File cachedFile = null;
|
||||||
private Exception failure = null;
|
private Exception failure = null;
|
||||||
@ -30,7 +31,7 @@ class DownloadTask implements IOptionDetails {
|
|||||||
private boolean newOptional = true;
|
private boolean newOptional = true;
|
||||||
private final UpdateManager.Options.Side downloadSide;
|
private final UpdateManager.Options.Side downloadSide;
|
||||||
|
|
||||||
public DownloadTask(IndexFile.File metadata, String defaultFormat, UpdateManager.Options.Side downloadSide) {
|
private DownloadTask(IndexFile.File metadata, String defaultFormat, UpdateManager.Options.Side downloadSide) {
|
||||||
this.metadata = metadata;
|
this.metadata = metadata;
|
||||||
if (metadata.hashFormat == null || metadata.hashFormat.length() == 0) {
|
if (metadata.hashFormat == null || metadata.hashFormat.length() == 0) {
|
||||||
metadata.hashFormat = defaultFormat;
|
metadata.hashFormat = defaultFormat;
|
||||||
@ -38,12 +39,12 @@ class DownloadTask implements IOptionDetails {
|
|||||||
this.downloadSide = downloadSide;
|
this.downloadSide = downloadSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalidate() {
|
void invalidate() {
|
||||||
invalidated = true;
|
invalidated = true;
|
||||||
alreadyUpToDate = false;
|
alreadyUpToDate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateFromCache(ManifestFile.File cachedFile) {
|
void updateFromCache(ManifestFile.File cachedFile) {
|
||||||
if (failure != null) return;
|
if (failure != null) return;
|
||||||
if (cachedFile == null) {
|
if (cachedFile == null) {
|
||||||
this.cachedFile = new ManifestFile.File();
|
this.cachedFile = new ManifestFile.File();
|
||||||
@ -53,7 +54,7 @@ class DownloadTask implements IOptionDetails {
|
|||||||
this.cachedFile = cachedFile;
|
this.cachedFile = cachedFile;
|
||||||
|
|
||||||
if (!invalidated) {
|
if (!invalidated) {
|
||||||
Hash currHash = null;
|
Hash currHash;
|
||||||
try {
|
try {
|
||||||
currHash = HashUtils.getHash(metadata.hashFormat, metadata.hash);
|
currHash = HashUtils.getHash(metadata.hashFormat, metadata.hash);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -73,7 +74,7 @@ class DownloadTask implements IOptionDetails {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void downloadMetadata(IndexFile parentIndexFile, URI indexUri) {
|
void downloadMetadata(IndexFile parentIndexFile, URI indexUri) {
|
||||||
if (failure != null) return;
|
if (failure != null) return;
|
||||||
if (metadataRequired) {
|
if (metadataRequired) {
|
||||||
try {
|
try {
|
||||||
@ -100,7 +101,7 @@ class DownloadTask implements IOptionDetails {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void download(String packFolder, URI indexUri) {
|
void download(String packFolder, URI indexUri) {
|
||||||
if (failure != null) return;
|
if (failure != null) return;
|
||||||
|
|
||||||
// Ensure it is removed
|
// Ensure it is removed
|
||||||
@ -188,18 +189,18 @@ class DownloadTask implements IOptionDetails {
|
|||||||
return failure;
|
return failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isOptional() {
|
boolean isOptional() {
|
||||||
if (metadata.linkedFile != null) {
|
if (metadata.linkedFile != null) {
|
||||||
return metadata.linkedFile.isOptional();
|
return metadata.linkedFile.isOptional();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewOptional() {
|
boolean isNewOptional() {
|
||||||
return isOptional() && this.newOptional;
|
return isOptional() && this.newOptional;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean correctSide() {
|
boolean correctSide() {
|
||||||
if (metadata.linkedFile != null) {
|
if (metadata.linkedFile != null) {
|
||||||
return metadata.linkedFile.side.hasSide(downloadSide);
|
return metadata.linkedFile.side.hasSide(downloadSide);
|
||||||
}
|
}
|
||||||
@ -231,7 +232,7 @@ class DownloadTask implements IOptionDetails {
|
|||||||
cachedFile.optionValue = value;
|
cachedFile.optionValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<DownloadTask> createTasksFromIndex(IndexFile index, String defaultFormat, UpdateManager.Options.Side downloadSide) {
|
static List<DownloadTask> createTasksFromIndex(IndexFile index, String defaultFormat, UpdateManager.Options.Side downloadSide) {
|
||||||
ArrayList<DownloadTask> tasks = new ArrayList<>();
|
ArrayList<DownloadTask> tasks = new ArrayList<>();
|
||||||
for (IndexFile.File file : index.files) {
|
for (IndexFile.File file : index.files) {
|
||||||
tasks.add(new DownloadTask(file, defaultFormat, downloadSide));
|
tasks.add(new DownloadTask(file, defaultFormat, downloadSide));
|
||||||
|
@ -13,6 +13,7 @@ import link.infra.packwiz.installer.metadata.hash.GeneralHashingSource;
|
|||||||
import link.infra.packwiz.installer.metadata.hash.Hash;
|
import link.infra.packwiz.installer.metadata.hash.Hash;
|
||||||
import link.infra.packwiz.installer.metadata.hash.HashUtils;
|
import link.infra.packwiz.installer.metadata.hash.HashUtils;
|
||||||
import link.infra.packwiz.installer.request.HandlerManager;
|
import link.infra.packwiz.installer.request.HandlerManager;
|
||||||
|
import link.infra.packwiz.installer.ui.IExceptionDetails;
|
||||||
import link.infra.packwiz.installer.ui.IUserInterface;
|
import link.infra.packwiz.installer.ui.IUserInterface;
|
||||||
import link.infra.packwiz.installer.ui.InstallProgress;
|
import link.infra.packwiz.installer.ui.InstallProgress;
|
||||||
import okio.Okio;
|
import okio.Okio;
|
||||||
@ -28,15 +29,15 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
public class UpdateManager {
|
public class UpdateManager {
|
||||||
|
|
||||||
public final Options opts;
|
private final Options opts;
|
||||||
public final IUserInterface ui;
|
public final IUserInterface ui;
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
|
|
||||||
public static class Options {
|
public static class Options {
|
||||||
public URI downloadURI = null;
|
URI downloadURI = null;
|
||||||
public String manifestFile = "packwiz.json"; // TODO: make configurable
|
String manifestFile = "packwiz.json"; // TODO: make configurable
|
||||||
public String packFolder = ".";
|
String packFolder = ".";
|
||||||
public Side side = Side.CLIENT;
|
Side side = Side.CLIENT;
|
||||||
|
|
||||||
public enum Side {
|
public enum Side {
|
||||||
@SerializedName("client")
|
@SerializedName("client")
|
||||||
@ -88,13 +89,13 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateManager(Options opts, IUserInterface ui) {
|
UpdateManager(Options opts, IUserInterface ui) {
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
this.ui = ui;
|
this.ui = ui;
|
||||||
this.start();
|
this.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void start() {
|
private void start() {
|
||||||
this.checkOptions();
|
this.checkOptions();
|
||||||
|
|
||||||
ui.submitProgress(new InstallProgress("Loading manifest file..."));
|
ui.submitProgress(new InstallProgress("Loading manifest file..."));
|
||||||
@ -190,11 +191,11 @@ public class UpdateManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void checkOptions() {
|
private void checkOptions() {
|
||||||
// TODO: implement
|
// TODO: implement
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processIndex(URI indexUri, Hash indexHash, String hashFormat, ManifestFile manifest, List<URI> invalidatedUris) {
|
private void processIndex(URI indexUri, Hash indexHash, String hashFormat, ManifestFile manifest, List<URI> invalidatedUris) {
|
||||||
if (manifest.indexFileHash != null && manifest.indexFileHash.equals(indexHash) && invalidatedUris.isEmpty()) {
|
if (manifest.indexFileHash != null && manifest.indexFileHash.equals(indexHash) && invalidatedUris.isEmpty()) {
|
||||||
System.out.println("Modpack files are already up to date!");
|
System.out.println("Modpack files are already up to date!");
|
||||||
return;
|
return;
|
||||||
@ -287,7 +288,7 @@ public class UpdateManager {
|
|||||||
|
|
||||||
// TODO: collect all exceptions, present in one dialog
|
// TODO: collect all exceptions, present in one dialog
|
||||||
// TODO: quit if there are exceptions or just remove failed tasks before presenting options
|
// TODO: quit if there are exceptions or just remove failed tasks before presenting options
|
||||||
List<DownloadTask> failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList());
|
List<IExceptionDetails> failedTasks = tasks.stream().filter(t -> t.getException() != null).collect(Collectors.toList());
|
||||||
|
|
||||||
List<DownloadTask> optionTasks = tasks.stream().filter(t -> t.getException() == null).filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList());
|
List<DownloadTask> optionTasks = tasks.stream().filter(t -> t.getException() == null).filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList());
|
||||||
// If options changed, present all options again
|
// If options changed, present all options again
|
||||||
|
@ -9,9 +9,6 @@ public interface IUserInterface {
|
|||||||
|
|
||||||
void handleException(Exception e);
|
void handleException(Exception e);
|
||||||
|
|
||||||
/**
|
|
||||||
* This might not exit straight away, return after calling this!
|
|
||||||
*/
|
|
||||||
default void handleExceptionAndExit(Exception e) {
|
default void handleExceptionAndExit(Exception e) {
|
||||||
handleException(e);
|
handleException(e);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
|
@ -101,6 +101,12 @@ public class InstallWindow implements IUserInterface {
|
|||||||
JOptionPane.showMessageDialog(null, "A fatal error occurred: \n" + e.getClass().getCanonicalName() + ": " + e.getMessage(), title, JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "A fatal error occurred: \n" + e.getClass().getCanonicalName() + ": " + e.getMessage(), title, JOptionPane.ERROR_MESSAGE);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
});
|
});
|
||||||
|
// Pause forever, so it blocks while we wait for System.exit to take effect
|
||||||
|
try {
|
||||||
|
Thread.currentThread().join();
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
// no u
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user