From 6a78701c7a8d3bf944557365f5301f7284df8a1b Mon Sep 17 00:00:00 2001 From: Kristof Date: Wed, 10 Jul 2024 13:14:23 +0200 Subject: [PATCH] Make ie4uinit.exe execution optional (#1240) * - do not execute ie4uinit if it is not available use 'where' to check if an executable is on the PATH * Add log message informing the user an old application icon may still be cached --- .../target/WindowsTargetConfiguration.java | 24 +++++++++++++++++++ 1 file changed, 24 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..80188f75 100644 --- a/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java +++ b/src/main/java/com/gluonhq/substrate/target/WindowsTargetConfiguration.java @@ -285,6 +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")) { + 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"); @@ -311,6 +315,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()) {