winemenubuilder: Introduce a reg_enum_keyW helper function.
The helper function reduces code duplication and makes the 'done' variable in the cleanup_associations function unnecessary. Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
d5a7d08f63
commit
5d8aac9cb0
|
@ -1753,6 +1753,30 @@ static WCHAR *freedesktop_mime_type_for_extension(struct list *native_mime_types
|
||||||
return match ? xwcsdup(match) : NULL;
|
return match ? xwcsdup(match) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static WCHAR *reg_enum_keyW(HKEY key, DWORD index)
|
||||||
|
{
|
||||||
|
WCHAR *subkey;
|
||||||
|
DWORD size = 1024 * sizeof(WCHAR);
|
||||||
|
LSTATUS ret;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
subkey = xmalloc(size);
|
||||||
|
ret = RegEnumKeyExW(key, index, subkey, &size, NULL, NULL, NULL, NULL);
|
||||||
|
if (ret == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
return subkey;
|
||||||
|
}
|
||||||
|
if (ret != ERROR_MORE_DATA)
|
||||||
|
{
|
||||||
|
heap_free(subkey);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
size *= 2;
|
||||||
|
heap_free(subkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static WCHAR* reg_get_valW(HKEY key, LPCWSTR subkey, LPCWSTR name)
|
static WCHAR* reg_get_valW(HKEY key, LPCWSTR subkey, LPCWSTR name)
|
||||||
{
|
{
|
||||||
DWORD size;
|
DWORD size;
|
||||||
|
@ -1857,27 +1881,16 @@ static BOOL cleanup_associations(void)
|
||||||
BOOL hasChanged = FALSE;
|
BOOL hasChanged = FALSE;
|
||||||
if ((assocKey = open_associations_reg_key()))
|
if ((assocKey = open_associations_reg_key()))
|
||||||
{
|
{
|
||||||
int i;
|
int i = 0;
|
||||||
BOOL done = FALSE;
|
for (;;)
|
||||||
for (i = 0; !done;)
|
|
||||||
{
|
|
||||||
WCHAR *extensionW = NULL;
|
|
||||||
DWORD size = 1024;
|
|
||||||
LSTATUS ret;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
heap_free(extensionW);
|
|
||||||
extensionW = xmalloc(size * sizeof(WCHAR));
|
|
||||||
ret = RegEnumKeyExW(assocKey, i, extensionW, &size, NULL, NULL, NULL, NULL);
|
|
||||||
size *= 2;
|
|
||||||
} while (ret == ERROR_MORE_DATA);
|
|
||||||
|
|
||||||
if (ret == ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
|
WCHAR *extensionW;
|
||||||
WCHAR *command;
|
WCHAR *command;
|
||||||
command = assoc_query(ASSOCSTR_COMMAND, extensionW, L"open");
|
|
||||||
if (command == NULL)
|
if (!(extensionW = reg_enum_keyW(assocKey, i)))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!(command = assoc_query(ASSOCSTR_COMMAND, extensionW, L"open")))
|
||||||
{
|
{
|
||||||
WCHAR *desktopFile = reg_get_valW(assocKey, extensionW, L"DesktopFile");
|
WCHAR *desktopFile = reg_get_valW(assocKey, extensionW, L"DesktopFile");
|
||||||
if (desktopFile)
|
if (desktopFile)
|
||||||
|
@ -1890,15 +1903,10 @@ static BOOL cleanup_associations(void)
|
||||||
heap_free(desktopFile);
|
heap_free(desktopFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
i++;
|
i++;
|
||||||
heap_free(command);
|
heap_free(command);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
if (ret != ERROR_NO_MORE_ITEMS)
|
|
||||||
WINE_ERR("error %d while reading registry\n", ret);
|
|
||||||
done = TRUE;
|
|
||||||
}
|
|
||||||
heap_free(extensionW);
|
heap_free(extensionW);
|
||||||
}
|
}
|
||||||
RegCloseKey(assocKey);
|
RegCloseKey(assocKey);
|
||||||
|
@ -1998,7 +2006,6 @@ static BOOL generate_associations(const WCHAR *packages_dir, const WCHAR *applic
|
||||||
{
|
{
|
||||||
struct wine_rb_tree mimeProgidTree = { winemenubuilder_rb_string_compare };
|
struct wine_rb_tree mimeProgidTree = { winemenubuilder_rb_string_compare };
|
||||||
struct list nativeMimeTypes = LIST_INIT(nativeMimeTypes);
|
struct list nativeMimeTypes = LIST_INIT(nativeMimeTypes);
|
||||||
LSTATUS ret = 0;
|
|
||||||
int i;
|
int i;
|
||||||
BOOL hasChanged = FALSE;
|
BOOL hasChanged = FALSE;
|
||||||
|
|
||||||
|
@ -2010,18 +2017,12 @@ static BOOL generate_associations(const WCHAR *packages_dir, const WCHAR *applic
|
||||||
|
|
||||||
for (i = 0; ; i++)
|
for (i = 0; ; i++)
|
||||||
{
|
{
|
||||||
WCHAR *extensionW = NULL;
|
WCHAR *extensionW;
|
||||||
DWORD size = 1024;
|
|
||||||
|
|
||||||
do
|
if (!(extensionW = reg_enum_keyW(HKEY_CLASSES_ROOT, i)))
|
||||||
{
|
break;
|
||||||
heap_free(extensionW);
|
|
||||||
extensionW = xmalloc(size * sizeof(WCHAR));
|
|
||||||
ret = RegEnumKeyExW(HKEY_CLASSES_ROOT, i, extensionW, &size, NULL, NULL, NULL, NULL);
|
|
||||||
size *= 2;
|
|
||||||
} while (ret == ERROR_MORE_DATA);
|
|
||||||
|
|
||||||
if (ret == ERROR_SUCCESS && extensionW[0] == '.' && !is_extension_banned(extensionW))
|
if (extensionW[0] == '.' && !is_extension_banned(extensionW))
|
||||||
{
|
{
|
||||||
WCHAR *commandW = NULL;
|
WCHAR *commandW = NULL;
|
||||||
WCHAR *executableW = NULL;
|
WCHAR *executableW = NULL;
|
||||||
|
@ -2129,8 +2130,6 @@ static BOOL generate_associations(const WCHAR *packages_dir, const WCHAR *applic
|
||||||
heap_free(progIdW);
|
heap_free(progIdW);
|
||||||
}
|
}
|
||||||
heap_free(extensionW);
|
heap_free(extensionW);
|
||||||
if (ret != ERROR_SUCCESS)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wine_rb_destroy(&mimeProgidTree, winemenubuilder_rb_destroy, NULL);
|
wine_rb_destroy(&mimeProgidTree, winemenubuilder_rb_destroy, NULL);
|
||||||
|
|
Loading…
Reference in New Issue