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

master
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);
else
uploadStopBtn.setDisable(false);
selectNspBtn.setOnAction(e->{ selectFilesBtnAction(); });
uploadStopBtn.setOnAction(e->{ uploadBtnAction(); });
selectNspBtn.setOnAction(e-> selectFilesBtnAction());
uploadStopBtn.setOnAction(e-> uploadBtnAction());
selectNspBtn.getStyleClass().add("buttonSelect");
@ -122,9 +122,12 @@ public class NSLMainController implements Initializable {
else
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"));
}
else if (FrontTabController.getSelectedProtocol().equals("GoldLeaf") && (! SettingsTabController.getNSPFileFilterForGL()))
fileChooser.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("Any file", "*.*"),
new FileChooser.ExtensionFilter("NSP ROM", "*.nsp")
);
else
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NSP ROM", "*.nsp"));
@ -142,7 +145,7 @@ public class NSLMainController implements Initializable {
if ((workThread == null || !workThread.isAlive())){
// Collect files
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"));
return;
}
@ -207,7 +210,7 @@ public class NSLMainController implements Initializable {
public void notifyTransmissionStarted(boolean isTransmissionStarted){
if (isTransmissionStarted) {
selectNspBtn.setDisable(true);
uploadStopBtn.setOnAction(e->{ stopBtnAction(); });
uploadStopBtn.setOnAction(e-> stopBtnAction());
uploadStopBtn.setText(resourceBundle.getString("btn_Stop"));
@ -219,7 +222,7 @@ public class NSLMainController implements Initializable {
}
else {
selectNspBtn.setDisable(false);
uploadStopBtn.setOnAction(e->{ uploadBtnAction(); });
uploadStopBtn.setOnAction(e-> uploadBtnAction());
uploadStopBtn.setText(resourceBundle.getString("btn_Upload"));
@ -258,24 +261,38 @@ public class NSLMainController implements Initializable {
}
List<File> filesDropped = new ArrayList<>();
try {
if (SettingsTabController.getTfXCISupport() && FrontTabController.getSelectedProtocol().equals("TinFoil")){
if (FrontTabController.getSelectedProtocol().equals("TinFoil") && SettingsTabController.getTfXCISupport()){
for (File fileOrDir : event.getDragboard().getFiles()) {
if (fileOrDir.getName().toLowerCase().endsWith(".nsp") || fileOrDir.getName().toLowerCase().endsWith(".xci"))
filesDropped.add(fileOrDir);
else if (fileOrDir.isDirectory())
if (fileOrDir.isDirectory()) {
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);
}
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 {
for (File fileOrDir : event.getDragboard().getFiles()) {
if (fileOrDir.getName().toLowerCase().endsWith(".nsp"))
filesDropped.add(fileOrDir);
else if (fileOrDir.isDirectory())
if (fileOrDir.isDirectory()){
for (File file : fileOrDir.listFiles())
if (file.getName().toLowerCase().endsWith(".nsp"))
if (file.getName().toLowerCase().endsWith(".nsp") && (! file.isDirectory()))
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.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.CheckBoxTableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.util.Callback;
import nsusbloader.MediatorControl;
import nsusbloader.NSLDataTypes.EFileStatus;
import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
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.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent keyEvent) {
table.setOnKeyPressed(keyEvent -> {
if (!rowsObsLst.isEmpty()) {
if (keyEvent.getCode() == KeyCode.DELETE && !MediatorControl.getInstance().getTransferActive()) {
rowsObsLst.removeAll(table.getSelectionModel().getSelectedItems());
@ -57,7 +49,6 @@ public class NSTableViewController implements Initializable {
}
}
keyEvent.consume();
}
});
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"));
fileSizeColumn.setCellValueFactory(new PropertyValueFactory<>("nspFileSize"));
// ><
uploadColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<NSLRowModel, Boolean>, ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<NSLRowModel, Boolean> paramFeatures) {
NSLRowModel model = paramFeatures.getValue();
uploadColumn.setCellValueFactory(paramFeatures -> {
NSLRowModel model = paramFeatures.getValue();
SimpleBooleanProperty booleanProperty = new SimpleBooleanProperty(model.isMarkForUpload());
SimpleBooleanProperty booleanProperty = new SimpleBooleanProperty(model.isMarkForUpload());
booleanProperty.addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observableValue, Boolean oldValue, Boolean newValue) {
model.setMarkForUpload(newValue);
}
});
return booleanProperty;
}
booleanProperty.addListener((observableValue, oldValue, newValue) -> model.setMarkForUpload(newValue));
return booleanProperty;
});
uploadColumn.setCellFactory(new Callback<TableColumn<NSLRowModel, Boolean>, TableCell<NSLRowModel, Boolean>>() {
@Override
public TableCell<NSLRowModel, Boolean> call(TableColumn<NSLRowModel, Boolean> paramFeatures) {
CheckBoxTableCell<NSLRowModel, Boolean> cell = new CheckBoxTableCell<>();
return cell;
}
});
uploadColumn.setCellFactory(paramFeatures -> new CheckBoxTableCell<>());
table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
new Callback<TableView<NSLRowModel>, TableRow<NSLRowModel>>() {
@Override
public TableRow<NSLRowModel> call(TableView<NSLRowModel> nslRowModelTableView) {
final TableRow<NSLRowModel> row = new TableRow<>();
ContextMenu contextMenu = new ContextMenu();
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete"));
deleteMenuItem.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
rowsObsLst.remove(row.getItem());
if (rowsObsLst.isEmpty())
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>() {
@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);
nslRowModelTableView -> {
final TableRow<NSLRowModel> row = new TableRow<>();
ContextMenu contextMenu = new ContextMenu();
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete"));
deleteMenuItem.setOnAction(actionEvent -> {
rowsObsLst.remove(row.getItem());
if (rowsObsLst.isEmpty())
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(actionEvent -> {
rowsObsLst.clear();
MediatorControl.getInstance().getContoller().disableUploadStopBtn(true); // TODO: change to something better
table.refresh();
});
contextMenu.getItems().addAll(deleteMenuItem, deleteAllMenuItem);
row.setContextMenu(contextMenu);
row.contextMenuProperty().bind(
Bindings.when(
Bindings.isNotNull(
row.itemProperty()))
.then(MediatorControl.getInstance().getTransferActive()?(ContextMenu)null:contextMenu)
.otherwise((ContextMenu) null)
);
row.setOnMouseClicked(new EventHandler<MouseEvent>() { // Just.. don't ask..
@Override
public void handle(MouseEvent mouseEvent) {
if (!row.isEmpty() && mouseEvent.getButton() == MouseButton.PRIMARY){
NSLRowModel thisItem = row.getItem();
thisItem.setMarkForUpload(!thisItem.isMarkForUpload());
table.refresh();
}
mouseEvent.consume();
}
});
return row;
}
row.setContextMenu(contextMenu);
row.contextMenuProperty().bind(
Bindings.when(
Bindings.isNotNull(
row.itemProperty()))
.then(MediatorControl.getInstance().getTransferActive()?null:contextMenu)
.otherwise((ContextMenu) null)
);
// Just.. don't ask..
row.setOnMouseClicked(mouseEvent -> {
if (!row.isEmpty() && mouseEvent.getButton() == MouseButton.PRIMARY){
NSLRowModel thisItem = row.getItem();
thisItem.setMarkForUpload(!thisItem.isMarkForUpload());
table.refresh();
}
mouseEvent.consume();
});
return row;
}
);
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
@ -233,8 +202,10 @@ public class NSTableViewController implements Initializable {
public void setNewProtocol(String newProtocol){
if (rowsObsLst.isEmpty())
return;
if (! newProtocol.equals("TinFoil"))
if (newProtocol.equals("GoldLeaf"))
rowsObsLst.removeIf(current -> current.getNspFileName().toLowerCase().endsWith("xci"));
else
rowsObsLst.removeIf(current -> ! current.getNspFileName().toLowerCase().endsWith("nsp"));
table.refresh();
}

View File

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

View File

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

View File

@ -2,7 +2,6 @@ package nsusbloader;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.control.DialogPane;
import javafx.scene.layout.Region;
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_GetSpecialPath = 0x0d;//13 // Information about special folders; simplified usage @ NS-UL
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};
@ -175,8 +175,8 @@ class GoldLeaf implements ITransferModule {
break;
case CMD_WriteFile:
someLength1 = arrToIntLE(readByte, 8) * 2; // Since GL 0.7
if (writeFile(new String(readByte, 12, someLength1, StandardCharsets.UTF_16LE),
arrToLongLE(readByte, 12+someLength1)))
//if (writeFile(new String(readByte, 12, someLength1, StandardCharsets.UTF_16LE), arrToLongLE(readByte, 12+someLength1)))
if (writeFile(new String(readByte, 12, someLength1, StandardCharsets.UTF_16LE)))
break main_loop;
break;
case CMD_SelectFile:
@ -771,12 +771,13 @@ class GoldLeaf implements ITransferModule {
/**
* Handle 'WriteFile'
* @param fileName full path including new file name in the end
* @param size requested size
*
* @return true if failed
* false if everything is ok
* */
private boolean writeFile(String fileName, long size) {
//System.out.println("writeFile "+fileName+" "+size);
//@param size requested size
//private boolean writeFile(String fileName, long size) {
private boolean writeFile(String fileName) {
if (fileName.startsWith("VIRT:/")){
return writeGL_FAIL("GL Handle 'WriteFile' command [not supported for virtual drive]");
}