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

Setting EXE icon #31

Open
ctrueden opened this issue Feb 1, 2024 · 1 comment
Open

Setting EXE icon #31

ctrueden opened this issue Feb 1, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation os:windows

Comments

@ctrueden
Copy link
Member

ctrueden commented Feb 1, 2024

The ImageJ Launcher has --set-icon hidden argument to call UpdateResource to set the native launcher EXE's icon.

int set_exe_icon(const char *exe_path, const char *ico_path)
{
	int id = 1, i;
	struct icon icon;
	HANDLE handle;

	if (suffixcmp(exe_path, -1, ".exe")) {
		error("Not an .exe file: '%s'", exe_path);
		return 1;
	}
	if (!file_exists(exe_path)) {
		error("File not found: '%s'", exe_path);
		return 1;
	}
	if (suffixcmp(ico_path, -1, ".ico")) {
		error("Not an .ico file: '%s'", ico_path);
		return 1;
	}
	if (!file_exists(ico_path)) {
		error("File not found: '%s'", ico_path);
		return 1;
	}

	if (parse_ico_file(ico_path, &icon))
		return 1;

	handle = BeginUpdateResource(exe_path, FALSE);
	if (!handle) {
		error("Could not update resources of '%s'", exe_path);
		return 1;
	}
	UpdateResource(handle, RT_GROUP_ICON,
			"MAINICON", MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
			icon.header, sizeof(struct header) + icon.count * sizeof(struct resource_directory));
	for (i = 0; i < icon.count; i++) {
		UpdateResource(handle, RT_ICON,
				MAKEINTRESOURCE(id++), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
				icon.images[i], icon.items[i].bytes_in_resource);
	}
	return !EndUpdateResource(handle, FALSE);
}

At first I thought this would be better served by an external tool. But it would actually be nice for the Jaunch configurator to have a set-icon directive that does this, making it as easy as possible for people to build out their own native launchers without needing to install another tool.

@ctrueden
Copy link
Member Author

Electron's rcedit.exe tool is a standalone program ~1MB in size that can edit EXE file icons and other resource metadata, which is currently actively maintained. So for the moment, to resolve this issue in Jaunch, let's simply document the recommendation to use it, rather than adding more C code to Jaunch.

@ctrueden ctrueden added the documentation Improvements or additions to documentation label Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation os:windows
Projects
None yet
Development

No branches or pull requests

1 participant