summaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/apputil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/apputil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/apputil.cpp82
1 files changed, 40 insertions, 42 deletions
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