Fix file type associations for Windows Vista.

Use Chip-Like icon from shell32.dll for all ROMs.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@886 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
spacy51 2009-08-15 19:48:32 +00:00
parent 0eccbe84bd
commit f986277ed8
3 changed files with 105 additions and 70 deletions

View File

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

View File

@ -218,74 +218,108 @@ 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;
LONG res = RegCreateKeyEx(HKEY_CLASSES_ROOT,
ext,
CString temp;
temp.Format( "Software\\Classes\\%s", ext );
LONG res = RegCreateKeyEx(
HKEY_CURRENT_USER,
temp,
0,
"",
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key,
&disp);
if(res == ERROR_SUCCESS) {
res = RegSetValueEx(key,
NULL );
if( res == ERROR_SUCCESS ) {
RegSetValueEx(
key,
"",
0,
REG_SZ,
(const UCHAR *)type,
lstrlen(type)+1);
RegCloseKey(key);
(const BYTE *)type,
lstrlen(type) + 1 );
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;
LONG res = RegCreateKeyEx(HKEY_CLASSES_ROOT,
type,
CString temp;
temp.Format( "Software\\Classes\\%s", type );
LONG res = RegCreateKeyEx(
HKEY_CURRENT_USER,
temp,
0,
"",
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key,
&disp);
if(res == ERROR_SUCCESS) {
res = RegSetValueEx(key,
"",
NULL );
if( res == ERROR_SUCCESS ) {
res = RegSetValueEx(
key,
"",//"FriendlyTypeName",
0,
REG_SZ,
(const UCHAR *)desc,
lstrlen(desc)+1);
(const BYTE *)desc,
lstrlen(desc) + 1 );
HKEY key2;
res = RegCreateKeyEx(key,
res = RegCreateKeyEx(
key,
"Shell\\Open\\Command",
0,
"",
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&key2,
&disp);
if(res == ERROR_SUCCESS) {
res = RegSetValueEx(key2,
NULL );
if( res == ERROR_SUCCESS ) {
RegSetValueEx(
key2,
"",
0,
REG_SZ,
(const UCHAR *)application,
lstrlen(application)+1);
(const BYTE *)application,
lstrlen(application) + 1 );
if( icon != NULL ) {
HKEY key3;
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;

View File

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