Skip to content

Commit

Permalink
DarkMatterCore/nxdumptool support
Browse files Browse the repository at this point in the history
Hotfix within adding DarkMatterCore/nxdumptool support: fix 'Stop' button functionality

Update NxdtUsbAbi1.java

Rename method isInvalidCommand() -> isInvalidCommand()

A bit more renames and debug things

More refactoring

Typos fixes

He just told me that 'NXDT_COMMAND_HEADER_SIZE was added to reflect the UsbCommandHeader struct from my codebase. No received command should ever be smaller than this. NXDT_COMMAND_SIZE was renamed to NXDT_MAX_COMMAND_SIZE for this reason.'

Some bug fixes

With debug

Few more fixes

Copy-paste Windows10 workaround fix

Add NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH validation

Fix NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH validation

If fileSize == 0 only one success reply sent

Add debug

rewrite timeouts

One more rewrite timeouts
  • Loading branch information
developersu committed May 12, 2020
1 parent 6334100 commit 77ae860
Show file tree
Hide file tree
Showing 18 changed files with 726 additions and 143 deletions.
135 changes: 0 additions & 135 deletions Outdated_README_KR.md

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<name>NS-USBloader</name>

<artifactId>ns-usbloader</artifactId>
<version>2.2.1-SNAPSHOT</version>
<version>3.0-SNAPSHOT</version>

<url>https://github.com/developersu/ns-usbloader/</url>
<description>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/nsusbloader/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,7 @@ public String getHostPort(){
// RCM //
public String getRecentRcm(int num){ return preferences.get(String.format("RCM_%02d", num), ""); }
public void setRecentRcm(int num, String value){ preferences.put(String.format("RCM_%02d", num), value); }
// NXDT //
public String getNXDTSaveToLocation(){ return preferences.get("nxdt_saveto", System.getProperty("user.home")); }
public void setNXDTSaveToLocation(String value){ preferences.put("nxdt_saveto", value); }
}
5 changes: 5 additions & 0 deletions src/main/java/nsusbloader/Controllers/NSLMainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class NSLMainController implements Initializable {
private SplitMergeController SplitMergeTabController;
@FXML
private RcmController RcmTabController;
@FXML
private NxdtController NXDTabController;

@Override
public void initialize(URL url, ResourceBundle rb) {
Expand Down Expand Up @@ -110,6 +112,8 @@ public SplitMergeController getSmCtrlr(){
}

public RcmController getRcmCtrlr(){ return RcmTabController; }

public NxdtController getNXDTabController(){ return NXDTabController; }
/**
* Save preferences before exit
* */
Expand All @@ -135,5 +139,6 @@ public void exit(){

SplitMergeTabController.updatePreferencesOnExit(); // NOTE: This shit above should be re-written to similar pattern
RcmTabController.updatePreferencesOnExit();
NXDTabController.updatePreferencesOnExit();
}
}
139 changes: 139 additions & 0 deletions src/main/java/nsusbloader/Controllers/NxdtController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
Copyright 2019-2020 Dmitry Isaenko
This file is part of NS-USBloader.
NS-USBloader is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
NS-USBloader is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with NS-USBloader. If not, see <https://www.gnu.org/licenses/>.
*/
package nsusbloader.Controllers;

import javafx.concurrent.Task;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Region;
import javafx.stage.DirectoryChooser;
import nsusbloader.AppPreferences;
import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EModule;
import nsusbloader.Utilities.NxdtTask;

import java.io.File;
import java.net.URL;
import java.util.ResourceBundle;

public class NxdtController implements Initializable {
@FXML
private Label saveToLocationLbl, statusLbl;

@FXML
private Button injectPldBtn;

private ResourceBundle rb;

private Region btnDumpStopImage;

private Task<Boolean> NxdtTask;
private Thread workThread;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
this.rb = resourceBundle;

File saveToValidator = new File(AppPreferences.getInstance().getNXDTSaveToLocation());
if (saveToValidator.exists())
saveToLocationLbl.setText(saveToValidator.getAbsolutePath());
else
saveToLocationLbl.setText(System.getProperty("user.home"));

btnDumpStopImage = new Region();
btnDumpStopImage.getStyleClass().add("regionDump");

injectPldBtn.getStyleClass().add("buttonUp");
injectPldBtn.setGraphic(btnDumpStopImage);

injectPldBtn.setOnAction(event -> startDumpProcess());
}

@FXML
private void bntSelectSaveTo(){
DirectoryChooser dc = new DirectoryChooser();
dc.setTitle(rb.getString("tabSplMrg_Btn_SelectFolder"));
dc.setInitialDirectory(new File(saveToLocationLbl.getText()));
File saveToDir = dc.showDialog(saveToLocationLbl.getScene().getWindow());
if (saveToDir != null)
saveToLocationLbl.setText(saveToDir.getAbsolutePath());
}
/**
* Start reading commands from NXDT button handler
* */
private void startDumpProcess(){
if ((workThread == null || ! workThread.isAlive())){
MediatorControl.getInstance().getContoller().logArea.clear();

NxdtTask = new NxdtTask(saveToLocationLbl.getText());
NxdtTask.setOnSucceeded(event -> {
if (NxdtTask.getValue())
statusLbl.setText(rb.getString("done_txt"));
else
statusLbl.setText(rb.getString("failure_txt"));
});

workThread = new Thread(NxdtTask);
workThread.setDaemon(true);
workThread.start();
}
}

/**
* Interrupt thread NXDT button handler
* */
private void stopBtnAction(){
if (workThread != null && workThread.isAlive()){
NxdtTask.cancel(false);
}
}

public void notifyThreadStarted(boolean isActive, EModule type){
if (! type.equals(EModule.NXDT)){
injectPldBtn.setDisable(isActive);
return;
}

if (isActive) {
btnDumpStopImage.getStyleClass().clear();
btnDumpStopImage.getStyleClass().add("regionStop");

injectPldBtn.setOnAction(e-> stopBtnAction());
injectPldBtn.setText(rb.getString("btn_Stop"));
injectPldBtn.getStyleClass().remove("buttonUp");
injectPldBtn.getStyleClass().add("buttonStop");
return;
}
btnDumpStopImage.getStyleClass().clear();
btnDumpStopImage.getStyleClass().add("regionDump");

injectPldBtn.setOnAction(e-> startDumpProcess());
injectPldBtn.setText(rb.getString("tabNXDT_Btn_Start"));
injectPldBtn.getStyleClass().remove("buttonStop");
injectPldBtn.getStyleClass().add("buttonUp");
}
/**
* Save application settings on exit
* */
public void updatePreferencesOnExit(){
AppPreferences.getInstance().setNXDTSaveToLocation(saveToLocationLbl.getText());
}
}
1 change: 1 addition & 0 deletions src/main/java/nsusbloader/MediatorControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public synchronized void setBgThreadActive(boolean isActive, EModule appModuleTy
mainCtrler.getFrontCtrlr().notifyTransmThreadStarted(isActive, appModuleType);
mainCtrler.getSmCtrlr().notifySmThreadStarted(isActive, appModuleType);
mainCtrler.getRcmCtrlr().notifySmThreadStarted(isActive, appModuleType);
mainCtrler.getNXDTabController().notifyThreadStarted(isActive, appModuleType);
}
public synchronized boolean getTransferActive() { return this.isTransferActive.get(); }
}
3 changes: 2 additions & 1 deletion src/main/java/nsusbloader/NSLDataTypes/EModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
public enum EModule {
USB_NET_TRANSFERS,
SPLIT_MERGE_TOOL,
RCM
RCM,
NXDT
}
4 changes: 3 additions & 1 deletion src/main/java/nsusbloader/NSLMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@
import javafx.stage.Stage;
import nsusbloader.Controllers.NSLMainController;

