fix broken hwi installs

This commit is contained in:
Craig Raw
2020-06-05 16:05:13 +02:00
parent f5a857317d
commit c5bcefd331
5 changed files with 54 additions and 4 deletions
@@ -607,7 +607,7 @@ public class AppController implements Initializable {
} else {
if(usbStatus == null) {
usbStatus = new UsbStatusButton();
statusBar.getRightItems().add(usbStatus);
statusBar.getRightItems().add(0, usbStatus);
} else {
usbStatus.getItems().remove(0, usbStatus.getItems().size());
}
@@ -24,7 +24,7 @@ public class MainApp extends Application {
GlyphFontRegistry.register(new FontAwesome5Brands());
Mode mode = Config.get().getMode();
if(true || mode == null) {
if(mode == null) {
WelcomeDialog welcomeDialog = new WelcomeDialog(getHostServices());
Optional<Mode> optionalMode = welcomeDialog.showAndWait();
if(optionalMode.isPresent()) {
@@ -87,6 +87,16 @@ public class Hwi {
private synchronized File getHwiExecutable() {
File hwiExecutable = Config.get().getHwi();
if(hwiExecutable != null && hwiExecutable.exists()) {
if(!testHwi(hwiExecutable)) {
if(Platform.getCurrent().getPlatformId().toLowerCase().equals("mac")) {
deleteDirectory(hwiExecutable.getParentFile());
} else {
hwiExecutable.delete();
}
}
}
if(hwiExecutable == null || !hwiExecutable.exists()) {
try {
Platform platform = Platform.getCurrent();
@@ -147,6 +157,29 @@ public class Hwi {
return hwiExecutable;
}
private boolean testHwi(File hwiExecutable) {
try {
List<String> command = List.of(hwiExecutable.getAbsolutePath(), "enumerate");
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();
int exitValue = process.waitFor();
return exitValue == 0;
} catch (Exception e) {
return false;
}
}
private boolean deleteDirectory(File directoryToBeDeleted) {
File[] allContents = directoryToBeDeleted.listFiles();
if (allContents != null) {
for (File file : allContents) {
deleteDirectory(file);
}
}
return directoryToBeDeleted.delete();
}
public static File newFile(File destinationDir, ZipEntry zipEntry, Set<PosixFilePermission> setFilePermissions) throws IOException {
String destDirPath = destinationDir.getCanonicalPath();