Guest User

wine MUI functionality

a guest
May 25th, 2020
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 9a00fbc1bd412f263cb641c111cc278da56d121b Mon Sep 17 00:00:00 2001
  2. From: nadeloehr on forums.winehq.org
  3. Date: Mon, 25 May 2020 10:15:47 +0200
  4. Subject: [PATCH] MUI functionality hack by cschulst on forums.winehq.org
  5.  
  6. ---
  7. dlls/user32/dialog.c   | 105 ++++++++++++++++++++++++++++++++++++++++-
  8.  dlls/user32/menu.c     |  51 +++++++++++++++++++-
  9.  dlls/user32/resource.c | 104 ++++++++++++++++++++++++++++++++++++++--
  10.  3 files changed, 252 insertions(+), 8 deletions(-)
  11.  
  12. diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c
  13. index 88c2930c06..87a0e027f2 100644
  14. --- a/dlls/user32/dialog.c
  15. +++ b/dlls/user32/dialog.c
  16. @@ -735,7 +735,59 @@ HWND WINAPI CreateDialogParamW( HINSTANCE hInst, LPCWSTR name, HWND owner,
  17.      HRSRC hrsrc;
  18.      LPCDLGTEMPLATEA ptr;
  19.  
  20. -    if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0;
  21. +    /* hack for rudimentary MUI functionality */
  22. +
  23. +    HINSTANCE mui = NULL;
  24. +    HINSTANCE muix = NULL;
  25. +    char szFilePathName[MAX_PATH];
  26. +    char *szModuleName;
  27. +    char szProgramName[20];
  28. +    char muiName[20];
  29. +    char muiLanguage[6];
  30. +    char smallLanguage[3];
  31. +    char bigLanguage[3];
  32. +
  33. +    memset(szProgramName, '\0', sizeof(szProgramName));
  34. +    GetModuleFileNameA(NULL, szFilePathName, MAX_PATH);
  35. +    szModuleName = strrchr(szFilePathName, 92);
  36. +    strcpy(szProgramName, szModuleName+1);
  37. +    strcpy(muiLanguage, getenv("LANGUAGE"));
  38. +    lstrcpynA(smallLanguage, muiLanguage, 3);
  39. +    lstrcpynA(bigLanguage, muiLanguage+3, 3);
  40. +    strcpy(muiName, smallLanguage);
  41. +    strcat(muiName, "-");
  42. +    strcat(muiName, bigLanguage);
  43. +    strcat(muiName, "/");
  44. +    strcat(muiName, szProgramName);
  45. +    strcat(muiName, ".mui");
  46. +
  47. +    /* Try to find a resource first in the MUI file and then fall back to the executable if no success */
  48. +
  49. +    muix = hInst; /* Save a copy of the instance value in case we need it later */
  50. +    mui = LoadLibraryA(muiName);
  51. +
  52. +    /* The original statement to find the resource is commented out and replaced */
  53. +
  54. +    /* if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return 0; */
  55. +
  56. +    if (mui) {
  57. +   hInst = mui;
  58. +   hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
  59. +
  60. +   if (!hrsrc) {
  61. +       hInst = muix;
  62. +       hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
  63. +       if (!hrsrc) return 0;
  64. +   }
  65. +    } /* MUI file found */
  66. +
  67. +    if (!mui) {
  68. +   hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
  69. +   if (!hrsrc) return 0;
  70. +    } /* No MUI file found */
  71. +
  72. +    /* End of hack for MUI functionality */
  73. +
  74.      if (!(ptr = LoadResource(hInst, hrsrc))) return 0;
  75.      return CreateDialogIndirectParamW( hInst, ptr, owner, dlgProc, param );
  76.  }
  77. @@ -860,9 +912,58 @@ INT_PTR WINAPI DialogBoxParamW( HINSTANCE hInst, LPCWSTR name,
  78.      HRSRC hrsrc;
  79.      LPCDLGTEMPLATEW ptr;
  80.  
  81. +    /* Construct the MUI file name for reference */
  82. +
  83. +    HINSTANCE mui = NULL;
  84. +    HINSTANCE muix = NULL;
  85. +    char szFilePathName[MAX_PATH];
  86. +    char *szModuleName;
  87. +    char szProgramName[20];
  88. +    char muiName[20];
  89. +    char muiLanguage[6];
  90. +    char smallLanguage[3];
  91. +    char bigLanguage[3];
  92. +
  93. +    memset(szProgramName, '\0', sizeof(szProgramName));
  94. +    GetModuleFileNameA(NULL, szFilePathName, MAX_PATH);
  95. +    szModuleName = strrchr(szFilePathName, 92);
  96. +    strcpy(szProgramName, szModuleName+1);
  97. +    strcpy(muiLanguage, getenv("LANGUAGE"));
  98. +    lstrcpynA(smallLanguage, muiLanguage, 3);
  99. +    lstrcpynA(bigLanguage, muiLanguage+3, 3);
  100. +    strcpy(muiName, smallLanguage);
  101. +    strcat(muiName, "-");
  102. +    strcat(muiName, bigLanguage);
  103. +    strcat(muiName, "/");
  104. +    strcat(muiName, szProgramName);
  105. +    strcat(muiName, ".mui");
  106. +
  107. +    /* Try to find a resource first in the MUI file and then fall back to the executable if no success */
  108. +
  109. +    muix = hInst; /* Save a copy of the instance value in case we need it later */
  110. +    mui = LoadLibraryA(muiName);
  111. +
  112.      if (owner && !IsWindow(owner)) return 0;
  113.  
  114. -    if (!(hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG ))) return -1;
  115. +    if (mui) {
  116. +        hInst = mui;
  117. +   hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
  118. +
  119. +   // TODO: in case !hrsrc -1 was returned, now its 0?
  120. +   if (!hrsrc) {
  121. +       hInst = muix;
  122. +       hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
  123. +       if (!hrsrc) return 0;
  124. +   }
  125. +    } /* MUI file found */
  126. +
  127. +    if (!mui) {
  128. +   hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
  129. +   if (!hrsrc) return 0;
  130. +    }
  131. +    
  132. +    /* end of MUI functionality in this function */
  133. +
  134.      if (!(ptr = LoadResource(hInst, hrsrc))) return -1;
  135.      if (!(hwnd = DIALOG_CreateIndirect( hInst, ptr, owner, dlgProc, param, TRUE, &owner ))) return -1;
  136.      return DIALOG_DoDialogBox( hwnd, owner );
  137. diff --git a/dlls/user32/menu.c b/dlls/user32/menu.c
  138. index 3b1e3f25f4..28a2b20503 100644
  139. --- a/dlls/user32/menu.c
  140. +++ b/dlls/user32/menu.c
  141. @@ -4652,8 +4652,55 @@ HMENU WINAPI LoadMenuA( HINSTANCE instance, LPCSTR name )
  142.   */
  143.  HMENU WINAPI LoadMenuW( HINSTANCE instance, LPCWSTR name )
  144.  {
  145. -    HRSRC hrsrc = FindResourceW( instance, name, (LPWSTR)RT_MENU );
  146. -    if (!hrsrc) return 0;
  147. +
  148. +
  149. +    /* begin of hack for rudimentary MUI functionality */
  150. +
  151. +    HRSRC hrsrc = NULL;
  152. +    HINSTANCE mui = NULL;
  153. +    HINSTANCE muix = NULL;
  154. +    char szFilePathName[MAX_PATH];
  155. +    char *szModuleName;
  156. +    char szProgramName[20];
  157. +    char muiName[20];
  158. +    char muiLanguage[6];
  159. +    char smallLanguage[3];
  160. +    char bigLanguage[3];
  161. +
  162. +    memset(szProgramName, '\0', sizeof(szProgramName));
  163. +    GetModuleFileNameA(NULL, szFilePathName, MAX_PATH);
  164. +    szModuleName = strrchr(szFilePathName, 92);
  165. +    strcpy(szProgramName, szModuleName+1);
  166. +    strcpy(muiLanguage, getenv("LANGUAGE"));
  167. +    lstrcpynA(smallLanguage, muiLanguage, 3);
  168. +    lstrcpynA(bigLanguage, muiLanguage+3, 3);
  169. +    strcpy(muiName, smallLanguage);
  170. +    strcat(muiName, "-");
  171. +    strcat(muiName, bigLanguage);
  172. +    strcat(muiName, "/");
  173. +    strcat(muiName, szProgramName);
  174. +    strcat(muiName, ".mui");
  175. +
  176. +    muix = instance;
  177. +    mui = LoadLibraryA(muiName);
  178. +    //HRSRC hrsrc = FindResourceW( instance, name, (LPWSTR)RT_MENU );
  179. +    //if (!hrsrc) return 0;
  180. +    if (mui) {
  181. +   instance = mui;
  182. +   hrsrc = FindResourceW( instance, name, (LPWSTR)RT_MENU );
  183. +
  184. +   if (!hrsrc) {
  185. +       instance = muix;
  186. +       hrsrc = FindResourceW( instance, name, (LPWSTR)RT_MENU );
  187. +       if (!hrsrc) return 0;
  188. +   }
  189. +    }
  190. +    if (!mui) {
  191. +   hrsrc = FindResourceW( instance, name, (LPWSTR)RT_MENU );
  192. +   if (!hrsrc) return 0;
  193. +    }
  194. +    /* end of hack for MUI functionality */
  195. +
  196.      return LoadMenuIndirectW( LoadResource( instance, hrsrc ));
  197.  }
  198.  
  199. diff --git a/dlls/user32/resource.c b/dlls/user32/resource.c
  200. index b487f1e424..60e2cf3dd1 100644
  201. --- a/dlls/user32/resource.c
  202. +++ b/dlls/user32/resource.c
  203. @@ -22,6 +22,7 @@
  204.  #include "config.h"
  205.  
  206.  #include <stdarg.h>
  207. +#include <stdlib.h> // for MUI hack
  208.  
  209.  #include "windef.h"
  210.  #include "winbase.h"
  211. @@ -62,7 +63,54 @@ HACCEL WINAPI LoadAcceleratorsW(HINSTANCE instance, LPCWSTR name)
  212.      HACCEL handle;
  213.      DWORD count;
  214.  
  215. -    if (!(rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR ))) return 0;
  216. +    /* begin of hack for rudimentary MUI functionality */
  217. +
  218. +    HINSTANCE mui = NULL;
  219. +    HINSTANCE muix = NULL;
  220. +    char szFilePathName[MAX_PATH];
  221. +    char *szModuleName;
  222. +    char szProgramName[20];
  223. +    char muiName[20];
  224. +    char muiLanguage[6];
  225. +    char smallLanguage[3];
  226. +    char bigLanguage[3];
  227. +
  228. +    memset(szProgramName, '\0', sizeof(szProgramName));
  229. +    GetModuleFileNameA(NULL, szFilePathName, MAX_PATH);
  230. +    szModuleName = strrchr(szFilePathName, 92);
  231. +    strcpy(szProgramName, szModuleName+1);
  232. +    strcpy(muiLanguage, getenv("LANGUAGE"));
  233. +    lstrcpynA(smallLanguage, muiLanguage, 3);
  234. +    lstrcpynA(bigLanguage, muiLanguage+3, 3);
  235. +    strcpy(muiName, smallLanguage);
  236. +    strcat(muiName, "-");
  237. +    strcat(muiName, bigLanguage);
  238. +    strcat(muiName, "/");
  239. +    strcat(muiName, szProgramName);
  240. +    strcat(muiName, ".mui");
  241. +
  242. +    muix = instance;
  243. +    mui = LoadLibraryA(muiName);
  244. +
  245. +    /*if (!(rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR ))) return 0;*/
  246. +    if (mui) {
  247. +   muix = instance;
  248. +   instance = mui;
  249. +   rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR );
  250. +
  251. +   if (!rsrc) {
  252. +       instance = muix;
  253. +       rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR );
  254. +       if (!rsrc) return 0;
  255. +   }
  256. +    }
  257. +    if (!mui) {
  258. +   rsrc = FindResourceW( instance, name, (LPWSTR)RT_ACCELERATOR );
  259. +   if (!rsrc) return 0;
  260. +    }
  261. +
  262. +    /* end of MUI functionality */
  263. +
  264.      table = LoadResource( instance, rsrc );
  265.      count = SizeofResource( instance, rsrc ) / sizeof(*table);
  266.      if (!count) return 0;
  267. @@ -251,10 +299,58 @@ INT WINAPI DECLSPEC_HOTPATCH LoadStringW( HINSTANCE instance, UINT resource_id,
  268.      if(buffer == NULL)
  269.          return 0;
  270.  
  271. +    /* begin of hack for rudimentary MUI functionality */
  272. +    
  273. +    HINSTANCE mui = NULL;
  274. +    HINSTANCE muix = NULL;
  275. +    char szFilePathName[MAX_PATH];
  276. +    char *szModuleName;
  277. +    char szProgramName[20];
  278. +    char muiName[20];
  279. +    char muiLanguage[6];
  280. +    char smallLanguage[3];
  281. +    char bigLanguage[3];
  282. +
  283. +    memset(szProgramName, '\0', sizeof(szProgramName));
  284. +    GetModuleFileNameA(NULL, szFilePathName, MAX_PATH);
  285. +    szModuleName = strrchr(szFilePathName, 92);
  286. +    strcpy(szProgramName, szModuleName+1);
  287. +    strcpy(muiLanguage, getenv("LANGUAGE"));
  288. +    lstrcpynA(smallLanguage, muiLanguage, 3);
  289. +    lstrcpynA(bigLanguage, muiLanguage+3, 3);
  290. +    strcpy(muiName, smallLanguage);
  291. +    strcat(muiName, "-");
  292. +    strcat(muiName, bigLanguage);
  293. +    strcat(muiName, "/");
  294. +    strcat(muiName, szProgramName);
  295. +    strcat(muiName, ".mui");
  296. +
  297. +    muix = instance;
  298. +    mui = LoadLibraryA(muiName);
  299. +
  300. +    TRACE("instance = %p, id = %04x, buffer = %p, length = %d\n",instance, resource_id, buffer, buflen);
  301. +
  302. +    if (buffer == NULL) return 0;
  303. +
  304.      /* Use loword (incremented by 1) as resourceid */
  305. -    hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
  306. -                           (LPWSTR)RT_STRING );
  307. -    if (!hrsrc) return 0;
  308. +    /*hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1),
  309. +                           (LPWSTR)RT_STRING );*/
  310. +    if (mui) {
  311. +   instance = mui;
  312. +   hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), (LPWSTR)RT_STRING );
  313. +   if (!hrsrc) {
  314. +            instance = muix;
  315. +       hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), (LPWSTR)RT_STRING );
  316. +       if (!hrsrc) return 0;
  317. +   }
  318. +    }
  319. +    if (!mui) {
  320. +   hrsrc = FindResourceW( instance, MAKEINTRESOURCEW((LOWORD(resource_id) >> 4) + 1), (LPWSTR)RT_STRING );
  321. +   if (!hrsrc) return 0;
  322. +    }
  323. +
  324. +    /* end of MUI functionality */
  325. +
  326.      hmem = LoadResource( instance, hrsrc );
  327.      if (!hmem) return 0;
  328.  
  329. --
  330. 2.17.1
RAW Paste Data