uninstaller: Iterate keys in HKEY_CURRENT_USER also as some programs install their uninstall information there.

This commit is contained in:
Aric Stewart 2007-12-03 12:07:31 +09:00 committed by Alexandre Julliard
parent 33a05f088e
commit 6312ccca55
1 changed files with 23 additions and 11 deletions

View File

@ -32,6 +32,7 @@
WINE_DEFAULT_DEBUG_CHANNEL(uninstaller); WINE_DEFAULT_DEBUG_CHANNEL(uninstaller);
typedef struct { typedef struct {
HKEY root;
WCHAR *key; WCHAR *key;
WCHAR *descr; WCHAR *descr;
WCHAR *command; WCHAR *command;
@ -182,7 +183,7 @@ static int cmp_by_name(const void *a, const void *b)
/** /**
* Fetch information from the uninstall key. * Fetch information from the uninstall key.
*/ */
static int FetchUninstallInformation(void) static int FetchFromRootKey(HKEY root)
{ {
HKEY hkeyUninst, hkeyApp; HKEY hkeyUninst, hkeyApp;
int i; int i;
@ -191,14 +192,9 @@ static int FetchUninstallInformation(void)
WCHAR key_app[1024]; WCHAR key_app[1024];
WCHAR *p; WCHAR *p;
numentries = 0; if (RegOpenKeyExW(root, PathUninstallW, 0, KEY_READ, &hkeyUninst) != ERROR_SUCCESS)
oldsel = -1;
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, PathUninstallW, 0, KEY_READ, &hkeyUninst) != ERROR_SUCCESS)
return 0; return 0;
if (!entries)
entries = HeapAlloc(GetProcessHeap(), 0, sizeof(uninst_entry));
lstrcpyW(key_app, PathUninstallW); lstrcpyW(key_app, PathUninstallW);
lstrcatW(key_app, BackSlashW); lstrcatW(key_app, BackSlashW);
p = key_app+lstrlenW(PathUninstallW)+1; p = key_app+lstrlenW(PathUninstallW)+1;
@ -207,12 +203,13 @@ static int FetchUninstallInformation(void)
for (i=0; RegEnumKeyExW( hkeyUninst, i, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS; ++i) for (i=0; RegEnumKeyExW( hkeyUninst, i, subKeyName, &sizeOfSubKeyName, NULL, NULL, NULL, NULL ) != ERROR_NO_MORE_ITEMS; ++i)
{ {
lstrcpyW(p, subKeyName); lstrcpyW(p, subKeyName);
RegOpenKeyExW(HKEY_LOCAL_MACHINE, key_app, 0, KEY_READ, &hkeyApp); RegOpenKeyExW(root, key_app, 0, KEY_READ, &hkeyApp);
if ((RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, NULL, &displen) == ERROR_SUCCESS) if ((RegQueryValueExW(hkeyApp, DisplayNameW, 0, 0, NULL, &displen) == ERROR_SUCCESS)
&& (RegQueryValueExW(hkeyApp, UninstallCommandlineW, 0, 0, NULL, &uninstlen) == ERROR_SUCCESS)) && (RegQueryValueExW(hkeyApp, UninstallCommandlineW, 0, 0, NULL, &uninstlen) == ERROR_SUCCESS))
{ {
numentries++; numentries++;
entries = HeapReAlloc(GetProcessHeap(), 0, entries, numentries*sizeof(uninst_entry)); entries = HeapReAlloc(GetProcessHeap(), 0, entries, numentries*sizeof(uninst_entry));
entries[numentries-1].root = root;
entries[numentries-1].key = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(subKeyName)+1)*sizeof(WCHAR)); entries[numentries-1].key = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(subKeyName)+1)*sizeof(WCHAR));
lstrcpyW(entries[numentries-1].key, subKeyName); lstrcpyW(entries[numentries-1].key, subKeyName);
entries[numentries-1].descr = HeapAlloc(GetProcessHeap(), 0, displen); entries[numentries-1].descr = HeapAlloc(GetProcessHeap(), 0, displen);
@ -228,11 +225,26 @@ static int FetchUninstallInformation(void)
RegCloseKey(hkeyApp); RegCloseKey(hkeyApp);
sizeOfSubKeyName = 255; sizeOfSubKeyName = 255;
} }
qsort(entries, numentries, sizeof(uninst_entry), cmp_by_name);
RegCloseKey(hkeyUninst); RegCloseKey(hkeyUninst);
return 1; return 1;
} }
static int FetchUninstallInformation(void)
{
int rc;
numentries = 0;
oldsel = -1;
if (!entries)
entries = HeapAlloc(GetProcessHeap(), 0, sizeof(uninst_entry));
rc = FetchFromRootKey(HKEY_LOCAL_MACHINE);
rc |= FetchFromRootKey(HKEY_CURRENT_USER);
qsort(entries, numentries, sizeof(uninst_entry), cmp_by_name);
return rc;
}
static void UninstallProgram(void) static void UninstallProgram(void)
{ {
@ -264,7 +276,7 @@ static void UninstallProgram(void)
if(MessageBoxW(0, errormsg, sAppName, MB_YESNO | MB_ICONQUESTION)==IDYES) if(MessageBoxW(0, errormsg, sAppName, MB_YESNO | MB_ICONQUESTION)==IDYES)
{ {
/* delete the application's uninstall entry */ /* delete the application's uninstall entry */
RegOpenKeyExW(HKEY_LOCAL_MACHINE, PathUninstallW, 0, KEY_READ, &hkey); RegOpenKeyExW(entries[i].root, PathUninstallW, 0, KEY_READ, &hkey);
RegDeleteKeyW(hkey, entries[i].key); RegDeleteKeyW(hkey, entries[i].key);
RegCloseKey(hkey); RegCloseKey(hkey);
} }