28
28
import javafx .scene .layout .AnchorPane ;
29
29
import javafx .scene .layout .Region ;
30
30
import javafx .stage .DirectoryChooser ;
31
+ import javafx .stage .FileChooser ;
31
32
import nsusbloader .AppPreferences ;
32
33
import nsusbloader .com .net .NETCommunications ;
33
34
import nsusbloader .com .usb .UsbCommunications ;
40
41
import java .io .File ;
41
42
import java .net .URL ;
42
43
import java .util .ArrayList ;
43
- import java .util .Arrays ;
44
44
import java .util .LinkedList ;
45
45
import java .util .List ;
46
46
import java .util .ResourceBundle ;
47
47
48
- import javax .swing .JFileChooser ;
49
- import javax .swing .UIManager ;
50
- import javax .swing .UnsupportedLookAndFeelException ;
51
- import javax .swing .filechooser .FileFilter ;
52
-
53
48
public class GamesController implements Initializable {
54
49
55
50
private static final String REGEX_ONLY_NSP = ".*\\ .nsp$" ;
@@ -70,7 +65,7 @@ public class GamesController implements Initializable {
70
65
public NSTableViewController tableFilesListController ; // Accessible from Mediator (for drag-n-drop support)
71
66
72
67
@ FXML
73
- private Button selectNspBtn , selectSplitNspBtn , uploadStopBtn ;
68
+ private Button selectNspBtn , selectSplitNspBtn , selectFolderBtn , uploadStopBtn ;
74
69
private String previouslyOpenedPath ;
75
70
private Region btnUpStopImage ;
76
71
private ResourceBundle resourceBundle ;
@@ -140,16 +135,17 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
140
135
switchThemeBtn .setGraphic (btnSwitchImage );
141
136
this .switchThemeBtn .setOnAction (e ->switchTheme ());
142
137
143
-
144
- uploadStopBtn .setDisable (getSelectedProtocol ().equals ("TinFoil" ));
145
138
selectNspBtn .setOnAction (e -> selectFilesBtnAction ());
139
+ selectNspBtn .getStyleClass ().add ("buttonSelect" );
140
+
141
+ selectFolderBtn .setOnAction (e -> selectFoldersBtnAction ());
142
+ selectFolderBtn .getStyleClass ().add ("buttonSelect" );
146
143
147
144
selectSplitNspBtn .setOnAction (e -> selectSplitBtnAction ());
148
145
selectSplitNspBtn .getStyleClass ().add ("buttonSelect" );
149
146
150
147
uploadStopBtn .setOnAction (e -> uploadBtnAction ());
151
-
152
- selectNspBtn .getStyleClass ().add ("buttonSelect" );
148
+ uploadStopBtn .setDisable (getSelectedProtocol ().equals ("TinFoil" ));
153
149
154
150
this .btnUpStopImage = new Region ();
155
151
btnUpStopImage .getStyleClass ().add ("regionUpload" );
@@ -196,69 +192,89 @@ String getNsIp(){
196
192
return nsIpTextField .getText ();
197
193
}
198
194
199
-
200
195
private boolean isGoldLeaf () {
201
- return getSelectedProtocol ().equals ("GoldLeaf" )
202
- && (!MediatorControl .getInstance ().getContoller ().getSettingsCtrlr ().getGoldleafSettings ().getNSPFileFilterForGL ());
196
+ return getSelectedProtocol ().equals ("GoldLeaf" );
203
197
}
204
198
205
199
private boolean isTinfoil () {
206
- return getSelectedProtocol ().equals ("TinFoil" )
207
- && MediatorControl .getInstance ().getContoller ().getSettingsCtrlr ().getTinfoilSettings ().isXciNszXczSupport ();
200
+ return getSelectedProtocol ().equals ("TinFoil" );
208
201
}
209
202
203
+ private boolean isNSPFileFilterForGL () {
204
+ return MediatorControl .getInstance ().getContoller ().getSettingsCtrlr ().getGoldleafSettings ().getNSPFileFilterForGL ();
205
+ }
206
+
207
+ private boolean isXciNszXczSupport () {
208
+ return MediatorControl .getInstance ().getContoller ().getSettingsCtrlr ().getTinfoilSettings ().isXciNszXczSupport ();
209
+ }
210
+
211
+ /**
212
+ * regex for selected program and selected file filter </br>
213
+ * tinfoil + xcinszxcz </br>
214
+ * tinfoil + nsponly </br>
215
+ * goldleaf </br>
216
+ * etc..
217
+ */
210
218
private String getRegexForFiles () {
211
- if (isTinfoil ())
219
+ if (isTinfoil () && isXciNszXczSupport () )
212
220
return REGEX_ALLFILES_TINFOIL ;
213
- else if (isGoldLeaf ())
214
- return REGEX_ONLY_NSP ;
215
221
else
216
222
return REGEX_ONLY_NSP ;
223
+ // currently only tinfoil supports all filetypes
224
+ // everything else only supports nsp
225
+ // else if (isGoldLeaf())
226
+ // return REGEX_ONLY_NSP;
227
+ // else
217
228
}
218
229
219
230
/**
220
231
* Functionality for selecting NSP button.
221
- * */
222
- private void selectFilesBtnAction (){
223
- final String regex = getRegexForFiles ();
224
- if (!UIManager .getLookAndFeel ().isNativeLookAndFeel ()) {
225
- try {
226
- UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
227
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e ) {
228
- // :shrug emoji:
229
- // defaults to Metal Look and Feel
230
- }
232
+ */
233
+ private void selectFilesBtnAction () {
234
+ FileChooser fileChooser = new FileChooser ();
235
+ fileChooser .setTitle (resourceBundle .getString ("btn_OpenFile" ));
236
+
237
+ fileChooser .setInitialDirectory (new File (FilesHelper .getRealFolder (previouslyOpenedPath )));
238
+
239
+ if (isTinfoil () && isXciNszXczSupport ()) {
240
+ fileChooser .getExtensionFilters ().add (new FileChooser .ExtensionFilter ("NSP/XCI/NSZ/XCZ" , "*.nsp" , "*.xci" , "*.nsz" , "*.xcz" ));
241
+ } else if (isGoldLeaf () && !isNSPFileFilterForGL ()) {
242
+ fileChooser .getExtensionFilters ().addAll (new FileChooser .ExtensionFilter ("Any file" , "*.*" ),
243
+ new FileChooser .ExtensionFilter ("NSP ROM" , "*.nsp" ));
244
+ } else {
245
+ fileChooser .getExtensionFilters ().add (new FileChooser .ExtensionFilter ("NSP ROM" , "*.nsp" ));
231
246
}
232
247
233
- JFileChooser fileChooser = new JFileChooser (new File (FilesHelper .getRealFolder (previouslyOpenedPath )));
234
- fileChooser .setFileSelectionMode (JFileChooser .FILES_AND_DIRECTORIES );
235
- fileChooser .setMultiSelectionEnabled (true );
236
- fileChooser .setFileFilter (new FileFilter () {
237
- public String getDescription () {
238
- return "Switch Files" ;
239
- }
240
- public boolean accept (File f ) {
241
- return f .isDirectory () || f .getName ().toLowerCase ().matches (regex );
242
- }
243
- });
244
-
245
- if (fileChooser .showOpenDialog (null ) == JFileChooser .APPROVE_OPTION ) {
246
- List <File > files = Arrays .asList (fileChooser .getSelectedFiles ());
247
- List <File > allFiles = new ArrayList <>();
248
+ List <File > filesList = fileChooser .showOpenMultipleDialog (usbNetPane .getScene ().getWindow ());
249
+ if (filesList != null && !filesList .isEmpty ()) {
250
+ tableFilesListController .setFiles (filesList );
251
+ uploadStopBtn .setDisable (false );
252
+ previouslyOpenedPath = filesList .get (0 ).getParent ();
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Functionality for selecting folders button.
258
+ * will scan all folders recursively for nsp-files
259
+ */
260
+ private void selectFoldersBtnAction () {
261
+ DirectoryChooser chooser = new DirectoryChooser ();
262
+ chooser .setTitle (resourceBundle .getString ("btn_OpenFolders" ));
263
+ chooser .setInitialDirectory (new File (FilesHelper .getRealFolder (previouslyOpenedPath )));
248
264
249
- if ( files . size () != 0 ) {
250
- files . stream (). filter ( File :: isDirectory ). forEach ( f -> collectFiles ( allFiles , f , regex ));
251
- files . stream (). filter ( f -> f . getName (). toLowerCase (). matches ( regex )). forEach ( allFiles :: add );
252
- }
265
+ File startFolder = chooser . showDialog ( usbNetPane . getScene (). getWindow ());
266
+ if ( startFolder != null ) {
267
+ List < File > allFiles = new ArrayList <>( );
268
+ collectFiles ( allFiles , startFolder , getRegexForFiles ());
253
269
254
- if (allFiles .size () > 0 ) {
270
+ if (! allFiles .isEmpty () ) {
255
271
tableFilesListController .setFiles (allFiles );
256
272
uploadStopBtn .setDisable (false );
257
- previouslyOpenedPath = allFiles . get ( 0 ) .getParent ();
273
+ previouslyOpenedPath = startFolder .getParent ();
258
274
}
259
275
}
260
276
}
261
-
277
+
262
278
/**
263
279
* used to recursively walk all directories, every file will be added to the storage list
264
280
* @param storage used to hold files
0 commit comments