Skip to content

Commit

Permalink
CLI advanced options
Browse files Browse the repository at this point in the history
  • Loading branch information
skycatminepokie committed Dec 20, 2024
1 parent 1f82da3 commit d5703a4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 7 deletions.
32 changes: 31 additions & 1 deletion src/main/java/com/skycatdev/binarysearchtool/CliUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -102,6 +131,7 @@ public void onFinished(ArrayList<Mod> problematicMods) {
System.out.printf("%s (%s)", problematicMod.name(), problematicMod.filename());
}
}
System.exit(0);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/skycatdev/binarysearchtool/SearchGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
23 changes: 17 additions & 6 deletions src/main/java/com/skycatdev/binarysearchtool/SearchHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Mod> 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)) {
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -337,7 +348,7 @@ public ArrayList<Mod> 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);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/skycatdev/binarysearchtool/SearchUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public interface SearchUi {

void sendInstructions(String instructions);

void sendNextStepInstructions();

@SuppressWarnings("unused")
void start();

Expand Down

0 comments on commit d5703a4

Please sign in to comment.