diff --git a/src/main/java/nsusbloader/Controllers/FrontController.java b/src/main/java/nsusbloader/Controllers/FrontController.java index f14b29c..354f01a 100644 --- a/src/main/java/nsusbloader/Controllers/FrontController.java +++ b/src/main/java/nsusbloader/Controllers/FrontController.java @@ -199,7 +199,7 @@ public class FrontController implements Initializable { else fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTfXciNszXczSupport()) + if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTinfoilSettings().isXciNszXczSupport()) fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP/XCI/NSZ/XCZ", "*.nsp", "*.xci", "*.nsz", "*.xcz")); else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL())) fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Any file", "*.*"), @@ -273,24 +273,25 @@ public class FrontController implements Initializable { } 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])$"; + final SettingsBlockTinfoilController tinfoilSettings = settings.getTinfoilSettings(); - if (settings.isNsIpValidate() && ! getNsIp().matches(ipValidationPattern)) { + if (tinfoilSettings.isValidateNSHostName() && ! getNsIp().matches(ipValidationPattern)) { if (!ServiceWindow.getConfirmationWindow(resourceBundle.getString("windowTitleBadIp"), resourceBundle.getString("windowBodyBadIp"))) return; } String nsIP = getNsIp(); - if (! settings.getExpertModeSelected()) + if (! tinfoilSettings.isExpertModeSelected()) usbNetCommunications = new NETCommunications(nspToUpload, nsIP, false, "", "", ""); else { usbNetCommunications = new NETCommunications( nspToUpload, nsIP, - settings.getNotServeSelected(), - settings.getAutoIpSelected()?"":settings.getHostIp(), - settings.getRandPortSelected()?"":settings.getHostPort(), - settings.getNotServeSelected()?settings.getHostExtra():"" + tinfoilSettings.isNoRequestsServe(), + tinfoilSettings.isAutoDetectIp()?"":tinfoilSettings.getHostIp(), + tinfoilSettings.isRandomlySelectPort()?"":tinfoilSettings.getHostPort(), + tinfoilSettings.isNoRequestsServe()?tinfoilSettings.getHostExtra():"" ); } } @@ -330,8 +331,9 @@ public class FrontController implements Initializable { private void handleDrop(DragEvent event){ List filesDropped = event.getDragboard().getFiles(); SettingsController settingsController = MediatorControl.getInstance().getContoller().getSettingsCtrlr(); + SettingsBlockTinfoilController tinfoilSettings = settingsController.getTinfoilSettings(); - if (getSelectedProtocol().equals("TinFoil") && settingsController.getTfXciNszXczSupport()) + if (getSelectedProtocol().equals("TinFoil") && tinfoilSettings.isXciNszXczSupport()) filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)")); else if (getSelectedProtocol().equals("GoldLeaf") && (! settingsController.getNSPFileFilterForGL())) filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$"))); diff --git a/src/main/java/nsusbloader/Controllers/SettingsBlockTinfoilController.java b/src/main/java/nsusbloader/Controllers/SettingsBlockTinfoilController.java new file mode 100644 index 0000000..ba7615a --- /dev/null +++ b/src/main/java/nsusbloader/Controllers/SettingsBlockTinfoilController.java @@ -0,0 +1,161 @@ +/* + Copyright 2019-2020 Dmitry Isaenko + + This file is part of NS-USBloader. + + NS-USBloader is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + NS-USBloader is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with NS-USBloader. If not, see . +*/ +package nsusbloader.Controllers; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.CheckBox; +import javafx.scene.control.TextField; +import javafx.scene.control.TextFormatter; +import javafx.scene.layout.VBox; +import nsusbloader.AppPreferences; +import nsusbloader.ServiceWindow; + +import java.net.URL; +import java.util.ResourceBundle; + +public class SettingsBlockTinfoilController implements Initializable { + @FXML + private CheckBox xciNszXczSupportCB, + validateNSHostNameCB, + networkExpertModeCB, + autoDetectIpCB, + randomlySelectPortCB, + noRequestsServeCB; + + @FXML + private VBox networkExpertSettingsVBox; + + @FXML + private TextField pcIpTF, + pcPortTF, + pcExtraTF; + + private ResourceBundle resourceBundle; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + this.resourceBundle = resourceBundle; + + final AppPreferences preferences = AppPreferences.getInstance(); + + networkExpertSettingsVBox.disableProperty().bind(networkExpertModeCB.selectedProperty().not()); + + pcIpTF.disableProperty().bind(autoDetectIpCB.selectedProperty()); + pcPortTF.disableProperty().bind(randomlySelectPortCB.selectedProperty()); + pcExtraTF.disableProperty().bind(noRequestsServeCB.selectedProperty().not()); + + xciNszXczSupportCB.setSelected(preferences.getTfXCI()); + validateNSHostNameCB.setSelected(preferences.getNsIpValidationNeeded()); + networkExpertModeCB.setSelected(preferences.getExpertMode()); + pcIpTF.setText(preferences.getHostIp()); + pcPortTF.setText(preferences.getHostPort()); + pcExtraTF.setText(preferences.getHostExtra()); + autoDetectIpCB.setSelected(preferences.getAutoDetectIp()); + randomlySelectPortCB.setSelected(preferences.getRandPort()); + boolean noServeRequestsFlag = preferences.getNotServeRequests(); + if (noServeRequestsFlag){ + noServeRequestAction(true); + } + noRequestsServeCB.setSelected(noServeRequestsFlag); + + pcIpTF.setTextFormatter(buildSpacelessTextFormatter()); + pcPortTF.setTextFormatter(buildPortTextFormatter()); + pcExtraTF.setTextFormatter(buildSpacelessTextFormatter()); + + autoDetectIpCB.setOnAction(e->pcIpTF.requestFocus()); + randomlySelectPortCB.setOnAction(e->pcPortTF.requestFocus()); + noRequestsServeCB.selectedProperty().addListener(((observableValue, oldValue, newValue) -> noServeRequestAction(newValue))); + } + + private TextFormatter buildSpacelessTextFormatter(){ + return new TextFormatter<>(change -> { + String text = change.getControlNewText(); + + if (text.contains(" ") || text.contains("\t")){ + return null; + } + return change; + }); + } + + private TextFormatter buildPortTextFormatter(){ + final String PORT_NUMBER_PATTERN = "^[0-9]{0,5}$"; + + return new TextFormatter<>(change -> { + String text = change.getControlNewText(); + if (text.isEmpty()) { + return change; + } + + if (! text.matches(PORT_NUMBER_PATTERN)) { + return null; + } + + int newPortNumber = Integer.parseInt(text); + + if (newPortNumber > 65535 || newPortNumber == 0) { + ServiceWindow.getErrorNotification(resourceBundle.getString("windowTitleErrorPort"), + resourceBundle.getString("windowBodyErrorPort")); + return null; + } + + return change; + }); + } + + private void noServeRequestAction(boolean isNoServe){ + if (isNoServe){ + autoDetectIpCB.setDisable(true); + autoDetectIpCB.setSelected(false); + randomlySelectPortCB.setDisable(true); + randomlySelectPortCB.setSelected(false); + } + else { + autoDetectIpCB.setDisable(false); + autoDetectIpCB.setSelected(true); + randomlySelectPortCB.setDisable(false); + randomlySelectPortCB.setSelected(true); + } + } + + public String getHostIp(){ return pcIpTF.getText(); } + public String getHostPort(){ return pcPortTF.getText(); } + public String getHostExtra(){ return pcExtraTF.getText(); } + public boolean isXciNszXczSupport(){ return xciNszXczSupportCB.isSelected(); } + public boolean isExpertModeSelected(){ return networkExpertModeCB.isSelected(); } + public boolean isAutoDetectIp(){ return autoDetectIpCB.isSelected(); } + public boolean isRandomlySelectPort(){ return randomlySelectPortCB.isSelected(); } + public boolean isNoRequestsServe(){ return noRequestsServeCB.isSelected(); } + public boolean isValidateNSHostName(){ return validateNSHostNameCB.isSelected(); } + + public void updatePreferencesOnExit(){ + AppPreferences preferences = AppPreferences.getInstance(); + + preferences.setNsIpValidationNeeded(isValidateNSHostName()); + preferences.setExpertMode(isExpertModeSelected()); + preferences.setAutoDetectIp(isAutoDetectIp()); + preferences.setRandPort(isRandomlySelectPort()); + preferences.setNotServeRequests(isNoRequestsServe()); + preferences.setHostIp(getHostIp()); + preferences.setHostPort(getHostPort()); + preferences.setHostExtra(getHostExtra()); + preferences.setTfXCI(isXciNszXczSupport()); + } +} diff --git a/src/main/java/nsusbloader/Controllers/SettingsController.java b/src/main/java/nsusbloader/Controllers/SettingsController.java index 0a8b64a..b1e57e3 100644 --- a/src/main/java/nsusbloader/Controllers/SettingsController.java +++ b/src/main/java/nsusbloader/Controllers/SettingsController.java @@ -38,21 +38,7 @@ import java.util.*; public class SettingsController implements Initializable { @FXML private CheckBox nspFilesFilterForGLCB, - validateNSHostNameCb, - expertModeCb, - autoDetectIpCb, - randPortCb, - dontServeCb, - autoCheckUpdCb, - tfXciSpprtCb; - - @FXML - private TextField pcIpTextField, - pcPortTextField, - pcExtraTextField; - - @FXML - private VBox expertSettingsVBox; + autoCheckUpdCb; @FXML private Hyperlink newVersionLink; @@ -67,6 +53,9 @@ public class SettingsController implements Initializable { @FXML private ChoiceBox glVersionChoiceBox; + @FXML + private SettingsBlockTinfoilController settingsBlockTinfoilController; + private HostServices hostServices; public static final String[] glSupportedVersions = {"v0.5", "v0.7.x", "v0.8"}; @@ -79,95 +68,8 @@ public class SettingsController implements Initializable { final AppPreferences preferences = AppPreferences.getInstance(); nspFilesFilterForGLCB.setSelected(preferences.getNspFileFilterGL()); - validateNSHostNameCb.setSelected(preferences.getNsIpValidationNeeded()); - expertSettingsVBox.setDisable(! preferences.getExpertMode()); - expertModeCb.setSelected(preferences.getExpertMode()); - expertModeCb.setOnAction(e-> expertSettingsVBox.setDisable(! expertModeCb.isSelected())); - autoDetectIpCb.setSelected(preferences.getAutoDetectIp()); - pcIpTextField.setDisable(preferences.getAutoDetectIp()); - autoDetectIpCb.setOnAction(e->{ - pcIpTextField.setDisable(autoDetectIpCb.isSelected()); - if (! autoDetectIpCb.isSelected()) - pcIpTextField.requestFocus(); - }); - randPortCb.setSelected(preferences.getRandPort()); - pcPortTextField.setDisable(preferences.getRandPort()); - randPortCb.setOnAction(e->{ - pcPortTextField.setDisable(randPortCb.isSelected()); - if (! randPortCb.isSelected()) - pcPortTextField.requestFocus(); - }); - - if (preferences.getNotServeRequests()){ - dontServeCb.setSelected(true); - - autoDetectIpCb.setSelected(false); - autoDetectIpCb.setDisable(true); - pcIpTextField.setDisable(false); - - randPortCb.setSelected(false); - randPortCb.setDisable(true); - pcPortTextField.setDisable(false); - } - pcExtraTextField.setDisable(! preferences.getNotServeRequests()); - - dontServeCb.setOnAction(e->{ - if (dontServeCb.isSelected()){ - autoDetectIpCb.setSelected(false); - autoDetectIpCb.setDisable(true); - pcIpTextField.setDisable(false); - - randPortCb.setSelected(false); - randPortCb.setDisable(true); - pcPortTextField.setDisable(false); - - pcExtraTextField.setDisable(false); - pcIpTextField.requestFocus(); - } - else { - autoDetectIpCb.setDisable(false); - autoDetectIpCb.setSelected(true); - pcIpTextField.setDisable(true); - - randPortCb.setDisable(false); - randPortCb.setSelected(true); - pcPortTextField.setDisable(true); - - pcExtraTextField.setDisable(true); - } - }); - - pcIpTextField.setText(preferences.getHostIp()); - pcPortTextField.setText(preferences.getHostPort()); - pcExtraTextField.setText(preferences.getHostExtra()); - - pcIpTextField.setTextFormatter(new TextFormatter<>(change -> { - if (change.getControlNewText().contains(" ") | change.getControlNewText().contains("\t")) - return null; - else - return change; - })); - pcPortTextField.setTextFormatter(new TextFormatter<>(change -> { - if (change.getControlNewText().matches("^[0-9]{0,5}$")) { - if (!change.getControlNewText().isEmpty() - && ((Integer.parseInt(change.getControlNewText()) > 65535) || (Integer.parseInt(change.getControlNewText()) == 0)) - ) { - ServiceWindow.getErrorNotification(resourceBundle.getString("windowTitleErrorPort"), resourceBundle.getString("windowBodyErrorPort")); - return null; - } - return change; - } - else - return null; - })); - pcExtraTextField.setTextFormatter(new TextFormatter<>(change -> { - if (change.getControlNewText().contains(" ") | change.getControlNewText().contains("\t")) - return null; - else - return change; - })); newVersionLink.setVisible(false); newVersionLink.setOnAction(e-> hostServices.showDocument(newVersionLink.getText())); @@ -182,8 +84,6 @@ public class SettingsController implements Initializable { setDriversInstallFeature(); - tfXciSpprtCb.setSelected(preferences.getTfXCI()); - SettingsLanguagesSetup settingsLanguagesSetup = new SettingsLanguagesSetup(); langCB.setItems(settingsLanguagesSetup.getLanguages()); langCB.getSelectionModel().select(settingsLanguagesSetup.getRecentLanguage()); @@ -247,18 +147,8 @@ public class SettingsController implements Initializable { } public boolean getNSPFileFilterForGL(){return nspFilesFilterForGLCB.isSelected(); } - public boolean getExpertModeSelected(){ return expertModeCb.isSelected(); } - public boolean getAutoIpSelected(){ return autoDetectIpCb.isSelected(); } - public boolean getRandPortSelected(){ return randPortCb.isSelected(); } - public boolean getNotServeSelected(){ return dontServeCb.isSelected(); } - public boolean isNsIpValidate(){ return validateNSHostNameCb.isSelected(); } - - public String getHostIp(){ return pcIpTextField.getText(); } - public String getHostPort(){ return pcPortTextField.getText(); } - public String getHostExtra(){ return pcExtraTextField.getText(); } public boolean getAutoCheckForUpdates(){ return autoCheckUpdCb.isSelected(); } - public boolean getTfXciNszXczSupport(){ return tfXciSpprtCb.isSelected(); } // Used also for NSZ/XCZ public void registerHostServices(HostServices hostServices){this.hostServices = hostServices;} @@ -270,21 +160,16 @@ public class SettingsController implements Initializable { public String getGlVer() { return glVersionChoiceBox.getValue(); } - + + public SettingsBlockTinfoilController getTinfoilSettings(){ return settingsBlockTinfoilController; } + 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()); + + settingsBlockTinfoilController.updatePreferencesOnExit(); } } \ No newline at end of file diff --git a/src/main/resources/NSLMain.fxml b/src/main/resources/NSLMain.fxml index a2d42d6..5ffb35c 100644 --- a/src/main/resources/NSLMain.fxml +++ b/src/main/resources/NSLMain.fxml @@ -71,7 +71,7 @@ Steps to roll NXDT functionality back: - + diff --git a/src/main/resources/SettingsBlockTinfoil.fxml b/src/main/resources/SettingsBlockTinfoil.fxml new file mode 100644 index 0000000..846e621 --- /dev/null +++ b/src/main/resources/SettingsBlockTinfoil.fxml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + diff --git a/src/main/resources/SettingsTab.fxml b/src/main/resources/SettingsTab.fxml index d1b7e80..e19498e 100644 --- a/src/main/resources/SettingsTab.fxml +++ b/src/main/resources/SettingsTab.fxml @@ -63,73 +63,7 @@ -