Skip to content

Commit

Permalink
Make ie4uinit.exe execution optional (#1240)
Browse files Browse the repository at this point in the history
* - 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
  • Loading branch information
kkriske authored Jul 10, 2024
1 parent 8cf189f commit 6a78701
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<String> getAdditionalSourceFiles() {
if (projectConfiguration.isSharedLibrary()) {
Expand Down

0 comments on commit 6a78701

Please sign in to comment.