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
|
#### 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
|
#### Used libraries & resources
|
||||||
* [OpenJFX](https://wiki.openjdk.java.net/display/OpenJFX/Main)
|
* [OpenJFX](https://wiki.openjdk.java.net/display/OpenJFX/Main)
|
||||||
|
|
|
@ -107,14 +107,14 @@ public class UsbConnect {
|
||||||
|
|
||||||
returningValue = LibUsb.init(contextNS);
|
returningValue = LibUsb.init(contextNS);
|
||||||
if (returningValue != LibUsb.SUCCESS)
|
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{
|
private void getDeviceList() throws Exception{
|
||||||
deviceList = new DeviceList();
|
deviceList = new DeviceList();
|
||||||
returningValue = LibUsb.getDeviceList(contextNS, deviceList);
|
returningValue = LibUsb.getDeviceList(contextNS, deviceList);
|
||||||
if (returningValue < 0)
|
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{
|
private void findDevice() throws Exception{
|
||||||
|
@ -122,12 +122,8 @@ public class UsbConnect {
|
||||||
DeviceDescriptor descriptor;
|
DeviceDescriptor descriptor;
|
||||||
|
|
||||||
for (Device device: deviceList){
|
for (Device device: deviceList){
|
||||||
descriptor = new DeviceDescriptor();
|
descriptor = getDeviceDescriptor(device);
|
||||||
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));
|
|
||||||
}
|
|
||||||
if ((descriptor.idVendor() == VENDOR_ID) && descriptor.idProduct() == PRODUCT_ID){
|
if ((descriptor.idVendor() == VENDOR_ID) && descriptor.idProduct() == PRODUCT_ID){
|
||||||
deviceNS = device;
|
deviceNS = device;
|
||||||
break;
|
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{
|
private void openDevice() throws Exception{
|
||||||
// Handle NS device
|
// Handle NS device
|
||||||
handlerNS = new DeviceHandle();
|
handlerNS = new DeviceHandle();
|
||||||
|
@ -150,7 +158,7 @@ public class UsbConnect {
|
||||||
handlerNS = null; // Avoid issue on close();
|
handlerNS = null; // Avoid issue on close();
|
||||||
if (returningValue == LibUsb.ERROR_ACCESS) {
|
if (returningValue == LibUsb.ERROR_ACCESS) {
|
||||||
throw new Exception(String.format(
|
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" +
|
"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" +
|
"Steps to set 'udev' rules:\n" +
|
||||||
"root # vim /etc/udev/rules.d/99-NS" + ((RCM_VID == VENDOR_ID) ? "RCM" : "") + ".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));
|
"root # udevadm control --reload-rules && udevadm trigger\n", UsbErrorCodes.getErrCode(returningValue), VENDOR_ID, PRODUCT_ID));
|
||||||
}
|
}
|
||||||
else
|
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(){
|
private void freeDeviceList(){
|
||||||
|
@ -182,13 +190,13 @@ public class UsbConnect {
|
||||||
private void setConfiguration(int configuration) throws Exception{
|
private void setConfiguration(int configuration) throws Exception{
|
||||||
returningValue = LibUsb.setConfiguration(handlerNS, configuration);
|
returningValue = LibUsb.setConfiguration(handlerNS, configuration);
|
||||||
if (returningValue != LibUsb.SUCCESS)
|
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{
|
private void claimInterface() throws Exception{
|
||||||
// Claim interface
|
// Claim interface
|
||||||
returningValue = LibUsb.claimInterface(handlerNS, DEFAULT_INTERFACE);
|
returningValue = LibUsb.claimInterface(handlerNS, DEFAULT_INTERFACE);
|
||||||
if (returningValue != LibUsb.SUCCESS)
|
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
|
// Try to release interface
|
||||||
returningValue = LibUsb.releaseInterface(handlerNS, DEFAULT_INTERFACE);
|
returningValue = LibUsb.releaseInterface(handlerNS, DEFAULT_INTERFACE);
|
||||||
|
|
||||||
if (returningValue != LibUsb.SUCCESS)
|
if (returningValue != LibUsb.SUCCESS) {
|
||||||
logPrinter.print("Release interface\n Returned: "+returningValue+" (sometimes it's not an issue)", EMsgType.WARNING);
|
logPrinter.print("Release interface failure: " +
|
||||||
else
|
UsbErrorCodes.getErrCode(returningValue) +
|
||||||
logPrinter.print("Release interface", EMsgType.PASS);
|
" (sometimes it's not an issue)", EMsgType.WARNING);
|
||||||
|
}
|
||||||
|
|
||||||
LibUsb.close(handlerNS);
|
LibUsb.close(handlerNS);
|
||||||
logPrinter.print("Requested handler close", EMsgType.INFO);
|
|
||||||
}
|
}
|
||||||
// Close context in the end
|
// Close context in the end
|
||||||
if (contextNS != null) {
|
if (contextNS != null)
|
||||||
LibUsb.exit(contextNS);
|
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"));
|
fileChooser.setTitle(resourceBundle.getString("btn_OpenFile"));
|
||||||
|
|
||||||
File validator = new File(previouslyOpenedPath);
|
File validator = new File(previouslyOpenedPath);
|
||||||
if (validator.exists())
|
if (validator.exists() && validator.isDirectory())
|
||||||
fileChooser.setInitialDirectory(validator);
|
fileChooser.setInitialDirectory(validator);
|
||||||
else
|
else
|
||||||
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||||
|
@ -227,7 +227,7 @@ public class FrontController implements Initializable {
|
||||||
dirChooser.setTitle(resourceBundle.getString("btn_OpenFile"));
|
dirChooser.setTitle(resourceBundle.getString("btn_OpenFile"));
|
||||||
|
|
||||||
File validator = new File(previouslyOpenedPath);
|
File validator = new File(previouslyOpenedPath);
|
||||||
if (validator.exists())
|
if (validator.exists() && validator.isDirectory())
|
||||||
dirChooser.setInitialDirectory(validator);
|
dirChooser.setInitialDirectory(validator);
|
||||||
else
|
else
|
||||||
dirChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
dirChooser.setInitialDirectory(new File(System.getProperty("user.home")));
|
||||||
|
|
|
@ -24,11 +24,12 @@ import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.SnapshotParameters;
|
||||||
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.*;
|
||||||
import javafx.scene.input.MouseButton;
|
import javafx.scene.paint.Paint;
|
||||||
import nsusbloader.MediatorControl;
|
import nsusbloader.MediatorControl;
|
||||||
import nsusbloader.NSLDataTypes.EFileStatus;
|
import nsusbloader.NSLDataTypes.EFileStatus;
|
||||||
|
|
||||||
|
@ -39,6 +40,8 @@ import java.util.List;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
public class NSTableViewController implements Initializable {
|
public class NSTableViewController implements Initializable {
|
||||||
|
private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat("application/x-java-serialized-object");
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TableView<NSLRowModel> table;
|
private TableView<NSLRowModel> table;
|
||||||
private ObservableList<NSLRowModel> rowsObsLst;
|
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..
|
table.setRowFactory( // this shit is made to implement context menu. It's such a pain..
|
||||||
nslRowModelTableView -> {
|
nslRowModelTableView -> {
|
||||||
final TableRow<NSLRowModel> row = new TableRow<>();
|
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();
|
ContextMenu contextMenu = new ContextMenu();
|
||||||
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete"));
|
MenuItem deleteMenuItem = new MenuItem(resourceBundle.getString("tab1_table_contextMenu_Btn_BtnDelete"));
|
||||||
deleteMenuItem.setOnAction(actionEvent -> {
|
deleteMenuItem.setOnAction(actionEvent -> {
|
||||||
|
@ -254,7 +302,10 @@ public class NSTableViewController implements Initializable {
|
||||||
current.getNspFileName().toLowerCase().endsWith("xcz"));
|
current.getNspFileName().toLowerCase().endsWith("xcz"));
|
||||||
}
|
}
|
||||||
else
|
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();
|
table.refresh();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue