]> localhost Git - scsi2sd-util.git/commitdiff
Fix progress bar while writing image
authorMichael McMaster <michael@codesrc.com>
Thu, 15 Apr 2021 05:49:11 +0000 (15:49 +1000)
committerMichael McMaster <michael@codesrc.com>
Thu, 15 Apr 2021 05:49:11 +0000 (15:49 +1000)
scsi2sd.ui/src/main/java/com/codesrc/scsi2sd/model/DiskConfig.java
scsi2sd.ui/src/main/java/com/codesrc/scsi2sd/presentation/DiskConfigController.java
scsi2sd.ui/src/main/java/com/codesrc/scsi2sd/presentation/MainController.java
scsi2sd.ui/src/main/resources/fx/disksTab.fxml

index 8d03c33a97606214fe37a5ab3381b08403abe741..7b2fdd5a885ea5209898d8869adba185a808c1e4 100644 (file)
@@ -57,7 +57,7 @@ public class DiskConfig {
 
     private Set<Quirks> quirks;
 
-    private int storageDevice;
+    private StorageDeviceEnum storageDevice;
 
     public DiskConfig(
             Type type,
@@ -111,7 +111,7 @@ public class DiskConfig {
 
         this.quirks = new HashSet<Quirks>();
 
-        this.storageDevice = 0;
+        this.storageDevice = StorageDeviceEnum.S2S_STORAGE_SD;
     }
 
     public DiskConfig(byte[] in) {
@@ -138,7 +138,7 @@ public class DiskConfig {
 
         this.quirks = Quirks.fromBitmask(BitUtil.letohs(in, 62));
 
-        storageDevice = BitUtil.uint8ToInt(in[64]);
+        storageDevice = StorageDeviceEnum.fromValue(in[64]);
     }
 
 
@@ -179,7 +179,7 @@ public class DiskConfig {
         out[62] = BitUtil.longToUint8(quirksMask);
         out[63] = BitUtil.longToUint8(quirksMask >> 8);
 
-        out[64] = BitUtil.intToUint8((this.scsiId & 0x07) == 1 ? 1 : 0);
+        out[64] = BitUtil.intToUint8(this.storageDevice.getValue());
 
         return out;
     }
@@ -271,6 +271,17 @@ public class DiskConfig {
         }
     }
 
+    public StorageDeviceEnum getStorageDevice()
+    {
+        return this.storageDevice;
+    }
+
+    public void setStorageDevice(StorageDeviceEnum storageDevice)
+    {
+        this.storageDevice = storageDevice;
+    }
+
+
     public DiskUnit getBestUnit() {
         var scsiSize = this.scsiSectors * this.bytesPerSector;
 
@@ -450,13 +461,17 @@ public class DiskConfig {
         } catch (NumberFormatException e) {
         }
 
-        this.storageDevice = 0;
+        this.storageDevice = StorageDeviceEnum.S2S_STORAGE_SD;
         var storageDeviceText = children.getOrDefault("storageDevice", "0");
         try {
-            var intValue = Integer.valueOf(storageDeviceText);
-            if (intValue >= 0 && intValue < 256) {
-                this.storageDevice = intValue;
+            var radix = 10;
+            if (devTypeText.toLowerCase().startsWith("0x")) {
+                radix = 16;
+                storageDeviceText = devTypeText.substring(2);
             }
+
+            var byteValue = Byte.valueOf(storageDeviceText, radix);
+            this.storageDevice = StorageDeviceEnum.fromValue(byteValue);
         } catch (NumberFormatException e) {
         }
 
@@ -576,7 +591,7 @@ public class DiskConfig {
             .append("  0    SD.\n")
             .append("  1    Flash.\n")
             .append("  ********************************************************* -->\n")
-            .append("  <storageDevice>").append(this.storageDevice).append("</storageDevice>\n")
+            .append("  <storageDevice>").append(this.storageDevice.getValue()).append("</storageDevice>\n")
             .append("\n\n")
 
             .append("\n\n")
index bc5f7d2a417fe627e5f78a4cc2e912658b9dd043..a65613f53638e346ac55cd82e4e281a9f498b5b3 100644 (file)
@@ -69,6 +69,8 @@ public class DiskConfigController implements Initializable, DocumentObserver {
     private TextField sdStartingByte;
 
     @FXML ComboBox scsiDeviceType;
+    @FXML ComboBox storageDevice;
+
 
     @FXML private TextField vendor;
     @FXML private TextField prodId;
@@ -152,6 +154,7 @@ public class DiskConfigController implements Initializable, DocumentObserver {
         this.scsiBytesPerSector.focusedProperty().addListener((obs, wasFocussed, isNowFocussed) -> {if (!isNowFocussed) this.setBytesPerSector();});
 
         this.scsiDeviceType.setOnAction((e) -> this.setDeviceType());
+        this.storageDevice.setOnAction((e) -> this.setStorageDevice());
 
         this.vendor.setOnAction((e) -> this.setVendor());
         this.vendor.focusedProperty().addListener((obs, wasFocussed, isNowFocussed) -> {if (!isNowFocussed) this.setVendor();});
@@ -185,6 +188,7 @@ public class DiskConfigController implements Initializable, DocumentObserver {
 
         this.scsiSizeUnit.getItems().addAll(DiskUnit.values());
         this.scsiDeviceType.getItems().addAll(Arrays.stream(DeviceTypeEnum.values()).filter(dt -> dt != DeviceTypeEnum.S2S_CFG_SEQUENTIAL).toArray());
+        this.storageDevice.getItems().addAll(StorageDeviceEnum.values());
 
         this.quirksMode.getItems().addAll(Quirks.values());
 
@@ -239,6 +243,7 @@ public class DiskConfigController implements Initializable, DocumentObserver {
             this.scsiSizeStr.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
             this.scsiBytesPerSector.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
             this.scsiDeviceType.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
+            this.storageDevice.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
             this.vendor.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
             this.prodId.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
             this.revision.setDisable(this.selectedConfig.getType() != DiskConfig.Type.DISK);
@@ -256,6 +261,7 @@ public class DiskConfigController implements Initializable, DocumentObserver {
             this.scsiBytesPerSector.setText(Integer.toString(this.selectedConfig.getBytesPerSector()));
             this.sdStartingByte.setText(Long.toString(this.selectedConfig.getSdSectorStart() * DiskConfig.SD_SECTOR_SIZE));
             this.scsiDeviceType.setValue(this.selectedConfig.getDeviceType());
+            this.storageDevice.setValue(this.selectedConfig.getStorageDevice());
             this.deviceTypeModifier.setText(String.valueOf(this.selectedConfig.getDeviceTypeModifier()));
             this.vendor.setText(this.selectedConfig.getVendor());
             this.prodId.setText(this.selectedConfig.getProdId());
@@ -440,6 +446,17 @@ public class DiskConfigController implements Initializable, DocumentObserver {
         }
     }
 
+    private void setStorageDevice()
+    {
+        if (this.selectedConfig != null)
+        {
+            this.selectedConfig.setStorageDevice((StorageDeviceEnum) this.storageDevice.getValue());
+
+            this.activeDocument.setModified(DiskConfigController.class.getName(), true);
+            this.refreshList();
+        }
+    }
+
     private void setVendor()
     {
         if (this.selectedConfig != null)
index ef8ec64640af7e27b12c2e3d2572bb1ac1cb0b62..f541e96f7c30b8a751e09b8631f02e7bf6193594 100644 (file)
@@ -36,7 +36,9 @@ import javafx.scene.layout.AnchorPane;
 import javafx.scene.layout.HBox;
 import javafx.scene.layout.VBox;
 import javafx.stage.FileChooser;
+import javafx.stage.Modality;
 import javafx.stage.Stage;
+import javafx.stage.StageStyle;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -421,8 +423,6 @@ public class MainController implements FXController, DocumentObserver {
 
     private void loadDefault()
     {
-        writeImageToDevice();
-
         var root = new ConfigRoot();
         root.setBoardConfig(new BoardConfig());
         root.setDiskList(new DiskList(2l*1024*1024*1024/512));
@@ -484,38 +484,54 @@ public class MainController implements FXController, DocumentObserver {
         }
 
         Stage stage = new Stage();
-        try {
-            // TODO allow selection of device.
-
-            //Scene scene = new Scene(this.window.getScene().getRoot(), 300, 75);
-            Scene scene = new Scene(new Group(), 300, 75);
-            stage.setScene(scene);
-            stage.setTitle("Image Progress");
-
-            final ProgressBar pb = new ProgressBar(0);
-            final HBox hb = new HBox();
-            hb.setSpacing(5);
-            hb.setAlignment(Pos.CENTER);
-            hb.getChildren().addAll(new Label("Writing Image"), pb);
-
-            final VBox vb = new VBox();
-            vb.setSpacing(5);
-            vb.getChildren().addAll(new Label(), hb);
-            scene.setRoot(vb);
-            stage.show();
-
-            this.getDevice().writeImage(
-                    deviceList.get(0).getStorageDevices().size() - 1,
-                    theFile,
-                    0);
-        } catch (Exception e) {
-            e.printStackTrace();
-            Alert alert = new Alert(Alert.AlertType.ERROR);
-            alert.setTitle("Imaging failed");
-            alert.setContentText(e.getLocalizedMessage());
-            alert.show();
-        } finally {
-            stage.hide();
-        }
+
+        // TODO allow selection of device.
+
+        //Scene scene = new Scene(this.window.getScene().getRoot(), 300, 75);
+        Scene scene = new Scene(new Group(), 300, 75);
+        stage.setScene(scene);
+        stage.setTitle("Image Progress");
+
+        final ProgressBar pb = new ProgressBar(0);
+          final HBox hb = new HBox();
+        hb.setSpacing(5);
+        hb.setAlignment(Pos.CENTER);
+        var progresssLabel = new Label("Writing Image 0.00%");
+        hb.getChildren().addAll(progresssLabel, pb);
+
+        final VBox vb = new VBox();
+        vb.setSpacing(5);
+        vb.getChildren().addAll(new Label(), hb);
+        scene.setRoot(vb);
+
+        stage.initOwner(this.window);
+        stage.initModality(Modality.APPLICATION_MODAL);
+        stage.initStyle(StageStyle.UNDECORATED);
+
+        stage.show();
+
+        new Thread(() -> {
+            try {
+                this.getDevice().writeImage(
+                        deviceList.get(0).getStorageDevices().size() - 1,
+                        theFile,
+                        0,
+                        progress -> Platform.runLater(() -> {
+                            pb.setProgress(progress);
+                            progresssLabel.setText(String.format("Writing Image %.2f %%", progress * 100));
+                        }));
+
+            } catch (Exception e) {
+                e.printStackTrace();
+                Platform.runLater(() -> {
+                    Alert alert = new Alert(Alert.AlertType.ERROR);
+                    alert.setTitle("Imaging failed");
+                    alert.setContentText(e.getLocalizedMessage());
+                    alert.show();
+                });
+            } finally {
+                Platform.runLater(() -> stage.hide());
+            }
+        }).start();
     }
 }
index 7b050a8b412a53a31f2362826a34ba1e29cf1d27..99afde852cc32eee2c2305b64ce4c98a512803a0 100644 (file)
@@ -80,6 +80,7 @@
                                                 <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                                 <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                                 <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
+                                                <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                                             </rowConstraints>
                                             <children>
                                                 <Label text="SCSI ID" />
@@ -91,6 +92,9 @@
                                                 <Label text="Enabled" GridPane.rowIndex="2" />
                                                 <CheckBox fx:id="enabled" prefHeight="25.0" prefWidth="270.0" GridPane.columnIndex="1" GridPane.rowIndex="2" />
 
+                                                <Label text="Storage Device" GridPane.rowIndex="3" />
+                                                <ComboBox fx:id="storageDevice" prefHeight="25.0" prefWidth="270.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
+
                                             </children>
                                         </GridPane>
                                     </children>