Update thmviewer to show theme load errors.
Sean Hall committed
Jun 22, 2020 at 17:01 UTC
4a30b5af2909452db7995b75406c45429c85f4ef
6 files changed
+94
-12
Tools.sln
+1
@@ -73,6 +73,7 @@ Global
73
{0DF5D4CF-8457-469D-8288-13775E984F70}.Release|x86.ActiveCfg = Release|Any CPU
74
{0DF5D4CF-8457-469D-8288-13775E984F70}.Release|x86.Build.0 = Release|Any CPU
75
{95228C13-97F5-484A-B4A2-ECF4618B0881}.Debug|Any CPU.ActiveCfg = Debug|Win32
76
+ {95228C13-97F5-484A-B4A2-ECF4618B0881}.Debug|Any CPU.Build.0 = Debug|Win32
77
{95228C13-97F5-484A-B4A2-ECF4618B0881}.Debug|x86.ActiveCfg = Debug|Win32
78
{95228C13-97F5-484A-B4A2-ECF4618B0881}.Debug|x86.Build.0 = Debug|Win32
79
{95228C13-97F5-484A-B4A2-ECF4618B0881}.Release|Any CPU.ActiveCfg = Release|Win32
src/thmviewer/load.cpp
+2
@@ -106,6 +106,8 @@ static DWORD WINAPI LoadThreadProc(
106
FILETIME ftModified = { };
107
FileGetTime(sczThemePath, NULL, NULL, &ftModified);
108
109
+ ::SendMessageW(hWnd, WM_THMVWR_THEME_LOAD_BEGIN, 0, 0);
110
+
111
// Try to load the theme file.
112
hr = ThemeLoadFromFile(sczThemePath, &pTheme);
113
if (FAILED(hr))
src/thmviewer/packages.config
+2
-2
@@ -1,5 +1,5 @@
1
-<?xml version="1.0" encoding="utf-8"?>
1
+<?xml version="1.0" encoding="utf-8"?>
2
<packages>
3
<package id="Nerdbank.GitVersioning" version="2.1.65" targetFramework="native" developmentDependency="true" />
4
- <package id="WixToolset.DUtil" version="4.0.6" targetFramework="native" />
4
+ <package id="WixToolset.DUtil" version="4.0.30" targetFramework="native" />
5
</packages>
\ No newline at end of file
src/thmviewer/precomp.h
+1
@@ -42,6 +42,7 @@ enum WM_THMVWR
42
WM_THMVWR_PARSE_FILE,
43
WM_THMVWR_NEW_THEME,
44
WM_THMVWR_THEME_LOAD_ERROR,
45
+ WM_THMVWR_THEME_LOAD_BEGIN,
46
};
47
48
extern "C" HRESULT DisplayStart(
src/thmviewer/thmviewer.cpp
+86
-8
@@ -6,6 +6,7 @@ static const LPCWSTR THMVWR_WINDOW_CLASS_MAIN = L"ThmViewerMain";
6
7
static THEME* vpTheme = NULL;
8
static DWORD vdwDisplayThreadId = 0;
9
+static LPWSTR vsczThemeLoadErrors = NULL;
10
11
enum THMVWR_CONTROL
12
{
@@ -39,6 +40,9 @@ static LRESULT CALLBACK MainWndProc(
40
__in WPARAM wParam,
41
__in LPARAM lParam
42
);
43
+static void OnThemeLoadBegin(
44
+ __in_z_opt LPWSTR sczThemeLoadErrors
45
+ );
46
static void OnThemeLoadError(
47
__in THEME* pTheme,
48
__in HRESULT hrFailure
@@ -48,6 +52,15 @@ static void OnNewTheme(
52
__in HWND hWnd,
53
__in HANDLE_THEME* pHandle
54
);
55
+static void CALLBACK ThmviewerTraceError(
56
+ __in_z LPCSTR szFile,
57
+ __in int iLine,
58
+ __in REPORT_LEVEL rl,
59
+ __in UINT source,
60
+ __in HRESULT hrError,
61
+ __in_z __format_string LPCSTR szFormat,
62
+ __in va_list args
63
+ );
64
65
66
int WINAPI wWinMain(
@@ -76,6 +89,8 @@ int WINAPI wWinMain(
89
ExitOnFailure(hr, "Failed to initialize COM.");
90
fComInitialized = TRUE;
91
92
+ DutilInitialize(&ThmviewerTraceError);
93
+
94
hr = ProcessCommandLine(lpCmdLine, &sczThemeFile, &sczWxlFile);
95
ExitOnFailure(hr, "Failed to process command line.");
96
@@ -161,6 +176,7 @@ LExit:
176
177
ThemeFree(vpTheme);
178
ThemeUninitialize();
179
+ DutilUninitialize();
180
181
// uninitialize COM
182
if (fComInitialized)
@@ -168,11 +184,45 @@ LExit:
184
::CoUninitialize();
185
}
186
187
+ ReleaseNullStr(vsczThemeLoadErrors);
188
ReleaseStr(sczThemeFile);
189
ReleaseStr(sczWxlFile);
190
return hr;
191
}
192
193
+static void CALLBACK ThmviewerTraceError(
194
+ __in_z LPCSTR /*szFile*/,
195
+ __in int /*iLine*/,
196
+ __in REPORT_LEVEL /*rl*/,
197
+ __in UINT source,
198
+ __in HRESULT hrError,
199
+ __in_z __format_string LPCSTR szFormat,
200
+ __in va_list args
201
+ )
202
+{
203
+ HRESULT hr = S_OK;
204
+ LPSTR sczFormattedAnsi = NULL;
205
+ LPWSTR sczMessage = NULL;
206
+
207
+ if (DUTIL_SOURCE_THMUTIL != source)
208
+ {
209
+ ExitFunction();
210
+ }
211
+
212
+ hr = StrAnsiAllocFormattedArgs(&sczFormattedAnsi, szFormat, args);
213
+ ExitOnFailure(hr, "Failed to format error log string.");
214
+
215
+ hr = StrAllocFormatted(&sczMessage, L"Error 0x%08x: %S\r\n", hrError, sczFormattedAnsi);
216
+ ExitOnFailure(hr, "Failed to prepend error number to error log string.");
217
+
218
+ hr = StrAllocConcat(&vsczThemeLoadErrors, sczMessage, 0);
219
+ ExitOnFailure(hr, "Failed to append theme load error.");
220
+
221
+LExit:
222
+ ReleaseStr(sczFormattedAnsi);
223
+ ReleaseStr(sczMessage);
224
+}
225
+
226
227
//
228
// ProcessCommandLine - process the provided command line arguments.
@@ -311,6 +361,10 @@ static LRESULT CALLBACK MainWndProc(
361
}
362
break;
363
364
+ case WM_THMVWR_THEME_LOAD_BEGIN:
365
+ OnThemeLoadBegin(vsczThemeLoadErrors);
366
+ return 0;
367
+
368
case WM_THMVWR_THEME_LOAD_ERROR:
369
OnThemeLoadError(vpTheme, lParam);
370
return 0;
@@ -351,6 +405,13 @@ static LRESULT CALLBACK MainWndProc(
405
return ThemeDefWindowProc(vpTheme, hWnd, uMsg, wParam, lParam);
406
}
407
408
+static void OnThemeLoadBegin(
409
+ __in_z_opt LPWSTR sczThemeLoadErrors
410
+ )
411
+{
412
+ ReleaseNullStr(sczThemeLoadErrors);
413
+}
414
+
415
static void OnThemeLoadError(
416
__in THEME* pTheme,
417
__in HRESULT hrFailure
@@ -358,6 +419,8 @@ static void OnThemeLoadError(
419
{
420
HRESULT hr = S_OK;
421
LPWSTR sczMessage = NULL;
422
+ LPWSTR* psczErrors = NULL;
423
+ UINT cErrors = 0;
424
TVINSERTSTRUCTW tvi = { };
425
426
// Add the application node.
@@ -368,22 +431,37 @@ static void OnThemeLoadError(
431
tvi.item.pszText = L"Failed to load theme.";
432
tvi.hParent = reinterpret_cast<HTREEITEM>(ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi)));
433
371
- hr = StrAllocFormatted(&sczMessage, L"Error 0x%08x.", hrFailure);
372
- ExitOnFailure(hr, "Failed to format error message.");
434
+ if (!vsczThemeLoadErrors)
435
+ {
436
+ hr = StrAllocFormatted(&sczMessage, L"Error 0x%08x.", hrFailure);
437
+ ExitOnFailure(hr, "Failed to format error message.");
438
+
439
+ tvi.item.pszText = sczMessage;
440
+ ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi));
441
374
- tvi.item.pszText = sczMessage;
375
- ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi));
442
+ hr = StrAllocFromError(&sczMessage, hrFailure, NULL);
443
+ ExitOnFailure(hr, "Failed to format error message text.");
444
377
- hr = StrAllocFromError(&sczMessage, hrFailure, NULL);
378
- ExitOnFailure(hr, "Failed to format error message text.");
445
+ tvi.item.pszText = sczMessage;
446
+ ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi));
447
+ }
448
+ else
449
+ {
450
+ hr = StrSplitAllocArray(&psczErrors, &cErrors, vsczThemeLoadErrors, L"\r\n");
451
+ ExitOnFailure(hr, "Failed to split theme load errors.");
452
380
- tvi.item.pszText = sczMessage;
381
- ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi));
453
+ for (DWORD i = 0; i < cErrors; ++i)
454
+ {
455
+ tvi.item.pszText = psczErrors[i];
456
+ ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_INSERTITEMW, 0, reinterpret_cast<LPARAM>(&tvi));
457
+ }
458
+ }
459
460
ThemeSendControlMessage(pTheme, THMVWR_CONTROL_TREE, TVM_EXPAND, TVE_EXPAND, reinterpret_cast<LPARAM>(tvi.hParent));
461
462
LExit:
463
ReleaseStr(sczMessage);
464
+ ReleaseMem(psczErrors);
465
}
466
467
src/thmviewer/thmviewer.vcxproj
+2
-2
@@ -2,7 +2,7 @@
2
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3
4
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5
- <Import Project="..\..\packages\WixToolset.DUtil.4.0.6\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.6\build\WixToolset.DUtil.props')" />
5
+ <Import Project="..\..\packages\WixToolset.DUtil.4.0.30\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.30\build\WixToolset.DUtil.props')" />
6
7
<ItemGroup Label="ProjectConfigurations">
8
<ProjectConfiguration Include="Debug|Win32">
@@ -70,6 +70,6 @@
70
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
71
</PropertyGroup>
72
<Error Condition="!Exists('..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Nerdbank.GitVersioning.2.1.65\build\Nerdbank.GitVersioning.targets'))" />
73
- <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.6\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.6\build\WixToolset.DUtil.props'))" />
73
+ <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.30\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.30\build\WixToolset.DUtil.props'))" />
74
</Target>
75
</Project>