Compare commits
No commits in common. "050982f8eaa22c071e7e9416f05a4c440bbd14b4" and "6e21c514a8503d5c970e5303698b37576ffc1214" have entirely different histories.
050982f8ea
...
6e21c514a8
3 changed files with 85 additions and 97 deletions
21
Jenkinsfile
vendored
21
Jenkinsfile
vendored
|
@ -7,25 +7,20 @@ pipeline {
|
||||||
}
|
}
|
||||||
|
|
||||||
stages {
|
stages {
|
||||||
stage('Build') {
|
|
||||||
steps {
|
|
||||||
sh 'mvn -B -DskipTests clean package'
|
|
||||||
}
|
|
||||||
post {
|
|
||||||
success {
|
|
||||||
archiveArtifacts artifacts: 'target/*.jar, target/*.exe'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stage('Test') {
|
stage('Test') {
|
||||||
steps {
|
steps {
|
||||||
sh 'mvn test'
|
sh 'mvn test'
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
stage('Build') {
|
||||||
|
steps {
|
||||||
|
sh 'mvn clean package'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
junit 'target/surefire-reports/*.xml'
|
archiveArtifacts artifacts: 'target/*.jar, target/*.exe', onlyIfSuccessful: true
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -45,7 +45,7 @@ class NxdtUsbAbi1 {
|
||||||
private final boolean isWindows;
|
private final boolean isWindows;
|
||||||
private boolean isWindows10;
|
private boolean isWindows10;
|
||||||
|
|
||||||
private static final int NXDT_MAX_DIRECTIVE_SIZE = 0x800000;//0x1000;
|
private static final int NXDT_MAX_DIRECTIVE_SIZE = 0x1000;
|
||||||
private static final int NXDT_FILE_CHUNK_SIZE = 0x800000;
|
private static final int NXDT_FILE_CHUNK_SIZE = 0x800000;
|
||||||
private static final int NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH = 0x300;
|
private static final int NXDT_FILE_PROPERTIES_MAX_NAME_LENGTH = 0x300;
|
||||||
|
|
||||||
|
@ -212,6 +212,8 @@ class NxdtUsbAbi1 {
|
||||||
String absoluteFilePath = getAbsoluteFilePath(filename);
|
String absoluteFilePath = getAbsoluteFilePath(filename);
|
||||||
File fileToDump = new File(absoluteFilePath);
|
File fileToDump = new File(absoluteFilePath);
|
||||||
|
|
||||||
|
boolean nspTransferMode = false;
|
||||||
|
|
||||||
if (checkSizes(fullSize, headerSize))
|
if (checkSizes(fullSize, headerSize))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -223,10 +225,15 @@ class NxdtUsbAbi1 {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (headerSize > 0){ // if NSP
|
if (headerSize > 0){ // if NSP
|
||||||
logPrinter.print("Receiving NSP file: '"+filename+"' ("+formatByteSize(fullSize)+")", EMsgType.PASS);
|
logPrinter.print("Receiving NSP file entry: '"+filename+"' ("+fullSize+" b)", EMsgType.INFO);
|
||||||
|
if (filename.equals(nspFile.getName())){
|
||||||
|
nspTransferMode = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
createNewNsp(filename, headerSize, fullSize, fileToDump);
|
createNewNsp(filename, headerSize, fullSize, fileToDump);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: Note, in case of a big amount of small files performance decreases dramatically. It's better to handle this only in case of 1-big-file-transfer
|
// TODO: Note, in case of a big amount of small files performance decreases dramatically. It's better to handle this only in case of 1-big-file-transfer
|
||||||
logPrinter.print("Receiving: '"+filename+"' ("+fullSize+" b)", EMsgType.INFO);
|
logPrinter.print("Receiving: '"+filename+"' ("+fullSize+" b)", EMsgType.INFO);
|
||||||
|
@ -237,7 +244,7 @@ class NxdtUsbAbi1 {
|
||||||
if (fullSize == 0)
|
if (fullSize == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (isNspTransfer())
|
if (nspTransferMode)
|
||||||
dumpNspFile(nspFile, fullSize);
|
dumpNspFile(nspFile, fullSize);
|
||||||
else
|
else
|
||||||
dumpFile(fileToDump, fullSize);
|
dumpFile(fileToDump, fullSize);
|
||||||
|
@ -254,8 +261,8 @@ class NxdtUsbAbi1 {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
private boolean checkSizes(long fileSize, int headerSize) throws Exception{
|
private boolean checkSizes(long fileSize, int headerSize) throws Exception{
|
||||||
if (headerSize >= fileSize){
|
if (fileSize >= headerSize){
|
||||||
logPrinter.print(String.format("File size (%d) should not be less or equal to header size (%d)!", fileSize, headerSize), EMsgType.FAIL);
|
logPrinter.print("File size should not be equal to header size for NSP files!", EMsgType.FAIL);
|
||||||
resetNsp();
|
resetNsp();
|
||||||
writeUsb(USBSTATUS_MALFORMED_REQUEST);
|
writeUsb(USBSTATUS_MALFORMED_REQUEST);
|
||||||
return true;
|
return true;
|
||||||
|
@ -268,6 +275,7 @@ class NxdtUsbAbi1 {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkFileSystem(File fileToDump, long fileSize) throws Exception{
|
private boolean checkFileSystem(File fileToDump, long fileSize) throws Exception{
|
||||||
// Check if enough space
|
// Check if enough space
|
||||||
if (fileToDump.getParentFile().getFreeSpace() <= fileSize){
|
if (fileToDump.getParentFile().getFreeSpace() <= fileSize){
|
||||||
|
@ -289,8 +297,7 @@ class NxdtUsbAbi1 {
|
||||||
nspFile = new NxdtNspFile(filename, headerSize, fileSize, fileToDump);
|
nspFile = new NxdtNspFile(filename, headerSize, fileSize, fileToDump);
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
logPrinter.print("Unable to create new file for: "+filename+" :"+e.getMessage(), EMsgType.FAIL);
|
logPrinter.print(e.getMessage(), EMsgType.FAIL);
|
||||||
e.printStackTrace();
|
|
||||||
writeUsb(USBSTATUS_HOSTIOERROR);
|
writeUsb(USBSTATUS_HOSTIOERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -303,9 +310,6 @@ class NxdtUsbAbi1 {
|
||||||
private long getLElong(byte[] bytes, int fromOffset){
|
private long getLElong(byte[] bytes, int fromOffset){
|
||||||
return ByteBuffer.wrap(bytes, fromOffset, 0x8).order(ByteOrder.LITTLE_ENDIAN).getLong();
|
return ByteBuffer.wrap(bytes, fromOffset, 0x8).order(ByteOrder.LITTLE_ENDIAN).getLong();
|
||||||
}
|
}
|
||||||
private boolean isNspTransfer(){
|
|
||||||
return nspFile != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAbsoluteFilePath(String filename) throws Exception{
|
private String getAbsoluteFilePath(String filename) throws Exception{
|
||||||
if (isRomFs(filename) && isWindows) // Since RomFS entry starts from '/' it should be replaced to '\'.
|
if (isRomFs(filename) && isWindows) // Since RomFS entry starts from '/' it should be replaced to '\'.
|
||||||
|
@ -363,10 +367,9 @@ class NxdtUsbAbi1 {
|
||||||
private void dumpNspFile(NxdtNspFile nsp, long size) throws Exception{
|
private void dumpNspFile(NxdtNspFile nsp, long size) throws Exception{
|
||||||
FileOutputStream fos = new FileOutputStream(nsp.getFile(), true);
|
FileOutputStream fos = new FileOutputStream(nsp.getFile(), true);
|
||||||
long nspSize = nsp.getFullSize();
|
long nspSize = nsp.getFullSize();
|
||||||
|
|
||||||
try (BufferedOutputStream bos = new BufferedOutputStream(fos)) {
|
|
||||||
long nspRemainingSize = nsp.getNspRemainingSize();
|
long nspRemainingSize = nsp.getNspRemainingSize();
|
||||||
|
|
||||||
|
try (BufferedOutputStream bos = new BufferedOutputStream(fos)) {
|
||||||
FileDescriptor fd = fos.getFD();
|
FileDescriptor fd = fos.getFD();
|
||||||
byte[] readBuffer;
|
byte[] readBuffer;
|
||||||
long received = 0;
|
long received = 0;
|
||||||
|
@ -390,6 +393,8 @@ class NxdtUsbAbi1 {
|
||||||
if (isWindows10)
|
if (isWindows10)
|
||||||
fd.sync();
|
fd.sync();
|
||||||
nspRemainingSize -= (lastChunkSize - 1);
|
nspRemainingSize -= (lastChunkSize - 1);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
nsp.setNspRemainingSize(nspRemainingSize);
|
nsp.setNspRemainingSize(nspRemainingSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,8 +427,7 @@ class NxdtUsbAbi1 {
|
||||||
raf.seek(0);
|
raf.seek(0);
|
||||||
raf.write(headerData);
|
raf.write(headerData);
|
||||||
}
|
}
|
||||||
logPrinter.print("NSP file: '"+nsp.getName()+"' successfully received!", EMsgType.PASS);
|
|
||||||
logPrinter.updateProgress(1.0);
|
|
||||||
writeUsb(USBSTATUS_SUCCESS);
|
writeUsb(USBSTATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
private void resetNsp(){
|
private void resetNsp(){
|
||||||
|
@ -530,13 +534,4 @@ class NxdtUsbAbi1 {
|
||||||
"\n Returned: " + UsbErrorCodes.getErrCode(result) +
|
"\n Returned: " + UsbErrorCodes.getErrCode(result) +
|
||||||
"\n (execution stopped)");
|
"\n (execution stopped)");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String formatByteSize(double length) {
|
|
||||||
final String[] unitNames = { "bytes", "KiB", "MiB", "GiB", "TiB"};
|
|
||||||
int i;
|
|
||||||
for (i = 0; length > 1024 && i < unitNames.length - 1; i++) {
|
|
||||||
length = length / 1024;
|
|
||||||
}
|
|
||||||
return String.format("%,.2f %s", length, unitNames[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,19 +64,14 @@ class GoldLeaf_08 extends TransferModule {
|
||||||
private long virtDriveSize;
|
private long virtDriveSize;
|
||||||
private HashMap<String, Long> splitFileSize;
|
private HashMap<String, Long> splitFileSize;
|
||||||
|
|
||||||
private final boolean isWindows;
|
private boolean isWindows;
|
||||||
private final String homePath;
|
private String homePath;
|
||||||
// For using in CMD_SelectFile with SPEC:/ prefix
|
// For using in CMD_SelectFile with SPEC:/ prefix
|
||||||
private File selectedFile;
|
private File selectedFile;
|
||||||
|
|
||||||
private final CancellableRunnable task;
|
private CancellableRunnable task;
|
||||||
|
|
||||||
GoldLeaf_08(DeviceHandle handler,
|
GoldLeaf_08(DeviceHandle handler, LinkedHashMap<String, File> nspMap, CancellableRunnable task, ILogPrinter logPrinter, boolean nspFilter){
|
||||||
LinkedHashMap<String, File> nspMap,
|
|
||||||
CancellableRunnable task,
|
|
||||||
ILogPrinter logPrinter,
|
|
||||||
boolean nspFilter)
|
|
||||||
{
|
|
||||||
super(handler, nspMap, task, logPrinter);
|
super(handler, nspMap, task, logPrinter);
|
||||||
|
|
||||||
this.task = task;
|
this.task = task;
|
||||||
|
@ -895,7 +890,7 @@ class GoldLeaf_08 extends TransferModule {
|
||||||
if (fileName.startsWith("VIRT:/")){
|
if (fileName.startsWith("VIRT:/")){
|
||||||
return writeGL_FAIL("GL Handle 'WriteFile' command [not supported for virtual drive]");
|
return writeGL_FAIL("GL Handle 'WriteFile' command [not supported for virtual drive]");
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
fileName = updateHomePath(fileName);
|
fileName = updateHomePath(fileName);
|
||||||
// Check if we didn't see this (or any) file during this session
|
// Check if we didn't see this (or any) file during this session
|
||||||
if (writeFilesMap.size() == 0 || (! writeFilesMap.containsKey(fileName))){
|
if (writeFilesMap.size() == 0 || (! writeFilesMap.containsKey(fileName))){
|
||||||
|
@ -932,6 +927,7 @@ class GoldLeaf_08 extends TransferModule {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle 'SelectFile'
|
* Handle 'SelectFile'
|
||||||
|
@ -942,16 +938,12 @@ class GoldLeaf_08 extends TransferModule {
|
||||||
File selectedFile = CompletableFuture.supplyAsync(() -> {
|
File selectedFile = CompletableFuture.supplyAsync(() -> {
|
||||||
FileChooser fChooser = new FileChooser();
|
FileChooser fChooser = new FileChooser();
|
||||||
fChooser.setTitle(MediatorControl.getInstance().getContoller().getResourceBundle().getString("btn_OpenFile")); // TODO: FIX BAD IMPLEMENTATION
|
fChooser.setTitle(MediatorControl.getInstance().getContoller().getResourceBundle().getString("btn_OpenFile")); // TODO: FIX BAD IMPLEMENTATION
|
||||||
fChooser.setInitialDirectory(new File(System.getProperty("user.home")));// TODO: Consider fixing; not a prio.
|
fChooser.setInitialDirectory(new File(System.getProperty("user.home"))); // TODO: Consider fixing; not a prio.
|
||||||
fChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("*", "*"));
|
fChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("*", "*"));
|
||||||
return fChooser.showOpenDialog(null); // Leave as is for now.
|
return fChooser.showOpenDialog(null); // Leave as is for now.
|
||||||
}, Platform::runLater).join();
|
}, Platform::runLater).join();
|
||||||
|
|
||||||
if (selectedFile == null){ // Nothing selected
|
if (selectedFile != null){
|
||||||
this.selectedFile = null;
|
|
||||||
return writeGL_FAIL("GL Handle 'SelectFile' command: Nothing selected");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<byte[]> command = new LinkedList<>();
|
List<byte[]> command = new LinkedList<>();
|
||||||
byte[] selectedFileNameBytes = ("SPEC:/"+selectedFile.getName()).getBytes(StandardCharsets.UTF_16LE);
|
byte[] selectedFileNameBytes = ("SPEC:/"+selectedFile.getName()).getBytes(StandardCharsets.UTF_16LE);
|
||||||
command.add(intToArrLE(selectedFileNameBytes.length / 2)); // since GL 0.7
|
command.add(intToArrLE(selectedFileNameBytes.length / 2)); // since GL 0.7
|
||||||
|
@ -964,6 +956,10 @@ class GoldLeaf_08 extends TransferModule {
|
||||||
this.selectedFile = selectedFile;
|
this.selectedFile = selectedFile;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Nothing selected; Report failure.
|
||||||
|
this.selectedFile = null;
|
||||||
|
return writeGL_FAIL("GL Handle 'SelectFile' command: Nothing selected");
|
||||||
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------*/
|
/*----------------------------------------------------*/
|
||||||
/* GL HELPERS */
|
/* GL HELPERS */
|
||||||
|
@ -1043,7 +1039,9 @@ class GoldLeaf_08 extends TransferModule {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private byte[] readGL_file(){
|
private byte[] readGL_file(){
|
||||||
ByteBuffer readBuffer = ByteBuffer.allocateDirect(8388608); // Just don't ask..
|
ByteBuffer readBuffer;
|
||||||
|
readBuffer = ByteBuffer.allocateDirect(8388608); // Just don't ask..
|
||||||
|
|
||||||
IntBuffer readBufTransferred = IntBuffer.allocate(1);
|
IntBuffer readBufTransferred = IntBuffer.allocate(1);
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
|
|
Loading…
Reference in a new issue