Fix #54; Update UsbConnect messages format
This commit is contained in:
parent
272702f043
commit
53fb421755
4 changed files with 83 additions and 26 deletions
|
@ -23,7 +23,7 @@ Sometimes I add new posts about this project [on my home page](https://developer
|
|||
|
||||
#### License
|
||||
|
||||
[GNU General Public License version 3]((https://github.com/developersu/ns-usbloader/blob/master/LICENSE)), or (at your option) any later version.
|
||||
[GNU General Public License version 3](https://github.com/developersu/ns-usbloader/blob/master/LICENSE), or (at your option) any later version.
|
||||
|
||||
#### Used libraries & resources
|
||||
* [OpenJFX](https://wiki.openjdk.java.net/display/OpenJFX/Main)
|
||||
|
|
|
@ -107,14 +107,14 @@ public class UsbConnect {
|
|||
|
||||
returningValue = LibUsb.init(contextNS);
|
||||
if (returningValue != LibUsb.SUCCESS)
|
||||
throw new Exception("libusb initialization\n Returned: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
throw new Exception("LibUSB initialization failed: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
|
||||
private void getDeviceList() throws Exception{
|
||||
deviceList = new DeviceList();
|
||||
returningValue = LibUsb.getDeviceList(contextNS, deviceList);
|
||||
if (returningValue < 0)
|
||||
throw new Exception("Get device list\n Returned: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
throw new Exception("Can't get device list: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
|
||||
private void findDevice() throws Exception{
|
||||
|
@ -122,12 +122,8 @@ public class UsbConnect {
|
|||
DeviceDescriptor descriptor;
|
||||
|
||||
for (Device device: deviceList){
|
||||
descriptor = new DeviceDescriptor();
|
||||
returningValue = LibUsb.getDeviceDescriptor(device, descriptor);
|
||||
if (returningValue != LibUsb.SUCCESS){
|
||||
this.freeDeviceList();
|
||||
throw new Exception("Read file descriptors for USB devices\n Returned: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
descriptor = getDeviceDescriptor(device);
|
||||
|
||||
if ((descriptor.idVendor() == VENDOR_ID) && descriptor.idProduct() == PRODUCT_ID){
|
||||
deviceNS = device;
|
||||
break;
|
||||
|
@ -139,6 +135,18 @@ public class UsbConnect {
|
|||
}
|
||||
}
|
||||
|
||||
private DeviceDescriptor getDeviceDescriptor(Device device) throws Exception{
|
||||
DeviceDescriptor descriptor = new DeviceDescriptor();
|
||||
|
||||
returningValue = LibUsb.getDeviceDescriptor(device, descriptor);
|
||||
|
||||
if (returningValue != LibUsb.SUCCESS){
|
||||
this.freeDeviceList();
|
||||
throw new Exception("Get USB device descriptor failure: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
private void openDevice() throws Exception{
|
||||
// Handle NS device
|
||||
handlerNS = new DeviceHandle();
|
||||
|
@ -150,7 +158,7 @@ public class UsbConnect {
|
|||
handlerNS = null; // Avoid issue on close();
|
||||
if (returningValue == LibUsb.ERROR_ACCESS) {
|
||||
throw new Exception(String.format(
|
||||
"Open NS USB device\n Returned: %s\n" +
|
||||
"Can't open NS USB device: %s\n" +
|
||||
"Double check that you have administrator privileges (you're 'root') or check 'udev' rules set for this user (linux only)!\n\n" +
|
||||
"Steps to set 'udev' rules:\n" +
|
||||
"root # vim /etc/udev/rules.d/99-NS" + ((RCM_VID == VENDOR_ID) ? "RCM" : "") + ".rules\n" +
|
||||
|
@ -158,7 +166,7 @@ public class UsbConnect {
|
|||
"root # udevadm control --reload-rules && udevadm trigger\n", UsbErrorCodes.getErrCode(returningValue), VENDOR_ID, PRODUCT_ID));
|
||||
}
|
||||
else
|
||||
throw new Exception("Open NS USB device\n Returned: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
throw new Exception("Can't open NS USB device: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
|
||||
private void freeDeviceList(){
|
||||
|
@ -182,13 +190,13 @@ public class UsbConnect {
|
|||
private void setConfiguration(int configuration) throws Exception{
|
||||
returningValue = LibUsb.setConfiguration(handlerNS, configuration);
|
||||
if (returningValue != LibUsb.SUCCESS)
|
||||
throw new Exception("Set active configuration to device\n Returned: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
throw new Exception("Unable to set active configuration on device: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
private void claimInterface() throws Exception{
|
||||
// Claim interface
|
||||
returningValue = LibUsb.claimInterface(handlerNS, DEFAULT_INTERFACE);
|
||||
if (returningValue != LibUsb.SUCCESS)
|
||||
throw new Exception("Claim interface\n Returned: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
throw new Exception("Claim interface failure: "+UsbErrorCodes.getErrCode(returningValue));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -222,18 +230,16 @@ public class UsbConnect {
|
|||
// Try to release interface
|
||||
returningValue = LibUsb.releaseInterface(handlerNS, DEFAULT_INTERFACE);
|
||||
|
||||
if (returningValue != LibUsb.SUCCESS)
|
||||
logPrinter.print("Release interface\n Returned: "+returningValue+" (sometimes it's not an issue)", EMsgType.WARNING);
|
||||
else
|
||||
logPrinter.print("Release interface", EMsgType.PASS);
|
||||
if (returningValue != LibUsb.SUCCESS) {
|
||||
logPrinter.print("Release interface failure: " +
|
||||
UsbErrorCodes.getErrCode(returningValue) +
|
||||
" (sometimes it's not an issue)", EMsgType.WARNING);
|
||||
}
|
||||
|
||||
LibUsb.close(handlerNS);
|
||||
logPrinter.print("Requested handler close", EMsgType.INFO);
|
||||
}
|
||||
// Close context in the end
|
||||
if (contextNS != null) {
|
||||
if (contextNS != null)
|
||||
LibUsb.exit(contextNS);
|
||||
logPrinter.print("Requested context close", EMsgType.INFO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ public class FrontController implements Initializable {
|
|||
fileChooser.setTitle(resourceBundle.getString("btn_OpenFile"));
|
||||
|
||||
File validator = new File(previouslyOpenedPath);
|
||||
if (validator.exists())
|
||||
if (validator.exists() && validator.isDirectory())
|
||||
fileChooser.setInitialDirectory(validator);
|
||||
else
|
||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||
|
@ -227,7 +227,7 @@ public class FrontController implements Initializable {
|
|||
dirChooser.setTitle(resourceBundle.getString("btn_OpenFile"));
|
||||
|
||||
File validator = new File(previouslyOpenedPath);
|
||||
if (validator.exists())
|
||||
if (validator.exists() && validator.isDirectory())
|
||||
dirChooser.setInitialDirectory(validator);
|
||||
else
|
||||
dirChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||
|
|
|
@ -24,11 +24,12 @@ import javafx.collections.FXCollections;
|
|||
import javafx.collections.ObservableList;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.SnapshotParameters;
|
||||
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.MouseButton;
|
||||
import javafx.scene.input.*;
|
||||
import javafx.scene.paint.Paint;
|
||||
import nsusbloader.MediatorControl;
|
||||
import nsusbloader.NSLDataTypes.EFileStatus;
|
||||
|
||||
|
@ -39,6 +40,8 @@ import java.util.List;
|
|||
import java.util.ResourceBundle;
|
||||
|
||||
public class NSTableViewController implements Initializable {
|
||||
private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat("application/x-java-serialized-object");
|
||||
|
||||
@FXML
|
||||
private TableView<NSLRowModel> table;
|
||||
private ObservableList<NSLRowModel> rowsObsLst;
|
||||
|
@ -124,6 +127,51 @@ public class NSTableViewController implements Initializable {
|
|||
table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
|
||||
nslRowModelTableView -> {
|
||||
final TableRow<NSLRowModel> row = new TableRow<>();
|
||||
/*
|
||||
// Add ability to move rows by mouse hold and move
|
||||
row.setOnDragDetected(mouseEvent -> {
|
||||
if (! row.isEmpty()){
|
||||
Integer rowIndex = row.getIndex();
|
||||
Dragboard dragboard = row.startDragAndDrop(TransferMode.MOVE);
|
||||
dragboard.setDragView(row.snapshot(null, null));
|
||||
ClipboardContent cContent = new ClipboardContent();
|
||||
cContent.put(SERIALIZED_MIME_TYPE, rowIndex);
|
||||
dragboard.setContent(cContent);
|
||||
mouseEvent.consume();
|
||||
}
|
||||
});
|
||||
|
||||
row.setOnDragOver(dragEvent -> {
|
||||
Dragboard dragboard = dragEvent.getDragboard();
|
||||
if (! dragboard.hasContent(SERIALIZED_MIME_TYPE))
|
||||
return;
|
||||
if (row.getIndex() != (Integer) dragboard.getContent(SERIALIZED_MIME_TYPE)) {
|
||||
dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
|
||||
dragEvent.consume();
|
||||
}
|
||||
});
|
||||
|
||||
row.setOnDragDropped(dragEvent -> {
|
||||
Dragboard dragboard = dragEvent.getDragboard();
|
||||
if (! dragboard.hasContent(SERIALIZED_MIME_TYPE))
|
||||
return;
|
||||
int draggedRowIndex = (Integer) dragboard.getContent(SERIALIZED_MIME_TYPE);
|
||||
NSLRowModel draggedRow = table.getItems().remove(draggedRowIndex);
|
||||
|
||||
int dropIndex;
|
||||
|
||||
if (row.isEmpty())
|
||||
dropIndex = table.getItems().size();
|
||||
else
|
||||
dropIndex = row.getIndex();
|
||||
|
||||
table.getItems().add(dropIndex, draggedRow);
|
||||
dragEvent.setDropCompleted(true);
|
||||
table.getSelectionModel().select(dropIndex);
|
||||
dragEvent.consume();
|
||||
});
|
||||
//*/
|
||||
|
||||
ContextMenu contextMenu = new ContextMenu();
|
||||
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete"));
|
||||
deleteMenuItem.setOnAction(actionEvent -> {
|
||||
|
@ -254,7 +302,10 @@ public class NSTableViewController implements Initializable {
|
|||
current.getNspFileName().toLowerCase().endsWith("xcz"));
|
||||
}
|
||||
else
|
||||
rowsObsLst.removeIf(current -> ! current.getNspFileName().toLowerCase().endsWith("nsp"));
|
||||
rowsObsLst.removeIf(current -> (! current.getNspFileName().toLowerCase().endsWith("nsp")) ||
|
||||
(! current.getNspFileName().toLowerCase().endsWith("nsz")) ||
|
||||
(! current.getNspFileName().toLowerCase().endsWith("xci")) ||
|
||||
(! current.getNspFileName().toLowerCase().endsWith("xcz")));
|
||||
table.refresh();
|
||||
}
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue