v0.2 bug fixes
This commit is contained in:
parent
42782929f9
commit
d3b25d57b1
6 changed files with 33 additions and 12 deletions
|
@ -16,7 +16,15 @@ public class AppPreferences {
|
||||||
theme = "/res/app_dark.css";
|
theme = "/res/app_dark.css";
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
public String getProtocol(){
|
||||||
|
String protocol = preferences.get("PROTOCOL", "TinFoil"); // Don't let user to change settings manually
|
||||||
|
if (!protocol.matches("(^TinFoil$)|(^GoldLeaf$)"))
|
||||||
|
protocol = "TinFoil";
|
||||||
|
return protocol;
|
||||||
|
}
|
||||||
public void setTheme(String theme){ preferences.put("THEME", theme); }
|
public void setTheme(String theme){ preferences.put("THEME", theme); }
|
||||||
|
public void setProtocol(String protocol){ preferences.put("PROTOCOL", protocol); }
|
||||||
|
|
||||||
|
|
||||||
public String getRecent(){ return preferences.get("RECENT", System.getProperty("user.home")); }
|
public String getRecent(){ return preferences.get("RECENT", System.getProperty("user.home")); }
|
||||||
public void setRecent(String path){ preferences.put("RECENT", path); }
|
public void setRecent(String path){ preferences.put("RECENT", path); }
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class NSLMainController implements Initializable {
|
||||||
@FXML
|
@FXML
|
||||||
public NSTableViewController tableFilesListController; // Accessible from Mediator
|
public NSTableViewController tableFilesListController; // Accessible from Mediator
|
||||||
|
|
||||||
|
private UsbCommunications usbCommunications;
|
||||||
private Thread usbThread;
|
private Thread usbThread;
|
||||||
|
|
||||||
private String previouslyOpenedPath;
|
private String previouslyOpenedPath;
|
||||||
|
@ -74,7 +75,7 @@ public class NSLMainController implements Initializable {
|
||||||
|
|
||||||
ObservableList<String> choiceProtocolList = FXCollections.observableArrayList("TinFoil", "GoldLeaf");
|
ObservableList<String> choiceProtocolList = FXCollections.observableArrayList("TinFoil", "GoldLeaf");
|
||||||
choiceProtocol.setItems(choiceProtocolList);
|
choiceProtocol.setItems(choiceProtocolList);
|
||||||
choiceProtocol.getSelectionModel().select(0); // TODO: shared settings
|
choiceProtocol.getSelectionModel().select(AppPreferences.getInstance().getProtocol()); // TODO: shared settings
|
||||||
choiceProtocol.setOnAction(e->tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem())); // Add listener to notify tableView controller
|
choiceProtocol.setOnAction(e->tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem())); // Add listener to notify tableView controller
|
||||||
tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); // Notify tableView controller
|
tableFilesListController.setNewProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); // Notify tableView controller
|
||||||
|
|
||||||
|
@ -99,6 +100,7 @@ public class NSLMainController implements Initializable {
|
||||||
switchThemeBtn.getScene().getStylesheets().remove("/res/app_light.css");
|
switchThemeBtn.getScene().getStylesheets().remove("/res/app_light.css");
|
||||||
switchThemeBtn.getScene().getStylesheets().add("/res/app_dark.css");
|
switchThemeBtn.getScene().getStylesheets().add("/res/app_dark.css");
|
||||||
}
|
}
|
||||||
|
AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Functionality for selecting NSP button.
|
* Functionality for selecting NSP button.
|
||||||
|
@ -142,8 +144,9 @@ public class NSLMainController implements Initializable {
|
||||||
for (File item: nspToUpload)
|
for (File item: nspToUpload)
|
||||||
logArea.appendText(" "+item.getAbsolutePath()+"\n");
|
logArea.appendText(" "+item.getAbsolutePath()+"\n");
|
||||||
}
|
}
|
||||||
UsbCommunications usbCommunications = new UsbCommunications(nspToUpload, choiceProtocol.getSelectionModel().getSelectedItem());
|
usbCommunications = new UsbCommunications(nspToUpload, choiceProtocol.getSelectionModel().getSelectedItem());
|
||||||
usbThread = new Thread(usbCommunications);
|
usbThread = new Thread(usbCommunications);
|
||||||
|
usbThread.setDaemon(true);
|
||||||
usbThread.start();
|
usbThread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +155,7 @@ public class NSLMainController implements Initializable {
|
||||||
* */
|
* */
|
||||||
private void stopBtnAction(){
|
private void stopBtnAction(){
|
||||||
if (usbThread != null && usbThread.isAlive()){
|
if (usbThread != null && usbThread.isAlive()){
|
||||||
usbThread.interrupt();
|
usbCommunications.cancel(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -189,7 +192,7 @@ public class NSLMainController implements Initializable {
|
||||||
* Save preferences before exit
|
* Save preferences before exit
|
||||||
* */
|
* */
|
||||||
public void exit(){
|
public void exit(){
|
||||||
AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0));
|
AppPreferences.getInstance().setProtocol(choiceProtocol.getSelectionModel().getSelectedItem());
|
||||||
AppPreferences.getInstance().setRecent(previouslyOpenedPath);
|
AppPreferences.getInstance().setRecent(previouslyOpenedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,9 @@ public class NSLRowModel {
|
||||||
case FAILED:
|
case FAILED:
|
||||||
this.status = "Failed";
|
this.status = "Failed";
|
||||||
break;
|
break;
|
||||||
|
case UNKNOWN:
|
||||||
|
this.status = "...";
|
||||||
|
break;
|
||||||
case INCORRECT_FILE_FAILED:
|
case INCORRECT_FILE_FAILED:
|
||||||
this.status = "Failed: Incorrect file";
|
this.status = "Failed: Incorrect file";
|
||||||
markForUpload = false;
|
markForUpload = false;
|
||||||
|
|
|
@ -125,7 +125,7 @@ public class NSTableViewController implements Initializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Return files ready for upload. Requested from NSLMainController only
|
* Return files ready for upload. Requested from NSLMainController only -> uploadBtnAction() //TODO: set undefined
|
||||||
* @return null if no files marked for upload
|
* @return null if no files marked for upload
|
||||||
* List<File> if there are files
|
* List<File> if there are files
|
||||||
* */
|
* */
|
||||||
|
@ -135,11 +135,15 @@ public class NSTableViewController implements Initializable {
|
||||||
return null;
|
return null;
|
||||||
else {
|
else {
|
||||||
for (NSLRowModel model: rowsObsLst){
|
for (NSLRowModel model: rowsObsLst){
|
||||||
if (model.isMarkForUpload())
|
if (model.isMarkForUpload()){
|
||||||
files.add(model.getNspFile());
|
files.add(model.getNspFile());
|
||||||
|
model.setStatus(EFileStatus.UNKNOWN);
|
||||||
}
|
}
|
||||||
if (!files.isEmpty())
|
}
|
||||||
|
if (!files.isEmpty()) {
|
||||||
|
table.refresh();
|
||||||
return files;
|
return files;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package nsusbloader.NSLDataTypes;
|
package nsusbloader.NSLDataTypes;
|
||||||
|
|
||||||
public enum EFileStatus {
|
public enum EFileStatus {
|
||||||
UPLOADED, INCORRECT_FILE_FAILED, FAILED
|
UPLOADED, INCORRECT_FILE_FAILED, FAILED, UNKNOWN
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import java.util.List;
|
||||||
import java.util.concurrent.BlockingQueue;
|
import java.util.concurrent.BlockingQueue;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
|
import static nsusbloader.RainbowHexDump.hexDumpUTF8;
|
||||||
|
|
||||||
public class UsbCommunications extends Task<Void> {
|
public class UsbCommunications extends Task<Void> {
|
||||||
private final int DEFAULT_INTERFACE = 0;
|
private final int DEFAULT_INTERFACE = 0;
|
||||||
|
|
||||||
|
@ -349,7 +351,7 @@ public class UsbCommunications extends Task<Void> {
|
||||||
byte[] receivedArray;
|
byte[] receivedArray;
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
if (Thread.currentThread().isInterrupted()) // Check if user interrupted process.
|
if (isCancelled()) // Check if user interrupted process.
|
||||||
return false;
|
return false;
|
||||||
receivedArray = readFromUsb();
|
receivedArray = readFromUsb();
|
||||||
if (receivedArray == null)
|
if (receivedArray == null)
|
||||||
|
@ -428,7 +430,7 @@ public class UsbCommunications extends Task<Void> {
|
||||||
int readPice = 8388608; // = 8Mb
|
int readPice = 8388608; // = 8Mb
|
||||||
|
|
||||||
while (currentOffset < receivedRangeSize){
|
while (currentOffset < receivedRangeSize){
|
||||||
if (Thread.currentThread().isInterrupted()) // Check if user interrupted process.
|
if (isCancelled()) // Check if user interrupted process.
|
||||||
return true;
|
return true;
|
||||||
if ((currentOffset + readPice) >= receivedRangeSize )
|
if ((currentOffset + readPice) >= receivedRangeSize )
|
||||||
readPice = Math.toIntExact(receivedRangeSize - currentOffset);
|
readPice = Math.toIntExact(receivedRangeSize - currentOffset);
|
||||||
|
@ -561,6 +563,7 @@ public class UsbCommunications extends Task<Void> {
|
||||||
readByte = readFromUsb();
|
readByte = readFromUsb();
|
||||||
if (readByte == null)
|
if (readByte == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Arrays.equals(readByte, CMD_ConnectionResponse)) {
|
if (Arrays.equals(readByte, CMD_ConnectionResponse)) {
|
||||||
if (!handleConnectionResponse(pfsElement))
|
if (!handleConnectionResponse(pfsElement))
|
||||||
return false;
|
return false;
|
||||||
|
@ -699,7 +702,7 @@ public class UsbCommunications extends Task<Void> {
|
||||||
|
|
||||||
while (readFrom < realNcaSize){
|
while (readFrom < realNcaSize){
|
||||||
|
|
||||||
if (Thread.currentThread().isInterrupted()) // Check if user interrupted process.
|
if (isCancelled()) // Check if user interrupted process.
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (realNcaSize - readFrom < readPice)
|
if (realNcaSize - readFrom < readPice)
|
||||||
|
@ -707,7 +710,7 @@ public class UsbCommunications extends Task<Void> {
|
||||||
readBuf = new byte[readPice];
|
readBuf = new byte[readPice];
|
||||||
if (bufferedInStream.read(readBuf) != readPice)
|
if (bufferedInStream.read(readBuf) != readPice)
|
||||||
return false;
|
return false;
|
||||||
|
//System.out.println("S: "+readFrom+" T: "+realNcaSize+" P: "+readPice); // DEBUG
|
||||||
if (!writeToUsb(readBuf))
|
if (!writeToUsb(readBuf))
|
||||||
return false;
|
return false;
|
||||||
//-----------------------------------------/
|
//-----------------------------------------/
|
||||||
|
|
Loading…
Reference in a new issue