mirror of
https://github.com/developersu/ns-usbloader.git
synced 2025-05-14 15:15:05 -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
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package nsusbloader;
|
||||
|
||||
import nsusbloader.Controllers.SettingsController;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.prefs.Preferences;
|
||||
|
||||
|
@ -29,41 +31,6 @@ public class AppPreferences {
|
|||
|
||||
private AppPreferences(){ preferences = Preferences.userRoot().node("NS-USBloader"); }
|
||||
|
||||
public void setAll(
|
||||
String Protocol,
|
||||
String PreviouslyOpened,
|
||||
String NetUsb,
|
||||
String NsIp,
|
||||
boolean NsIpValidate,
|
||||
boolean ExpertMode,
|
||||
boolean AutoIp,
|
||||
boolean RandPort,
|
||||
boolean NotServe,
|
||||
String HostIp,
|
||||
String HostPort,
|
||||
String HostExtra,
|
||||
boolean autoCheck4Updates,
|
||||
boolean tinfoilXciSupport,
|
||||
boolean nspFileFilterForGl,
|
||||
String useOldGlVersion
|
||||
){
|
||||
setProtocol(Protocol);
|
||||
setRecent(PreviouslyOpened);
|
||||
setNetUsb(NetUsb);
|
||||
setNsIp(NsIp);
|
||||
setNsIpValidationNeeded(NsIpValidate);
|
||||
setExpertMode(ExpertMode);
|
||||
setAutoDetectIp(AutoIp);
|
||||
setRandPort(RandPort);
|
||||
setNotServeRequests(NotServe);
|
||||
setHostIp(HostIp);
|
||||
setHostPort(HostPort);
|
||||
setHostExtra(HostExtra);
|
||||
setAutoCheckUpdates(autoCheck4Updates);
|
||||
setTfXCI(tinfoilXciSupport);
|
||||
setNspFileFilterGL(nspFileFilterForGl);
|
||||
setUseOldGlVersion(useOldGlVersion);
|
||||
}
|
||||
public String getTheme(){
|
||||
String theme = preferences.get("THEME", "/res/app_dark.css"); // Don't let user to change settings manually
|
||||
if (!theme.matches("(^/res/app_dark.css$)|(^/res/app_light.css$)"))
|
||||
|
@ -135,8 +102,12 @@ public class AppPreferences {
|
|||
public boolean getNspFileFilterGL(){return preferences.getBoolean("GL_NSP_FILTER", false); }
|
||||
public void setNspFileFilterGL(boolean prop){preferences.putBoolean("GL_NSP_FILTER", prop);}
|
||||
|
||||
public String getUseOldGlVersion(){ return preferences.get("OldGlVersion", ""); }
|
||||
public void setUseOldGlVersion(String version){ preferences.put("OldGlVersion", version);}
|
||||
public String getGlVersion(){
|
||||
int recentGlVersionIndex = SettingsController.glSupportedVersions.length - 1;
|
||||
String recentGlVersion = SettingsController.glSupportedVersions[recentGlVersionIndex];
|
||||
return preferences.get("gl_version", recentGlVersion);
|
||||
}
|
||||
public void setGlVersion(String version){ preferences.put("gl_version", version);}
|
||||
|
||||
public double getSceneWidth(){ return preferences.getDouble("WIND_WIDTH", 850.0); }
|
||||
public void setSceneWidth(double value){ preferences.putDouble("WIND_WIDTH", value); }
|
||||
|
|
|
@ -40,7 +40,7 @@ import java.util.concurrent.CompletableFuture;
|
|||
/**
|
||||
* GoldLeaf 0.8 processing
|
||||
*/
|
||||
class GoldLeaf extends TransferModule {
|
||||
class GoldLeaf_08 extends TransferModule {
|
||||
private boolean nspFilterForGl;
|
||||
|
||||
// CMD
|
||||
|
@ -70,7 +70,7 @@ class GoldLeaf extends TransferModule {
|
|||
// For using in CMD_SelectFile with SPEC:/ prefix
|
||||
private File selectedFile;
|
||||
|
||||
GoldLeaf(DeviceHandle handler, LinkedHashMap<String, File> nspMap, ICommunications task, ILogPrinter logPrinter, boolean nspFilter){
|
||||
GoldLeaf_08(DeviceHandle handler, LinkedHashMap<String, File> nspMap, ICommunications task, ILogPrinter logPrinter, boolean nspFilter){
|
||||
super(handler, nspMap, task, logPrinter);
|
||||
|
||||
final byte CMD_GetDriveCount = 1;
|
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
package nsusbloader.COM.USB;
|
||||
|
||||
import javafx.concurrent.Task;
|
||||
import nsusbloader.COM.ICommunications;
|
||||
import nsusbloader.ModelControllers.ILogPrinter;
|
||||
import nsusbloader.ModelControllers.Log;
|
||||
|
@ -69,8 +68,8 @@ public class UsbCommunications implements ICommunications {
|
|||
case "TinFoil":
|
||||
module = new TinFoil(handler, nspMap, this, logPrinter);
|
||||
break;
|
||||
case "GoldLeaf":
|
||||
module = new GoldLeaf(handler, nspMap, this, logPrinter, nspFilterForGl);
|
||||
case "GoldLeafv0.8":
|
||||
module = new GoldLeaf_08(handler, nspMap, this, logPrinter, nspFilterForGl);
|
||||
break;
|
||||
case "GoldLeafv0.7.x":
|
||||
module = new GoldLeaf_07(handler, nspMap, this, logPrinter, nspFilterForGl);
|
||||
|
|
|
@ -20,7 +20,6 @@ package nsusbloader.Controllers;
|
|||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.*;
|
||||
|
@ -267,7 +266,7 @@ public class FrontController implements Initializable {
|
|||
SettingsController settings = MediatorControl.getInstance().getContoller().getSettingsCtrlr();
|
||||
// If USB selected
|
||||
if (getSelectedProtocol().equals("GoldLeaf") || ( getSelectedProtocol().equals("TinFoil") && getSelectedNetUsb().equals("USB") ) ){
|
||||
usbNetCommunications = new UsbCommunications(nspToUpload, getSelectedProtocol() + settings.getGlOldVer(), settings.getNSPFileFilterForGL());
|
||||
usbNetCommunications = new UsbCommunications(nspToUpload, getSelectedProtocol() + settings.getGlVer(), settings.getNSPFileFilterForGL());
|
||||
}
|
||||
else { // NET INSTALL OVER TINFOIL
|
||||
final String ipValidationPattern = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.([01]?\\d\\d?|2[0-4]\\d|25[0-5])$";
|
||||
|
@ -381,4 +380,13 @@ public class FrontController implements Initializable {
|
|||
public String getRecentPath(){
|
||||
return previouslyOpenedPath;
|
||||
}
|
||||
|
||||
public void updatePreferencesOnExit(){
|
||||
AppPreferences preferences = AppPreferences.getInstance();
|
||||
|
||||
preferences.setProtocol(getSelectedProtocol());
|
||||
preferences.setRecent(getRecentPath());
|
||||
preferences.setNetUsb(getSelectedNetUsb());
|
||||
preferences.setNsIp(getNsIp());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,25 +118,8 @@ public class NSLMainController implements Initializable {
|
|||
* Save preferences before exit
|
||||
* */
|
||||
public void exit(){
|
||||
AppPreferences.getInstance().setAll(
|
||||
FrontTabController.getSelectedProtocol(),
|
||||
FrontTabController.getRecentPath(),
|
||||
FrontTabController.getSelectedNetUsb(),
|
||||
FrontTabController.getNsIp(),
|
||||
SettingsTabController.isNsIpValidate(),
|
||||
SettingsTabController.getExpertModeSelected(),
|
||||
SettingsTabController.getAutoIpSelected(),
|
||||
SettingsTabController.getRandPortSelected(),
|
||||
SettingsTabController.getNotServeSelected(),
|
||||
SettingsTabController.getHostIp(),
|
||||
SettingsTabController.getHostPort(),
|
||||
SettingsTabController.getHostExtra(),
|
||||
SettingsTabController.getAutoCheckForUpdates(),
|
||||
SettingsTabController.getTfXciNszXczSupport(),
|
||||
SettingsTabController.getNSPFileFilterForGL(),
|
||||
SettingsTabController.getGlOldVer()
|
||||
);
|
||||
|
||||
FrontTabController.updatePreferencesOnExit();
|
||||
SettingsTabController.updatePreferencesOnExit();
|
||||
SplitMergeTabController.updatePreferencesOnExit(); // NOTE: This shit above should be re-written to similar pattern
|
||||
RcmTabController.updatePreferencesOnExit();
|
||||
NXDTabController.updatePreferencesOnExit();
|
||||
|
|
|
@ -76,14 +76,11 @@ public class SettingsController implements Initializable {
|
|||
private ChoiceBox<String> langCB;
|
||||
|
||||
@FXML
|
||||
private CheckBox glOldVerCheck;
|
||||
|
||||
@FXML
|
||||
private ChoiceBox<String> glOldVerChoice;
|
||||
private ChoiceBox<String> glVersionChoiceBox;
|
||||
|
||||
private HostServices hs;
|
||||
|
||||
private static final String[] oldGlSupportedVersions = {"v0.5", "v0.7.x"};
|
||||
public static final String[] glSupportedVersions = {"v0.5", "v0.7.x", "v0.8"};
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
|
@ -273,19 +270,9 @@ public class SettingsController implements Initializable {
|
|||
.getString("windowBodyRestartToApplyLang"));
|
||||
});
|
||||
// Set supported old versions
|
||||
glOldVerChoice.getItems().addAll(oldGlSupportedVersions);
|
||||
String oldVer = AppPreferences.getInstance().getUseOldGlVersion(); // Overhead; Too much validation of consistency
|
||||
if (Arrays.asList(oldGlSupportedVersions).contains(oldVer)) {
|
||||
glOldVerChoice.getSelectionModel().select(oldVer);
|
||||
glOldVerChoice.setDisable(false);
|
||||
glOldVerCheck.setSelected(true);
|
||||
}
|
||||
else {
|
||||
glOldVerChoice.getSelectionModel().select(0);
|
||||
glOldVerChoice.setDisable(true);
|
||||
glOldVerCheck.setSelected(false);
|
||||
}
|
||||
glOldVerCheck.setOnAction(e-> glOldVerChoice.setDisable(! glOldVerCheck.isSelected()) );
|
||||
glVersionChoiceBox.getItems().addAll(glSupportedVersions);
|
||||
String oldVer = AppPreferences.getInstance().getGlVersion(); // Overhead; Too much validation of consistency
|
||||
glVersionChoiceBox.getSelectionModel().select(oldVer);
|
||||
}
|
||||
|
||||
private boolean isWindows(){
|
||||
|
@ -313,10 +300,24 @@ public class SettingsController implements Initializable {
|
|||
newVersionLink.setText("https://github.com/developersu/ns-usbloader/releases/tag/"+newVer);
|
||||
}
|
||||
|
||||
public String getGlOldVer() {
|
||||
if (glOldVerCheck.isSelected())
|
||||
return glOldVerChoice.getValue();
|
||||
else
|
||||
return "";
|
||||
public String getGlVer() {
|
||||
return glVersionChoiceBox.getValue();
|
||||
}
|
||||
|
||||
public void updatePreferencesOnExit(){
|
||||
AppPreferences preferences = AppPreferences.getInstance();
|
||||
|
||||
preferences.setNsIpValidationNeeded(isNsIpValidate());
|
||||
preferences.setExpertMode(getExpertModeSelected());
|
||||
preferences.setAutoDetectIp(getAutoIpSelected());
|
||||
preferences.setRandPort(getRandPortSelected());
|
||||
preferences.setNotServeRequests(getNotServeSelected());
|
||||
preferences.setHostIp(getHostIp());
|
||||
preferences.setHostPort(getHostPort());
|
||||
preferences.setHostExtra(getHostExtra());
|
||||
preferences.setAutoCheckUpdates(getAutoCheckForUpdates());
|
||||
preferences.setTfXCI(getTfXciNszXczSupport());
|
||||
preferences.setNspFileFilterGL(getNSPFileFilterForGL());
|
||||
preferences.setGlVersion(getGlVer());
|
||||
}
|
||||
}
|
|
@ -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