import java.io.File;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.ResourceBundle;

public class NSLMain extends Application {

public static final String appVersion = "v2.2.1";
public static final String appVersion = "v3.0";

@Override
public void start(Stage primaryStage) throws Exception{
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/nsusbloader/RainbowHexDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,31 @@ public static void hexDumpUTF8(byte[] byteArray){
System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET);
for (byte b: byteArray)
System.out.print(String.format("%02x ", b));
//System.out.println();
System.out.println();
System.out.print("\t\t\t"
+ new String(byteArray, StandardCharsets.UTF_8)
+ "\n");
}

public static void hexDumpUTF8ForWin(byte[] byteArray){
for (int i=0; i < byteArray.length; i++)
System.out.print(String.format("%02d-", i%100));
System.out.println(">"+byteArray.length);
for (byte b: byteArray)
System.out.print(String.format("%02x ", b));
System.out.println();
System.out.print(new String(byteArray, StandardCharsets.UTF_8)
+ "\n");
}

public static void hexDumpUTF16LE(byte[] byteArray){
System.out.print(ANSI_BLUE);
for (int i=0; i < byteArray.length; i++)
System.out.print(String.format("%02d-", i%100));
System.out.println(">"+ANSI_RED+byteArray.length+ANSI_RESET);
for (byte b: byteArray)
System.out.print(String.format("%02x ", b));
System.out.print("\t\t\t"
+ new String(byteArray, StandardCharsets.UTF_16LE)
System.out.print(new String(byteArray, StandardCharsets.UTF_16LE)
+ "\n");
}
}
Loading

0 comments on commit 77ae860

Please sign in to comment.