| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include "gdk/gdk.h" |
| 28 |
|
| 29 |
#include "gtkprivate.h" |
| 30 |
|
| 31 |
#include <windows.h> |
| 32 |
#include <commctrl.h> |
| 33 |
|
| 34 |
extern IMAGE_DOS_HEADER __ImageBase; |
| 35 |
|
| 36 |
static inline HMODULE |
| 37 |
this_module (void) |
| 38 |
{ |
| 39 |
return (HMODULE) &__ImageBase; |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#define EMPIRIC_MANIFEST_RESOURCE_INDEX 2 |
| 46 |
|
| 47 |
static wchar_t * |
| 48 |
g_wcsdup (const wchar_t *wcs) |
| 49 |
{ |
| 50 |
wchar_t *new_wcs = NULL; |
| 51 |
gsize length; |
| 52 |
|
| 53 |
if G_LIKELY (wcs) |
| 54 |
{ |
| 55 |
length = wcslen (wcs) + 1; |
| 56 |
new_wcs = g_new (wchar_t, length); |
| 57 |
wcscpy (new_wcs, wcs); |
| 58 |
new_wcs[length - 1] = L'\0'; |
| 59 |
} |
| 60 |
|
| 61 |
return new_wcs; |
| 62 |
} |
| 63 |
|
| 64 |
static BOOL CALLBACK |
| 65 |
find_first_manifest (HMODULE module_handle, |
| 66 |
LPCWSTR resource_type, |
| 67 |
LPWSTR resource_name, |
| 68 |
LONG_PTR user_data) |
| 69 |
{ |
| 70 |
LPWSTR *result_name = (LPWSTR *) user_data; |
| 71 |
|
| 72 |
if (resource_type == RT_MANIFEST) |
| 73 |
{ |
| 74 |
if (IS_INTRESOURCE (resource_name)) |
| 75 |
*result_name = resource_name; |
| 76 |
else |
| 77 |
*result_name = g_wcsdup (resource_name); |
| 78 |
return FALSE; |
| 79 |
} |
| 80 |
return TRUE; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
void |
| 100 |
_gtk_load_dll_with_libgtk3_manifest (const wchar_t *dll_name) |
| 101 |
{ |
| 102 |
HANDLE activation_ctx_handle; |
| 103 |
ACTCTX activation_ctx_descriptor; |
| 104 |
ULONG_PTR activation_cookie; |
| 105 |
LPWSTR resource_name; |
| 106 |
BOOL activated; |
| 107 |
DWORD error_code; |
| 108 |
|
| 109 |
resource_name = NULL; |
| 110 |
EnumResourceNames (this_module (), RT_MANIFEST, find_first_manifest, |
| 111 |
(LONG_PTR) &resource_name); |
| 112 |
|
| 113 |
if (resource_name == NULL) |
| 114 |
resource_name = MAKEINTRESOURCE (EMPIRIC_MANIFEST_RESOURCE_INDEX); |
| 115 |
|
| 116 |
memset (&activation_ctx_descriptor, 0, sizeof (activation_ctx_descriptor)); |
| 117 |
activation_ctx_descriptor.cbSize = sizeof (activation_ctx_descriptor); |
| 118 |
activation_ctx_descriptor.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID | |
| 119 |
ACTCTX_FLAG_HMODULE_VALID | |
| 120 |
ACTCTX_FLAG_SET_PROCESS_DEFAULT; |
| 121 |
activation_ctx_descriptor.hModule = this_module (); |
| 122 |
activation_ctx_descriptor.lpResourceName = resource_name; |
| 123 |
activation_ctx_handle = CreateActCtx (&activation_ctx_descriptor); |
| 124 |
error_code = GetLastError (); |
| 125 |
|
| 126 |
if (activation_ctx_handle == INVALID_HANDLE_VALUE && |
| 127 |
error_code != ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET) |
| 128 |
g_warning ("Failed to CreateActCtx for module %p, resource %p: %lu", |
| 129 |
this_module (), resource_name, GetLastError ()); |
| 130 |
else if (error_code != ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET) |
| 131 |
{ |
| 132 |
activation_cookie = 0; |
| 133 |
activated = ActivateActCtx (activation_ctx_handle, &activation_cookie); |
| 134 |
|
| 135 |
if (!activated) |
| 136 |
g_warning ("Failed to ActivateActCtx: %lu", GetLastError ()); |
| 137 |
|
| 138 |
LoadLibrary (dll_name); |
| 139 |
|
| 140 |
if (activated && !DeactivateActCtx (0, activation_cookie)) |
| 141 |
g_warning ("Failed to DeactivateActCtx: %lu", GetLastError ()); |
| 142 |
|
| 143 |
ReleaseActCtx (activation_ctx_handle); |
| 144 |
} |
| 145 |
|
| 146 |
if (!IS_INTRESOURCE (resource_name)) |
| 147 |
g_free (resource_name); |
| 148 |
} |
| 149 |
|
| 150 |
const char * |
| 151 |
_gtk_get_libdir (void) |
| 152 |
{ |
| 153 |
static char *gtk_libdir = NULL; |
| 154 |
if (gtk_libdir == NULL) |
| 155 |
{ |
| 156 |
char *root = g_win32_get_package_installation_directory_of_module (this_module ()); |
| 157 |
char *slash = strrchr (root, '\\'); |
| 158 |
if (slash != NULL && |
| 159 |
g_ascii_strcasecmp (slash + 1, ".libs") == 0) |
| 160 |
gtk_libdir = g_strdup (GTK_LIBDIR); |
| 161 |
else |
| 162 |
gtk_libdir = g_build_filename (root, "lib", NULL); |
| 163 |
g_free (root); |
| 164 |
} |
| 165 |
|
| 166 |
return gtk_libdir; |
| 167 |
} |
| 168 |
|
| 169 |
const char * |
| 170 |
_gtk_get_localedir (void) |
| 171 |
{ |
| 172 |
static char *gtk_localedir = NULL; |
| 173 |
if (gtk_localedir == NULL) |
| 174 |
{ |
| 175 |
const char *p; |
| 176 |
char *root, *temp; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
p = GTK_LOCALEDIR; |
| 182 |
p += strlen (GTK_LOCALEDIR); |
| 183 |
while (*--p != '/') |
| 184 |
; |
| 185 |
while (*--p != '/') |
| 186 |
; |
| 187 |
|
| 188 |
root = g_win32_get_package_installation_directory_of_module (this_module ()); |
| 189 |
temp = g_build_filename (root, p, NULL); |
| 190 |
g_free (root); |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
gtk_localedir = g_win32_locale_filename_from_utf8 (temp); |
| 196 |
g_free (temp); |
| 197 |
} |
| 198 |
return gtk_localedir; |
| 199 |
} |
| 200 |
|
| 201 |
const char * |
| 202 |
_gtk_get_datadir (void) |
| 203 |
{ |
| 204 |
static char *gtk_datadir = NULL; |
| 205 |
if (gtk_datadir == NULL) |
| 206 |
{ |
| 207 |
char *root = g_win32_get_package_installation_directory_of_module (this_module ()); |
| 208 |
gtk_datadir = g_build_filename (root, "share", NULL); |
| 209 |
g_free (root); |
| 210 |
} |
| 211 |
|
| 212 |
return gtk_datadir; |
| 213 |
} |
| 214 |
|
| 215 |
const char * |
| 216 |
_gtk_get_sysconfdir (void) |
| 217 |
{ |
| 218 |
static char *gtk_sysconfdir = NULL; |
| 219 |
if (gtk_sysconfdir == NULL) |
| 220 |
{ |
| 221 |
char *root = g_win32_get_package_installation_directory_of_module (this_module ()); |
| 222 |
gtk_sysconfdir = g_build_filename (root, "etc", NULL); |
| 223 |
g_free (root); |
| 224 |
} |
| 225 |
|
| 226 |
return gtk_sysconfdir; |
| 227 |
} |
| 228 |
|
| 229 |
const char * |
| 230 |
_gtk_get_data_prefix (void) |
| 231 |
{ |
| 232 |
static char *gtk_data_prefix = NULL; |
| 233 |
if (gtk_data_prefix == NULL) |
| 234 |
gtk_data_prefix = g_win32_get_package_installation_directory_of_module (this_module ()); |
| 235 |
|
| 236 |
return gtk_data_prefix; |
| 237 |
} |