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"; | ||||
|         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 setProtocol(String protocol){ preferences.put("PROTOCOL", protocol); } | ||||
| 
 | ||||
| 
 | ||||
|     public String getRecent(){ return preferences.get("RECENT", System.getProperty("user.home")); } | ||||
|     public void setRecent(String path){ preferences.put("RECENT", path); } | ||||
|  |  | |||
|  | @ -42,6 +42,7 @@ public class NSLMainController implements Initializable { | |||
|     @FXML | ||||
|     public NSTableViewController tableFilesListController;            // Accessible from Mediator | ||||
| 
 | ||||
|     private UsbCommunications usbCommunications; | ||||
|     private Thread usbThread; | ||||
| 
 | ||||
|     private String previouslyOpenedPath; | ||||
|  | @ -74,7 +75,7 @@ public class NSLMainController implements Initializable { | |||
| 
 | ||||
|         ObservableList<String> choiceProtocolList = FXCollections.observableArrayList("TinFoil", "GoldLeaf"); | ||||
|         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 | ||||
|         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().add("/res/app_dark.css"); | ||||
|         } | ||||
|         AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0)); | ||||
|     } | ||||
|     /** | ||||
|      * Functionality for selecting NSP button. | ||||
|  | @ -142,8 +144,9 @@ public class NSLMainController implements Initializable { | |||
|                 for (File item: nspToUpload) | ||||
|                     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.setDaemon(true); | ||||
|             usbThread.start(); | ||||
|         } | ||||
|     } | ||||
|  | @ -152,7 +155,7 @@ public class NSLMainController implements Initializable { | |||
|      * */ | ||||
|     private void stopBtnAction(){ | ||||
|         if (usbThread != null && usbThread.isAlive()){ | ||||
|             usbThread.interrupt(); | ||||
|             usbCommunications.cancel(false); | ||||
|         } | ||||
|     } | ||||
|     /** | ||||
|  | @ -189,7 +192,7 @@ public class NSLMainController implements Initializable { | |||
|      * Save preferences before exit | ||||
|      * */ | ||||
|     public void exit(){ | ||||
|         AppPreferences.getInstance().setTheme(switchThemeBtn.getScene().getStylesheets().get(0)); | ||||
|         AppPreferences.getInstance().setProtocol(choiceProtocol.getSelectionModel().getSelectedItem()); | ||||
|         AppPreferences.getInstance().setRecent(previouslyOpenedPath); | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -45,6 +45,9 @@ public class NSLRowModel { | |||
|             case FAILED: | ||||
|                 this.status = "Failed"; | ||||
|                 break; | ||||
|             case UNKNOWN: | ||||
|                 this.status = "..."; | ||||
|                 break; | ||||
|             case INCORRECT_FILE_FAILED: | ||||
|                 this.status = "Failed: Incorrect file"; | ||||
|                 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 | ||||
|      *         List<File> if there are files | ||||
|      * */ | ||||
|  | @ -135,11 +135,15 @@ public class NSTableViewController implements Initializable { | |||
|             return null; | ||||
|         else { | ||||
|             for (NSLRowModel model: rowsObsLst){ | ||||
|                 if (model.isMarkForUpload()) | ||||
|                 if (model.isMarkForUpload()){ | ||||
|                     files.add(model.getNspFile()); | ||||
|                     model.setStatus(EFileStatus.UNKNOWN); | ||||
|                 } | ||||
|             if (!files.isEmpty()) | ||||
|             } | ||||
|             if (!files.isEmpty()) { | ||||
|                 table.refresh(); | ||||
|                 return files; | ||||
|             } | ||||
|             else | ||||
|                 return null; | ||||
|         } | ||||
|  |  | |||
|  | @ -1,5 +1,5 @@ | |||
| package nsusbloader.NSLDataTypes; | ||||
| 
 | ||||
| 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.LinkedBlockingQueue; | ||||
| 
 | ||||
| import static nsusbloader.RainbowHexDump.hexDumpUTF8; | ||||
| 
 | ||||
| public class UsbCommunications extends Task<Void> { | ||||
|     private final int DEFAULT_INTERFACE = 0; | ||||
| 
 | ||||
|  | @ -349,7 +351,7 @@ public class UsbCommunications extends Task<Void> { | |||
|             byte[] receivedArray; | ||||
| 
 | ||||
|             while (true){ | ||||
|                 if (Thread.currentThread().isInterrupted())     // Check if user interrupted process. | ||||
|                 if (isCancelled())     // Check if user interrupted process. | ||||
|                     return false; | ||||
|                 receivedArray = readFromUsb(); | ||||
|                 if (receivedArray == null) | ||||
|  | @ -428,7 +430,7 @@ public class UsbCommunications extends Task<Void> { | |||
|                 int readPice = 8388608;                     // = 8Mb | ||||
| 
 | ||||
|                 while (currentOffset < receivedRangeSize){ | ||||
|                     if (Thread.currentThread().isInterrupted())     // Check if user interrupted process. | ||||
|                     if (isCancelled())     // Check if user interrupted process. | ||||
|                         return true; | ||||
|                     if ((currentOffset + readPice) >= receivedRangeSize ) | ||||
|                         readPice = Math.toIntExact(receivedRangeSize - currentOffset); | ||||
|  | @ -561,6 +563,7 @@ public class UsbCommunications extends Task<Void> { | |||
|                 readByte = readFromUsb(); | ||||
|                 if (readByte == null) | ||||
|                     return false; | ||||
| 
 | ||||
|                 if (Arrays.equals(readByte, CMD_ConnectionResponse)) { | ||||
|                     if (!handleConnectionResponse(pfsElement)) | ||||
|                         return false; | ||||
|  | @ -699,7 +702,7 @@ public class UsbCommunications extends Task<Void> { | |||
| 
 | ||||
|                 while (readFrom < realNcaSize){ | ||||
| 
 | ||||
|                     if (Thread.currentThread().isInterrupted())     // Check if user interrupted process. | ||||
|                     if (isCancelled())     // Check if user interrupted process. | ||||
|                         return false; | ||||
| 
 | ||||
|                     if (realNcaSize - readFrom < readPice) | ||||
|  | @ -707,7 +710,7 @@ public class UsbCommunications extends Task<Void> { | |||
|                     readBuf = new byte[readPice]; | ||||
|                     if (bufferedInStream.read(readBuf) != readPice) | ||||
|                         return false; | ||||
| 
 | ||||
|                     //System.out.println("S: "+readFrom+" T: "+realNcaSize+" P: "+readPice);    //  DEBUG | ||||
|                     if (!writeToUsb(readBuf)) | ||||
|                         return false; | ||||
|                     //-----------------------------------------/ | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Dmitry Isaenko
						Dmitry Isaenko