v0.8 Misc changes and fix for #33. Thank you, @satelliteseeker

This commit is contained in:
Dmitry Isaenko 2019-09-25 07:24:38 +03:00
parent 703f5759a1
commit 5c5f86b77a
6 changed files with 95 additions and 111 deletions

View file

@ -61,8 +61,8 @@ public class NSLMainController implements Initializable {
uploadStopBtn.setDisable(true); uploadStopBtn.setDisable(true);
else else
uploadStopBtn.setDisable(false); uploadStopBtn.setDisable(false);
selectNspBtn.setOnAction(e->{ selectFilesBtnAction(); }); selectNspBtn.setOnAction(e-> selectFilesBtnAction());
uploadStopBtn.setOnAction(e->{ uploadBtnAction(); }); uploadStopBtn.setOnAction(e-> uploadBtnAction());
selectNspBtn.getStyleClass().add("buttonSelect"); selectNspBtn.getStyleClass().add("buttonSelect");
@ -122,9 +122,12 @@ public class NSLMainController implements Initializable {
else else
fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
if (SettingsTabController.getTfXCISupport() && FrontTabController.getSelectedProtocol().equals("TinFoil")){ if (FrontTabController.getSelectedProtocol().equals("TinFoil") && SettingsTabController.getTfXCISupport())
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP/XCI", "*.nsp", "*.xci")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP/XCI", "*.nsp", "*.xci"));
} else if (FrontTabController.getSelectedProtocol().equals("GoldLeaf") && (! SettingsTabController.getNSPFileFilterForGL()))
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Any file", "*.*"),
new FileChooser.ExtensionFilter("NSP ROM", "*.nsp")
);
else else
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP ROM", "*.nsp")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP ROM", "*.nsp"));
@ -142,7 +145,7 @@ public class NSLMainController implements Initializable {
if ((workThread == null || !workThread.isAlive())){ if ((workThread == null || !workThread.isAlive())){
// Collect files // Collect files
List<File> nspToUpload; List<File> nspToUpload;
if ((nspToUpload = FrontTabController.tableFilesListController.getFilesForUpload()) == null && FrontTabController.getSelectedProtocol().equals("TinFoil")) { if (FrontTabController.tableFilesListController.getFilesForUpload() == null && FrontTabController.getSelectedProtocol().equals("TinFoil")) {
logArea.setText(resourceBundle.getString("tab3_Txt_NoFolderOrFileSelected")); logArea.setText(resourceBundle.getString("tab3_Txt_NoFolderOrFileSelected"));
return; return;
} }
@ -207,7 +210,7 @@ public class NSLMainController implements Initializable {
public void notifyTransmissionStarted(boolean isTransmissionStarted){ public void notifyTransmissionStarted(boolean isTransmissionStarted){
if (isTransmissionStarted) { if (isTransmissionStarted) {
selectNspBtn.setDisable(true); selectNspBtn.setDisable(true);
uploadStopBtn.setOnAction(e->{ stopBtnAction(); }); uploadStopBtn.setOnAction(e-> stopBtnAction());
uploadStopBtn.setText(resourceBundle.getString("btn_Stop")); uploadStopBtn.setText(resourceBundle.getString("btn_Stop"));
@ -219,7 +222,7 @@ public class NSLMainController implements Initializable {
} }
else { else {
selectNspBtn.setDisable(false); selectNspBtn.setDisable(false);
uploadStopBtn.setOnAction(e->{ uploadBtnAction(); }); uploadStopBtn.setOnAction(e-> uploadBtnAction());
uploadStopBtn.setText(resourceBundle.getString("btn_Upload")); uploadStopBtn.setText(resourceBundle.getString("btn_Upload"));
@ -258,24 +261,38 @@ public class NSLMainController implements Initializable {
} }
List<File> filesDropped = new ArrayList<>(); List<File> filesDropped = new ArrayList<>();
try { try {
if (SettingsTabController.getTfXCISupport() && FrontTabController.getSelectedProtocol().equals("TinFoil")){ if (FrontTabController.getSelectedProtocol().equals("TinFoil") && SettingsTabController.getTfXCISupport()){
for (File fileOrDir : event.getDragboard().getFiles()) { for (File fileOrDir : event.getDragboard().getFiles()) {
if (fileOrDir.getName().toLowerCase().endsWith(".nsp") || fileOrDir.getName().toLowerCase().endsWith(".xci")) if (fileOrDir.isDirectory()) {
filesDropped.add(fileOrDir);
else if (fileOrDir.isDirectory())
for (File file : fileOrDir.listFiles()) for (File file : fileOrDir.listFiles())
if (file.getName().toLowerCase().endsWith(".nsp") || file.getName().toLowerCase().endsWith(".xci")) if ((! file.isDirectory()) && (file.getName().toLowerCase().endsWith(".nsp") || file.getName().toLowerCase().endsWith(".xci")))
filesDropped.add(file); filesDropped.add(file);
}
else if (fileOrDir.getName().toLowerCase().endsWith(".nsp") || fileOrDir.getName().toLowerCase().endsWith(".xci"))
filesDropped.add(fileOrDir);
}
}// TODO: Somehow improve this double-action function in settings.
else if (FrontTabController.getSelectedProtocol().equals("GoldLeaf") && (! SettingsTabController.getNSPFileFilterForGL())){
for (File fileOrDir : event.getDragboard().getFiles()) {
if (fileOrDir.isDirectory()) {
for (File file : fileOrDir.listFiles())
if ((! file.isDirectory()) && (! file.isHidden()))
filesDropped.add(file);
}
else
filesDropped.add(fileOrDir);
} }
} }
else { else {
for (File fileOrDir : event.getDragboard().getFiles()) { for (File fileOrDir : event.getDragboard().getFiles()) {
if (fileOrDir.getName().toLowerCase().endsWith(".nsp")) if (fileOrDir.isDirectory()){
filesDropped.add(fileOrDir);
else if (fileOrDir.isDirectory())
for (File file : fileOrDir.listFiles()) for (File file : fileOrDir.listFiles())
if (file.getName().toLowerCase().endsWith(".nsp")) if (file.getName().toLowerCase().endsWith(".nsp") && (! file.isDirectory()))
filesDropped.add(file); filesDropped.add(file);
}
else if (fileOrDir.getName().toLowerCase().endsWith(".nsp"))
filesDropped.add(fileOrDir);
} }
} }
} }

View file

@ -2,28 +2,22 @@ package nsusbloader.Controllers;
import javafx.beans.binding.Bindings; import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton; import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import nsusbloader.MediatorControl; import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EFileStatus; import nsusbloader.NSLDataTypes.EFileStatus;
import java.io.File; import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -40,9 +34,7 @@ public class NSTableViewController implements Initializable {
table.setEditable(false); // At least with hacks it works as expected. Otherwise - null pointer exception table.setEditable(false); // At least with hacks it works as expected. Otherwise - null pointer exception
table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setOnKeyPressed(new EventHandler<KeyEvent>() { table.setOnKeyPressed(keyEvent -> {
@Override
public void handle(KeyEvent keyEvent) {
if (!rowsObsLst.isEmpty()) { if (!rowsObsLst.isEmpty()) {
if (keyEvent.getCode() == KeyCode.DELETE && !MediatorControl.getInstance().getTransferActive()) { if (keyEvent.getCode() == KeyCode.DELETE && !MediatorControl.getInstance().getTransferActive()) {
rowsObsLst.removeAll(table.getSelectionModel().getSelectedItems()); rowsObsLst.removeAll(table.getSelectionModel().getSelectedItems());
@ -57,7 +49,6 @@ public class NSTableViewController implements Initializable {
} }
} }
keyEvent.consume(); keyEvent.consume();
}
}); });
TableColumn<NSLRowModel, String> statusColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Status")); TableColumn<NSLRowModel, String> statusColumn = new TableColumn<>(resourceBundle.getString("tab1_table_Lbl_Status"));
@ -92,82 +83,60 @@ public class NSTableViewController implements Initializable {
fileNameColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileName")); fileNameColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileName"));
fileSizeColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileSize")); fileSizeColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileSize"));
// >< // ><
uploadColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NSLRowModel, Boolean>, ObservableValue<Boolean>>() { uploadColumn.setCellValueFactory(paramFeatures -> {
@Override NSLRowModel model = paramFeatures.getValue();
public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<NSLRowModel, Boolean> paramFeatures) {
NSLRowModel model = paramFeatures.getValue();
SimpleBooleanProperty booleanProperty = new SimpleBooleanProperty(model.isMarkForUpload()); SimpleBooleanProperty booleanProperty = new SimpleBooleanProperty(model.isMarkForUpload());
booleanProperty.addListener(new ChangeListener<Boolean>() { booleanProperty.addListener((observableValue, oldValue, newValue) -> model.setMarkForUpload(newValue));
@Override return booleanProperty;
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean oldValue, Boolean newValue) {
model.setMarkForUpload(newValue);
}
});
return booleanProperty;
}
}); });
uploadColumn.setCellFactory(new Callback<TableColumn<NSLRowModel, Boolean>, TableCell<NSLRowModel, Boolean>>() { uploadColumn.setCellFactory(paramFeatures -> new CheckBoxTableCell<>());
@Override
public TableCell<NSLRowModel, Boolean> call(TableColumn<NSLRowModel, Boolean> paramFeatures) {
CheckBoxTableCell<NSLRowModel, Boolean> cell = new CheckBoxTableCell<>();
return cell;
}
});
table.setRowFactory( // this shit is made to implement context menu. It's such a pain.. table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
new Callback<TableView<NSLRowModel>, TableRow<NSLRowModel>>() { nslRowModelTableView -> {
@Override final TableRow<NSLRowModel> row = new TableRow<>();
public TableRow<NSLRowModel> call(TableView<NSLRowModel> nslRowModelTableView) { ContextMenu contextMenu = new ContextMenu();
final TableRow<NSLRowModel> row = new TableRow<>(); MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete"));
ContextMenu contextMenu = new ContextMenu(); deleteMenuItem.setOnAction(actionEvent -> {
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete")); rowsObsLst.remove(row.getItem());
deleteMenuItem.setOnAction(new EventHandler<ActionEvent>() { if (rowsObsLst.isEmpty())
@Override MediatorControl.getInstance().getContoller().disableUploadStopBtn(true); // TODO: change to something better
public void handle(ActionEvent actionEvent) { table.refresh();
rowsObsLst.remove(row.getItem()); });
if (rowsObsLst.isEmpty()) MenuItem deleteAllMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_DeleteAll"));
MediatorControl.getInstance().getContoller().disableUploadStopBtn(true); // TODO: change to something better deleteAllMenuItem.setOnAction(actionEvent -> {
table.refresh(); rowsObsLst.clear();
} MediatorControl.getInstance().getContoller().disableUploadStopBtn(true); // TODO: change to something better
}); table.refresh();
MenuItem deleteAllMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_DeleteAll")); });
deleteAllMenuItem.setOnAction(new EventHandler<ActionEvent>() { contextMenu.getItems().addAll(deleteMenuItem, deleteAllMenuItem);
@Override
public void handle(ActionEvent actionEvent) {
rowsObsLst.clear();
MediatorControl.getInstance().getContoller().disableUploadStopBtn(true); // TODO: change to something better
table.refresh();
}
});
contextMenu.getItems().addAll(deleteMenuItem, deleteAllMenuItem);
row.setContextMenu(contextMenu); row.setContextMenu(contextMenu);
row.contextMenuProperty().bind( row.contextMenuProperty().bind(
Bindings.when( Bindings.when(
Bindings.isNotNull( Bindings.isNotNull(
row.itemProperty())) row.itemProperty()))
.then(MediatorControl.getInstance().getTransferActive()?(ContextMenu)null:contextMenu) .then(MediatorControl.getInstance().getTransferActive()?null:contextMenu)
.otherwise((ContextMenu) null) .otherwise((ContextMenu) null)
); );
row.setOnMouseClicked(new EventHandler<MouseEvent>() { // Just.. don't ask.. // Just.. don't ask..
@Override row.setOnMouseClicked(mouseEvent -> {
public void handle(MouseEvent mouseEvent) { if (!row.isEmpty() && mouseEvent.getButton() == MouseButton.PRIMARY){
if (!row.isEmpty() && mouseEvent.getButton() == MouseButton.PRIMARY){ NSLRowModel thisItem = row.getItem();
NSLRowModel thisItem = row.getItem(); thisItem.setMarkForUpload(!thisItem.isMarkForUpload());
thisItem.setMarkForUpload(!thisItem.isMarkForUpload()); table.refresh();
table.refresh(); }
} mouseEvent.consume();
mouseEvent.consume(); });
} return row;
});
return row;
}
} }
); );
table.setItems(rowsObsLst); table.setItems(rowsObsLst);
table.getColumns().addAll(statusColumn, fileNameColumn, fileSizeColumn, uploadColumn); table.getColumns().add(statusColumn);
table.getColumns().add(fileNameColumn);
table.getColumns().add(fileSizeColumn);
table.getColumns().add(uploadColumn);
} }
/** /**
* Add files when user selected them * Add files when user selected them
@ -233,8 +202,10 @@ public class NSTableViewController implements Initializable {
public void setNewProtocol(String newProtocol){ public void setNewProtocol(String newProtocol){
if (rowsObsLst.isEmpty()) if (rowsObsLst.isEmpty())
return; return;
if (! newProtocol.equals("TinFoil")) if (newProtocol.equals("GoldLeaf"))
rowsObsLst.removeIf(current -> current.getNspFileName().toLowerCase().endsWith("xci")); rowsObsLst.removeIf(current -> current.getNspFileName().toLowerCase().endsWith("xci"));
else
rowsObsLst.removeIf(current -> ! current.getNspFileName().toLowerCase().endsWith("nsp"));
table.refresh(); table.refresh();
} }

View file

@ -72,9 +72,7 @@ public class SettingsController implements Initializable {
expertSettingsVBox.setDisable(!AppPreferences.getInstance().getExpertMode()); expertSettingsVBox.setDisable(!AppPreferences.getInstance().getExpertMode());
expertModeCb.setSelected(AppPreferences.getInstance().getExpertMode()); expertModeCb.setSelected(AppPreferences.getInstance().getExpertMode());
expertModeCb.setOnAction(e->{ expertModeCb.setOnAction(e-> expertSettingsVBox.setDisable(!expertModeCb.isSelected()));
expertSettingsVBox.setDisable(!expertModeCb.isSelected());
});
autoDetectIpCb.setSelected(AppPreferences.getInstance().getAutoDetectIp()); autoDetectIpCb.setSelected(AppPreferences.getInstance().getAutoDetectIp());
pcIpTextField.setDisable(AppPreferences.getInstance().getAutoDetectIp()); pcIpTextField.setDisable(AppPreferences.getInstance().getAutoDetectIp());
@ -141,7 +139,7 @@ public class SettingsController implements Initializable {
else else
return change; return change;
})); }));
pcPortTextField.setTextFormatter(new TextFormatter<Object>(change -> { pcPortTextField.setTextFormatter(new TextFormatter<>(change -> {
if (change.getControlNewText().matches("^[0-9]{0,5}$")) { if (change.getControlNewText().matches("^[0-9]{0,5}$")) {
if (!change.getControlNewText().isEmpty() if (!change.getControlNewText().isEmpty()
&& ((Integer.parseInt(change.getControlNewText()) > 65535) || (Integer.parseInt(change.getControlNewText()) == 0)) && ((Integer.parseInt(change.getControlNewText()) > 65535) || (Integer.parseInt(change.getControlNewText()) == 0))
@ -162,9 +160,7 @@ public class SettingsController implements Initializable {
})); }));
newVersionLink.setVisible(false); newVersionLink.setVisible(false);
newVersionLink.setOnAction(e->{ newVersionLink.setOnAction(e-> hs.showDocument(newVersionLink.getText()));
hs.showDocument(newVersionLink.getText());
});
autoCheckUpdCb.setSelected(AppPreferences.getInstance().getAutoCheckUpdates()); autoCheckUpdCb.setSelected(AppPreferences.getInstance().getAutoCheckUpdates());
@ -201,7 +197,7 @@ public class SettingsController implements Initializable {
File jarFile; File jarFile;
try{ try{
jarFile = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "utf-8")); jarFile = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"));
} }
catch (UnsupportedEncodingException uee){ catch (UnsupportedEncodingException uee){
uee.printStackTrace(); uee.printStackTrace();

View file

@ -46,7 +46,7 @@ public class MessagesConsumer extends AnimationTimer {
ArrayList<String> messages = new ArrayList<>(); ArrayList<String> messages = new ArrayList<>();
int msgRecieved = msgQueue.drainTo(messages); int msgRecieved = msgQueue.drainTo(messages);
if (msgRecieved > 0) if (msgRecieved > 0)
messages.forEach(msg -> logsArea.appendText(msg)); messages.forEach(logsArea::appendText);
ArrayList<Double> progress = new ArrayList<>(); ArrayList<Double> progress = new ArrayList<>();
int progressRecieved = progressQueue.drainTo(progress); int progressRecieved = progressQueue.drainTo(progress);

View file

@ -2,7 +2,6 @@ package nsusbloader;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.layout.Region; import javafx.scene.layout.Region;
import javafx.stage.Stage; import javafx.stage.Stage;

View file

@ -68,7 +68,7 @@ class GoldLeaf implements ITransferModule {
final byte CMD_GetSpecialPathCount = 0x0c;//12 // Special folders count; simplified usage @ NS-UL final byte CMD_GetSpecialPathCount = 0x0c;//12 // Special folders count; simplified usage @ NS-UL
final byte CMD_GetSpecialPath = 0x0d;//13 // Information about special folders; simplified usage @ NS-UL final byte CMD_GetSpecialPath = 0x0d;//13 // Information about special folders; simplified usage @ NS-UL
final byte CMD_SelectFile = 0x0e;//14 final byte CMD_SelectFile = 0x0e;//14
final byte CMD_Max = 0x0f;//15 // not used @ NS-UL & GT //final byte CMD_Max = 0x0f;//15 // not used @ NS-UL & GT
final byte[] CMD_GLCI = new byte[]{0x47, 0x4c, 0x43, 0x49}; final byte[] CMD_GLCI = new byte[]{0x47, 0x4c, 0x43, 0x49};
@ -175,8 +175,8 @@ class GoldLeaf implements ITransferModule {
break; break;
case CMD_WriteFile: case CMD_WriteFile:
someLength1 = arrToIntLE(readByte, 8) * 2; // Since GL 0.7 someLength1 = arrToIntLE(readByte, 8) * 2; // Since GL 0.7
if (writeFile(new String(readByte, 12, someLength1, StandardCharsets.UTF_16LE), //if (writeFile(new String(readByte, 12, someLength1, StandardCharsets.UTF_16LE), arrToLongLE(readByte, 12+someLength1)))
arrToLongLE(readByte, 12+someLength1))) if (writeFile(new String(readByte, 12, someLength1, StandardCharsets.UTF_16LE)))
break main_loop; break main_loop;
break; break;
case CMD_SelectFile: case CMD_SelectFile:
@ -771,12 +771,13 @@ class GoldLeaf implements ITransferModule {
/** /**
* Handle 'WriteFile' * Handle 'WriteFile'
* @param fileName full path including new file name in the end * @param fileName full path including new file name in the end
* @param size requested size *
* @return true if failed * @return true if failed
* false if everything is ok * false if everything is ok
* */ * */
private boolean writeFile(String fileName, long size) { //@param size requested size
//System.out.println("writeFile "+fileName+" "+size); //private boolean writeFile(String fileName, long size) {
private boolean writeFile(String fileName) {
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]");
} }