mirror of
https://github.com/packwiz/packwiz-installer.git
synced 2025-04-19 21:16:30 +02:00
Add cancellation from options list
This commit is contained in:
parent
a9bd83e96b
commit
4d8e695fc4
@ -13,7 +13,6 @@ 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.IOptionDetails;
|
|
||||||
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;
|
||||||
@ -31,6 +30,7 @@ public class UpdateManager {
|
|||||||
|
|
||||||
public final Options opts;
|
public final Options opts;
|
||||||
public final IUserInterface ui;
|
public final IUserInterface ui;
|
||||||
|
private boolean cancelled;
|
||||||
|
|
||||||
public static class Options {
|
public static class Options {
|
||||||
public URI downloadURI = null;
|
public URI downloadURI = null;
|
||||||
@ -155,7 +155,7 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manifest.packFileHash != null && packFileSource.hashIsEqual(manifest.packFileHash) && invalidatedUris.size() == 0) {
|
if (manifest.packFileHash != null && packFileSource.hashIsEqual(manifest.packFileHash) && invalidatedUris.isEmpty()) {
|
||||||
System.out.println("Modpack is already up to date!");
|
System.out.println("Modpack is already up to date!");
|
||||||
// todo: --force?
|
// todo: --force?
|
||||||
return;
|
return;
|
||||||
@ -171,6 +171,10 @@ public class UpdateManager {
|
|||||||
ui.handleExceptionAndExit(e1);
|
ui.handleExceptionAndExit(e1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: update MMC params, java args etc
|
// TODO: update MMC params, java args etc
|
||||||
|
|
||||||
manifest.packFileHash = packFileSource.getHash();
|
manifest.packFileHash = packFileSource.getHash();
|
||||||
@ -189,7 +193,7 @@ public class UpdateManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void processIndex(URI indexUri, Hash indexHash, String hashFormat, ManifestFile manifest, List<URI> invalidatedUris) {
|
protected void processIndex(URI indexUri, Hash indexHash, String hashFormat, ManifestFile manifest, List<URI> invalidatedUris) {
|
||||||
if (manifest.indexFileHash != null && manifest.indexFileHash.equals(indexHash) && invalidatedUris.size() == 0) {
|
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;
|
||||||
}
|
}
|
||||||
@ -283,10 +287,21 @@ public class UpdateManager {
|
|||||||
// 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<DownloadTask> 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());
|
||||||
// If options changed, present all options again
|
// If options changed, present all options again
|
||||||
if (tasks.stream().filter(DownloadTask::correctSide).anyMatch(DownloadTask::isNewOptional)) {
|
if (optionTasks.stream().anyMatch(DownloadTask::isNewOptional)) {
|
||||||
List<IOptionDetails> opts = tasks.stream().filter(DownloadTask::correctSide).filter(DownloadTask::isOptional).collect(Collectors.toList());
|
// new ArrayList is requires so it's an IOptionDetails rather than a DownloadTask list
|
||||||
ui.showOptions(opts);
|
Future<Boolean> cancelledResult = ui.showOptions(new ArrayList<>(optionTasks));
|
||||||
|
try {
|
||||||
|
if (cancelledResult.get()) {
|
||||||
|
cancelled = true;
|
||||||
|
// TODO: Should the UI be closed somehow??
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
|
// Interrupted means cancelled???
|
||||||
|
ui.handleExceptionAndExit(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: different thread pool type?
|
// TODO: different thread pool type?
|
||||||
@ -299,26 +314,26 @@ public class UpdateManager {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
for (int i = 0; i < tasks.size(); i++) {
|
for (int i = 0; i < tasks.size(); i++) {
|
||||||
DownloadTask ret;
|
DownloadTask task;
|
||||||
try {
|
try {
|
||||||
ret = completionService.take().get();
|
task = completionService.take().get();
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
} catch (InterruptedException | ExecutionException e) {
|
||||||
// TODO: collect all exceptions, present in one dialog
|
// TODO: collect all exceptions, present in one dialog
|
||||||
ui.handleException(e);
|
ui.handleException(e);
|
||||||
ret = null;
|
task = null;
|
||||||
}
|
}
|
||||||
// Update manifest - If there were no errors cachedFile has already been modified in place (good old pass by reference)
|
// Update manifest - If there were no errors cachedFile has already been modified in place (good old pass by reference)
|
||||||
if (ret != null && ret.getException() != null) {
|
if (task != null && task.getException() != null) {
|
||||||
manifest.cachedFiles.put(ret.metadata.file, ret.cachedFile.getRevert());
|
manifest.cachedFiles.put(task.metadata.file, task.cachedFile.getRevert());
|
||||||
}
|
}
|
||||||
// TODO: show errors properly?
|
// TODO: show errors properly?
|
||||||
String progress;
|
String progress;
|
||||||
if (ret != null) {
|
if (task != null) {
|
||||||
if (ret.getException() != null) {
|
if (task.getException() != null) {
|
||||||
progress = "Failed to download " + ret.metadata.getName() + ": " + ret.getException().getMessage();
|
progress = "Failed to download " + task.metadata.getName() + ": " + task.getException().getMessage();
|
||||||
ret.getException().printStackTrace();
|
task.getException().printStackTrace();
|
||||||
} else {
|
} else {
|
||||||
progress = "Downloaded " + ret.metadata.getName();
|
progress = "Downloaded " + task.metadata.getName();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
progress = "Failed to download, unknown reason";
|
progress = "Failed to download, unknown reason";
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package link.infra.packwiz.installer.ui;
|
package link.infra.packwiz.installer.ui;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public class CLIHandler implements IUserInterface {
|
public class CLIHandler implements IUserInterface {
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class CLIHandler implements IUserInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showOptions(List<IOptionDetails> option) {
|
public Future<Boolean> showOptions(List<IOptionDetails> option) {
|
||||||
throw new RuntimeException("Optional mods not implemented for CLI! Make sure your optional mods are only on the client side!");
|
throw new RuntimeException("Optional mods not implemented for CLI! Make sure your optional mods are only on the client side!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package link.infra.packwiz.installer.ui;
|
package link.infra.packwiz.installer.ui;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
public interface IUserInterface {
|
public interface IUserInterface {
|
||||||
|
|
||||||
@ -22,6 +23,6 @@ public interface IUserInterface {
|
|||||||
|
|
||||||
void executeManager(Runnable task);
|
void executeManager(Runnable task);
|
||||||
|
|
||||||
void showOptions(List<IOptionDetails> option);
|
Future<Boolean> showOptions(List<IOptionDetails> option);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import javax.swing.*;
|
|||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class InstallWindow implements IUserInterface {
|
public class InstallWindow implements IUserInterface {
|
||||||
@ -160,8 +161,8 @@ public class InstallWindow implements IUserInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showOptions(List<IOptionDetails> option) {
|
public Future<Boolean> showOptions(List<IOptionDetails> option) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user