diff --git a/src/main/java/nsusbloader/Controllers/NxdtController.java b/src/main/java/nsusbloader/Controllers/NxdtController.java index 6a51586..74ba291 100644 --- a/src/main/java/nsusbloader/Controllers/NxdtController.java +++ b/src/main/java/nsusbloader/Controllers/NxdtController.java @@ -73,10 +73,8 @@ public class NxdtController implements Initializable { dc.setTitle(rb.getString("tabSplMrg_Btn_SelectFolder")); dc.setInitialDirectory(new File(saveToLocationLbl.getText())); File saveToDir = dc.showDialog(saveToLocationLbl.getScene().getWindow()); - if (saveToDir != null) { + if (saveToDir != null) saveToLocationLbl.setText(saveToDir.getAbsolutePath()); - statusLbl.setText("FreeSpace: "+saveToDir.getParentFile().getFreeSpace()); //TODO:REMOVE DEBUG - } } /** * Start reading commands from NXDT button handler diff --git a/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java b/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java index 6527929..0ee9b4e 100644 --- a/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java +++ b/src/main/java/nsusbloader/Utilities/NxdtUsbAbi1.java @@ -40,6 +40,7 @@ class NxdtUsbAbi1 { private String saveToPath; private boolean isWindows; + private boolean isWindows10; private static final int NXDT_MAX_COMMAND_SIZE = 0x1000; private static final int NXDT_FILE_CHUNK_SIZE = 0x800000; @@ -86,6 +87,9 @@ class NxdtUsbAbi1 { this.task = task; this.logPrinter = logPrinter; this.isWindows = System.getProperty("os.name").toLowerCase().contains("windows"); + + if (isWindows) + isWindows10 = System.getProperty("os.name").toLowerCase().contains("windows 10"); if (! saveToPath.endsWith(File.separator)) this.saveToPath = saveToPath + File.separator; @@ -119,11 +123,11 @@ class NxdtUsbAbi1 { handleSendFileProperties(directive); break; case CMD_ENDSESSION: - logPrinter.print("Session successfully ended", EMsgType.PASS); + logPrinter.print("Session successfully ended.", EMsgType.PASS); return; default: writeUsb(USBSTATUS_UNSUPPORTED_CMD); - logPrinter.print("Unsupported command: " + command, EMsgType.FAIL); + logPrinter.print(String.format("Unsupported command 0x%08x", command), EMsgType.FAIL); } } } @@ -138,21 +142,22 @@ class NxdtUsbAbi1 { }; private boolean isInvalidDirective(byte[] message) throws Exception{ + if (message.length < 0x10){ + writeUsb(USBSTATUS_MALFORMED_REQUEST); + logPrinter.print("Directive is too small. Only "+message.length+" bytes received.", EMsgType.FAIL); + return true; + } + if (! Arrays.equals(Arrays.copyOfRange(message, 0,4), MAGIC_NXDT)){ writeUsb(USBSTATUS_INVALID_MAGIC); logPrinter.print("Invalid 'MAGIC'", EMsgType.FAIL); return true; } - if (message.length < 0x10){ - writeUsb(USBSTATUS_MALFORMED_REQUEST); - logPrinter.print("Directive is too small to be a command. Only "+message.length+" bytes received.", EMsgType.FAIL); - return true; - } int payloadSize = getLEint(message, 0x8); if (payloadSize + 0x10 != message.length){ writeUsb(USBSTATUS_MALFORMED_REQUEST); - logPrinter.print("Invalid directive size. "+message.length+" bytes received while "+payloadSize+" expected.", EMsgType.FAIL); + logPrinter.print("Invalid directive info block size. "+message.length+" bytes received while "+payloadSize+" expected.", EMsgType.FAIL); return true; } return false; @@ -207,7 +212,10 @@ class NxdtUsbAbi1 { writeUsb(USBSTATUS_SUCCESS); - dumpFile(fileToDump, fileSize); + if (isWindows10) + dumpFileOnWindowsTen(fileToDump, fileSize); + else + dumpFile(fileToDump, fileSize); writeUsb(USBSTATUS_SUCCESS); @@ -259,6 +267,32 @@ class NxdtUsbAbi1 { bos.close(); } + // @see https://bugs.openjdk.java.net/browse/JDK-8146538 + private void dumpFileOnWindowsTen(File file, long size) throws Exception{ + FileOutputStream fos = new FileOutputStream(file, true); + BufferedOutputStream bos = new BufferedOutputStream(fos); + FileDescriptor fd = fos.getFD(); + + byte[] readBuffer; + long received = 0; + int bufferSize; + + while (received < size){ + readBuffer = readUsbFile(); + + bos.write(readBuffer); + fd.sync(); // Fixes flushing under Windows (unharmful for other OS) + + bufferSize = readBuffer.length; + received += bufferSize; + + logPrinter.updateProgress((received + bufferSize) / (size / 100.0) / 100.0); + } + + logPrinter.updateProgress(1.0); + bos.close(); + } + /** * Sending any byte array to USB device * @return 'false' if no issues