From cddca70b03754bb5c0dea20361f69c8d7366aab2 Mon Sep 17 00:00:00 2001 From: skycatminepokie <52087591+skycatminepokie@users.noreply.github.com> Date: Fri, 20 Dec 2024 19:55:01 -0800 Subject: [PATCH] Fix CLI, but for real this time I think Closes #12 --- .../com/skycatdev/binarysearchtool/CliUi.java | 67 ++++++++++--------- .../binarysearchtool/SearchHandler.java | 10 +-- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/skycatdev/binarysearchtool/CliUi.java b/src/main/java/com/skycatdev/binarysearchtool/CliUi.java index 173f7ea..858c3d5 100644 --- a/src/main/java/com/skycatdev/binarysearchtool/CliUi.java +++ b/src/main/java/com/skycatdev/binarysearchtool/CliUi.java @@ -4,8 +4,9 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Queue; import java.util.Scanner; -import java.util.Stack; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; @@ -94,38 +95,6 @@ public void onBisectFinished() { showBisectMenu(); } - private void showBisectMenu() { - asyncDisplayOption("", "Is the problem fixed?", MessageType.NONE, new Option[]{ - new Option("Yes", this::success), - new Option("No", this::failure), - new Option("List", () -> { - showLists(); - showBisectMenu(); - }) - }); - } - - private void showLists() { - if (getSearchHandler() == null) { - asyncDisplayOption("", "SearchHandler was null when trying to display lists. Please report this.", MessageType.ERROR, new Option[]{new Option("OK", null)}); - return; - } - System.out.println("Might be the problem:"); - for (Mod mod : getSearchHandler().getCandidateMods()){ - System.out.println(mod.name()); - } - System.out.println(); - System.out.println("Not the problem:"); - for (Mod mod: getSearchHandler().getWorkingMods()) { - System.out.println(mod.name()); - } - System.out.println(); - System.out.println("Mods we're testing now:"); - for (Mod mod : getSearchHandler().getTestingMods()) { - System.out.println(mod.name()); - } - } - @Override public void onFinished(ArrayList problematicMods) { assert searchHandler != null : "searchHandler should be the one calling, why is it null?"; @@ -170,6 +139,38 @@ public void sendNextStepInstructions() { sendInstructions("Next step is ready! Launch Minecraft, test (or crash), then close it (or crash). Then respond to the prompt."); } + private void showBisectMenu() { + asyncDisplayOption("", "Is the problem fixed?", MessageType.NONE, new Option[]{ + new Option("Yes", this::success), + new Option("No", this::failure), + new Option("List", () -> { + showLists(); + showBisectMenu(); + }) + }); + } + + private void showLists() { + if (getSearchHandler() == null) { + asyncDisplayOption("", "SearchHandler was null when trying to display lists. Please report this.", MessageType.ERROR, new Option[]{new Option("OK", null)}); + return; + } + System.out.println("Might be the problem:"); + for (Mod mod : getSearchHandler().getCandidateMods()) { + System.out.println(mod.name()); + } + System.out.println(); + System.out.println("Not the problem:"); + for (Mod mod : getSearchHandler().getWorkingMods()) { + System.out.println(mod.name()); + } + System.out.println(); + System.out.println("Mods we're testing now:"); + for (Mod mod : getSearchHandler().getTestingMods()) { + System.out.println(mod.name()); + } + } + @Override public void start() { System.out.println("Starting, please wait..."); diff --git a/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java b/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java index bf3db7e..a1d5766 100644 --- a/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java +++ b/src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java @@ -189,11 +189,11 @@ public void bisect(boolean lastSuccessful) { // Ready for next step if (candidateMods.size() == 1) { iterations++; + enableAll(mods); finished = true; ui.updateLists(candidateMods, workingMods); ui.updateProgress(iterations, maxIterations); ui.onFinished(candidateMods); - enableAll(mods); return; } else { if (candidateMods.isEmpty()) { @@ -259,11 +259,11 @@ private void disableAll(ArrayList mods) { private void disableMod(Mod mod) { assert modsPath != null; - if (!mod.tryDisable(modsPath)) { + while (!mod.tryDisable(modsPath)) { try { ui.asyncDisplayOption("Disable failed", "Couldn't disable \"%s\". Make sure Minecraft is closed.".formatted(mod.name()), MessageType.WARNING, new Option[]{ new Option("Abort", this::onFatalError), - new Option("Try again", () -> disableMod(mod)) + new Option("Try again", null) }).get(); } catch (ExecutionException | InterruptedException e) { ui.asyncDisplayOption("Uh-oh", "Failed to disable gracefully", MessageType.ERROR, new Option[]{new Option("OK, cya", this::onFatalError)}); @@ -329,11 +329,11 @@ private void enableAll(ArrayList mods) { private void enableMod(Mod mod) { assert modsPath != null; - if (!mod.tryEnable(modsPath)) { + while (!mod.tryEnable(modsPath)) { try { ui.asyncDisplayOption("Enable failed", "Couldn't enable \"%s\". Make sure Minecraft is closed.".formatted(mod.name()), MessageType.WARNING, new Option[]{ new Option("Abort", this::onFatalError), - new Option("Try again", () -> enableMod(mod)) + new Option("Try again", null) }).get(); } catch (ExecutionException | InterruptedException e) { ui.asyncDisplayOption("Uh-oh", "Failed to enable gracefully", MessageType.ERROR, new Option[]{new Option("OK, cya", this::onFatalError)});