Skip to content

Commit

Permalink
Add split-files support for every 'protocol' supported
Browse files Browse the repository at this point in the history
  • Loading branch information
developersu committed Oct 26, 2019
1 parent 077aa9b commit 049c07f
Show file tree
Hide file tree
Showing 28 changed files with 616 additions and 263 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ With GUI and cookies. Works on Windows, macOS and Linux.

Sometimes I add new posts about this project [on my home page](https://developersu.blogspot.com/search/label/NS-USBloader).

![Screenshot](https://farm8.staticflickr.com/7809/46703921964_53f60f04ed_o.png)
![Screenshot](https://live.staticflickr.com/65535/48962978677_4c3913e8a9_o.png)

#### License

Expand Down Expand Up @@ -99,7 +99,7 @@ There are three tabs. First one is main.

At the top of you selecting from drop-down application and protocol that you're going to use. For GoldLeaf only USB is available. Lamp icon stands for switching themes (light or dark).

Then you may drag-n-drop folder with NSPs OR files to application or use 'Select NSP files' button. Multiple selection for files available. Click it again and select files from another folder it you want, it will be added into the table.
Then you may drag-n-drop files (split-files aka folders) to application or use 'Select NSP files' button. Multiple selection for files available. Click it again and select files from another folder it you want, it will be added into the table.

Table.

Expand Down Expand Up @@ -140,13 +140,16 @@ usb4java since NS-USBloader-v0.2.3 switched to 1.2.0 instead of 1.3.0. This shou

### Translators!
If you want to see this app translated to your language, go grab [this file](https://github.com/developersu/ns-usbloader/blob/master/src/main/resources/locale.properties) and translate it.
Upload somewhere (create PR, use pastebin/google drive/whatever else). [Create new issue](https://github.com/developersu/ns-usbloader/issues) and post a link. I'll grab it and add.

Upload somewhere (create PR, use pastebin/google drive/whatever else). [Create new issue](https://github.com/developersu/ns-usbloader/issues) and post a link. I'll grab it and add.

To convert files of any locale to readable format (and vise-versa) you can use this site [https://itpro.cz/juniconv/](https://itpro.cz/juniconv/)


#### TODO (maybe):
- [x] [Android support](https://github.com/developersu/ns-usbloader-mobile)
- [ ] File order sort (non-critical)
- [ ] More deep file analyze before uploading.
- [ ] XCI support

## Support this app

Expand Down
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>0.8.2-SNAPSHOT</version>
<version>0.9-SNAPSHOT</version>

<url>https://github.com/developersu/ns-usbloader/</url>
<description>
Expand Down
91 changes: 91 additions & 0 deletions src/main/java/nsusbloader/COM/Helpers/NSSplitReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package nsusbloader.COM.Helpers;

import java.io.*;

/**
* Handle Split files
* */
public class NSSplitReader implements Closeable {

private final String splitFileDir;
private final long referenceSplitChunkSize;

private byte subFileNum;
private long curPosition;
private BufferedInputStream biStream;

public NSSplitReader(File file, long seekToPosition) throws IOException, NullPointerException {
this.splitFileDir = file.getAbsolutePath()+File.separator;
File subFile = new File(file.getAbsolutePath()+File.separator+"00");
if (! file.exists())
throw new FileNotFoundException("File not found on "+file.getAbsolutePath()+File.separator+"00");
this.referenceSplitChunkSize = subFile.length();
this.subFileNum = (byte) (seekToPosition / referenceSplitChunkSize);
this.biStream = new BufferedInputStream(new FileInputStream(splitFileDir + String.format("%02d", subFileNum)));
this.curPosition = seekToPosition;

seekToPosition -= referenceSplitChunkSize * subFileNum;

if (seekToPosition != biStream.skip(seekToPosition))
throw new IOException("Unable to seek to requested position of "+seekToPosition+" for file "+splitFileDir+String.format("%02d", subFileNum));
}

public long seek(long position) throws IOException{

byte subFileRequested = (byte) (position / referenceSplitChunkSize);

if ((subFileRequested != this.subFileNum) || (curPosition > position)) {
biStream.close();
biStream = new BufferedInputStream(new FileInputStream(splitFileDir + String.format("%02d", subFileRequested)));
this.subFileNum = subFileRequested;
this.curPosition = referenceSplitChunkSize * subFileRequested;
}

long retVal = biStream.skip(position - curPosition);

retVal += curPosition;
this.curPosition = position;
return retVal;
}

public int read(byte[] readBuffer) throws IOException, NullPointerException {
final int requested = readBuffer.length;
int readPrtOne;

if ( (curPosition + requested) <= (referenceSplitChunkSize * (subFileNum+1))) {
if ((readPrtOne = biStream.read(readBuffer)) < 0 )
return readPrtOne;
curPosition += readPrtOne;
return readPrtOne;
}

int partOne = (int) (referenceSplitChunkSize * (subFileNum+1) - curPosition);
int partTwo = requested - partOne;
int readPrtTwo;

if ( (readPrtOne = biStream.read(readBuffer, 0, partOne)) < 0)
return readPrtOne;

curPosition += readPrtOne;

if (readPrtOne != partOne)
return readPrtOne;

biStream.close();
subFileNum += 1;
biStream = new BufferedInputStream(new FileInputStream(splitFileDir + String.format("%02d", subFileNum)));

if ( (readPrtTwo = biStream.read(readBuffer, partOne, partTwo) ) < 0)
return readPrtTwo;

curPosition += readPrtTwo;

return readPrtOne + readPrtTwo;
}

@Override
public void close() throws IOException {
if (biStream != null)
biStream.close();
}
}
Loading

0 comments on commit 049c07f

Please sign in to comment.