mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-13 06:34:43 -04:00
Refactor save-settings chain on exit (see Controllers package)
Remove concept of 'OldGoldleaf version'. Now all supported version of GoldLeaf listed in Settings tab and one of them has to be always selected. Add GoldLeaf CLI support Remove unnecessary tails of 'extras' from CLI Tinfoil/Awoo NET mode.
This commit is contained in:
parent
dc995e1bae
commit
8da07a37ba
16 changed files with 196 additions and 107 deletions
|
@ -66,6 +66,10 @@ public class CommandLineInterface {
|
|||
new TinfoilUsb(tfArguments);
|
||||
return;
|
||||
}
|
||||
if (cli.hasOption("g") || cli.hasOption("goldleaf")){
|
||||
final String[] glArguments = cli.getOptionValues("goldleaf");
|
||||
new GoldLeaf(glArguments);
|
||||
}
|
||||
}
|
||||
catch (ParseException pe){
|
||||
System.out.println(pe.getLocalizedMessage() +
|
||||
|
@ -128,7 +132,13 @@ public class CommandLineInterface {
|
|||
.hasArgs()
|
||||
.argName("FILE1 ...")
|
||||
.build();
|
||||
|
||||
/* GoldLeaf USB */
|
||||
final Option glOption = Option.builder("g")
|
||||
.longOpt("goldleaf")
|
||||
.desc("Install via GoldLeaf mode. Check '-g help' for information.")
|
||||
.hasArgs()
|
||||
.argName("...")
|
||||
.build();
|
||||
|
||||
final OptionGroup group = new OptionGroup();
|
||||
group.addOption(rcmOption);
|
||||
|
@ -137,6 +147,7 @@ public class CommandLineInterface {
|
|||
group.addOption(versionOption);
|
||||
group.addOption(helpOption);
|
||||
group.addOption(tinfoilOption);
|
||||
group.addOption(glOption);
|
||||
|
||||
options.addOptionGroup(group);
|
||||
|
||||
|
|
116
src/main/java/nsusbloader/cli/GoldLeaf.java
Normal file
116
src/main/java/nsusbloader/cli/GoldLeaf.java
Normal file
|
@ -0,0 +1,116 @@
|
|||
package nsusbloader.cli;
|
||||
|
||||
import nsusbloader.COM.ICommunications;
|
||||
import nsusbloader.COM.USB.UsbCommunications;
|
||||
import nsusbloader.Controllers.SettingsController;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GoldLeaf {
|
||||
|
||||
private final String[] arguments;
|
||||
private List<File> filesList;
|
||||
private String goldLeafVersion;
|
||||
private boolean filterForNsp;
|
||||
|
||||
private int parseFileSince = 1;
|
||||
|
||||
public GoldLeaf(String[] arguments) throws InterruptedException, IncorrectSetupException{
|
||||
this.arguments = arguments;
|
||||
|
||||
checkArguments();
|
||||
parseGoldLeafVersion();
|
||||
parseFilesArguments();
|
||||
runGoldLeafBackend();
|
||||
}
|
||||
|
||||
public void checkArguments() throws IncorrectSetupException{
|
||||
if (arguments == null || arguments.length == 0) {
|
||||
throw new IncorrectSetupException("No arguments.\n" +
|
||||
"Try 'ns-usbloader -g help' for more information.");
|
||||
}
|
||||
|
||||
if (arguments.length == 1){
|
||||
if (isHelpDirective(arguments[0])){
|
||||
showHelp();
|
||||
}
|
||||
}
|
||||
|
||||
if (arguments.length > 1 && arguments[1].equals("filter")){
|
||||
filterForNsp = true;
|
||||
}
|
||||
}
|
||||
private boolean isHelpDirective(String argument){
|
||||
return argument.equals("help");
|
||||
}
|
||||
private void showHelp() throws IncorrectSetupException{
|
||||
throw new IncorrectSetupException("Usage:\n"
|
||||
+ "\tns-usbloader -g ver=<arg1> [filter] FILE1 ...\n"
|
||||
+ "\tns-usbloader --goldleaf ver=<arg1> [filter] FILE1 ..."
|
||||
+ "\n\nOption:"
|
||||
+ "\n\tver=<goldleaf_version>\tDefine GoldLeaf version (mandatory)\n\n"
|
||||
+ "\n\tfilter\t\nShow only *.nsp in GoldLeaf (optional)\n\n"
|
||||
+ getGlSupportedVersions());
|
||||
}
|
||||
private String getGlSupportedVersions(){
|
||||
StringBuilder builder = new StringBuilder("Supported version: \n");
|
||||
|
||||
for (String a : SettingsController.glSupportedVersions){
|
||||
builder.append("\t");
|
||||
builder.append(a);
|
||||
builder.append("\n");
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public void parseGoldLeafVersion() throws IncorrectSetupException{
|
||||
String argument1 = arguments[0];
|
||||
|
||||
if (! argument1.startsWith("ver=")) {
|
||||
throw new IncorrectSetupException("First argument must be 'ver=<goldleaf_version>'\n" +
|
||||
"Try 'ns-usbloader -g help' for more information.");
|
||||
}
|
||||
|
||||
goldLeafVersion = argument1.replaceAll("^ver=", "");
|
||||
|
||||
if (goldLeafVersion.isEmpty()) {
|
||||
throw new IncorrectSetupException("No spaces allowed before or after 'ver=<goldleaf_version>' argument.\n" +
|
||||
"Try 'ns-usbloader -g help' for more information.");
|
||||
}
|
||||
|
||||
for (String version : SettingsController.glSupportedVersions){
|
||||
if (version.equals(goldLeafVersion))
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IncorrectSetupException("GoldLeaf " + goldLeafVersion + " is not supported.\n" +
|
||||
getGlSupportedVersions());
|
||||
}
|
||||
|
||||
public void parseFilesArguments() throws IncorrectSetupException{
|
||||
filesList = new ArrayList<>();
|
||||
File file;
|
||||
|
||||
for (; parseFileSince < arguments.length; parseFileSince++) {
|
||||
file = new File(arguments[parseFileSince]);
|
||||
if (file.exists())
|
||||
filesList.add(file);
|
||||
}
|
||||
|
||||
if (filesList.size() == 0 && goldLeafVersion.equals("v0.5")) {
|
||||
throw new IncorrectSetupException("File(s) doesn't exist but should be set for GoldLeaf v0.5.\n" +
|
||||
"Try 'ns-usbloader -g help' for more information.");
|
||||
}
|
||||
}
|
||||
|
||||
public void runGoldLeafBackend() throws InterruptedException {
|
||||
ICommunications task = new UsbCommunications(filesList,
|
||||
"GoldLeaf"+goldLeafVersion,
|
||||
filterForNsp);
|
||||
Thread thread = new Thread(task);
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// TODO: Add 'don't serve requests' option
|
||||
public class TinfoilNet {
|
||||
|
||||
private final String[] arguments;
|
||||
|
@ -33,7 +32,7 @@ public class TinfoilNet {
|
|||
|
||||
private String hostIp = "";
|
||||
private String hostPortNum = "";
|
||||
private String hostExtras = "";
|
||||
//private String hostExtras = ""; // TODO: Add 'don't serve requests' option or remove this
|
||||
|
||||
private int parseFileSince = 1;
|
||||
|
||||
|
@ -79,21 +78,23 @@ public class TinfoilNet {
|
|||
+ "\tns-usbloader --tfn nsip=<arg1> [hostip=<arg2>] FILE1 ..."
|
||||
+ "\n\nOptions:"
|
||||
+ "\n\tnsip=<ip>\t\t\tDefine NS IP address (mandatory)"
|
||||
+ "\n\thostip=<ip[:port][/extra]>\tDefine this host IP address. Will be obtained automatically if not set.");
|
||||
+ "\n\thostip=<ip[:port]>\tDefine this host IP address. Will be obtained automatically if not set.");
|
||||
}
|
||||
|
||||
private void parseNsIP() throws IncorrectSetupException{
|
||||
String argument1 = arguments[0];
|
||||
|
||||
if (! argument1.startsWith("nsip="))
|
||||
if (! argument1.startsWith("nsip=")) {
|
||||
throw new IncorrectSetupException("First argument must be 'nsip=<ip_address>'\n" +
|
||||
"Try 'ns-usbloader -n help' for more information.");
|
||||
}
|
||||
|
||||
nsIp = argument1.replaceAll("^nsip=", "");
|
||||
|
||||
if (nsIp.isEmpty())
|
||||
if (nsIp.isEmpty()) {
|
||||
throw new IncorrectSetupException("No spaces allowed before or after 'nsip=<ip_address>' argument.\n" +
|
||||
"Try 'ns-usbloader -n help' for more information.");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseHostSettings(){
|
||||
|
@ -106,10 +107,10 @@ public class TinfoilNet {
|
|||
hostIp = argument2.replaceAll("(^hostip=)|(:.+?$)|(:$)", "");
|
||||
|
||||
if (argument2.contains(":"))
|
||||
hostPortNum = argument2.replaceAll("(^.+:)|(/.+?$)|(/$)", "");
|
||||
|
||||
if (argument2.contains("/"))
|
||||
hostExtras = argument2.replaceAll("^[^/]*/", "");
|
||||
hostPortNum = argument2.replaceAll("(^.+:)", "");
|
||||
// hostPortNum = argument2.replaceAll("(^.+:)|(/.+?$)|(/$)", "");
|
||||
//if (argument2.contains("/"))
|
||||
// hostExtras = argument2.replaceAll("^[^/]*/", "");
|
||||
}
|
||||
|
||||
private void parseFilesArguments() throws IncorrectSetupException{
|
||||
|
@ -135,7 +136,7 @@ public class TinfoilNet {
|
|||
false,
|
||||
hostIp,
|
||||
hostPortNum,
|
||||
hostExtras);
|
||||
"");
|
||||
Thread netCommThread = new Thread(netCommunications);
|
||||
netCommThread.start();
|
||||
netCommThread.join();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue