From 02b49d9cb20e66bd337e70029a81e72870344807 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Wed, 21 Aug 2019 06:36:51 +0300 Subject: [PATCH] XML support [basic] --- README.md | 8 +- .../java/konogonka/Child/ChildWindow.java | 30 ++++---- .../konogonka/Controllers/MainController.java | 10 ++- .../Controllers/NSP/NSPController.java | 2 +- .../Controllers/TIK/TIKController.java | 1 - .../Controllers/XML/XMLController.java | 75 +++++++++++++++++++ src/main/resources/FXML/XML/XMLTab.fxml | 11 +++ src/main/resources/FXML/landingPage.fxml | 8 ++ src/main/resources/locale.properties | 2 +- src/main/resources/locale_fra.properties | 2 +- src/main/resources/locale_rus.properties | 2 +- src/main/resources/locale_ukr.properties | 2 +- 12 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 src/main/java/konogonka/Controllers/XML/XMLController.java create mode 100644 src/main/resources/FXML/XML/XMLTab.fxml diff --git a/README.md b/README.md index 6b813dc..98b56b0 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,10 @@ Deep WIP multi-tool to work with XCI/NSP/NCA/NRO(?) files ### System requirements -JRE/JDK 8u60 or higher. \ No newline at end of file +JRE/JDK 8u60 or higher. + +### Checklist + +* [ ] LogPrinter to singleton implementation +* [ ] CNMT support +* [ ] support \ No newline at end of file diff --git a/src/main/java/konogonka/Child/ChildWindow.java b/src/main/java/konogonka/Child/ChildWindow.java index ee41ffb..359ab04 100644 --- a/src/main/java/konogonka/Child/ChildWindow.java +++ b/src/main/java/konogonka/Child/ChildWindow.java @@ -6,8 +6,8 @@ import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.stage.Stage; import konogonka.Controllers.IRowModel; -import konogonka.Controllers.NCA.NCAController; -import konogonka.Controllers.TIK.TIKController; +import konogonka.Controllers.ITabController; +import konogonka.Controllers.XML.XMLController; import konogonka.Tools.ISuperProvider; import java.io.IOException; @@ -29,19 +29,18 @@ public class ChildWindow { else if(model.getFileName().endsWith(".tik")){ loaderSettings = new FXMLLoader(getClass().getResource("/FXML/TIK/TIKTab.fxml")); } + else if(model.getFileName().endsWith(".xml")){ + loaderSettings = new FXMLLoader(getClass().getResource("/FXML/XML/XMLTab.fxml")); + } else if(model.getFileName().endsWith(".cert")){ // TODO: IMPLEMENT return; } - else if(model.getFileName().endsWith(".tik")){ + else if(model.getFileName().endsWith(".cnmt")){ // TODO: IMPLEMENT return; } - else if(model.getFileName().endsWith(".xml")){ - // TODO: IMPLEMENT - return; - } - else + else // TODO: Dynamic detection function return; Locale userLocale = new Locale(Locale.getDefault().getISO3Language()); @@ -49,15 +48,14 @@ public class ChildWindow { loaderSettings.setResources(resourceBundle); Parent parentAbout = loaderSettings.load(); - - // TODO: REFACTOR - if (model.getFileName().endsWith(".nca")){ - NCAController ncaController = loaderSettings.getController(); - ncaController.analyze(provider.getFile(), provider.getRawFileDataStart()+model.getFileOffset()); + // TODO: fix? + if(model.getFileName().endsWith(".xml")){ + XMLController myController = loaderSettings.getController(); + myController.analyze(provider.getFile(), provider.getRawFileDataStart()+model.getFileOffset(), model.getFileSize()); } - else if(model.getFileName().endsWith(".tik")){ - TIKController tikController = loaderSettings.getController(); - tikController.analyze(provider.getFile(), provider.getRawFileDataStart()+model.getFileOffset()); + else { + ITabController myController = loaderSettings.getController(); + myController.analyze(provider.getFile(), provider.getRawFileDataStart()+model.getFileOffset()); } diff --git a/src/main/java/konogonka/Controllers/MainController.java b/src/main/java/konogonka/Controllers/MainController.java index 5b7f279..7e10a2e 100644 --- a/src/main/java/konogonka/Controllers/MainController.java +++ b/src/main/java/konogonka/Controllers/MainController.java @@ -11,6 +11,7 @@ import konogonka.Controllers.NCA.NCAController; import konogonka.Controllers.NSP.NSPController; import konogonka.Controllers.TIK.TIKController; import konogonka.Controllers.XCI.XCIController; +import konogonka.Controllers.XML.XMLController; import konogonka.MediatorControl; import konogonka.Settings.SettingsWindow; import konogonka.Tools.ISuperProvider; @@ -47,6 +48,8 @@ public class MainController implements Initializable { private NCAController NCATabController; @FXML private TIKController TIKTabController; + @FXML + private XMLController XMLTabController; private File selectedFile; @@ -80,7 +83,7 @@ public class MainController implements Initializable { else fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); - fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NS files", "*.nsp", "*.xci", "*.nca", "*.tik")); + fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NS files", "*.nsp", "*.xci", "*.nca", "*.tik", "*.xml")); this.selectedFile = fileChooser.showOpenDialog(analyzeBtn.getScene().getWindow()); @@ -89,6 +92,7 @@ public class MainController implements Initializable { XCITabController.resetTab(); NCATabController.resetTab(); TIKTabController.resetTab(); + XMLTabController.resetTab(); if (this.selectedFile != null && this.selectedFile.exists()) { filenameSelected.setText(this.selectedFile.getAbsolutePath()); @@ -102,6 +106,8 @@ public class MainController implements Initializable { tabPane.getSelectionModel().select(2); else if (this.selectedFile.getName().toLowerCase().endsWith(".tik")) tabPane.getSelectionModel().select(3); + else if (this.selectedFile.getName().toLowerCase().endsWith(".xml")) + tabPane.getSelectionModel().select(4); } logArea.clear(); @@ -118,6 +124,8 @@ public class MainController implements Initializable { NCATabController.analyze(selectedFile); else if (selectedFile.getName().toLowerCase().endsWith("tik")) TIKTabController.analyze(selectedFile); + else if (selectedFile.getName().toLowerCase().endsWith("xml")) + XMLTabController.analyze(selectedFile); } @FXML private void showHideLogs(){ diff --git a/src/main/java/konogonka/Controllers/NSP/NSPController.java b/src/main/java/konogonka/Controllers/NSP/NSPController.java index c7998a1..b947646 100644 --- a/src/main/java/konogonka/Controllers/NSP/NSPController.java +++ b/src/main/java/konogonka/Controllers/NSP/NSPController.java @@ -94,7 +94,7 @@ public class NSPController implements ITabController { * */ @Override public void analyze(File selectedFile, long offset){ - // TODO: IMPLEMENT + // TODO: IMPLEMENT? return; } @Override diff --git a/src/main/java/konogonka/Controllers/TIK/TIKController.java b/src/main/java/konogonka/Controllers/TIK/TIKController.java index d9cb518..855d29b 100644 --- a/src/main/java/konogonka/Controllers/TIK/TIKController.java +++ b/src/main/java/konogonka/Controllers/TIK/TIKController.java @@ -6,7 +6,6 @@ import javafx.scene.control.Label; import javafx.scene.control.TextField; import konogonka.AppPreferences; import konogonka.Controllers.ITabController; -import konogonka.MediatorControl; import konogonka.Tools.TIK.TIKProvider; import konogonka.Workers.AnalyzerTIK; diff --git a/src/main/java/konogonka/Controllers/XML/XMLController.java b/src/main/java/konogonka/Controllers/XML/XMLController.java new file mode 100644 index 0000000..d1d0f89 --- /dev/null +++ b/src/main/java/konogonka/Controllers/XML/XMLController.java @@ -0,0 +1,75 @@ +package konogonka.Controllers.XML; + +import javafx.fxml.FXML; +import javafx.scene.control.TextArea; +import konogonka.Controllers.ITabController; +import konogonka.MediatorControl; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.util.ResourceBundle; + +public class XMLController implements ITabController { + @FXML + + private TextArea mainTa; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { } + + /** + * Read from start to end + * */ + @Override + public void analyze(File file) { analyze(file, 0); } + /** + * Read from offset to end + * */ + @Override + public void analyze(File file, long offset) { + try { + if (file.length() - offset > 10485760) // 10mB + throw new Exception("XMLController -> analyze(): File is too big. It must be something wrong with it. Usually they're smaller"); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + if (bis.skip(offset) != offset) + throw new Exception("XMLController -> analyze(): Unable to skip requested range"); + int readChunk = (int) (file.length() - offset); + byte[] buffer = new byte[readChunk]; // Let it be 1kB + if (bis.read(buffer) != readChunk) + throw new Exception("XMLController -> analyze(): Unable to read requested range"); + mainTa.appendText(new String(buffer, 0, readChunk, StandardCharsets.UTF_8)); + bis.close(); + } + catch (Exception e){ + MediatorControl.getInstance().getContoller().logArea.appendText("XMLController -> analyze(): \n"+e.getMessage()); + } + } + /** + * Read from offset to length + * */ + public void analyze(File file, long offset, long fileSize) { + System.out.println(file.length()+" "+offset+" "+fileSize); + try { + if (fileSize > 10485760) // 10mB + throw new Exception("XMLController -> analyze(): File is too big. It must be something wrong with it. Usually they're smaller"); + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); + if (bis.skip(offset) != offset) + throw new Exception("XMLController -> analyze(): Unable to skip requested range"); + byte[] buffer = new byte[(int)fileSize]; // Let it be 1kB + if (bis.read(buffer) != fileSize) + throw new Exception("XMLController -> analyze(): Unable to read requested range"); + mainTa.appendText(new String(buffer, 0, (int) fileSize, StandardCharsets.UTF_8)); + bis.close(); + } + catch (Exception e){ + MediatorControl.getInstance().getContoller().logArea.appendText("XMLController -> analyze(): \n"+e.getMessage()); + } + } + @Override + public void resetTab() { + mainTa.setText(null); + } +} diff --git a/src/main/resources/FXML/XML/XMLTab.fxml b/src/main/resources/FXML/XML/XMLTab.fxml new file mode 100644 index 0000000..0a0942e --- /dev/null +++ b/src/main/resources/FXML/XML/XMLTab.fxml @@ -0,0 +1,11 @@ + + + + + + + + +