From d5703a4361c7a80a10ceb4884196725418b1881e Mon Sep 17 00:00:00 2001 From: skycatminepokie <52087591+skycatminepokie@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:12:48 -0800 Subject: [PATCH] CLI advanced options --- .../com/skycatdev/binarysearchtool/CliUi.java | 32 ++++++++++++++++++- .../skycatdev/binarysearchtool/SearchGui.java | 5 +++ .../binarysearchtool/SearchHandler.java | 23 +++++++++---- .../skycatdev/binarysearchtool/SearchUi.java | 2 ++ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/skycatdev/binarysearchtool/CliUi.java b/src/main/java/com/skycatdev/binarysearchtool/CliUi.java index b05aeb5..98953fa 100644 --- a/src/main/java/com/skycatdev/binarysearchtool/CliUi.java +++ b/src/main/java/com/skycatdev/binarysearchtool/CliUi.java @@ -83,7 +83,36 @@ public void failure() { @Override public void initialize(SearchHandler searchHandler) { this.searchHandler = searchHandler; - asyncDisplayOption("", "Ready to start?", MessageType.NONE, new Option[]{new Option("start", this::start)}); + displayStartMenu(); + } + + private void displayStartMenu() { + asyncDisplayOption("", "Ready to start?", MessageType.NONE, new Option[]{new Option("start", this::start), new Option("advanced", this::openAdvancedOptions)}); + } + + private void openAdvancedOptions() { + System.out.println("Advanced options"); + System.out.println("Heh, the only thing we have is force-enabling mods. Type the id of the mod you'd like to force-enable, or \"back\" to go back"); + String id = scanner.nextLine(); + if (id.equals("back")) { + displayStartMenu(); + return; + } + if (getSearchHandler() == null) { + asyncDisplayOption("", "SearchHandler was not initialized when opening advanced options. Please report this.", MessageType.NONE, new Option[]{new Option("OK", () -> System.exit(-1))}); + return; + } + if (getSearchHandler().forceEnable(id)) { + System.out.println("Success!"); + } else { + System.out.println("Could not force enable mod. Either it was already force-enabled, or it does not exist."); + } + openAdvancedOptions(); + } + + @Override + public void sendNextStepInstructions() { + sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). Then respond to the prompt."); } @Override @@ -102,6 +131,7 @@ public void onFinished(ArrayList problematicMods) { System.out.printf("%s (%s)", problematicMod.name(), problematicMod.filename()); } } + System.exit(0); } @Override diff --git a/src/main/java/com/skycatdev/binarysearchtool/SearchGui.java b/src/main/java/com/skycatdev/binarysearchtool/SearchGui.java index bff0929..fe276b7 100644 --- a/src/main/java/com/skycatdev/binarysearchtool/SearchGui.java +++ b/src/main/java/com/skycatdev/binarysearchtool/SearchGui.java @@ -212,6 +212,11 @@ public void sendInstructions(String instructions) { SwingUtilities.invokeLater(() -> instructionsArea.setText(instructions)); } + @Override + public void sendNextStepInstructions() { + sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). If the error is gone, press Success. If it's still there, press Failure."); + } + @Override public void start() { Main.log("Requested start searching"); diff --git a/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java b/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java index 62697de..f17dfa2 100644 --- a/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java +++ b/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java @@ -8,10 +8,7 @@ import java.io.*; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.concurrent.ExecutionException; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -131,6 +128,20 @@ private void addDeps(Mod mod) { } } + /** + * Try to force enable a mod by id. + * @param id The id of the mod to force enable. + * @return {@code false} if the mod was already force enabled or does not exist + */ + public boolean forceEnable(String id) { + Optional optMod = mods.stream().filter((mod) -> mod.mainId().equals(id)).findAny(); + //noinspection OptionalIsPresent + if (optMod.isPresent()) { + return addForceEnabled(optMod.get()); + } + return false; + } + @SuppressWarnings("UnusedReturnValue") public boolean addForceEnabled(Mod mod) { if (forceEnabled.contains(mod)) { @@ -235,7 +246,7 @@ public void bisect(boolean lastSuccessful) { // Enable mods we're using enableAll(testingMods); enableAll(testingDependencies); - ui.sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). If the error is gone, press Success. If it's still there, press Failure."); + ui.sendNextStepInstructions(); ui.onBisectFinished(); Main.log("Bottom of bisect"); } @@ -337,7 +348,7 @@ public ArrayList getMods() { /** * Call after the error has been acknowledged by a button press. */ - private void onFatalError() { + public void onFatalError() { mods.forEach((mod) -> { assert modsPath != null; mod.tryEnable(modsPath); diff --git a/src/main/java/com/skycatdev/binarysearchtool/SearchUi.java b/src/main/java/com/skycatdev/binarysearchtool/SearchUi.java index 6a4dad9..02cf20f 100644 --- a/src/main/java/com/skycatdev/binarysearchtool/SearchUi.java +++ b/src/main/java/com/skycatdev/binarysearchtool/SearchUi.java @@ -31,6 +31,8 @@ public interface SearchUi { void sendInstructions(String instructions); + void sendNextStepInstructions(); + @SuppressWarnings("unused") void start();