Update to latest dutil.
Sean Hall committed
Jun 22, 2020 at 17:16 UTC
95d029b5b7fac931149f1fafdd2b12ad09fe3146
5 files changed
+68
-10
src/wcautil/inc/wcautil.h
+17
-4
@@ -6,14 +6,22 @@
6
extern "C" {
7
#endif
8
9
+#include "dutilsources.h"
10
+
11
#define WIXAPI __stdcall
10
-#define ExitTrace WcaLogError
12
+#ifndef DUTIL_SOURCE_DEFAULT
13
+#define DUTIL_SOURCE_DEFAULT DUTIL_SOURCE_EXTERNAL
14
+#endif
15
16
#include "dutil.h"
17
14
-#define MessageExitOnLastError(x, e, s, ...) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (FAILED(x)) { ExitTrace(x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; } }
15
-#define MessageExitOnFailure(x, e, s, ...) if (FAILED(x)) { ExitTrace(x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, INSTALLMESSAGE_ERROR | MB_OK, -1, __VA_ARGS__); goto LExit; }
16
-#define MessageExitOnNullWithLastError(p, x, e, s, ...) if (NULL == p) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (!FAILED(x)) { x = E_FAIL; } ExitTrace(x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; }
18
+#define MessageExitOnLastErrorSource(d, x, e, s, ...) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (FAILED(x)) { ExitTraceSource(d, x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; } }
19
+#define MessageExitOnFailureSource(d, x, e, s, ...) if (FAILED(x)) { ExitTraceSource(d, x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, INSTALLMESSAGE_ERROR | MB_OK, -1, __VA_ARGS__); goto LExit; }
20
+#define MessageExitOnNullWithLastErrorSource(d, p, x, e, s, ...) if (NULL == p) { x = ::GetLastError(); x = HRESULT_FROM_WIN32(x); if (!FAILED(x)) { x = E_FAIL; } ExitTraceSource(d, x, "%s", s, __VA_ARGS__); WcaErrorMessage(e, x, MB_OK, -1, __VA_ARGS__); goto LExit; }
21
+
22
+#define MessageExitOnLastError(x, e, s, ...) MessageExitOnLastErrorSource(DUTIL_SOURCE_DEFAULT, x, e, s, __VA_ARGS__)
23
+#define MessageExitOnFailure(x, e, s, ...) MessageExitOnFailureSource(DUTIL_SOURCE_DEFAULT, x, e, s, __VA_ARGS__)
24
+#define MessageExitOnNullWithLastError(p, x, e, s, ...) MessageExitOnNullWithLastErrorSource(DUTIL_SOURCE_DEFAULT, p, x, e, s, __VA_ARGS__)
25
26
// Generic action enum.
27
typedef enum WCA_ACTION
@@ -101,6 +109,11 @@ void __cdecl WcaLogError(
109
__in LPCSTR szMessage,
110
...
111
);
112
+void WIXAPI WcaLogErrorArgs(
113
+ __in HRESULT hr,
114
+ __in LPCSTR szMessage,
115
+ __in va_list args
116
+ );
117
118
UINT WIXAPI WcaProcessMessage(
119
__in INSTALLMESSAGE eMessageType,
src/wcautil/packages.config
+1
-1
@@ -1,5 +1,5 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<packages>
3
<package id="Nerdbank.GitVersioning" version="2.1.65" developmentDependency="true" targetFramework="net40" />
4
- <package id="WixToolset.DUtil" version="4.0.28" targetFramework="native" />
4
+ <package id="WixToolset.DUtil" version="4.0.30" targetFramework="native" />
5
</packages>
\ No newline at end of file
src/wcautil/wcalog.cpp
+21
-3
@@ -228,7 +228,7 @@ extern "C" BOOL WIXAPI WcaDisplayAssert(
228
229
230
/********************************************************************
231
- WcaLogError() - called before ExitOnXXX() macro exists the function
231
+ WcaLogError() - called before ExitOnXXX() macro exits the function
232
233
NOTE: writes the hresult and error string to the MSI log
234
********************************************************************/
@@ -238,14 +238,32 @@ extern "C" void WcaLogError(
238
...
239
)
240
{
241
- char szBuffer[LOG_BUFFER];
241
va_list dots;
242
243
va_start(dots, szMessage);
245
- StringCchVPrintfA(szBuffer, countof(szBuffer), szMessage, dots);
244
+ WcaLogErrorArgs(hr, szMessage, dots);
245
va_end(dots);
246
+}
247
+
248
+
249
+/********************************************************************
250
+ WcaLogErrorArgs() - called before ExitOnXXX() macro exits the function
251
+
252
+ NOTE: writes the hresult and error string to the MSI log
253
+********************************************************************/
254
+extern "C" void WcaLogErrorArgs(
255
+ __in HRESULT hr,
256
+ __in LPCSTR szMessage,
257
+ __in va_list args
258
+ )
259
+{
260
+ char szBuffer[LOG_BUFFER];
261
+
262
+ StringCchVPrintfA(szBuffer, countof(szBuffer), szMessage, args);
263
264
// log the message if using Wca common layer
265
if (WcaIsInitialized())
266
+ {
267
WcaLog(LOGMSG_STANDARD, "Error 0x%x: %s", hr, szBuffer);
268
+ }
269
}
src/wcautil/wcautil.cpp
+27
@@ -12,6 +12,15 @@ static MSIHANDLE s_hDatabase;
12
static char s_szCustomActionLogName[32];
13
static UINT s_iRetVal;
14
15
+static void CALLBACK WcaTraceError(
16
+ __in_z LPCSTR szFile,
17
+ __in int iLine,
18
+ __in REPORT_LEVEL rl,
19
+ __in UINT source,
20
+ __in HRESULT hrError,
21
+ __in_z __format_string LPCSTR szFormat,
22
+ __in va_list args
23
+ );
24
25
/********************************************************************
26
WcaGlobalInitialize() - initializes the Wca library, should be
@@ -24,6 +33,7 @@ extern "C" void WIXAPI WcaGlobalInitialize(
33
)
34
{
35
g_hInstCADLL = hInst;
36
+ DutilInitialize(&WcaTraceError);
37
MemInitialize();
38
39
AssertSetModule(g_hInstCADLL);
@@ -49,6 +59,7 @@ extern "C" void WIXAPI WcaGlobalFinalize()
59
}
60
#endif
61
MemUninitialize();
62
+ DutilUninitialize();
63
g_hInstCADLL = NULL;
64
}
65
@@ -214,3 +225,19 @@ extern "C" BOOL WIXAPI WcaCancelDetected()
225
{
226
return ERROR_INSTALL_USEREXIT == s_iRetVal;
227
}
228
+
229
+static void CALLBACK WcaTraceError(
230
+ __in_z LPCSTR /*szFile*/,
231
+ __in int /*iLine*/,
232
+ __in REPORT_LEVEL /*rl*/,
233
+ __in UINT source,
234
+ __in HRESULT hrError,
235
+ __in_z __format_string LPCSTR szFormat,
236
+ __in va_list args
237
+ )
238
+{
239
+ if (DUTIL_SOURCE_DEFAULT == source)
240
+ {
241
+ WcaLogErrorArgs(hrError, szFormat, args);
242
+ }
243
+}
src/wcautil/wcautil.vcxproj
+2
-2
@@ -1,7 +1,7 @@
1
<?xml version="1.0" encoding="utf-8"?>
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
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4
- <Import Project="..\..\packages\WixToolset.DUtil.4.0.28\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.28\build\WixToolset.DUtil.props')" />
4
+ <Import Project="..\..\packages\WixToolset.DUtil.4.0.30\build\WixToolset.DUtil.props" Condition="Exists('..\..\packages\WixToolset.DUtil.4.0.30\build\WixToolset.DUtil.props')" />
5
<ItemGroup Label="ProjectConfigurations">
6
<ProjectConfiguration Include="Debug|ARM">
7
<Configuration>Debug</Configuration>
@@ -97,6 +97,6 @@
97
<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>
98
</PropertyGroup>
99
<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'))" />
100
- <Error Condition="!Exists('..\..\packages\WixToolset.DUtil.4.0.28\build\WixToolset.DUtil.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WixToolset.DUtil.4.0.28\build\WixToolset.DUtil.props'))" />
100
+ <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'))" />
101
</Target>
102
</Project>
\ No newline at end of file