Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Icon to Windows native binary #1090

Merged
merged 5 commits into from
Jan 21, 2022

Conversation

abhinayagarwal
Copy link
Collaborator

Taking inspiration from @freya022's comment, I have been able to add an icon to the native exe by linking an icon object.

To create the icon object, we have a static file. Use rc.exe command to compile the resource file and then cvtres.exe to convert the output file into an linkable object.

Issue

Fixes #1086

Progress

super.link();
clearExplorerCache();
} catch (IOException ioe) {
ioe.printStackTrace();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically don't print stack traces from here, use Logger.logSevere() instead. You can use logFatal() too, but that will throw a RTE. But since link already propagates an IOE, I'd remove the try-catch, and add a check to super.link(). If it fails, return false. Else continue with the cache.

} else {
FileOps.copyResource("/native/windows/assets/icon.ico", iconDir.resolve("icon.ico"));
Logger.logInfo("Default icon.ico image used. " +
"Consider adding a custom icon to '/native/windows/assets'.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean src/windows/assets?

// Copy icon.ico to gvm/tmp/icon
if (Files.exists(userAssets) && Files.isDirectory(userAssets) && Files.exists(userAssets.resolve("icon.ico"))) {
FileOps.copyFile(userAssets.resolve("icon.ico"), iconDir.resolve("icon.ico")) ;
Logger.logInfo("User provided icon.ico image used as application icon.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to logDebug

FileOps.copyFile(userAssets.resolve("icon.ico"), iconDir.resolve("icon.ico")) ;
Logger.logInfo("User provided icon.ico image used as application icon.");
} else {
FileOps.copyResource("/native/windows/assets/icon.ico", iconDir.resolve("icon.ico"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add it to gensrc first, then copy it to tmp/icon

@@ -0,0 +1,3 @@
LANGUAGE 0x00, 0x00

1 ICON "icon.ico"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line

Files.createDirectories(windowsAssetPath);
FileOps.copyResource("/native/windows/assets/icon.ico", windowsAssetPath.resolve("icon.ico"));
FileOps.copyFile(windowsAssetPath.resolve("icon.ico"), tmpIconDir.resolve("icon.ico"));
Logger.logInfo("Default icon.ico image used. " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard message is:

Logger.logInfo("Default icon.ico image generated in " + windowsAssetPath + ".\n" +
                    "Consider copying it to " + rootPath + " before performing any modification");

@westinyang
Copy link

How should it be used? Creating a gluonfx app, where should custom icons be placed?

@simeonlin
Copy link

If it helps someone:
Put your File under src\windows\assets\icon.ico

(according westinyang's question)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Icon to Windows native binary
4 participants