Few more fixes
This commit is contained in:
parent
c78fdcdf12
commit
9871510547
2 changed files with 44 additions and 12 deletions
|
@ -73,10 +73,8 @@ public class NxdtController implements Initializable {
|
||||||
dc.setTitle(rb.getString("tabSplMrg_Btn_SelectFolder"));
|
dc.setTitle(rb.getString("tabSplMrg_Btn_SelectFolder"));
|
||||||
dc.setInitialDirectory(new File(saveToLocationLbl.getText()));
|
dc.setInitialDirectory(new File(saveToLocationLbl.getText()));
|
||||||
File saveToDir = dc.showDialog(saveToLocationLbl.getScene().getWindow());
|
File saveToDir = dc.showDialog(saveToLocationLbl.getScene().getWindow());
|
||||||
if (saveToDir != null) {
|
if (saveToDir != null)
|
||||||
saveToLocationLbl.setText(saveToDir.getAbsolutePath());
|
saveToLocationLbl.setText(saveToDir.getAbsolutePath());
|
||||||
statusLbl.setText("FreeSpace: "+saveToDir.getParentFile().getFreeSpace()); //TODO:REMOVE DEBUG
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Start reading commands from NXDT button handler
|
* Start reading commands from NXDT button handler
|
||||||
|
|
|
@ -40,6 +40,7 @@ class NxdtUsbAbi1 {
|
||||||
private String saveToPath;
|
private String saveToPath;
|
||||||
|
|
||||||
private boolean isWindows;
|
private boolean isWindows;
|
||||||
|
private boolean isWindows10;
|
||||||
|
|
||||||
private static final int NXDT_MAX_COMMAND_SIZE = 0x1000;
|
private static final int NXDT_MAX_COMMAND_SIZE = 0x1000;
|
||||||
private static final int NXDT_FILE_CHUNK_SIZE = 0x800000;
|
private static final int NXDT_FILE_CHUNK_SIZE = 0x800000;
|
||||||
|
@ -86,6 +87,9 @@ class NxdtUsbAbi1 {
|
||||||
this.task = task;
|
this.task = task;
|
||||||
this.logPrinter = logPrinter;
|
this.logPrinter = logPrinter;
|
||||||
this.isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
|
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))
|
if (! saveToPath.endsWith(File.separator))
|
||||||
this.saveToPath = saveToPath + File.separator;
|
this.saveToPath = saveToPath + File.separator;
|
||||||
|
@ -119,11 +123,11 @@ class NxdtUsbAbi1 {
|
||||||
handleSendFileProperties(directive);
|
handleSendFileProperties(directive);
|
||||||
break;
|
break;
|
||||||
case CMD_ENDSESSION:
|
case CMD_ENDSESSION:
|
||||||
logPrinter.print("Session successfully ended", EMsgType.PASS);
|
logPrinter.print("Session successfully ended.", EMsgType.PASS);
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
writeUsb(USBSTATUS_UNSUPPORTED_CMD);
|
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{
|
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)){
|
if (! Arrays.equals(Arrays.copyOfRange(message, 0,4), MAGIC_NXDT)){
|
||||||
writeUsb(USBSTATUS_INVALID_MAGIC);
|
writeUsb(USBSTATUS_INVALID_MAGIC);
|
||||||
logPrinter.print("Invalid 'MAGIC'", EMsgType.FAIL);
|
logPrinter.print("Invalid 'MAGIC'", EMsgType.FAIL);
|
||||||
return true;
|
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);
|
int payloadSize = getLEint(message, 0x8);
|
||||||
if (payloadSize + 0x10 != message.length){
|
if (payloadSize + 0x10 != message.length){
|
||||||
writeUsb(USBSTATUS_MALFORMED_REQUEST);
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -207,7 +212,10 @@ class NxdtUsbAbi1 {
|
||||||
|
|
||||||
writeUsb(USBSTATUS_SUCCESS);
|
writeUsb(USBSTATUS_SUCCESS);
|
||||||
|
|
||||||
dumpFile(fileToDump, fileSize);
|
if (isWindows10)
|
||||||
|
dumpFileOnWindowsTen(fileToDump, fileSize);
|
||||||
|
else
|
||||||
|
dumpFile(fileToDump, fileSize);
|
||||||
|
|
||||||
writeUsb(USBSTATUS_SUCCESS);
|
writeUsb(USBSTATUS_SUCCESS);
|
||||||
|
|
||||||
|
@ -259,6 +267,32 @@ class NxdtUsbAbi1 {
|
||||||
bos.close();
|
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
|
* Sending any byte array to USB device
|
||||||
* @return 'false' if no issues
|
* @return 'false' if no issues
|
||||||
|
|
Loading…
Reference in a new issue