diff --git a/src/main/java/nsusbloader/AppPreferences.java b/src/main/java/nsusbloader/AppPreferences.java index 9da2df5..0a7119a 100644 --- a/src/main/java/nsusbloader/AppPreferences.java +++ b/src/main/java/nsusbloader/AppPreferences.java @@ -102,6 +102,9 @@ public class AppPreferences { public boolean getAutoCheckUpdates(){return preferences.getBoolean("AUTOCHECK4UPDATES", false); } public void setAutoCheckUpdates(boolean prop){preferences.putBoolean("AUTOCHECK4UPDATES", prop); } + public boolean getDirectoriesChooserForRoms(){return preferences.getBoolean("dirchooser4roms", false); } + public void setDirectoriesChooserForRoms(boolean prop){preferences.putBoolean("dirchooser4roms", prop); } + public boolean getTfXCI(){return preferences.getBoolean("TF_XCI", true);} public void setTfXCI(boolean prop){ preferences.putBoolean("TF_XCI", prop); } diff --git a/src/main/java/nsusbloader/Controllers/GamesController.java b/src/main/java/nsusbloader/Controllers/GamesController.java index e193c13..d204c82 100644 --- a/src/main/java/nsusbloader/Controllers/GamesController.java +++ b/src/main/java/nsusbloader/Controllers/GamesController.java @@ -69,9 +69,9 @@ public class GamesController implements Initializable { public NSTableViewController tableFilesListController; // Accessible from Mediator (for drag-n-drop support) @FXML - private Button selectNspBtn, selectSplitNspBtn, selectFolderBtn, uploadStopBtn; + private Button selectNspBtn, selectSplitNspBtn, uploadStopBtn; private String previouslyOpenedPath; - private Region btnUpStopImage; + private Region btnUpStopImage, btnSelectImage; private ResourceBundle resourceBundle; private CancellableRunnable usbNetCommunications; private Thread workThread; @@ -79,11 +79,12 @@ public class GamesController implements Initializable { @Override public void initialize(URL url, ResourceBundle resourceBundle) { this.resourceBundle = resourceBundle; + AppPreferences preferences = AppPreferences.getInstance(); ObservableList choiceProtocolList = FXCollections.observableArrayList("TinFoil", "GoldLeaf"); choiceProtocol.setItems(choiceProtocolList); - choiceProtocol.getSelectionModel().select(AppPreferences.getInstance().getProtocol()); + choiceProtocol.getSelectionModel().select(preferences.getProtocol()); choiceProtocol.setOnAction(e-> { tableFilesListController.setNewProtocol(getSelectedProtocol()); if (getSelectedProtocol().equals("GoldLeaf")) { @@ -106,7 +107,7 @@ public class GamesController implements Initializable { ObservableList choiceNetUsbList = FXCollections.observableArrayList("USB", "NET"); choiceNetUsb.setItems(choiceNetUsbList); - choiceNetUsb.getSelectionModel().select(AppPreferences.getInstance().getNetUsb()); + choiceNetUsb.getSelectionModel().select(preferences.getNetUsb()); if (getSelectedProtocol().equals("GoldLeaf")) { choiceNetUsb.setDisable(true); choiceNetUsb.getSelectionModel().select("USB"); @@ -122,7 +123,7 @@ public class GamesController implements Initializable { } }); // Set and configure NS IP field behavior - nsIpTextField.setText(AppPreferences.getInstance().getNsIp()); + nsIpTextField.setText(preferences.getNsIp()); if (getSelectedProtocol().equals("TinFoil") && getSelectedNetUsb().equals("NET")){ nsIpLbl.setVisible(true); nsIpTextField.setVisible(true); @@ -139,12 +140,9 @@ public class GamesController implements Initializable { switchThemeBtn.setGraphic(btnSwitchImage); this.switchThemeBtn.setOnAction(e->switchTheme()); - selectNspBtn.setOnAction(e-> selectFilesBtnAction()); selectNspBtn.getStyleClass().add("buttonSelect"); - - selectFolderBtn.setOnAction(e-> selectFoldersBtnAction()); - selectFolderBtn.getStyleClass().add("buttonSelect"); - selectFolderBtn.setTooltip(new Tooltip(resourceBundle.getString("btn_OpenFolders_tooltip"))); + this.btnSelectImage = new Region(); + setFilesSelectorButtonBehaviour(preferences.getDirectoriesChooserForRoms()); selectSplitNspBtn.setOnAction(e-> selectSplitBtnAction()); selectSplitNspBtn.getStyleClass().add("buttonSelect"); @@ -158,7 +156,7 @@ public class GamesController implements Initializable { uploadStopBtn.getStyleClass().add("buttonUp"); uploadStopBtn.setGraphic(btnUpStopImage); - this.previouslyOpenedPath = AppPreferences.getInstance().getRecent(); + this.previouslyOpenedPath = preferences.getRecent(); } /** * Changes UI theme on the go @@ -206,11 +204,11 @@ public class GamesController implements Initializable { } private boolean isAllFiletypesAllowedForGL() { - return ! MediatorControl.getInstance().getContoller().getSettingsCtrlr().getGoldleafSettings().getNSPFileFilterForGL(); + return ! MediatorControl.getInstance().getSettingsController().getGoldleafSettings().getNSPFileFilterForGL(); } private boolean isXciNszXczSupport() { - return MediatorControl.getInstance().getContoller().getSettingsCtrlr().getTinfoilSettings().isXciNszXczSupport(); + return MediatorControl.getInstance().getSettingsController().getTinfoilSettings().isXciNszXczSupport(); } /** @@ -301,6 +299,9 @@ public class GamesController implements Initializable { final String filesRegex, final String foldersRegex) { + if (startFolder == null) + return; + final String startFolderNameInLowercase = startFolder.getName().toLowerCase(); if (startFolder.isFile()) { @@ -368,7 +369,7 @@ public class GamesController implements Initializable { nspToUpload = new LinkedList<>(); } - SettingsController settings = MediatorControl.getInstance().getContoller().getSettingsCtrlr(); + SettingsController settings = MediatorControl.getInstance().getSettingsController(); // If USB selected if (getSelectedProtocol().equals("GoldLeaf") ){ final SettingsBlockGoldleafController goldleafSettings = settings.getGoldleafSettings(); @@ -509,7 +510,25 @@ public class GamesController implements Initializable { Platform.runLater(() -> update.accept(result)); }).start(); } - + + public void updateFilesSelectorButtonBehaviour(boolean isDirectoryChooser){ + btnSelectImage.getStyleClass().clear(); + setFilesSelectorButtonBehaviour(isDirectoryChooser); + } + private void setFilesSelectorButtonBehaviour(boolean isDirectoryChooser){ + if (isDirectoryChooser){ + selectNspBtn.setOnAction(e -> selectFoldersBtnAction()); + btnSelectImage.getStyleClass().add("regionScanFolders"); + selectSplitNspBtn.setVisible(false); + } + else { + selectNspBtn.setOnAction(e -> selectFilesBtnAction()); + btnSelectImage.getStyleClass().add("regionSelectFiles"); + selectSplitNspBtn.setVisible(true); + } + selectNspBtn.setGraphic(btnSelectImage); + //selectFolderBtn.setTooltip(new Tooltip(resourceBundle.getString("btn_OpenFolders_tooltip"))); + } /** * Get 'Recent' path */ diff --git a/src/main/java/nsusbloader/Controllers/NSLMainController.java b/src/main/java/nsusbloader/Controllers/NSLMainController.java index 0e74123..21dc530 100644 --- a/src/main/java/nsusbloader/Controllers/NSLMainController.java +++ b/src/main/java/nsusbloader/Controllers/NSLMainController.java @@ -41,7 +41,7 @@ public class NSLMainController implements Initializable { public ProgressBar progressBar; // Accessible from Mediator @FXML - public GamesController GamesTabController; // Accessible from Mediator | todo: incapsulate + private GamesController GamesTabController; // Accessible from Mediator | todo: incapsulate @FXML private SettingsController SettingsTabController; @FXML diff --git a/src/main/java/nsusbloader/Controllers/NSTableViewController.java b/src/main/java/nsusbloader/Controllers/NSTableViewController.java index b47e47c..5017829 100644 --- a/src/main/java/nsusbloader/Controllers/NSTableViewController.java +++ b/src/main/java/nsusbloader/Controllers/NSTableViewController.java @@ -38,8 +38,6 @@ import java.util.List; import java.util.ResourceBundle; public class NSTableViewController implements Initializable { - private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat("application/x-java-serialized-object"); - @FXML private TableView table; private ObservableList rowsObsLst; @@ -57,7 +55,7 @@ public class NSTableViewController implements Initializable { if (keyEvent.getCode() == KeyCode.DELETE && !MediatorControl.getInstance().getTransferActive()) { rowsObsLst.removeAll(table.getSelectionModel().getSelectedItems()); if (rowsObsLst.isEmpty()) - MediatorControl.getInstance().getContoller().getGamesCtrlr().disableUploadStopBtn(true); // TODO: change to something better + MediatorControl.getInstance().getGamesController().disableUploadStopBtn(true); // TODO: change to something better table.refresh(); } else if (keyEvent.getCode() == KeyCode.SPACE) { for (NSLRowModel item : table.getSelectionModel().getSelectedItems()) { @@ -175,13 +173,13 @@ public class NSTableViewController implements Initializable { deleteMenuItem.setOnAction(actionEvent -> { rowsObsLst.remove(row.getItem()); if (rowsObsLst.isEmpty()) - MediatorControl.getInstance().getContoller().getGamesCtrlr().disableUploadStopBtn(true); // TODO: change to something better + MediatorControl.getInstance().getGamesController().disableUploadStopBtn(true); // TODO: change to something better table.refresh(); }); MenuItem deleteAllMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_DeleteAll")); deleteAllMenuItem.setOnAction(actionEvent -> { rowsObsLst.clear(); - MediatorControl.getInstance().getContoller().getGamesCtrlr().disableUploadStopBtn(true); // TODO: change to something better + MediatorControl.getInstance().getGamesController().disableUploadStopBtn(true); // TODO: change to something better table.refresh(); }); contextMenu.getItems().addAll(deleteMenuItem, deleteAllMenuItem); @@ -226,7 +224,7 @@ public class NSTableViewController implements Initializable { } else { rowsObsLst.add(new NSLRowModel(file, true)); - MediatorControl.getInstance().getContoller().getGamesCtrlr().disableUploadStopBtn(false); // TODO: change to something better + MediatorControl.getInstance().getGamesController().disableUploadStopBtn(false); // TODO: change to something better } table.refresh(); } @@ -246,7 +244,7 @@ public class NSTableViewController implements Initializable { else { for (File file: newFiles) rowsObsLst.add(new NSLRowModel(file, true)); - MediatorControl.getInstance().getContoller().getGamesCtrlr().disableUploadStopBtn(false); // TODO: change to something better + MediatorControl.getInstance().getGamesController().disableUploadStopBtn(false); // TODO: change to something better } //rowsObsLst.get(0).setMarkForUpload(true); table.refresh(); diff --git a/src/main/java/nsusbloader/Controllers/SettingsBlockGenericController.java b/src/main/java/nsusbloader/Controllers/SettingsBlockGenericController.java index 00a416b..95ef545 100644 --- a/src/main/java/nsusbloader/Controllers/SettingsBlockGenericController.java +++ b/src/main/java/nsusbloader/Controllers/SettingsBlockGenericController.java @@ -28,6 +28,7 @@ import javafx.scene.control.ChoiceBox; import javafx.scene.control.Hyperlink; import javafx.scene.layout.Region; import nsusbloader.AppPreferences; +import nsusbloader.MediatorControl; import nsusbloader.ModelControllers.UpdatesChecker; import nsusbloader.ServiceWindow; import nsusbloader.UI.LocaleHolder; @@ -47,7 +48,8 @@ public class SettingsBlockGenericController implements Initializable { driversInstallBtn, checkForUpdBtn; @FXML - private CheckBox autoCheckForUpdatesCB; + private CheckBox autoCheckForUpdatesCB, + direcroriesChooserForRomsCB; @FXML private Hyperlink newVersionHyperlink; @@ -61,6 +63,10 @@ public class SettingsBlockGenericController implements Initializable { final AppPreferences preferences = AppPreferences.getInstance(); autoCheckForUpdatesCB.setSelected(preferences.getAutoCheckUpdates()); + direcroriesChooserForRomsCB.setSelected(preferences.getDirectoriesChooserForRoms()); + direcroriesChooserForRomsCB.setOnAction(actionEvent -> + MediatorControl.getInstance().getGamesController().updateFilesSelectorButtonBehaviour(direcroriesChooserForRomsCB.isSelected()) + ); Region btnSwitchImage = new Region(); btnSwitchImage.getStyleClass().add("regionUpdatesCheck"); @@ -124,7 +130,13 @@ public class SettingsBlockGenericController implements Initializable { ResourceBundle.getBundle("locale", newLocale).getString("windowBodyRestartToApplyLang")); } - private boolean getAutoCheckForUpdates(){ return autoCheckForUpdatesCB.isSelected(); } + private boolean getAutoCheckForUpdates(){ + return autoCheckForUpdatesCB.isSelected(); + } + + public boolean isDirectoriesChooserForRoms(){ + return direcroriesChooserForRomsCB.isSelected(); + } protected void registerHostServices(HostServices hostServices){ this.hostServices = hostServices;} @@ -135,5 +147,6 @@ public class SettingsBlockGenericController implements Initializable { void updatePreferencesOnExit() { AppPreferences.getInstance().setAutoCheckUpdates(getAutoCheckForUpdates()); + AppPreferences.getInstance().setDirectoriesChooserForRoms(isDirectoriesChooserForRoms()); } } diff --git a/src/main/java/nsusbloader/Controllers/SplitMergeController.java b/src/main/java/nsusbloader/Controllers/SplitMergeController.java index 2611e33..59656ac 100644 --- a/src/main/java/nsusbloader/Controllers/SplitMergeController.java +++ b/src/main/java/nsusbloader/Controllers/SplitMergeController.java @@ -151,7 +151,7 @@ public class SplitMergeController implements Initializable { convertBtn.setOnAction(actionEvent -> setConvertBtnAction()); } - public void notifySmThreadStarted(boolean isStart, EModule type){ // todo: refactor: remove everything, place to separate container and just disable. + public void notifyThreadStarted(boolean isStart, EModule type){ // todo: refactor: remove everything, place to separate container and just disable. if (! type.equals(EModule.SPLIT_MERGE_TOOL)){ smToolPane.setDisable(isStart); return; diff --git a/src/main/java/nsusbloader/MediatorControl.java b/src/main/java/nsusbloader/MediatorControl.java index a644e50..3717ad2 100644 --- a/src/main/java/nsusbloader/MediatorControl.java +++ b/src/main/java/nsusbloader/MediatorControl.java @@ -18,14 +18,15 @@ */ package nsusbloader; -import nsusbloader.Controllers.NSLMainController; +import nsusbloader.Controllers.*; import nsusbloader.NSLDataTypes.EModule; +import java.util.ResourceBundle; import java.util.concurrent.atomic.AtomicBoolean; public class MediatorControl { - private AtomicBoolean isTransferActive = new AtomicBoolean(false); // Overcoded just for sure - private NSLMainController mainCtrler; + private final AtomicBoolean isTransferActive = new AtomicBoolean(false); // Overcoded just for sure + private NSLMainController mainController; public static MediatorControl getInstance(){ return MediatorControlHold.INSTANCE; @@ -35,16 +36,26 @@ public class MediatorControl { private static final MediatorControl INSTANCE = new MediatorControl(); } public void setController(NSLMainController controller){ - this.mainCtrler = controller; + this.mainController = controller; + } + + public NSLMainController getContoller(){ return mainController; } + public GamesController getGamesController(){ return mainController.getGamesCtrlr(); }; + public SettingsController getSettingsController(){ return mainController.getSettingsCtrlr(); }; + public SplitMergeController getSplitMergeController(){ return mainController.getSmCtrlr(); }; + public RcmController getRcmController(){ return mainController.getRcmCtrlr(); }; + public NxdtController getNxdtController(){ return mainController.getNXDTabController(); }; + + public ResourceBundle getResourceBundle(){ + return mainController.getResourceBundle(); } - public NSLMainController getContoller(){ return this.mainCtrler; } public synchronized void setBgThreadActive(boolean isActive, EModule appModuleType) { isTransferActive.set(isActive); - mainCtrler.getGamesCtrlr().notifyThreadStarted(isActive, appModuleType); - mainCtrler.getSmCtrlr().notifySmThreadStarted(isActive, appModuleType); - mainCtrler.getRcmCtrlr().notifyThreadStarted(isActive, appModuleType); - mainCtrler.getNXDTabController().notifyThreadStarted(isActive, appModuleType); + getGamesController().notifyThreadStarted(isActive, appModuleType); + getSplitMergeController().notifyThreadStarted(isActive, appModuleType); + getRcmController().notifyThreadStarted(isActive, appModuleType); + getNxdtController().notifyThreadStarted(isActive, appModuleType); } public synchronized boolean getTransferActive() { return this.isTransferActive.get(); } } diff --git a/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java b/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java index 2b62f36..8baa5be 100644 --- a/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java +++ b/src/main/java/nsusbloader/ModelControllers/MessagesConsumer.java @@ -61,7 +61,7 @@ public class MessagesConsumer extends AnimationTimer { this.progressBar = MediatorControl.getInstance().getContoller().progressBar; this.statusMap = statusMap; - this.tableViewController = MediatorControl.getInstance().getContoller().GamesTabController.tableFilesListController; + this.tableViewController = MediatorControl.getInstance().getGamesController().tableFilesListController; this.oneLinerStatus = oneLinerStatus; @@ -100,13 +100,13 @@ public class MessagesConsumer extends AnimationTimer { switch (appModuleType){ case RCM: - MediatorControl.getInstance().getContoller().getRcmCtrlr().setOneLineStatus(oneLinerStatus.get()); + MediatorControl.getInstance().getRcmController().setOneLineStatus(oneLinerStatus.get()); break; case NXDT: - MediatorControl.getInstance().getContoller().getNXDTabController().setOneLineStatus(oneLinerStatus.get()); + MediatorControl.getInstance().getNxdtController().setOneLineStatus(oneLinerStatus.get()); break; case SPLIT_MERGE_TOOL: - MediatorControl.getInstance().getContoller().getSmCtrlr().setOneLineStatus(oneLinerStatus.get()); + MediatorControl.getInstance().getSplitMergeController().setOneLineStatus(oneLinerStatus.get()); break; } diff --git a/src/main/java/nsusbloader/com/usb/GoldLeaf_07.java b/src/main/java/nsusbloader/com/usb/GoldLeaf_07.java index 00fa19b..eb3eca3 100644 --- a/src/main/java/nsusbloader/com/usb/GoldLeaf_07.java +++ b/src/main/java/nsusbloader/com/usb/GoldLeaf_07.java @@ -914,7 +914,7 @@ class GoldLeaf_07 extends TransferModule { private boolean selectFile(){ File selectedFile = CompletableFuture.supplyAsync(() -> { FileChooser fChooser = new FileChooser(); - fChooser.setTitle(MediatorControl.getInstance().getContoller().getResourceBundle().getString("btn_OpenFile")); // TODO: FIX BAD IMPLEMENTATION + fChooser.setTitle(MediatorControl.getInstance().getResourceBundle().getString("btn_OpenFile")); // TODO: FIX BAD IMPLEMENTATION fChooser.setInitialDirectory(new File(System.getProperty("user.home"))); // TODO: Consider fixing; not a prio. fChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("*", "*")); return fChooser.showOpenDialog(null); // Leave as is for now. diff --git a/src/main/java/nsusbloader/com/usb/GoldLeaf_08.java b/src/main/java/nsusbloader/com/usb/GoldLeaf_08.java index f6a29ac..4e260cc 100644 --- a/src/main/java/nsusbloader/com/usb/GoldLeaf_08.java +++ b/src/main/java/nsusbloader/com/usb/GoldLeaf_08.java @@ -941,7 +941,7 @@ class GoldLeaf_08 extends TransferModule { private boolean selectFile(){ File selectedFile = CompletableFuture.supplyAsync(() -> { FileChooser fChooser = new FileChooser(); - fChooser.setTitle(MediatorControl.getInstance().getContoller().getResourceBundle().getString("btn_OpenFile")); // TODO: FIX BAD IMPLEMENTATION + fChooser.setTitle(MediatorControl.getInstance().getResourceBundle().getString("btn_OpenFile")); // TODO: FIX BAD IMPLEMENTATION fChooser.setInitialDirectory(new File(System.getProperty("user.home")));// TODO: Consider fixing; not a prio. fChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("*", "*")); return fChooser.showOpenDialog(null); // Leave as is for now. diff --git a/src/main/resources/GamesTab.fxml b/src/main/resources/GamesTab.fxml index 15a924a..8f23f8e 100644 --- a/src/main/resources/GamesTab.fxml +++ b/src/main/resources/GamesTab.fxml @@ -54,14 +54,6 @@ - - - - -