From 64de20a3e6a27173d6dea8ede91d0b345da9b943 Mon Sep 17 00:00:00 2001 From: Konloch Date: Wed, 2 Oct 2024 08:54:53 -0600 Subject: [PATCH] English Command Replaced With Language Command You can now use `-language ger` or `-language de` to select languages --- .../bytecodeviewer/cli/BCVCommandLine.java | 28 ++++- .../club/bytecodeviewer/cli/CLICommand.java | 2 + .../cli/actions/commands/EnglishCommand.java | 28 ----- .../cli/actions/commands/HelpCommand.java | 1 + .../cli/actions/commands/LanguageCommand.java | 112 ++++++++++++++++++ 5 files changed, 139 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/EnglishCommand.java create mode 100644 src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/LanguageCommand.java diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/BCVCommandLine.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/BCVCommandLine.java index a60c532c..04538590 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/cli/BCVCommandLine.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/BCVCommandLine.java @@ -2,7 +2,7 @@ package the.bytecode.club.bytecodeviewer.cli; import org.apache.commons.cli.*; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.cli.actions.commands.HelpCommand; +import the.bytecode.club.bytecodeviewer.cli.actions.commands.*; import the.bytecode.club.bytecodeviewer.util.SleepUtil; import java.io.File; @@ -27,15 +27,19 @@ public class BCVCommandLine OPTIONS.addOption("t", true, "sets the target class to decompile, append all to decomp all as zip."); OPTIONS.addOption("nowait", true, "won't wait the 5 seconds to allow the user to read the CLI."); + COMMANDS.add(new CleanCommand()); + COMMANDS.add(new CleanBootCommand()); + COMMANDS.add(new DecompilerCommand()); + COMMANDS.add(new LanguageCommand()); COMMANDS.add(new HelpCommand()); + COMMANDS.add(new ListCommand()); for(CLICommand command : COMMANDS) OPTIONS.addOption(command.name, command.hasArgs, command.description); isCLI = containsCLICommand(args); - if(isCLI) - parseCommandLine(args); + parseCommandLine(args); } private boolean containsCLICommand(String[] args) @@ -65,19 +69,25 @@ public class BCVCommandLine { CommandLine cmd = PARSER.parse(OPTIONS, args); + if(cmd.hasOption("language")) + System.out.println("OK: " + cmd.getOptionValue("language")); + //TODO this is a backwards way of searching and will cause collisions // I'm sure the Apache CLI has a better way of navigating this for(CLICommand command : COMMANDS) { + System.out.println("OK: " + command.name); if(cmd.hasOption(command.name)) { + System.out.println("ON: " + command.name); command.runCommand(cmd); return; } } - handleCLIDecompilation(cmd); + if(isCLI) + handleCLIDecompilation(cmd); } catch (Exception e) { @@ -144,6 +154,16 @@ public class BCVCommandLine //TODO decompiling happens here } + public CLICommand getCommand(String name) + { + for(CLICommand command : COMMANDS) + if(command.name.equals(name) + || command.nameFormatted.equals(name)) + return command; + + return null; + } + public boolean isCLI() { return isCLI; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/CLICommand.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CLICommand.java index 7fd9bb55..86c51fe7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/cli/CLICommand.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/CLICommand.java @@ -10,6 +10,7 @@ public abstract class CLICommand { public final String name; + public final String nameFormatted; public final String description; public final boolean hasArgs; public final boolean isCLI; @@ -17,6 +18,7 @@ public abstract class CLICommand protected CLICommand(String name, String description, boolean hasArgs, boolean isCLI) { this.name = name; + this.nameFormatted = "-" + name; this.description = description; this.hasArgs = hasArgs; this.isCLI = isCLI; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/EnglishCommand.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/EnglishCommand.java deleted file mode 100644 index a609a387..00000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/EnglishCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package the.bytecode.club.bytecodeviewer.cli.actions.commands; - -import org.apache.commons.cli.CommandLine; -import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.Constants; -import the.bytecode.club.bytecodeviewer.cli.CLICommand; -import the.bytecode.club.bytecodeviewer.translation.Language; - -import java.io.File; - -/** - * @author Konloch - * @since 10/2/2024 - */ -public class EnglishCommand extends CLICommand -{ - - public EnglishCommand() - { - super("english", "Forces English language translations and continues to boot into the GUI", false, false); - } - - @Override - public void runCommand(CommandLine cmd) - { - Configuration.language = Language.ENGLISH; - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/HelpCommand.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/HelpCommand.java index d7af4f2e..1b25c575 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/HelpCommand.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/HelpCommand.java @@ -28,6 +28,7 @@ public class HelpCommand extends CLICommand "-o Selects the output file", "-t Must either be the fully qualified classname or \"all\" to decompile all as zip", "-nowait Doesn't wait for the user to read the CLI messages", + "==BCV GUI Commands==", "-cleanboot Deletes the BCV directory and continues to boot into the GUI", "-english Forces English language translations" diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/LanguageCommand.java b/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/LanguageCommand.java new file mode 100644 index 00000000..e4d3603d --- /dev/null +++ b/src/main/java/the/bytecode/club/bytecodeviewer/cli/actions/commands/LanguageCommand.java @@ -0,0 +1,112 @@ +package the.bytecode.club.bytecodeviewer.cli.actions.commands; + +import org.apache.commons.cli.CommandLine; +import the.bytecode.club.bytecodeviewer.Configuration; +import the.bytecode.club.bytecodeviewer.cli.CLICommand; +import the.bytecode.club.bytecodeviewer.translation.Language; + +/** + * @author Konloch + * @since 10/2/2024 + */ +public class LanguageCommand extends CLICommand +{ + + public LanguageCommand() + { + super("language", "Forces specific language translations and continues to boot into the GUI", true, false); + } + + @Override + public void runCommand(CommandLine cmd) + { + Language language = Language.ENGLISH; + + String inputLanguage = cmd.getOptionValue("language"); + String inputLanguageLowerCase = inputLanguage.toLowerCase(); + boolean found = false; + + //strict matching + for(Language lang : Language.values()) + { + if(lang.name().equalsIgnoreCase(inputLanguage)) + { + language = lang; + found = true; + break; + } + + if(lang.getReadableName().equalsIgnoreCase(inputLanguage)) + { + language = lang; + found = true; + break; + } + + for(String languageCode : lang.getLanguageCode()) + { + if(languageCode.equalsIgnoreCase(inputLanguage)) + { + language = lang; + found = true; + break; + } + } + } + + //loose matching by name + if(!found) + { + for (Language lang : Language.values()) + { + if (lang.name().toLowerCase().contains(inputLanguageLowerCase)) + { + language = lang; + found = true; + break; + } + } + } + + if(!found) + { + for (Language lang : Language.values()) + { + if (lang.getReadableName().toLowerCase().contains(inputLanguageLowerCase)) + { + language = lang; + found = true; + break; + } + } + } + + //loose matching by language code + if(!found) + { + for (Language lang : Language.values()) + { + for(String languageCode : lang.getLanguageCode()) + { + if(languageCode.toLowerCase().contains(inputLanguageLowerCase)) + { + language = lang; + found = true; + break; + } + } + } + } + + if(found) + { + System.out.println("Changing language to: " + language); + + Configuration.language = language; + } + else + { + System.out.println("Could not find supported language: " + language); + } + } +}