diff options
Diffstat (limited to '')
-rw-r--r-- | src/dutil/locutil.cpp | 125 |
1 files changed, 70 insertions, 55 deletions
diff --git a/src/dutil/locutil.cpp b/src/dutil/locutil.cpp index b3cc042c..c4567c03 100644 --- a/src/dutil/locutil.cpp +++ b/src/dutil/locutil.cpp | |||
@@ -2,6 +2,21 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | |||
6 | // Exit macros | ||
7 | #define LocExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
8 | #define LocExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
9 | #define LocExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
10 | #define LocExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
11 | #define LocExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
12 | #define LocExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_LOCUTIL, x, s, __VA_ARGS__) | ||
13 | #define LocExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_LOCUTIL, p, x, e, s, __VA_ARGS__) | ||
14 | #define LocExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, p, x, s, __VA_ARGS__) | ||
15 | #define LocExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_LOCUTIL, p, x, e, s, __VA_ARGS__) | ||
16 | #define LocExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_LOCUTIL, p, x, s, __VA_ARGS__) | ||
17 | #define LocExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_LOCUTIL, e, x, s, __VA_ARGS__) | ||
18 | #define LocExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_LOCUTIL, g, x, s, __VA_ARGS__) | ||
19 | |||
5 | // prototypes | 20 | // prototypes |
6 | static HRESULT ParseWxl( | 21 | static HRESULT ParseWxl( |
7 | __in IXMLDOMDocument* pixd, | 22 | __in IXMLDOMDocument* pixd, |
@@ -63,10 +78,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
63 | if (wzLanguage && *wzLanguage) | 78 | if (wzLanguage && *wzLanguage) |
64 | { | 79 | { |
65 | hr = PathConcat(wzBasePath, wzLanguage, &sczProbePath); | 80 | hr = PathConcat(wzBasePath, wzLanguage, &sczProbePath); |
66 | ExitOnFailure(hr, "Failed to concat base path to language."); | 81 | LocExitOnFailure(hr, "Failed to concat base path to language."); |
67 | 82 | ||
68 | hr = PathConcat(sczProbePath, wzLocFileName, &sczProbePath); | 83 | hr = PathConcat(sczProbePath, wzLocFileName, &sczProbePath); |
69 | ExitOnFailure(hr, "Failed to concat loc file name to probe path."); | 84 | LocExitOnFailure(hr, "Failed to concat loc file name to probe path."); |
70 | 85 | ||
71 | if (FileExistsEx(sczProbePath, NULL)) | 86 | if (FileExistsEx(sczProbePath, NULL)) |
72 | { | 87 | { |
@@ -81,16 +96,16 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
81 | DWORD dwFlags = MUI_LANGUAGE_ID | MUI_MERGE_USER_FALLBACK | MUI_MERGE_SYSTEM_FALLBACK; | 96 | DWORD dwFlags = MUI_LANGUAGE_ID | MUI_MERGE_USER_FALLBACK | MUI_MERGE_SYSTEM_FALLBACK; |
82 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, NULL, &cchLangs)) | 97 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, NULL, &cchLangs)) |
83 | { | 98 | { |
84 | ExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return buffer size."); | 99 | LocExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return buffer size."); |
85 | } | 100 | } |
86 | 101 | ||
87 | hr = StrAlloc(&sczLangsBuff, cchLangs); | 102 | hr = StrAlloc(&sczLangsBuff, cchLangs); |
88 | ExitOnFailure(hr, "Failed to allocate buffer for languages"); | 103 | LocExitOnFailure(hr, "Failed to allocate buffer for languages"); |
89 | 104 | ||
90 | nLangs = 0; | 105 | nLangs = 0; |
91 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, sczLangsBuff, &cchLangs)) | 106 | if (!(*pvfnGetThreadPreferredUILanguages)(dwFlags, &nLangs, sczLangsBuff, &cchLangs)) |
92 | { | 107 | { |
93 | ExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return language list."); | 108 | LocExitWithLastError(hr, "GetThreadPreferredUILanguages failed to return language list."); |
94 | } | 109 | } |
95 | 110 | ||
96 | LPWSTR szLangs = sczLangsBuff; | 111 | LPWSTR szLangs = sczLangsBuff; |
@@ -98,14 +113,14 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
98 | { | 113 | { |
99 | // StrHexDecode assumes low byte is first. We'll need to swap the bytes once we parse out the value. | 114 | // StrHexDecode assumes low byte is first. We'll need to swap the bytes once we parse out the value. |
100 | hr = StrHexDecode(szLangs, reinterpret_cast<BYTE*>(&langid), sizeof(langid)); | 115 | hr = StrHexDecode(szLangs, reinterpret_cast<BYTE*>(&langid), sizeof(langid)); |
101 | ExitOnFailure(hr, "Failed to parse langId."); | 116 | LocExitOnFailure(hr, "Failed to parse langId."); |
102 | 117 | ||
103 | langid = MAKEWORD(HIBYTE(langid), LOBYTE(langid)); | 118 | langid = MAKEWORD(HIBYTE(langid), LOBYTE(langid)); |
104 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 119 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
105 | ExitOnFailure(hr, "Failed to format user preferred langid."); | 120 | LocExitOnFailure(hr, "Failed to format user preferred langid."); |
106 | 121 | ||
107 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 122 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
108 | ExitOnFailure(hr, "Failed to concat user preferred langid file name to base path."); | 123 | LocExitOnFailure(hr, "Failed to concat user preferred langid file name to base path."); |
109 | 124 | ||
110 | if (FileExistsEx(sczProbePath, NULL)) | 125 | if (FileExistsEx(sczProbePath, NULL)) |
111 | { | 126 | { |
@@ -117,10 +132,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
117 | langid = ::GetUserDefaultUILanguage(); | 132 | langid = ::GetUserDefaultUILanguage(); |
118 | 133 | ||
119 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 134 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
120 | ExitOnFailure(hr, "Failed to format user langid."); | 135 | LocExitOnFailure(hr, "Failed to format user langid."); |
121 | 136 | ||
122 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 137 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
123 | ExitOnFailure(hr, "Failed to concat user langid file name to base path."); | 138 | LocExitOnFailure(hr, "Failed to concat user langid file name to base path."); |
124 | 139 | ||
125 | if (FileExistsEx(sczProbePath, NULL)) | 140 | if (FileExistsEx(sczProbePath, NULL)) |
126 | { | 141 | { |
@@ -132,10 +147,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
132 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); | 147 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); |
133 | 148 | ||
134 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 149 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
135 | ExitOnFailure(hr, "Failed to format user langid (default sublang)."); | 150 | LocExitOnFailure(hr, "Failed to format user langid (default sublang)."); |
136 | 151 | ||
137 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 152 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
138 | ExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); | 153 | LocExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); |
139 | 154 | ||
140 | if (FileExistsEx(sczProbePath, NULL)) | 155 | if (FileExistsEx(sczProbePath, NULL)) |
141 | { | 156 | { |
@@ -146,10 +161,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
146 | langid = ::GetSystemDefaultUILanguage(); | 161 | langid = ::GetSystemDefaultUILanguage(); |
147 | 162 | ||
148 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 163 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
149 | ExitOnFailure(hr, "Failed to format system langid."); | 164 | LocExitOnFailure(hr, "Failed to format system langid."); |
150 | 165 | ||
151 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 166 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
152 | ExitOnFailure(hr, "Failed to concat system langid file name to base path."); | 167 | LocExitOnFailure(hr, "Failed to concat system langid file name to base path."); |
153 | 168 | ||
154 | if (FileExistsEx(sczProbePath, NULL)) | 169 | if (FileExistsEx(sczProbePath, NULL)) |
155 | { | 170 | { |
@@ -161,10 +176,10 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
161 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); | 176 | langid = MAKELANGID(langid & 0x3FF, SUBLANG_DEFAULT); |
162 | 177 | ||
163 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); | 178 | hr = StrAllocFormatted(&sczLangIdFile, L"%u\\%ls", langid, wzLocFileName); |
164 | ExitOnFailure(hr, "Failed to format user langid (default sublang)."); | 179 | LocExitOnFailure(hr, "Failed to format user langid (default sublang)."); |
165 | 180 | ||
166 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); | 181 | hr = PathConcat(wzBasePath, sczLangIdFile, &sczProbePath); |
167 | ExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); | 182 | LocExitOnFailure(hr, "Failed to concat user langid file name to base path (default sublang)."); |
168 | 183 | ||
169 | if (FileExistsEx(sczProbePath, NULL)) | 184 | if (FileExistsEx(sczProbePath, NULL)) |
170 | { | 185 | { |
@@ -174,7 +189,7 @@ extern "C" HRESULT DAPI LocProbeForFile( | |||
174 | 189 | ||
175 | // Finally, look for the loc file in the base path. | 190 | // Finally, look for the loc file in the base path. |
176 | hr = PathConcat(wzBasePath, wzLocFileName, &sczProbePath); | 191 | hr = PathConcat(wzBasePath, wzLocFileName, &sczProbePath); |
177 | ExitOnFailure(hr, "Failed to concat loc file name to base path."); | 192 | LocExitOnFailure(hr, "Failed to concat loc file name to base path."); |
178 | 193 | ||
179 | if (!FileExistsEx(sczProbePath, NULL)) | 194 | if (!FileExistsEx(sczProbePath, NULL)) |
180 | { | 195 | { |
@@ -203,10 +218,10 @@ extern "C" HRESULT DAPI LocLoadFromFile( | |||
203 | IXMLDOMDocument* pixd = NULL; | 218 | IXMLDOMDocument* pixd = NULL; |
204 | 219 | ||
205 | hr = XmlLoadDocumentFromFile(wzWxlFile, &pixd); | 220 | hr = XmlLoadDocumentFromFile(wzWxlFile, &pixd); |
206 | ExitOnFailure(hr, "Failed to load WXL file as XML document."); | 221 | LocExitOnFailure(hr, "Failed to load WXL file as XML document."); |
207 | 222 | ||
208 | hr = ParseWxl(pixd, ppWixLoc); | 223 | hr = ParseWxl(pixd, ppWixLoc); |
209 | ExitOnFailure(hr, "Failed to parse WXL."); | 224 | LocExitOnFailure(hr, "Failed to parse WXL."); |
210 | 225 | ||
211 | LExit: | 226 | LExit: |
212 | ReleaseObject(pixd); | 227 | ReleaseObject(pixd); |
@@ -227,16 +242,16 @@ extern "C" HRESULT DAPI LocLoadFromResource( | |||
227 | IXMLDOMDocument* pixd = NULL; | 242 | IXMLDOMDocument* pixd = NULL; |
228 | 243 | ||
229 | hr = ResReadData(hModule, szResource, &pvResource, &cbResource); | 244 | hr = ResReadData(hModule, szResource, &pvResource, &cbResource); |
230 | ExitOnFailure(hr, "Failed to read theme from resource."); | 245 | LocExitOnFailure(hr, "Failed to read theme from resource."); |
231 | 246 | ||
232 | hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8); | 247 | hr = StrAllocStringAnsi(&sczXml, reinterpret_cast<LPCSTR>(pvResource), cbResource, CP_UTF8); |
233 | ExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string."); | 248 | LocExitOnFailure(hr, "Failed to convert XML document data from UTF-8 to unicode string."); |
234 | 249 | ||
235 | hr = XmlLoadDocument(sczXml, &pixd); | 250 | hr = XmlLoadDocument(sczXml, &pixd); |
236 | ExitOnFailure(hr, "Failed to load theme resource as XML document."); | 251 | LocExitOnFailure(hr, "Failed to load theme resource as XML document."); |
237 | 252 | ||
238 | hr = ParseWxl(pixd, ppWixLoc); | 253 | hr = ParseWxl(pixd, ppWixLoc); |
239 | ExitOnFailure(hr, "Failed to parse WXL."); | 254 | LocExitOnFailure(hr, "Failed to parse WXL."); |
240 | 255 | ||
241 | LExit: | 256 | LExit: |
242 | ReleaseObject(pixd); | 257 | ReleaseObject(pixd); |
@@ -280,7 +295,7 @@ extern "C" HRESULT DAPI LocLocalizeString( | |||
280 | for (DWORD i = 0; i < pWixLoc->cLocStrings; ++i) | 295 | for (DWORD i = 0; i < pWixLoc->cLocStrings; ++i) |
281 | { | 296 | { |
282 | hr = StrReplaceStringAll(ppsczInput, pWixLoc->rgLocStrings[i].wzId, pWixLoc->rgLocStrings[i].wzText); | 297 | hr = StrReplaceStringAll(ppsczInput, pWixLoc->rgLocStrings[i].wzId, pWixLoc->rgLocStrings[i].wzText); |
283 | ExitOnFailure(hr, "Localizing string failed."); | 298 | LocExitOnFailure(hr, "Localizing string failed."); |
284 | } | 299 | } |
285 | 300 | ||
286 | LExit: | 301 | LExit: |
@@ -348,15 +363,15 @@ extern "C" HRESULT DAPI LocAddString( | |||
348 | 363 | ||
349 | ++pWixLoc->cLocStrings; | 364 | ++pWixLoc->cLocStrings; |
350 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemReAlloc(pWixLoc->rgLocStrings, sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); | 365 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemReAlloc(pWixLoc->rgLocStrings, sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); |
351 | ExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to reallocate memory for localization strings."); | 366 | LocExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to reallocate memory for localization strings."); |
352 | 367 | ||
353 | LOC_STRING* pLocString = pWixLoc->rgLocStrings + (pWixLoc->cLocStrings - 1); | 368 | LOC_STRING* pLocString = pWixLoc->rgLocStrings + (pWixLoc->cLocStrings - 1); |
354 | 369 | ||
355 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", wzId); | 370 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", wzId); |
356 | ExitOnFailure(hr, "Failed to set localization string Id."); | 371 | LocExitOnFailure(hr, "Failed to set localization string Id."); |
357 | 372 | ||
358 | hr = StrAllocString(&pLocString->wzText, wzLocString, 0); | 373 | hr = StrAllocString(&pLocString->wzText, wzLocString, 0); |
359 | ExitOnFailure(hr, "Failed to set localization string Text."); | 374 | LocExitOnFailure(hr, "Failed to set localization string Text."); |
360 | 375 | ||
361 | pLocString->bOverridable = bOverridable; | 376 | pLocString->bOverridable = bOverridable; |
362 | 377 | ||
@@ -376,11 +391,11 @@ static HRESULT ParseWxl( | |||
376 | WIX_LOCALIZATION* pWixLoc = NULL; | 391 | WIX_LOCALIZATION* pWixLoc = NULL; |
377 | 392 | ||
378 | pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE)); | 393 | pWixLoc = static_cast<WIX_LOCALIZATION*>(MemAlloc(sizeof(WIX_LOCALIZATION), TRUE)); |
379 | ExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file."); | 394 | LocExitOnNull(pWixLoc, hr, E_OUTOFMEMORY, "Failed to allocate memory for Wxl file."); |
380 | 395 | ||
381 | // read the WixLocalization tag | 396 | // read the WixLocalization tag |
382 | hr = pixd->get_documentElement(&pWxlElement); | 397 | hr = pixd->get_documentElement(&pWxlElement); |
383 | ExitOnFailure(hr, "Failed to get localization element."); | 398 | LocExitOnFailure(hr, "Failed to get localization element."); |
384 | 399 | ||
385 | // get the Language attribute if present | 400 | // get the Language attribute if present |
386 | pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET; | 401 | pWixLoc->dwLangId = WIX_LOCALIZATION_LANGUAGE_NOT_SET; |
@@ -389,14 +404,14 @@ static HRESULT ParseWxl( | |||
389 | { | 404 | { |
390 | hr = S_OK; | 405 | hr = S_OK; |
391 | } | 406 | } |
392 | ExitOnFailure(hr, "Failed to get Language value."); | 407 | LocExitOnFailure(hr, "Failed to get Language value."); |
393 | 408 | ||
394 | // store the strings and controls in a node list | 409 | // store the strings and controls in a node list |
395 | hr = ParseWxlStrings(pWxlElement, pWixLoc); | 410 | hr = ParseWxlStrings(pWxlElement, pWixLoc); |
396 | ExitOnFailure(hr, "Parsing localization strings failed."); | 411 | LocExitOnFailure(hr, "Parsing localization strings failed."); |
397 | 412 | ||
398 | hr = ParseWxlControls(pWxlElement, pWixLoc); | 413 | hr = ParseWxlControls(pWxlElement, pWixLoc); |
399 | ExitOnFailure(hr, "Parsing localization controls failed."); | 414 | LocExitOnFailure(hr, "Parsing localization controls failed."); |
400 | 415 | ||
401 | *ppWixLoc = pWixLoc; | 416 | *ppWixLoc = pWixLoc; |
402 | pWixLoc = NULL; | 417 | pWixLoc = NULL; |
@@ -420,27 +435,27 @@ static HRESULT ParseWxlStrings( | |||
420 | DWORD dwIdx = 0; | 435 | DWORD dwIdx = 0; |
421 | 436 | ||
422 | hr = XmlSelectNodes(pElement, L"String", &pixnl); | 437 | hr = XmlSelectNodes(pElement, L"String", &pixnl); |
423 | ExitOnLastError(hr, "Failed to get String child nodes of Wxl File."); | 438 | LocExitOnLastError(hr, "Failed to get String child nodes of Wxl File."); |
424 | 439 | ||
425 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocStrings)); | 440 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocStrings)); |
426 | ExitOnLastError(hr, "Failed to get number of String child nodes in Wxl File."); | 441 | LocExitOnLastError(hr, "Failed to get number of String child nodes in Wxl File."); |
427 | 442 | ||
428 | if (0 < pWixLoc->cLocStrings) | 443 | if (0 < pWixLoc->cLocStrings) |
429 | { | 444 | { |
430 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemAlloc(sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); | 445 | pWixLoc->rgLocStrings = static_cast<LOC_STRING*>(MemAlloc(sizeof(LOC_STRING) * pWixLoc->cLocStrings, TRUE)); |
431 | ExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to allocate memory for localization strings."); | 446 | LocExitOnNull(pWixLoc->rgLocStrings, hr, E_OUTOFMEMORY, "Failed to allocate memory for localization strings."); |
432 | 447 | ||
433 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) | 448 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) |
434 | { | 449 | { |
435 | hr = ParseWxlString(pixn, dwIdx, pWixLoc); | 450 | hr = ParseWxlString(pixn, dwIdx, pWixLoc); |
436 | ExitOnFailure(hr, "Failed to parse localization string."); | 451 | LocExitOnFailure(hr, "Failed to parse localization string."); |
437 | 452 | ||
438 | ++dwIdx; | 453 | ++dwIdx; |
439 | ReleaseNullObject(pixn); | 454 | ReleaseNullObject(pixn); |
440 | } | 455 | } |
441 | 456 | ||
442 | hr = S_OK; | 457 | hr = S_OK; |
443 | ExitOnFailure(hr, "Failed to enumerate all localization strings."); | 458 | LocExitOnFailure(hr, "Failed to enumerate all localization strings."); |
444 | } | 459 | } |
445 | 460 | ||
446 | LExit: | 461 | LExit: |
@@ -472,27 +487,27 @@ static HRESULT ParseWxlControls( | |||
472 | DWORD dwIdx = 0; | 487 | DWORD dwIdx = 0; |
473 | 488 | ||
474 | hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl); | 489 | hr = XmlSelectNodes(pElement, L"UI|Control", &pixnl); |
475 | ExitOnLastError(hr, "Failed to get UI child nodes of Wxl File."); | 490 | LocExitOnLastError(hr, "Failed to get UI child nodes of Wxl File."); |
476 | 491 | ||
477 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls)); | 492 | hr = pixnl->get_length(reinterpret_cast<long*>(&pWixLoc->cLocControls)); |
478 | ExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File."); | 493 | LocExitOnLastError(hr, "Failed to get number of UI child nodes in Wxl File."); |
479 | 494 | ||
480 | if (0 < pWixLoc->cLocControls) | 495 | if (0 < pWixLoc->cLocControls) |
481 | { | 496 | { |
482 | pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE)); | 497 | pWixLoc->rgLocControls = static_cast<LOC_CONTROL*>(MemAlloc(sizeof(LOC_CONTROL) * pWixLoc->cLocControls, TRUE)); |
483 | ExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls."); | 498 | LocExitOnNull(pWixLoc->rgLocControls, hr, E_OUTOFMEMORY, "Failed to allocate memory for localized controls."); |
484 | 499 | ||
485 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) | 500 | while (S_OK == (hr = XmlNextElement(pixnl, &pixn, NULL))) |
486 | { | 501 | { |
487 | hr = ParseWxlControl(pixn, dwIdx, pWixLoc); | 502 | hr = ParseWxlControl(pixn, dwIdx, pWixLoc); |
488 | ExitOnFailure(hr, "Failed to parse localized control."); | 503 | LocExitOnFailure(hr, "Failed to parse localized control."); |
489 | 504 | ||
490 | ++dwIdx; | 505 | ++dwIdx; |
491 | ReleaseNullObject(pixn); | 506 | ReleaseNullObject(pixn); |
492 | } | 507 | } |
493 | 508 | ||
494 | hr = S_OK; | 509 | hr = S_OK; |
495 | ExitOnFailure(hr, "Failed to enumerate all localized controls."); | 510 | LocExitOnFailure(hr, "Failed to enumerate all localized controls."); |
496 | } | 511 | } |
497 | 512 | ||
498 | LExit: | 513 | LExit: |
@@ -527,16 +542,16 @@ static HRESULT ParseWxlString( | |||
527 | 542 | ||
528 | // Id | 543 | // Id |
529 | hr = XmlGetAttribute(pixn, L"Id", &bstrText); | 544 | hr = XmlGetAttribute(pixn, L"Id", &bstrText); |
530 | ExitOnFailure(hr, "Failed to get Xml attribute Id in Wxl file."); | 545 | LocExitOnFailure(hr, "Failed to get Xml attribute Id in Wxl file."); |
531 | 546 | ||
532 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", bstrText); | 547 | hr = StrAllocFormatted(&pLocString->wzId, L"#(loc.%s)", bstrText); |
533 | ExitOnFailure(hr, "Failed to duplicate Xml attribute Id in Wxl file."); | 548 | LocExitOnFailure(hr, "Failed to duplicate Xml attribute Id in Wxl file."); |
534 | 549 | ||
535 | ReleaseNullBSTR(bstrText); | 550 | ReleaseNullBSTR(bstrText); |
536 | 551 | ||
537 | // Overrideable | 552 | // Overrideable |
538 | hr = XmlGetAttribute(pixn, L"Overridable", &bstrText); | 553 | hr = XmlGetAttribute(pixn, L"Overridable", &bstrText); |
539 | ExitOnFailure(hr, "Failed to get Xml attribute Overridable."); | 554 | LocExitOnFailure(hr, "Failed to get Xml attribute Overridable."); |
540 | 555 | ||
541 | if (S_OK == hr) | 556 | if (S_OK == hr) |
542 | { | 557 | { |
@@ -547,10 +562,10 @@ static HRESULT ParseWxlString( | |||
547 | 562 | ||
548 | // Text | 563 | // Text |
549 | hr = XmlGetText(pixn, &bstrText); | 564 | hr = XmlGetText(pixn, &bstrText); |
550 | ExitOnFailure(hr, "Failed to get Xml text in Wxl file."); | 565 | LocExitOnFailure(hr, "Failed to get Xml text in Wxl file."); |
551 | 566 | ||
552 | hr = StrAllocString(&pLocString->wzText, bstrText, 0); | 567 | hr = StrAllocString(&pLocString->wzText, bstrText, 0); |
553 | ExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file."); | 568 | LocExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file."); |
554 | 569 | ||
555 | LExit: | 570 | LExit: |
556 | ReleaseBSTR(bstrText); | 571 | ReleaseBSTR(bstrText); |
@@ -572,39 +587,39 @@ static HRESULT ParseWxlControl( | |||
572 | 587 | ||
573 | // Id | 588 | // Id |
574 | hr = XmlGetAttribute(pixn, L"Control", &bstrText); | 589 | hr = XmlGetAttribute(pixn, L"Control", &bstrText); |
575 | ExitOnFailure(hr, "Failed to get Xml attribute Control in Wxl file."); | 590 | LocExitOnFailure(hr, "Failed to get Xml attribute Control in Wxl file."); |
576 | 591 | ||
577 | hr = StrAllocString(&pLocControl->wzControl, bstrText, 0); | 592 | hr = StrAllocString(&pLocControl->wzControl, bstrText, 0); |
578 | ExitOnFailure(hr, "Failed to duplicate Xml attribute Control in Wxl file."); | 593 | LocExitOnFailure(hr, "Failed to duplicate Xml attribute Control in Wxl file."); |
579 | 594 | ||
580 | ReleaseNullBSTR(bstrText); | 595 | ReleaseNullBSTR(bstrText); |
581 | 596 | ||
582 | // X | 597 | // X |
583 | pLocControl->nX = LOC_CONTROL_NOT_SET; | 598 | pLocControl->nX = LOC_CONTROL_NOT_SET; |
584 | hr = XmlGetAttributeNumber(pixn, L"X", reinterpret_cast<DWORD*>(&pLocControl->nX)); | 599 | hr = XmlGetAttributeNumber(pixn, L"X", reinterpret_cast<DWORD*>(&pLocControl->nX)); |
585 | ExitOnFailure(hr, "Failed to get control X attribute."); | 600 | LocExitOnFailure(hr, "Failed to get control X attribute."); |
586 | 601 | ||
587 | // Y | 602 | // Y |
588 | pLocControl->nY = LOC_CONTROL_NOT_SET; | 603 | pLocControl->nY = LOC_CONTROL_NOT_SET; |
589 | hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pLocControl->nY)); | 604 | hr = XmlGetAttributeNumber(pixn, L"Y", reinterpret_cast<DWORD*>(&pLocControl->nY)); |
590 | ExitOnFailure(hr, "Failed to get control Y attribute."); | 605 | LocExitOnFailure(hr, "Failed to get control Y attribute."); |
591 | 606 | ||
592 | // Width | 607 | // Width |
593 | pLocControl->nWidth = LOC_CONTROL_NOT_SET; | 608 | pLocControl->nWidth = LOC_CONTROL_NOT_SET; |
594 | hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pLocControl->nWidth)); | 609 | hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pLocControl->nWidth)); |
595 | ExitOnFailure(hr, "Failed to get control width attribute."); | 610 | LocExitOnFailure(hr, "Failed to get control width attribute."); |
596 | 611 | ||
597 | // Height | 612 | // Height |
598 | pLocControl->nHeight = LOC_CONTROL_NOT_SET; | 613 | pLocControl->nHeight = LOC_CONTROL_NOT_SET; |
599 | hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pLocControl->nHeight)); | 614 | hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pLocControl->nHeight)); |
600 | ExitOnFailure(hr, "Failed to get control height attribute."); | 615 | LocExitOnFailure(hr, "Failed to get control height attribute."); |
601 | 616 | ||
602 | // Text | 617 | // Text |
603 | hr = XmlGetText(pixn, &bstrText); | 618 | hr = XmlGetText(pixn, &bstrText); |
604 | ExitOnFailure(hr, "Failed to get control text in Wxl file."); | 619 | LocExitOnFailure(hr, "Failed to get control text in Wxl file."); |
605 | 620 | ||
606 | hr = StrAllocString(&pLocControl->wzText, bstrText, 0); | 621 | hr = StrAllocString(&pLocControl->wzText, bstrText, 0); |
607 | ExitOnFailure(hr, "Failed to duplicate control text in Wxl file."); | 622 | LocExitOnFailure(hr, "Failed to duplicate control text in Wxl file."); |
608 | 623 | ||
609 | LExit: | 624 | LExit: |
610 | ReleaseBSTR(bstrText); | 625 | ReleaseBSTR(bstrText); |