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

Associate ROM files with SameBoy on Windows #643

Closed
Rangi42 opened this issue Jun 26, 2024 · 4 comments
Closed

Associate ROM files with SameBoy on Windows #643

Rangi42 opened this issue Jun 26, 2024 · 4 comments

Comments

@Rangi42
Copy link
Contributor

Rangi42 commented Jun 26, 2024

This could be done by having the user run a .reg or .bat file; that's what I do for Polished Map. (See also)

I believe this C code will be the equivalent:

bool set_registry_string(HKEY hive, const char *folder, const char *name, const char *value) {
	HKEY hkey;
	LONG status = RegCreateKeyExA(hive, folder, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL);
	if (status != ERROR_SUCCESS || hkey == NULL) {
		return false;
	}
	status = RegSetValueExA(hkey, name, 0, REG_SZ, value, strlen(value) + 1);
	RegCloseKey(hkey);
	return status == ERROR_SUCCESS;
}

	set_registry_string(HKEY_CURRENT_USER, "Software\\Classes\\.gbc", "", "SameBoy");
	set_registry_string(HKEY_CURRENT_USER, "Software\\Classes\\SameBoy", "", "Game Boy Color ROM");
	set_registry_string(HKEY_CURRENT_USER, "Software\\Classes\\SameBoy\\shell\\open\\command", "", "\"C:\Programs\SameBoy\sameboy.exe\" \"%%1\"");

(Of course SameBoy should figure out the right .exe path to pass for the open command. And you might use the W or A or neither functions, not sure if SameBoy is used to using wide strings or not.)

@LIJI32
Copy link
Owner

LIJI32 commented Jun 26, 2024

I'll give it a look, if I get it working I'll also add the cartridge icons in Windows .ico format.
(SameBoy internally wraps fopen and co. to use UTF-8 strings for source compatibility with every other OS)

@LIJI32
Copy link
Owner

LIJI32 commented Jun 26, 2024

More thoughts:

  1. Is there a way to do this less aggressively? i.e. don't overwrite existing associations.
  2. How would I associate a specific icon resource with these types?
  3. Can I add myself as a "valid open handler" for a file without "stealing" the default handler for a file type?

@Rangi42
Copy link
Contributor Author

Rangi42 commented Jun 26, 2024

  1. Check if "Software\\Classes\\.gbc" already exists with RegOpenKeyEx, and if so, ask the user whether to continue?
  2. Create HKCR\SameBoy\DefaultIcon and set it to the .ico path. (Or to use e.g. icon -42 within an EXE or DLL, you can do sameboy.exe,-42.)
  3. Add sameboy.exe to HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.gbc\OpenWithList.

@LIJI32
Copy link
Owner

LIJI32 commented Nov 15, 2024

Done and implemented, thanks!

@LIJI32 LIJI32 closed this as completed Nov 15, 2024
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

No branches or pull requests

2 participants