Bundle drivers to windows installer #156

This commit is contained in:
Dmitry Isaenko 2023-12-26 14:39:05 +03:00
parent 88ca0815ed
commit c0bf247666
4 changed files with 35 additions and 10 deletions

View file

@ -1,5 +1,5 @@
/*
Copyright 2019-2020 Dmitry Isaenko
Copyright 2019-2023 Dmitry Isaenko
This file is part of NS-USBloader.
@ -25,8 +25,8 @@ import java.net.URL;
public class DownloadDriversTask extends Task<String> {
public static final long DRIVERS_FILE_SIZE = 3857375;
private static final String driverFileLocationURL = "https://github.com/developersu/NS-Drivers/releases/download/v1.0/Drivers_set.exe";
private static final long driversFileSize = 3857375;
private static File driversInstallerFile;
@ -38,7 +38,7 @@ public class DownloadDriversTask extends Task<String> {
}
private boolean isDriversDownloaded(){
return driversInstallerFile != null && driversInstallerFile.length() == driversFileSize;
return driversInstallerFile != null && driversInstallerFile.length() == DRIVERS_FILE_SIZE;
}
private boolean downloadDrivers(){
@ -64,7 +64,7 @@ public class DownloadDriversTask extends Task<String> {
while ((bytesRead = bis.read(dataBuffer, 0, 1024)) != -1) {
fos.write(dataBuffer, 0, bytesRead);
totalRead += bytesRead;
updateProgress(totalRead, driversFileSize);
updateProgress(totalRead, DRIVERS_FILE_SIZE);
if (this.isCancelled()) {
bis.close();
fos.close();

View file

@ -1,5 +1,5 @@
/*
Copyright 2019-2020 Dmitry Isaenko
Copyright 2019-2023 Dmitry Isaenko
This file is part of NS-USBloader.
@ -32,16 +32,32 @@ import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import nsusbloader.AppPreferences;
import java.io.File;
import java.util.ResourceBundle;
public class DriversInstall {
private static volatile boolean isRunning;
private final ResourceBundle resourceBundle;
private Label runInstallerStatusLabel;
public DriversInstall(ResourceBundle rb){
this.resourceBundle = rb;
if (isDriversDistributesWithExecutable())
runInstaller("Drivers_set.exe");
else
runDownloadProcess();
}
private boolean isDriversDistributesWithExecutable(){
final File drivers = new File("Drivers_set.exe");
return drivers.length() == DownloadDriversTask.DRIVERS_FILE_SIZE;
}
private void runDownloadProcess(){
if (DriversInstall.isRunning)
return;
@ -49,11 +65,11 @@ public class DriversInstall {
DownloadDriversTask downloadTask = new DownloadDriversTask();
Button cancelButton = new Button(rb.getString("btn_Cancel"));
Button cancelButton = new Button(resourceBundle.getString("btn_Cancel"));
HBox hBoxInformation = new HBox();
hBoxInformation.setAlignment(Pos.TOP_LEFT);
hBoxInformation.getChildren().add(new Label(rb.getString("windowBodyDownloadDrivers")));
hBoxInformation.getChildren().add(new Label(resourceBundle.getString("windowBodyDownloadDrivers")));
ProgressBar progressBar = new ProgressBar();
progressBar.setPrefWidth(Double.MAX_VALUE);
@ -90,7 +106,7 @@ public class DriversInstall {
Stage stage = new Stage();
stage.setTitle(rb.getString("windowTitleDownloadDrivers"));
stage.setTitle(resourceBundle.getString("windowTitleDownloadDrivers"));
stage.getIcons().addAll(
new Image("/res/dwnload_ico32x32.png"), //TODO: REDRAW
new Image("/res/dwnload_ico48x48.png"),
@ -115,7 +131,7 @@ public class DriversInstall {
stage.toFront();
downloadTask.setOnSucceeded(event -> {
cancelButton.setText(rb.getString("btn_Close"));
cancelButton.setText(resourceBundle.getString("btn_Close"));
String returnedValue = downloadTask.getValue();