From 73b53d15a468219975d5a7b91b12920624610461 Mon Sep 17 00:00:00 2001 From: Kristof Dhondt Date: Wed, 20 Dec 2023 21:12:13 +0100 Subject: [PATCH 1/2] - do not execute ie4uinit if it is not available use 'where' to check if an executable is on the PATH --- .../target/WindowsTargetConfiguration.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java b/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java index b4334de0..14faf4ae 100644 --- a/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java +++ b/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java @@ -285,6 +285,7 @@ private void createIconResource() throws InterruptedException, IOException { // During development if user changes the application icon, the same is not reflected immediately in Explorer. // To fix this, a cache clearance of the Windows explorer is required. private void clearExplorerCache() throws IOException, InterruptedException { + if (!executableOnPath("ie4uinit.exe")) return; ProcessRunner clearCache = new ProcessRunner("ie4uinit"); clearCache.addArg(findCacheFlag()); clearCache.runProcess("Clear Explorer cache"); @@ -311,6 +312,26 @@ private String findCacheFlag() throws IOException, InterruptedException { return flag; } + /** + * Returns whether the passed executable is available on the PATH. + * For best result, the extension should be included in the executable, as "foo" will return true for "foo.bat". + * But running "foo" in a ProcessBuilder will look for "foo.exe" and fail to run. + * + * @param executable name of the executable to check + * @return true if the executable is available on the PATH. + */ + private boolean executableOnPath(String executable) { + try { + ProcessRunner whereProcess = new ProcessRunner("cmd.exe", "/c", "where", "/q", executable); + whereProcess.showSevereMessage(false); + int exit = whereProcess.runProcess("find executable"); + return exit == 0; + } catch (IOException | InterruptedException e) { + Logger.logInfo(String.format("Unable to validate if %s is available on the PATH, assuming it is not.", executable)); + return false; + } + } + @Override List getAdditionalSourceFiles() { if (projectConfiguration.isSharedLibrary()) { From 44f0cf40d78ae1df9caa12953cc0ce13607ac0c1 Mon Sep 17 00:00:00 2001 From: Kristof Dhondt Date: Sun, 28 Apr 2024 14:36:48 +0200 Subject: [PATCH 2/2] Add log message informing the user an old application icon may still be cached --- .../gluonhq/substrate/target/WindowsTargetConfiguration.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java b/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java index 14faf4ae..80188f75 100644 --- a/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java +++ b/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java @@ -285,7 +285,10 @@ private void createIconResource() throws InterruptedException, IOException { // During development if user changes the application icon, the same is not reflected immediately in Explorer. // To fix this, a cache clearance of the Windows explorer is required. private void clearExplorerCache() throws IOException, InterruptedException { - if (!executableOnPath("ie4uinit.exe")) return; + if (!executableOnPath("ie4uinit.exe")) { + Logger.logInfo("The application icon cache could not be cleared. As a result, the icon may not have been updated properly."); + return; + } ProcessRunner clearCache = new ProcessRunner("ie4uinit"); clearCache.addArg(findCacheFlag()); clearCache.runProcess("Clear Explorer cache");