English Command Replaced With Language Command
You can now use `-language ger` or `-language de` to select languages
This commit is contained in:
parent
e6f9f16d86
commit
64de20a3e6
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ public class HelpCommand extends CLICommand
|
|||
"-o <output file> Selects the output file",
|
||||
"-t <target classname> 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"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user