Skip to content

Commit 63d3f7d

Browse files
committed
Settings-tab refactoring: move General-application and Goldleaf-related options blocks to separate fxmls.
Move list of the GoldLeaf supported versions to the AppPreferences class.
1 parent d1500f2 commit 63d3f7d

15 files changed

+311
-220
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<name>NS-USBloader</name>
99

1010
<artifactId>ns-usbloader</artifactId>
11-
<version>4.2-SNAPSHOT</version>
11+
<version>4.2.1-SNAPSHOT</version>
1212

1313
<url>https://github.com/developersu/ns-usbloader/</url>
1414
<description>

src/main/java/nsusbloader/AppPreferences.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
*/
1919
package nsusbloader;
2020

21-
import nsusbloader.Controllers.SettingsController;
22-
2321
import java.util.Locale;
2422
import java.util.prefs.Preferences;
2523

@@ -29,6 +27,7 @@ public class AppPreferences {
2927

3028
private final Preferences preferences;
3129
private final Locale locale;
30+
public static final String[] goldleafSupportedVersions = {"v0.5", "v0.7.x", "v0.8"};
3231

3332
private AppPreferences(){
3433
this.preferences = Preferences.userRoot().node("NS-USBloader");
@@ -54,6 +53,7 @@ public String getNetUsb(){
5453
netUsb = "USB";
5554
return netUsb;
5655
}
56+
5757
public void setTheme(String theme){ preferences.put("THEME", theme); }
5858
public void setProtocol(String protocol){ preferences.put("PROTOCOL", protocol); }
5959
public void setNetUsb(String netUsb){ preferences.put("NETUSB", netUsb); }
@@ -109,8 +109,8 @@ public String getHostPort(){
109109
public void setNspFileFilterGL(boolean prop){preferences.putBoolean("GL_NSP_FILTER", prop);}
110110

111111
public String getGlVersion(){
112-
int recentGlVersionIndex = SettingsController.glSupportedVersions.length - 1;
113-
String recentGlVersion = SettingsController.glSupportedVersions[recentGlVersionIndex];
112+
int recentGlVersionIndex = goldleafSupportedVersions.length - 1;
113+
String recentGlVersion = goldleafSupportedVersions[recentGlVersionIndex];
114114
return preferences.get("gl_version", recentGlVersion);
115115
}
116116
public void setGlVersion(String version){ preferences.put("gl_version", version);}

src/main/java/nsusbloader/Controllers/FrontController.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ private void selectFilesBtnAction(){
201201

202202
if (getSelectedProtocol().equals("TinFoil") && MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTinfoilSettings().isXciNszXczSupport())
203203
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP/XCI/NSZ/XCZ", "*.nsp", "*.xci", "*.nsz", "*.xcz"));
204-
else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getNSPFileFilterForGL()))
204+
else if (getSelectedProtocol().equals("GoldLeaf") && (! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getGoldleafSettings().getNSPFileFilterForGL()))
205205
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Any file", "*.*"),
206206
new FileChooser.ExtensionFilter("NSP ROM", "*.nsp")
207207
);
@@ -266,10 +266,11 @@ private void uploadBtnAction(){
266266
SettingsController settings = MediatorControl.getInstance().getContoller().getSettingsCtrlr();
267267
// If USB selected
268268
if (getSelectedProtocol().equals("GoldLeaf") ){
269-
usbNetCommunications = new UsbCommunications(nspToUpload, "GoldLeaf" + settings.getGlVer(), settings.getNSPFileFilterForGL());
269+
final SettingsBlockGoldleafController goldleafSettings = settings.getGoldleafSettings();
270+
usbNetCommunications = new UsbCommunications(nspToUpload, "GoldLeaf" + goldleafSettings.getGlVer(), goldleafSettings.getNSPFileFilterForGL());
270271
}
271272
else if (( getSelectedProtocol().equals("TinFoil") && getSelectedNetUsb().equals("USB") )){
272-
usbNetCommunications = new UsbCommunications(nspToUpload, "TinFoil", settings.getNSPFileFilterForGL());
273+
usbNetCommunications = new UsbCommunications(nspToUpload, "TinFoil", false);
273274
}
274275
else { // NET INSTALL OVER TINFOIL
275276
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])$";
@@ -332,10 +333,11 @@ private void handleDrop(DragEvent event){
332333
List<File> filesDropped = event.getDragboard().getFiles();
333334
SettingsController settingsController = MediatorControl.getInstance().getContoller().getSettingsCtrlr();
334335
SettingsBlockTinfoilController tinfoilSettings = settingsController.getTinfoilSettings();
336+
SettingsBlockGoldleafController goldleafController = settingsController.getGoldleafSettings();
335337

336338
if (getSelectedProtocol().equals("TinFoil") && tinfoilSettings.isXciNszXczSupport())
337339
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches("(.*\\.nsp$)|(.*\\.xci$)|(.*\\.nsz$)|(.*\\.xcz$)"));
338-
else if (getSelectedProtocol().equals("GoldLeaf") && (! settingsController.getNSPFileFilterForGL()))
340+
else if (getSelectedProtocol().equals("GoldLeaf") && (! goldleafController.getNSPFileFilterForGL()))
339341
filesDropped.removeIf(file -> (file.isDirectory() && ! file.getName().toLowerCase().matches(".*\\.nsp$")));
340342
else
341343
filesDropped.removeIf(file -> ! file.getName().toLowerCase().matches(".*\\.nsp$"));

src/main/java/nsusbloader/Controllers/NSLMainController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void initialize(URL url, ResourceBundle rb) {
6969
List<String> result = updTask.getValue();
7070
if (result != null){
7171
if (!result.get(0).isEmpty()) {
72-
SettingsTabController.setNewVersionLink(result.get(0));
72+
SettingsTabController.getGenericSettings().setNewVersionLink(result.get(0));
7373
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionAval"), resourceBundle.getString("windowTitleNewVersionAval") + ": " + result.get(0) + "\n\n" + result.get(1));
7474
}
7575
}
@@ -93,7 +93,7 @@ public ResourceBundle getResourceBundle() {
9393
/**
9494
* Provide hostServices to Settings tab
9595
* */
96-
public void setHostServices(HostServices hs ){ SettingsTabController.registerHostServices(hs);}
96+
public void setHostServices(HostServices hs ){ SettingsTabController.getGenericSettings().registerHostServices(hs);}
9797

9898
/**
9999
* Get 'Settings' controller

src/main/java/nsusbloader/Controllers/RcmController.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,20 @@ public class RcmController implements Initializable {
7373
@Override
7474
public void initialize(URL url, ResourceBundle resourceBundle) {
7575
this.rb = resourceBundle;
76+
final AppPreferences preferences = AppPreferences.getInstance();
77+
7678
rcmToggleGrp.selectToggle(pldrRadio1);
7779
pldrRadio1.setOnAction(e -> statusLbl.setText(""));
7880
pldrRadio2.setOnAction(e -> statusLbl.setText(""));
7981
pldrRadio3.setOnAction(e -> statusLbl.setText(""));
8082
pldrRadio4.setOnAction(e -> statusLbl.setText(""));
8183
pldrRadio5.setOnAction(e -> statusLbl.setText(""));
8284

83-
String recentRcm1 = AppPreferences.getInstance().getRecentRcm(1);
84-
String recentRcm2 = AppPreferences.getInstance().getRecentRcm(2);
85-
String recentRcm3 = AppPreferences.getInstance().getRecentRcm(3);
86-
String recentRcm4 = AppPreferences.getInstance().getRecentRcm(4);
87-
String recentRcm5 = AppPreferences.getInstance().getRecentRcm(5);
85+
String recentRcm1 = preferences.getRecentRcm(1);
86+
String recentRcm2 = preferences.getRecentRcm(2);
87+
String recentRcm3 = preferences.getRecentRcm(3);
88+
String recentRcm4 = preferences.getRecentRcm(4);
89+
String recentRcm5 = preferences.getRecentRcm(5);
8890

8991
if (File.separator.equals("/"))
9092
this.myRegexp = "^.+/";
@@ -112,7 +114,6 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
112114
payloadFPathLbl5.setText(recentRcm5);
113115
}
114116

115-
// TODO: write logic ?? Like in case PAYLOADER exist, button active. If not: not active?
116117
injectPldBtn.setOnAction(actionEvent -> smash());
117118
}
118119

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/*
2+
Copyright 2019-2020 Dmitry Isaenko
3+
4+
This file is part of NS-USBloader.
5+
6+
NS-USBloader is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
NS-USBloader is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package nsusbloader.Controllers;
20+
21+
import javafx.application.HostServices;
22+
import javafx.concurrent.Task;
23+
import javafx.fxml.FXML;
24+
import javafx.fxml.Initializable;
25+
import javafx.scene.control.Button;
26+
import javafx.scene.control.CheckBox;
27+
import javafx.scene.control.ChoiceBox;
28+
import javafx.scene.control.Hyperlink;
29+
import javafx.scene.layout.Region;
30+
import nsusbloader.AppPreferences;
31+
import nsusbloader.ModelControllers.UpdatesChecker;
32+
import nsusbloader.ServiceWindow;
33+
import nsusbloader.UI.LocaleHolder;
34+
import nsusbloader.UI.SettingsLanguagesSetup;
35+
import nsusbloader.Utilities.WindowsDrivers.DriversInstall;
36+
37+
import java.net.URL;
38+
import java.util.List;
39+
import java.util.Locale;
40+
import java.util.ResourceBundle;
41+
42+
public class SettingsBlockGenericController implements Initializable {
43+
@FXML
44+
private ChoiceBox<LocaleHolder> languagesChB;
45+
@FXML
46+
private Button submitLanguageBtn,
47+
driversInstallBtn,
48+
checkForUpdBtn;
49+
@FXML
50+
private CheckBox autoCheckForUpdatesCB;
51+
@FXML
52+
private Hyperlink newVersionHyperlink;
53+
54+
private ResourceBundle resourceBundle;
55+
56+
private HostServices hostServices;
57+
58+
@Override
59+
public void initialize(URL url, ResourceBundle resourceBundle) {
60+
this.resourceBundle = resourceBundle;
61+
final AppPreferences preferences = AppPreferences.getInstance();
62+
63+
autoCheckForUpdatesCB.setSelected(preferences.getAutoCheckUpdates());
64+
65+
Region btnSwitchImage = new Region();
66+
btnSwitchImage.getStyleClass().add("regionUpdatesCheck");
67+
checkForUpdBtn.setGraphic(btnSwitchImage);
68+
69+
setDriversInstallFeature();
70+
71+
SettingsLanguagesSetup settingsLanguagesSetup = new SettingsLanguagesSetup();
72+
languagesChB.setItems(settingsLanguagesSetup.getLanguages());
73+
languagesChB.getSelectionModel().select(settingsLanguagesSetup.getRecentLanguage());
74+
75+
newVersionHyperlink.setOnAction(e-> hostServices.showDocument(newVersionHyperlink.getText()));
76+
checkForUpdBtn.setOnAction(e->checkForUpdatesAction());
77+
submitLanguageBtn.setOnAction(e->languageButtonAction());
78+
}
79+
80+
private void setDriversInstallFeature(){
81+
if (isWindows()){
82+
Region btnDrvImage = new Region();
83+
btnDrvImage.getStyleClass().add("regionWindows");
84+
driversInstallBtn.setGraphic(btnDrvImage);
85+
driversInstallBtn.setVisible(true);
86+
driversInstallBtn.setOnAction(actionEvent -> new DriversInstall(resourceBundle));
87+
}
88+
}
89+
private boolean isWindows(){
90+
return System.getProperty("os.name").toLowerCase().replace(" ", "").contains("windows");
91+
}
92+
93+
private void checkForUpdatesAction(){
94+
Task<List<String>> updTask = new UpdatesChecker();
95+
updTask.setOnSucceeded(event->{
96+
List<String> result = updTask.getValue();
97+
98+
if (result == null){
99+
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionUnknown"),
100+
resourceBundle.getString("windowBodyNewVersionUnknown"));
101+
return;
102+
}
103+
104+
if (result.get(0).isEmpty()){
105+
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionNOTAval"),
106+
resourceBundle.getString("windowBodyNewVersionNOTAval"));
107+
return;
108+
}
109+
110+
setNewVersionLink(result.get(0));
111+
ServiceWindow.getInfoNotification(resourceBundle.getString("windowTitleNewVersionAval"),
112+
resourceBundle.getString("windowTitleNewVersionAval")+": "+result.get(0) + "\n\n" + result.get(1));
113+
});
114+
Thread updates = new Thread(updTask);
115+
updates.setDaemon(true);
116+
updates.start();
117+
}
118+
119+
private void languageButtonAction(){
120+
LocaleHolder localeHolder = languagesChB.getSelectionModel().getSelectedItem();
121+
AppPreferences.getInstance().setLocale(localeHolder.getLocaleCode());
122+
Locale newLocale = localeHolder.getLocale();
123+
ServiceWindow.getInfoNotification("",
124+
ResourceBundle.getBundle("locale", newLocale).getString("windowBodyRestartToApplyLang"));
125+
}
126+
127+
private boolean getAutoCheckForUpdates(){ return autoCheckForUpdatesCB.isSelected(); }
128+
129+
protected void registerHostServices(HostServices hostServices){ this.hostServices = hostServices;}
130+
131+
void setNewVersionLink(String newVer){
132+
newVersionHyperlink.setVisible(true);
133+
newVersionHyperlink.setText("https://github.com/developersu/ns-usbloader/releases/tag/"+newVer);
134+
}
135+
136+
void updatePreferencesOnExit() {
137+
AppPreferences.getInstance().setAutoCheckUpdates(getAutoCheckForUpdates());
138+
}
139+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2019-2020 Dmitry Isaenko
3+
4+
This file is part of NS-USBloader.
5+
6+
NS-USBloader is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
NS-USBloader is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
package nsusbloader.Controllers;
20+
21+
import javafx.fxml.FXML;
22+
import javafx.fxml.Initializable;
23+
import javafx.scene.control.CheckBox;
24+
import javafx.scene.control.ChoiceBox;
25+
import nsusbloader.AppPreferences;
26+
27+
import java.net.URL;
28+
import java.util.ResourceBundle;
29+
30+
public class SettingsBlockGoldleafController implements Initializable {
31+
@FXML
32+
private CheckBox nspFilesFilterForGLCB;
33+
@FXML
34+
private ChoiceBox<String> glVersionChoiceBox;
35+
36+
@Override
37+
public void initialize(URL url, ResourceBundle resourceBundle) {
38+
final AppPreferences preferences = AppPreferences.getInstance();
39+
40+
nspFilesFilterForGLCB.setSelected(preferences.getNspFileFilterGL());
41+
glVersionChoiceBox.getItems().addAll(AppPreferences.goldleafSupportedVersions);
42+
43+
glVersionChoiceBox.getSelectionModel().select(preferences.getGlVersion());
44+
}
45+
46+
public boolean getNSPFileFilterForGL(){return nspFilesFilterForGLCB.isSelected(); }
47+
48+
public String getGlVer() {
49+
return glVersionChoiceBox.getValue();
50+
}
51+
52+
void updatePreferencesOnExit(){
53+
final AppPreferences preferences = AppPreferences.getInstance();
54+
55+
preferences.setNspFileFilterGL(getNSPFileFilterForGL());
56+
preferences.setGlVersion(getGlVer());
57+
}
58+
}

src/main/java/nsusbloader/Controllers/SettingsBlockTinfoilController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void noServeRequestAction(boolean isNoServe){
145145
public boolean isNoRequestsServe(){ return noRequestsServeCB.isSelected(); }
146146
public boolean isValidateNSHostName(){ return validateNSHostNameCB.isSelected(); }
147147

148-
public void updatePreferencesOnExit(){
148+
void updatePreferencesOnExit(){
149149
AppPreferences preferences = AppPreferences.getInstance();
150150

151151
preferences.setNsIpValidationNeeded(isValidateNSHostName());

0 commit comments

Comments
 (0)