aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-06-24 12:26:27 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-06-27 11:14:21 -0500
commit78b5daf01555d86293c1012ed3de704752880a6a (patch)
tree45524478c868cf63042a5e2ad78cfcd15aac43d6 /src/libs/dutil/WixToolset.DUtil
parent4f41db7eaa48b0e061a68fd5fc70ce6d127d9039 (diff)
downloadwix-78b5daf01555d86293c1012ed3de704752880a6a.tar.gz
wix-78b5daf01555d86293c1012ed3de704752880a6a.tar.bz2
wix-78b5daf01555d86293c1012ed3de704752880a6a.zip
Move LoadSystemLibrary and LoadSystemLibraryWithPath into apputil.
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/app2util.cpp60
-rw-r--r--src/libs/dutil/WixToolset.DUtil/apputil.cpp82
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dutil.cpp61
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dutil.vcxproj1
-rw-r--r--src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters3
-rw-r--r--src/libs/dutil/WixToolset.DUtil/inc/apputil.h5
-rw-r--r--src/libs/dutil/WixToolset.DUtil/inc/dutil.h30
7 files changed, 137 insertions, 105 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/app2util.cpp b/src/libs/dutil/WixToolset.DUtil/app2util.cpp
new file mode 100644
index 00000000..d2e21e39
--- /dev/null
+++ b/src/libs/dutil/WixToolset.DUtil/app2util.cpp
@@ -0,0 +1,60 @@
1// 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.
2
3#include "precomp.h"
4
5// Exit macros
6#define AppExitOnLastError(x, s, ...) ExitOnLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
7#define AppExitOnLastErrorDebugTrace(x, s, ...) ExitOnLastErrorDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
8#define AppExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
9#define AppExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
10#define AppExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
11#define AppExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_APPUTIL, x, e, s, __VA_ARGS__)
12#define AppExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
13#define AppExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
14#define AppExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
15#define AppExitOnNullDebugTrace(p, x, e, s, ...) ExitOnNullDebugTraceSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
16#define AppExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
17#define AppExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_APPUTIL, e, x, s, __VA_ARGS__)
18#define AppExitOnGdipFailure(g, x, s, ...) ExitOnGdipFailureSource(DUTIL_SOURCE_APPUTIL, g, x, s, __VA_ARGS__)
19
20DAPI_(void) AppFreeCommandLineArgs(
21 __in LPWSTR* argv
22 )
23{
24 // The "ignored" hack in AppParseCommandLine requires an adjustment.
25 LPWSTR* argvOriginal = argv - 1;
26 ::LocalFree(argvOriginal);
27}
28
29DAPI_(HRESULT) AppParseCommandLine(
30 __in LPCWSTR wzCommandLine,
31 __in int* pArgc,
32 __in LPWSTR** pArgv
33 )
34{
35 HRESULT hr = S_OK;
36 LPWSTR sczCommandLine = NULL;
37 LPWSTR* argv = NULL;
38 int argc = 0;
39
40 // CommandLineToArgvW tries to treat the first argument as the path to the process,
41 // which fails pretty miserably if your first argument is something like
42 // FOO="C:\Program Files\My Company". So give it something harmless to play with.
43 hr = StrAllocConcat(&sczCommandLine, L"ignored ", 0);
44 AppExitOnFailure(hr, "Failed to initialize command line.");
45
46 hr = StrAllocConcat(&sczCommandLine, wzCommandLine, 0);
47 AppExitOnFailure(hr, "Failed to copy command line.");
48
49 argv = ::CommandLineToArgvW(sczCommandLine, &argc);
50 AppExitOnNullWithLastError(argv, hr, "Failed to parse command line.");
51
52 // Skip "ignored" argument/hack.
53 *pArgv = argv + 1;
54 *pArgc = argc - 1;
55
56LExit:
57 ReleaseStr(sczCommandLine);
58
59 return hr;
60}
diff --git a/src/libs/dutil/WixToolset.DUtil/apputil.cpp b/src/libs/dutil/WixToolset.DUtil/apputil.cpp
index 7e0bbc7b..147d1d1e 100644
--- a/src/libs/dutil/WixToolset.DUtil/apputil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/apputil.cpp
@@ -8,6 +8,7 @@
8#define AppExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) 8#define AppExitWithLastError(x, s, ...) ExitWithLastErrorSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
9#define AppExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) 9#define AppExitOnFailure(x, s, ...) ExitOnFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
10#define AppExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) 10#define AppExitOnRootFailure(x, s, ...) ExitOnRootFailureSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
11#define AppExitWithRootFailure(x, e, s, ...) ExitWithRootFailureSource(DUTIL_SOURCE_APPUTIL, x, e, s, __VA_ARGS__)
11#define AppExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__) 12#define AppExitOnFailureDebugTrace(x, s, ...) ExitOnFailureDebugTraceSource(DUTIL_SOURCE_APPUTIL, x, s, __VA_ARGS__)
12#define AppExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__) 13#define AppExitOnNull(p, x, e, s, ...) ExitOnNullSource(DUTIL_SOURCE_APPUTIL, p, x, e, s, __VA_ARGS__)
13#define AppExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__) 14#define AppExitOnNullWithLastError(p, x, s, ...) ExitOnNullWithLastErrorSource(DUTIL_SOURCE_APPUTIL, p, x, s, __VA_ARGS__)
@@ -31,20 +32,50 @@ static HRESULT EscapeCommandLineArgument(
31 __out_z LPWSTR* psczEscaped 32 __out_z LPWSTR* psczEscaped
32 ); 33 );
33 34
34DAPI_(void) AppFreeCommandLineArgs( 35DAPI_(HRESULT) LoadSystemLibrary(
35 __in LPWSTR* argv 36 __in_z LPCWSTR wzModuleName,
37 __out HMODULE* phModule
36 ) 38 )
37{ 39{
38 // The "ignored" hack in AppParseCommandLine requires an adjustment. 40 HRESULT hr = LoadSystemLibraryWithPath(wzModuleName, phModule, NULL);
39 LPWSTR* argvOriginal = argv - 1; 41 return hr;
40 ::LocalFree(argvOriginal);
41} 42}
42 43
43/******************************************************************** 44DAPI_(HRESULT) LoadSystemLibraryWithPath(
44AppInitialize - initializes the standard safety precautions for an 45 __in_z LPCWSTR wzModuleName,
45 installation application. 46 __out HMODULE* phModule,
47 __deref_out_z_opt LPWSTR* psczPath
48 )
49{
50 HRESULT hr = S_OK;
51 DWORD cch = 0;
52 WCHAR wzPath[MAX_PATH] = { };
53
54 cch = ::GetSystemDirectoryW(wzPath, MAX_PATH);
55 AppExitOnNullWithLastError(cch, hr, "Failed to get the Windows system directory.");
56
57 if (L'\\' != wzPath[cch - 1])
58 {
59 hr = ::StringCchCatNW(wzPath, MAX_PATH, L"\\", 1);
60 AppExitOnRootFailure(hr, "Failed to terminate the string with a backslash.");
61 }
62
63 hr = ::StringCchCatW(wzPath, MAX_PATH, wzModuleName);
64 AppExitOnRootFailure(hr, "Failed to create the fully-qualified path to %ls.", wzModuleName);
65
66 *phModule = ::LoadLibraryW(wzPath);
67 AppExitOnNullWithLastError(*phModule, hr, "Failed to load the library %ls.", wzModuleName);
68
69 if (psczPath)
70 {
71 hr = StrAllocString(psczPath, wzPath, MAX_PATH);
72 AppExitOnFailure(hr, "Failed to copy the path to library.");
73 }
74
75LExit:
76 return hr;
77}
46 78
47********************************************************************/
48DAPI_(void) AppInitialize( 79DAPI_(void) AppInitialize(
49 __in_ecount(cSafelyLoadSystemDlls) LPCWSTR rgsczSafelyLoadSystemDlls[], 80 __in_ecount(cSafelyLoadSystemDlls) LPCWSTR rgsczSafelyLoadSystemDlls[],
50 __in DWORD cSafelyLoadSystemDlls 81 __in DWORD cSafelyLoadSystemDlls
@@ -101,39 +132,6 @@ DAPI_(void) AppInitializeUnsafe()
101 ::HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0); 132 ::HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
102} 133}
103 134
104DAPI_(HRESULT) AppParseCommandLine(
105 __in LPCWSTR wzCommandLine,
106 __in int* pArgc,
107 __in LPWSTR** pArgv
108 )
109{
110 HRESULT hr = S_OK;
111 LPWSTR sczCommandLine = NULL;
112 LPWSTR* argv = NULL;
113 int argc = 0;
114
115 // CommandLineToArgvW tries to treat the first argument as the path to the process,
116 // which fails pretty miserably if your first argument is something like
117 // FOO="C:\Program Files\My Company". So give it something harmless to play with.
118 hr = StrAllocConcat(&sczCommandLine, L"ignored ", 0);
119 AppExitOnFailure(hr, "Failed to initialize command line.");
120
121 hr = StrAllocConcat(&sczCommandLine, wzCommandLine, 0);
122 AppExitOnFailure(hr, "Failed to copy command line.");
123
124 argv = ::CommandLineToArgvW(sczCommandLine, &argc);
125 AppExitOnNullWithLastError(argv, hr, "Failed to parse command line.");
126
127 // Skip "ignored" argument/hack.
128 *pArgv = argv + 1;
129 *pArgc = argc - 1;
130
131LExit:
132 ReleaseStr(sczCommandLine);
133
134 return hr;
135}
136
137DAPI_(HRESULT) AppAppendCommandLineArgument( 135DAPI_(HRESULT) AppAppendCommandLineArgument(
138 __deref_inout_z LPWSTR* psczCommandLine, 136 __deref_inout_z LPWSTR* psczCommandLine,
139 __in_z LPCWSTR wzArgument 137 __in_z LPCWSTR wzArgument
diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.cpp b/src/libs/dutil/WixToolset.DUtil/dutil.cpp
index dd4fa8bf..83b53f64 100644
--- a/src/libs/dutil/WixToolset.DUtil/dutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/dutil.cpp
@@ -486,64 +486,3 @@ extern "C" void DAPI Dutil_RootFailure(
486 486
487 TraceError(hrError, "Root failure at %s:%d", szFile, iLine); 487 TraceError(hrError, "Root failure at %s:%d", szFile, iLine);
488} 488}
489
490/*******************************************************************
491 LoadSystemLibrary - Fully qualifies the path to a module in the
492 Windows system directory and loads it.
493
494 Returns
495 E_MODNOTFOUND - The module could not be found.
496 * - Another error occured.
497********************************************************************/
498extern "C" HRESULT DAPI LoadSystemLibrary(
499 __in_z LPCWSTR wzModuleName,
500 __out HMODULE *phModule
501 )
502{
503 HRESULT hr = LoadSystemLibraryWithPath(wzModuleName, phModule, NULL);
504 return hr;
505}
506
507/*******************************************************************
508 LoadSystemLibraryWithPath - Fully qualifies the path to a module in
509 the Windows system directory and loads it
510 and returns the path
511
512 Returns
513 E_MODNOTFOUND - The module could not be found.
514 * - Another error occured.
515********************************************************************/
516extern "C" HRESULT DAPI LoadSystemLibraryWithPath(
517 __in_z LPCWSTR wzModuleName,
518 __out HMODULE *phModule,
519 __deref_out_z_opt LPWSTR* psczPath
520 )
521{
522 HRESULT hr = S_OK;
523 DWORD cch = 0;
524 WCHAR wzPath[MAX_PATH] = { };
525
526 cch = ::GetSystemDirectoryW(wzPath, MAX_PATH);
527 DExitOnNullWithLastError(cch, hr, "Failed to get the Windows system directory.");
528
529 if (L'\\' != wzPath[cch - 1])
530 {
531 hr = ::StringCchCatNW(wzPath, MAX_PATH, L"\\", 1);
532 DExitOnRootFailure(hr, "Failed to terminate the string with a backslash.");
533 }
534
535 hr = ::StringCchCatW(wzPath, MAX_PATH, wzModuleName);
536 DExitOnRootFailure(hr, "Failed to create the fully-qualified path to %ls.", wzModuleName);
537
538 *phModule = ::LoadLibraryW(wzPath);
539 DExitOnNullWithLastError(*phModule, hr, "Failed to load the library %ls.", wzModuleName);
540
541 if (psczPath)
542 {
543 hr = StrAllocString(psczPath, wzPath, MAX_PATH);
544 DExitOnFailure(hr, "Failed to copy the path to library.");
545 }
546
547LExit:
548 return hr;
549}
diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj
index 3100768d..3e3c42b7 100644
--- a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj
+++ b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj
@@ -46,6 +46,7 @@
46 <ItemGroup> 46 <ItemGroup>
47 <ClCompile Include="acl2util.cpp" /> 47 <ClCompile Include="acl2util.cpp" />
48 <ClCompile Include="aclutil.cpp" /> 48 <ClCompile Include="aclutil.cpp" />
49 <ClCompile Include="app2util.cpp" />
49 <ClCompile Include="apputil.cpp" /> 50 <ClCompile Include="apputil.cpp" />
50 <ClCompile Include="apuputil.cpp" /> 51 <ClCompile Include="apuputil.cpp" />
51 <ClCompile Include="atomutil.cpp" /> 52 <ClCompile Include="atomutil.cpp" />
diff --git a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters
index c966c965..07698f9e 100644
--- a/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters
+++ b/src/libs/dutil/WixToolset.DUtil/dutil.vcxproj.filters
@@ -21,6 +21,9 @@
21 <ClCompile Include="aclutil.cpp"> 21 <ClCompile Include="aclutil.cpp">
22 <Filter>Source Files</Filter> 22 <Filter>Source Files</Filter>
23 </ClCompile> 23 </ClCompile>
24 <ClCompile Include="app2util.cpp">
25 <Filter>Source Files</Filter>
26 </ClCompile>
24 <ClCompile Include="apputil.cpp"> 27 <ClCompile Include="apputil.cpp">
25 <Filter>Source Files</Filter> 28 <Filter>Source Files</Filter>
26 </ClCompile> 29 </ClCompile>
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/apputil.h b/src/libs/dutil/WixToolset.DUtil/inc/apputil.h
index 11280102..95a98e73 100644
--- a/src/libs/dutil/WixToolset.DUtil/inc/apputil.h
+++ b/src/libs/dutil/WixToolset.DUtil/inc/apputil.h
@@ -16,6 +16,11 @@ void DAPI AppFreeCommandLineArgs(
16 __in LPWSTR* argv 16 __in LPWSTR* argv
17 ); 17 );
18 18
19/********************************************************************
20AppInitialize - initializes the standard safety precautions for an
21 installation application.
22
23********************************************************************/
19void DAPI AppInitialize( 24void DAPI AppInitialize(
20 __in_ecount(cSafelyLoadSystemDlls) LPCWSTR rgsczSafelyLoadSystemDlls[], 25 __in_ecount(cSafelyLoadSystemDlls) LPCWSTR rgsczSafelyLoadSystemDlls[],
21 __in DWORD cSafelyLoadSystemDlls 26 __in DWORD cSafelyLoadSystemDlls
diff --git a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h
index 618349da..4a29b66b 100644
--- a/src/libs/dutil/WixToolset.DUtil/inc/dutil.h
+++ b/src/libs/dutil/WixToolset.DUtil/inc/dutil.h
@@ -205,8 +205,34 @@ extern "C" {
205#endif 205#endif
206 206
207// other functions 207// other functions
208HRESULT DAPI LoadSystemLibrary(__in_z LPCWSTR wzModuleName, __out HMODULE *phModule); 208
209HRESULT DAPI LoadSystemLibraryWithPath(__in_z LPCWSTR wzModuleName, __out HMODULE *phModule, __deref_out_z_opt LPWSTR* psczPath); 209/*******************************************************************
210 LoadSystemLibrary - Fully qualifies the path to a module in the
211 Windows system directory and loads it.
212
213 Returns
214 E_MODNOTFOUND - The module could not be found.
215 * - Another error occured.
216********************************************************************/
217HRESULT DAPI LoadSystemLibrary(
218 __in_z LPCWSTR wzModuleName,
219 __out HMODULE* phModule
220 );
221
222/*******************************************************************
223 LoadSystemLibraryWithPath - Fully qualifies the path to a module in
224 the Windows system directory and loads it
225 and returns the path
226
227 Returns
228 E_MODNOTFOUND - The module could not be found.
229 * - Another error occured.
230********************************************************************/
231HRESULT DAPI LoadSystemLibraryWithPath(
232 __in_z LPCWSTR wzModuleName,
233 __out HMODULE* phModule,
234 __deref_out_z_opt LPWSTR* psczPath
235 );
210 236
211#ifdef __cplusplus 237#ifdef __cplusplus
212} 238}