From d23e59a5f67fe44cb77feade5f4ae7443484c54d Mon Sep 17 00:00:00 2001 From: Jago de Vreede Date: Mon, 23 Sep 2024 20:22:59 +0200 Subject: [PATCH] feat: Show install or update depending on if SDKMAN is installed or not --- .../io/github/jagodevreede/sdkmanui/Main.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sdkman-ui/src/main/java/io/github/jagodevreede/sdkmanui/Main.java b/sdkman-ui/src/main/java/io/github/jagodevreede/sdkmanui/Main.java index 3ef28fa..6f66a93 100644 --- a/sdkman-ui/src/main/java/io/github/jagodevreede/sdkmanui/Main.java +++ b/sdkman-ui/src/main/java/io/github/jagodevreede/sdkmanui/Main.java @@ -122,18 +122,29 @@ private void install() { } File currentRunningFolder = currentExecutable.getParentFile(); if (!currentRunningFolder.equals(installFolder)) { - SERVICE_REGISTRY.getPopupView().showConfirmation("Installation", "Do you want to install/update SDKMAN UI?", () -> { + File installedExecutable = new File(installFolder, currentExecutable.getName()); + SERVICE_REGISTRY.getPopupView().showConfirmation("Installation", "Do you want to " + (installedExecutable.exists() ? "update" : "install") + " SDKMAN UI?", () -> { try { installFolder.mkdirs(); boolean configured = SERVICE_REGISTRY.getApi().configureEnvironmentPath(); // REPLACE_EXISTING seems to fail on windows, so remove and copy - new File(installFolder, currentExecutable.getName()).delete(); - Files.copy(currentExecutable.toPath(), new File(installFolder, currentExecutable.getName()).toPath(), StandardCopyOption.REPLACE_EXISTING); + boolean oldVersion = installedExecutable.delete(); + Files.copy(currentExecutable.toPath(), installedExecutable.toPath(), StandardCopyOption.REPLACE_EXISTING); updateScriptAndVersion(); - StringBuilder confirmationMessage = new StringBuilder("SDKMAN UI has been installed, you can now remove "); - confirmationMessage.append(currentExecutable.getAbsolutePath()); + StringBuilder confirmationMessage = new StringBuilder("SDKMAN UI has been "); + if (oldVersion) { + confirmationMessage.append("updated"); + } else { + confirmationMessage.append("installed"); + } + String tmpdir = System.getProperty("java.io.tmpdir"); + if (!currentRunningFolder.getAbsolutePath().startsWith(tmpdir)) { + confirmationMessage.append(",\nyou can now remove "); + confirmationMessage.append(currentExecutable.getAbsolutePath()); + } + if (configured) { confirmationMessage.append("\nyou need to relogin to be able to use `sdkui` from the command line."); }