[glib/fix-gnulib-msvc-isnan: 30/37] GWin32AppInfo: Drop read_resource_string(), use GWin32RegistryKey
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/fix-gnulib-msvc-isnan: 30/37] GWin32AppInfo: Drop read_resource_string(), use GWin32RegistryKey
- Date: Tue, 9 Jun 2020 10:23:41 +0000 (UTC)
commit 35097db806b4725d6749427482a8bb64e3ed3200
Author: Руслан Ижбулатов <lrn1986 gmail com>
Date: Sun Jan 26 23:42:31 2020 +0000
GWin32AppInfo: Drop read_resource_string(), use GWin32RegistryKey
Now GWin32RegistryKey can internally do the same thing that
read_resource_string() does, and more.
gio/gwin32appinfo.c | 92 +++----------------------------------------------
gio/gwin32registrykey.c | 37 +++++++++++++-------
2 files changed, 29 insertions(+), 100 deletions(-)
---
diff --git a/gio/gwin32appinfo.c b/gio/gwin32appinfo.c
index 829e8c481..ec3e2b70c 100644
--- a/gio/gwin32appinfo.c
+++ b/gio/gwin32appinfo.c
@@ -497,80 +497,6 @@ static GWin32RegistryKey *classes_root_key;
*/
#include "giowin32-private.c"
-static gunichar2 *
-read_resource_string (gunichar2 *res)
-{
- gunichar2 *id_str;
- gunichar2 *id_str_end;
- gunichar2 *filename_str;
- unsigned long id;
- HMODULE resource_module;
- gunichar2 *buffer;
- int string_length;
- int buffer_length;
-
- if (res == NULL || res[0] != L'@')
- return res;
-
- id_str = wcsrchr (res, L'-');
-
- if (id_str == NULL || id_str[-1] != L',')
- return res;
-
- id_str += 1;
-
- id = wcstoul (id_str, &id_str_end, 10);
-
- if (id_str_end == id_str || id_str_end[0] != L'\0' || id == ULONG_MAX)
- return res;
-
- filename_str = &res[1];
- id_str[-2] = L'\0';
-
- resource_module = LoadLibraryExW (filename_str,
- 0,
- LOAD_LIBRARY_AS_DATAFILE |
- LOAD_LIBRARY_AS_IMAGE_RESOURCE);
-
- g_free (res);
-
- if (resource_module == NULL)
- return NULL;
-
- buffer_length = 256;
- string_length = buffer_length - 1;
-
- while (TRUE)
- {
- buffer = g_malloc (buffer_length * sizeof (gunichar2));
- string_length = LoadStringW (resource_module, id, buffer, buffer_length);
-
- if (string_length != 0 && string_length == buffer_length - 1)
- {
- g_free (buffer);
- buffer_length *= 2;
- }
- else
- {
- if (string_length == 0)
- g_clear_pointer (&buffer, g_free);
-
- break;
- }
- }
-
- FreeLibrary (resource_module);
-
- if (buffer)
- {
- gunichar2 *result = g_wcsdup (buffer, -1);
- g_free (buffer);
- return result;
- }
-
- return NULL;
-}
-
static void
read_handler_icon (GWin32RegistryKey *proxy_key,
GWin32RegistryKey *program_key,
@@ -1687,7 +1613,7 @@ read_capable_app (gunichar2 *input_app_key_path, gboolean user_specific, gboolea
friendly_name = NULL;
success = g_win32_registry_key_get_value_w (capabilities,
- NULL,
+ g_win32_registry_get_os_dirs_w (),
TRUE,
L"LocalizedString",
&vtype,
@@ -1695,11 +1621,9 @@ read_capable_app (gunichar2 *input_app_key_path, gboolean user_specific, gboolea
NULL,
NULL);
- if (success && (vtype != G_WIN32_REGISTRY_VALUE_STR || friendly_name[0] != L'@'))
+ if (success && vtype != G_WIN32_REGISTRY_VALUE_STR)
g_clear_pointer (&friendly_name, g_free);
- friendly_name = read_resource_string (friendly_name);
-
if (friendly_name && app->localized_pretty_name == NULL)
{
app->localized_pretty_name = g_wcsdup (friendly_name, -1);
@@ -1713,7 +1637,7 @@ read_capable_app (gunichar2 *input_app_key_path, gboolean user_specific, gboolea
description = NULL;
success = g_win32_registry_key_get_value_w (capabilities,
- NULL,
+ g_win32_registry_get_os_dirs_w (),
TRUE,
L"ApplicationDescription",
&vtype,
@@ -1724,8 +1648,6 @@ read_capable_app (gunichar2 *input_app_key_path, gboolean user_specific, gboolea
if (success && vtype != G_WIN32_REGISTRY_VALUE_STR)
g_clear_pointer (&description, g_free);
- description = read_resource_string (description);
-
if (description && app->description == NULL)
{
app->description = g_wcsdup (description, -1);
@@ -1780,7 +1702,7 @@ read_capable_app (gunichar2 *input_app_key_path, gboolean user_specific, gboolea
narrow_application_name = NULL;
success = g_win32_registry_key_get_value_w (capabilities,
- NULL,
+ g_win32_registry_get_os_dirs_w (),
TRUE,
L"ApplicationName",
&vtype,
@@ -1791,8 +1713,6 @@ read_capable_app (gunichar2 *input_app_key_path, gboolean user_specific, gboolea
if (success && vtype != G_WIN32_REGISTRY_VALUE_STR)
g_clear_pointer (&narrow_application_name, g_free);
- narrow_application_name = read_resource_string (narrow_application_name);
-
/* TODO: do something with the narrow name. Maybe make a kind of sub-app?
* Narrow name is a more precise name of the application in given context.
* I.e. Thunderbird's name is "Thunderbird", whereas its narrow name is
@@ -2252,7 +2172,7 @@ read_exeapps (void)
friendly_app_name = NULL;
success = g_win32_registry_key_get_value_w (incapable_app,
- NULL,
+ g_win32_registry_get_os_dirs_w (),
TRUE,
L"FriendlyAppName",
&vtype,
@@ -2263,8 +2183,6 @@ read_exeapps (void)
if (success && vtype != G_WIN32_REGISTRY_VALUE_STR)
g_clear_pointer (&friendly_app_name, g_free);
- friendly_app_name = read_resource_string (friendly_app_name);
-
no_open_with = FALSE;
success = g_win32_registry_key_get_value_w (incapable_app,
NULL,
diff --git a/gio/gwin32registrykey.c b/gio/gwin32registrykey.c
index e37953f9a..9e6dd2ba9 100644
--- a/gio/gwin32registrykey.c
+++ b/gio/gwin32registrykey.c
@@ -1934,6 +1934,8 @@ g_win32_registry_get_os_dirs (void)
-1, NULL, NULL, NULL);
if (new_mui_os_dirs[new_array_index] != NULL)
new_array_index += 1;
+ else
+ g_critical ("Failed to convert to a system directory #%zu to UTF-8", array_index);
}
g_once_init_leave (&mui_os_dirs, new_mui_os_dirs);
@@ -2026,23 +2028,32 @@ g_win32_registry_key_get_value (GWin32RegistryKey *key,
if (mui_dll_dirs != NULL &&
mui_dll_dirs != mui_os_dirs)
{
- gsize mui_dll_dirs_index;
+ gsize i;
mui_dll_dirs_count = g_strv_length ((gchar **) mui_dll_dirs);
+ mui_dll_dirs_utf16 = g_new0 (gunichar2 *, mui_dll_dirs_count + 1);
- if (mui_dll_dirs_count > 0)
+ for (i = 0; mui_dll_dirs[i] != NULL; i++)
{
- mui_dll_dirs_utf16 = g_new0 (gunichar2 *, mui_dll_dirs_count + 1);
-
- for (mui_dll_dirs_count = 0, mui_dll_dirs_index = 0;
- mui_dll_dirs[mui_dll_dirs_index] != NULL;
- mui_dll_dirs_index++)
- {
- mui_dll_dirs_utf16[mui_dll_dirs_count] = g_utf8_to_utf16 (mui_dll_dirs[mui_dll_dirs_index],
- -1, NULL, NULL, NULL);
- if (mui_dll_dirs_utf16[mui_dll_dirs_count] != NULL)
- mui_dll_dirs_count += 1;
- }
+ mui_dll_dirs_utf16[i] = g_utf8_to_utf16 (mui_dll_dirs[i], -1, NULL, NULL, error);
+
+ if (mui_dll_dirs_utf16[i] == NULL)
+ break;
+ }
+
+ if (mui_dll_dirs[i] != NULL)
+ {
+ g_prefix_error (error,
+ "A mui_dll_dirs string #%zu `%s' failed to convert: ",
+ i, mui_dll_dirs[i]);
+
+ for (i = 0; i < mui_dll_dirs_count; i++)
+ g_free (mui_dll_dirs_utf16[i]);
+
+ g_free (mui_dll_dirs_utf16);
+ g_free (value_name_w);
+
+ return FALSE;
}
}
else if (mui_dll_dirs != NULL &&
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]