Fix file type associations for Windows Vista.

Use Chip-Like icon from shell32.dll for all ROMs.
This commit is contained in:
spacy51 2009-08-15 19:48:32 +00:00
parent 4d4f53425e
commit daa8105c07
3 changed files with 105 additions and 70 deletions

View File

@ -95,7 +95,8 @@ void Associate::OnOk()
commandPath.Format("\"%s\" \"%%1\"", applicationPath); commandPath.Format("\"%s\" \"%%1\"", applicationPath);
regAssociateType("VisualBoyAdvance.Binary", regAssociateType("VisualBoyAdvance.Binary",
"Binary", "Binary",
commandPath); commandPath,
"%SystemRoot%\\system32\\SHELL32.dll,-13");
for(int i = 0; i < 7; i++) { for(int i = 0; i < 7; i++) {
if(mask & (1<<i)) { if(mask & (1<<i)) {

View File

@ -218,77 +218,111 @@ void regDeleteValue(char *key)
} }
} }
bool regCreateFileType(const char *ext, const char *type) bool regCreateFileType( const char *ext, const char *type )
{ {
DWORD disp = 0; HKEY key;
HKEY key; CString temp;
LONG res = RegCreateKeyEx(HKEY_CLASSES_ROOT, temp.Format( "Software\\Classes\\%s", ext );
ext, LONG res = RegCreateKeyEx(
0, HKEY_CURRENT_USER,
"", temp,
REG_OPTION_NON_VOLATILE, 0,
KEY_ALL_ACCESS, NULL,
NULL, REG_OPTION_NON_VOLATILE,
&key, KEY_ALL_ACCESS,
&disp); NULL,
if(res == ERROR_SUCCESS) { &key,
res = RegSetValueEx(key, NULL );
"", if( res == ERROR_SUCCESS ) {
0, RegSetValueEx(
REG_SZ, key,
(const UCHAR *)type, "",
lstrlen(type)+1); 0,
RegCloseKey(key); REG_SZ,
return true; (const BYTE *)type,
} lstrlen(type) + 1 );
return false; RegCloseKey( key );
// Notify Windows that extensions have changed
SHChangeNotify( SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL );
return true;
}
return false;
} }
bool regAssociateType(const char *type, const char *desc, const char *application) bool regAssociateType( const char *type, const char *desc, const char *application, const char *icon )
{ {
DWORD disp = 0; HKEY key;
HKEY key; CString temp;
LONG res = RegCreateKeyEx(HKEY_CLASSES_ROOT, temp.Format( "Software\\Classes\\%s", type );
type, LONG res = RegCreateKeyEx(
0, HKEY_CURRENT_USER,
"", temp,
REG_OPTION_NON_VOLATILE, 0,
KEY_ALL_ACCESS, NULL,
NULL, REG_OPTION_NON_VOLATILE,
&key, KEY_ALL_ACCESS,
&disp); NULL,
if(res == ERROR_SUCCESS) { &key,
res = RegSetValueEx(key, NULL );
"", if( res == ERROR_SUCCESS ) {
0, res = RegSetValueEx(
REG_SZ, key,
(const UCHAR *)desc, "",//"FriendlyTypeName",
lstrlen(desc)+1); 0,
HKEY key2; REG_SZ,
res = RegCreateKeyEx(key, (const BYTE *)desc,
"Shell\\Open\\Command", lstrlen(desc) + 1 );
0, HKEY key2;
"", res = RegCreateKeyEx(
REG_OPTION_NON_VOLATILE, key,
KEY_ALL_ACCESS, "Shell\\Open\\Command",
NULL, 0,
&key2, NULL,
&disp); REG_OPTION_NON_VOLATILE,
if(res == ERROR_SUCCESS) { KEY_ALL_ACCESS,
res = RegSetValueEx(key2, NULL,
"", &key2,
0, NULL );
REG_SZ, if( res == ERROR_SUCCESS ) {
(const UCHAR *)application, RegSetValueEx(
lstrlen(application)+1); key2,
RegCloseKey(key2); "",
RegCloseKey(key); 0,
return true; REG_SZ,
} (const BYTE *)application,
lstrlen(application) + 1 );
RegCloseKey(key); if( icon != NULL ) {
} HKEY key3;
return false; res = RegCreateKeyEx(
key,
"DefaultIcon",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key3,
NULL );
if( res == ERROR_SUCCESS ) {
RegSetValueEx(
key3,
"",
0,
REG_SZ,
(const BYTE *)icon,
lstrlen(icon) + 1 );
}
RegCloseKey(key3);
}
RegCloseKey(key2);
RegCloseKey(key);
// Notify Windows that extensions have changed
SHChangeNotify( SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL );
return true;
}
RegCloseKey(key);
}
return false;
} }
static void regExportSettingsToINI(HKEY key, const char *section) static void regExportSettingsToINI(HKEY key, const char *section)

View File

@ -12,7 +12,7 @@ void regSetBinaryValue(const char *key, char *value, int count);
void regDeleteValue(char *key); void regDeleteValue(char *key);
void regInit(const char *); void regInit(const char *);
void regShutdown(); void regShutdown();
bool regCreateFileType(const char *ext, const char *type); bool regCreateFileType( const char *ext, const char *type );
bool regAssociateType(const char *type, const char *desc, const char *application); bool regAssociateType( const char *type, const char *desc, const char *application, const char *icon = NULL );
void regExportSettingsToINI(); void regExportSettingsToINI();
#endif // VBA_REG_H #endif // VBA_REG_H