From 4eace88e868abb4b36be6ec7971ff88e5e4f1e5c Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Wed, 28 Aug 2019 04:54:35 +0300 Subject: [PATCH] Now possible to set location of the exported files via Settings. --- src/main/java/konogonka/AppPreferences.java | 4 +++ .../konogonka/Controllers/MainController.java | 2 +- .../NPDM/ServiceAccessControlController.java | 13 ++++---- .../Controllers/NSP/NSPController.java | 6 ++-- .../Controllers/XCI/HFSBlockController.java | 3 +- .../Settings/SettingsController.java | 17 ++++++++++ .../ACID/KernelAccessControlProvider.java | 4 ++- .../ACID/ServiceAccessControlProvider.java | 12 +++---- .../Tools/NPDM/LCollectionEntry.java | 15 --------- .../FXML/Settings/SettingsLayout.fxml | 31 ++++++++++++++++++- 10 files changed, 70 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/konogonka/Tools/NPDM/LCollectionEntry.java diff --git a/src/main/java/konogonka/AppPreferences.java b/src/main/java/konogonka/AppPreferences.java index 433cfc0..948e53d 100644 --- a/src/main/java/konogonka/AppPreferences.java +++ b/src/main/java/konogonka/AppPreferences.java @@ -1,5 +1,6 @@ package konogonka; +import java.io.File; import java.util.prefs.Preferences; public class AppPreferences { @@ -25,6 +26,9 @@ public class AppPreferences { titleKeysCount = getTitleKeysCount(); } + public void setExtractFilesDir(String path){preferences.put("extract_path", path);} + public String getExtractFilesDir(){return preferences.get("extract_path", System.getProperty("user.dir"));} + public void setAll( String xciHeaderKey, String headerKey diff --git a/src/main/java/konogonka/Controllers/MainController.java b/src/main/java/konogonka/Controllers/MainController.java index d9e79eb..814082d 100644 --- a/src/main/java/konogonka/Controllers/MainController.java +++ b/src/main/java/konogonka/Controllers/MainController.java @@ -89,7 +89,7 @@ public class MainController implements Initializable { fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NS files", "*.nsp", "*.xci", "*.nca", "*.tik", "*.xml", "*.npdm")); this.selectedFile = fileChooser.showOpenDialog(analyzeBtn.getScene().getWindow()); - + // todo: fix analyzeBtn.setDisable(true); NSPTabController.resetTab(); XCITabController.resetTab(); diff --git a/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java b/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java index 653d4a0..5a1a77a 100644 --- a/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java +++ b/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java @@ -6,10 +6,10 @@ import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; -import konogonka.Tools.NPDM.LCollectionEntry; import java.net.URL; -import java.util.LinkedList; +import java.util.LinkedHashMap; +import java.util.Map; import java.util.ResourceBundle; public class ServiceAccessControlController implements Initializable { @@ -25,13 +25,12 @@ public class ServiceAccessControlController implements Initializable { SACPane.getChildren().clear(); } - public void populateFields(LinkedList collection){ + public void populateFields(LinkedHashMap collection){ resetTab(); - for (LCollectionEntry entry : collection) { - - Label control = new Label(String.format("0x%02x", entry.getKey())); - Label serviceName = new Label(entry.getValue()); + for (Map.Entry entry : collection.entrySet()) { + Label control = new Label(String.format("0x%02x", (Byte) entry.getValue())); + Label serviceName = new Label((String) entry.getKey()); control.setPadding(new Insets(5.0, 5.0, 5.0, 5.0)); serviceName.setPadding(new Insets(5.0, 5.0, 5.0, 5.0)); diff --git a/src/main/java/konogonka/Controllers/NSP/NSPController.java b/src/main/java/konogonka/Controllers/NSP/NSPController.java index 88bc3f2..4124fb8 100644 --- a/src/main/java/konogonka/Controllers/NSP/NSPController.java +++ b/src/main/java/konogonka/Controllers/NSP/NSPController.java @@ -4,6 +4,7 @@ import javafx.concurrent.Task; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; +import konogonka.AppPreferences; import konogonka.Controllers.IRowModel; import konogonka.Controllers.ITabController; import konogonka.MediatorControl; @@ -51,9 +52,7 @@ public class NSPController implements ITabController { List models = tableFilesListController.getFilesForDump(); ISuperProvider provider = tableFilesListController.getProvider(); if (models != null && !models.isEmpty() && (provider != null)){ - - //File dir = new File(System.getProperty("user.dir")+File.separator+selectedFile.getName()+" extracted"); // todo: move option to settings - File dir = new File(System.getProperty("user.dir")+File.separator+provider.getFile().getName()+" extracted"); // todo: move option to settings + File dir = new File(AppPreferences.getInstance().getExtractFilesDir()+File.separator+provider.getFile().getName()+" extracted"); try { dir.mkdir(); } @@ -65,7 +64,6 @@ public class NSPController implements ITabController { extractBtn.setDisable(true); - //Extractor extractor = new Extractor(rawFileDataStart, models, dir.getAbsolutePath()+File.separator, selectedFile); //TODO: REMOVE Extractor extractor = new Extractor(provider, models, dir.getAbsolutePath()+File.separator); extractor.setOnSucceeded(e->{ extractBtn.setDisable(false); diff --git a/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java b/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java index a62419f..d4cfc36 100644 --- a/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java +++ b/src/main/java/konogonka/Controllers/XCI/HFSBlockController.java @@ -5,6 +5,7 @@ import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TitledPane; +import konogonka.AppPreferences; import konogonka.Controllers.IRowModel; import konogonka.MediatorControl; import konogonka.Tools.ISuperProvider; @@ -94,7 +95,7 @@ public class HFSBlockController implements Initializable { ISuperProvider provider = hfs0tableFilesListMainController.getProvider(); if (models != null && !models.isEmpty() && (provider != null)){ - File dir = new File(System.getProperty("user.dir")+File.separator+selectedFile.getName()+" "+type+" extracted"); + File dir = new File(AppPreferences.getInstance().getExtractFilesDir()+File.separator+selectedFile.getName()+" "+type+" extracted"); try { dir.mkdir(); } diff --git a/src/main/java/konogonka/Settings/SettingsController.java b/src/main/java/konogonka/Settings/SettingsController.java index 149f6fb..4aca963 100644 --- a/src/main/java/konogonka/Settings/SettingsController.java +++ b/src/main/java/konogonka/Settings/SettingsController.java @@ -3,8 +3,10 @@ package konogonka.Settings; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.TextFormatter; +import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; import javafx.stage.Stage; import konogonka.AppPreferences; @@ -33,8 +35,22 @@ public class SettingsController implements Initializable { xciHdrKeyTF, hdrKeyTF; + @FXML + private Button extractFilesToBtn; + @FXML + private Label extractFilesPathLbl; @Override public void initialize(URL url, ResourceBundle resourceBundle) { + extractFilesPathLbl.setText(AppPreferences.getInstance().getExtractFilesDir()); + extractFilesToBtn.setOnAction(e -> { + DirectoryChooser dirChooser = new DirectoryChooser(); + dirChooser.setTitle("Extract files to..."); + dirChooser.setInitialDirectory(new File(System.getProperty("user.home"))); + File dir = dirChooser.showDialog(extractFilesToBtn.getScene().getWindow()); + if (dir != null && dir.exists()) + extractFilesPathLbl.setText(dir.getAbsolutePath()); + }); + ListSelectorKAEKAppController.initSelector(32, "key_area_key_application_"); ListSelectorKAEKOceanController.initSelector(32, "key_area_key_ocean_"); ListSelectorKAEKSysController.initSelector(32, "key_area_key_system_"); @@ -227,6 +243,7 @@ public class SettingsController implements Initializable { for (int i = 0; i < titleKeysSet.length; i++) AppPreferences.getInstance().setTitleKey(i, titleKeysSet[i]); } + AppPreferences.getInstance().setExtractFilesDir(extractFilesPathLbl.getText()); thisStage.close(); }); } diff --git a/src/main/java/konogonka/Tools/NPDM/ACID/KernelAccessControlProvider.java b/src/main/java/konogonka/Tools/NPDM/ACID/KernelAccessControlProvider.java index 23c9c9a..d916315 100644 --- a/src/main/java/konogonka/Tools/NPDM/ACID/KernelAccessControlProvider.java +++ b/src/main/java/konogonka/Tools/NPDM/ACID/KernelAccessControlProvider.java @@ -1,8 +1,10 @@ package konogonka.Tools.NPDM.ACID; +import konogonka.RainbowHexDump; + public class KernelAccessControlProvider { KernelAccessControlProvider(byte[] bytes){ - + RainbowHexDump.hexDumpUTF8(bytes); } } diff --git a/src/main/java/konogonka/Tools/NPDM/ACID/ServiceAccessControlProvider.java b/src/main/java/konogonka/Tools/NPDM/ACID/ServiceAccessControlProvider.java index 0b40857..bcea121 100644 --- a/src/main/java/konogonka/Tools/NPDM/ACID/ServiceAccessControlProvider.java +++ b/src/main/java/konogonka/Tools/NPDM/ACID/ServiceAccessControlProvider.java @@ -1,16 +1,14 @@ package konogonka.Tools.NPDM.ACID; -import konogonka.Tools.NPDM.LCollectionEntry; - import java.nio.charset.StandardCharsets; -import java.util.LinkedList; +import java.util.LinkedHashMap; public class ServiceAccessControlProvider { - private LinkedList collection; + private LinkedHashMap collection; public ServiceAccessControlProvider(byte[] bytes){ - collection = new LinkedList<>(); + collection = new LinkedHashMap<>(); byte key; String value; @@ -19,7 +17,7 @@ public class ServiceAccessControlProvider { while (i < bytes.length){ key = bytes[i]; value = new String(bytes, i+1, getSize(key), StandardCharsets.UTF_8); - collection.add(new LCollectionEntry(key, value)); + collection.put(value, key); i += getSize(key)+1; } } @@ -28,5 +26,5 @@ public class ServiceAccessControlProvider { return ((byte) 0x7 & control) + (byte) 0x01; } - public LinkedList getCollection() { return collection; } + public LinkedHashMap getCollection() { return collection; } } diff --git a/src/main/java/konogonka/Tools/NPDM/LCollectionEntry.java b/src/main/java/konogonka/Tools/NPDM/LCollectionEntry.java deleted file mode 100644 index 817bab2..0000000 --- a/src/main/java/konogonka/Tools/NPDM/LCollectionEntry.java +++ /dev/null @@ -1,15 +0,0 @@ -package konogonka.Tools.NPDM; - -public class LCollectionEntry { - private byte key; - private String value; - - public LCollectionEntry(byte key, String value){ - this.key = key; - this.value = value; - } - - public byte getKey() { return key; } - - public String getValue() { return value; } -} diff --git a/src/main/resources/FXML/Settings/SettingsLayout.fxml b/src/main/resources/FXML/Settings/SettingsLayout.fxml index 7ade0e6..7ca1282 100644 --- a/src/main/resources/FXML/Settings/SettingsLayout.fxml +++ b/src/main/resources/FXML/Settings/SettingsLayout.fxml @@ -22,7 +22,36 @@ - + + + + + + + +