diff options
Diffstat (limited to 'src/ext/Bal/wixiuiba/wixiuiba.cpp')
-rw-r--r-- | src/ext/Bal/wixiuiba/wixiuiba.cpp | 186 |
1 files changed, 11 insertions, 175 deletions
diff --git a/src/ext/Bal/wixiuiba/wixiuiba.cpp b/src/ext/Bal/wixiuiba/wixiuiba.cpp index 3e751893..92261e9b 100644 --- a/src/ext/Bal/wixiuiba/wixiuiba.cpp +++ b/src/ext/Bal/wixiuiba/wixiuiba.cpp | |||
@@ -2,191 +2,27 @@ | |||
2 | 2 | ||
3 | #include "precomp.h" | 3 | #include "precomp.h" |
4 | 4 | ||
5 | static INTERNAL_UI_BA_STATE vstate = { }; | ||
6 | |||
7 | |||
8 | // internal function declarations | ||
9 | |||
10 | static HRESULT LoadModulePaths( | ||
11 | __in INTERNAL_UI_BA_STATE* pState | ||
12 | ); | ||
13 | static HRESULT LoadInternalUIBAConfiguration( | ||
14 | __in INTERNAL_UI_BA_STATE* pState, | ||
15 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs | ||
16 | ); | ||
17 | static HRESULT CreatePrerequisiteBA( | ||
18 | __in INTERNAL_UI_BA_STATE* pState, | ||
19 | __in IBootstrapperEngine* pEngine, | ||
20 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
21 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
22 | ); | ||
23 | |||
24 | 5 | ||
25 | // function definitions | 6 | // function definitions |
26 | 7 | ||
27 | extern "C" BOOL WINAPI DllMain( | 8 | EXTERN_C int WINAPI wWinMain( |
28 | __in HINSTANCE hInstance, | 9 | __in HINSTANCE hInstance, |
29 | __in DWORD dwReason, | 10 | __in_opt HINSTANCE /* hPrevInstance */, |
30 | __in LPVOID /*pvReserved*/ | 11 | __in_z_opt LPWSTR /*lpCmdLine*/, |
31 | ) | 12 | __in int /*nCmdShow*/ |
32 | { | ||
33 | switch (dwReason) | ||
34 | { | ||
35 | case DLL_PROCESS_ATTACH: | ||
36 | ::DisableThreadLibraryCalls(hInstance); | ||
37 | vstate.hInstance = hInstance; | ||
38 | break; | ||
39 | |||
40 | case DLL_PROCESS_DETACH: | ||
41 | vstate.hInstance = NULL; | ||
42 | break; | ||
43 | } | ||
44 | |||
45 | return TRUE; | ||
46 | } | ||
47 | |||
48 | // Note: This function assumes that COM was already initialized on the thread. | ||
49 | extern "C" HRESULT WINAPI BootstrapperApplicationCreate( | ||
50 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
51 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
52 | ) | ||
53 | { | ||
54 | HRESULT hr = S_OK; | ||
55 | IBootstrapperEngine* pEngine = NULL; | ||
56 | |||
57 | hr = BalInitializeFromCreateArgs(pArgs, &pEngine); | ||
58 | ExitOnFailure(hr, "Failed to initialize Bal."); | ||
59 | |||
60 | if (!vstate.fInitialized) | ||
61 | { | ||
62 | hr = XmlInitialize(); | ||
63 | BalExitOnFailure(hr, "Failed to initialize XML."); | ||
64 | |||
65 | hr = LoadModulePaths(&vstate); | ||
66 | BalExitOnFailure(hr, "Failed to load the module paths."); | ||
67 | |||
68 | hr = LoadInternalUIBAConfiguration(&vstate, pArgs); | ||
69 | BalExitOnFailure(hr, "Failed to get the InternalUIBA configuration."); | ||
70 | |||
71 | vstate.fInitialized = TRUE; | ||
72 | } | ||
73 | |||
74 | if (vstate.prereqData.fAlwaysInstallPrereqs && !vstate.prereqData.fCompleted || | ||
75 | FAILED(vstate.prereqData.hrFatalError)) | ||
76 | { | ||
77 | BalLog(BOOTSTRAPPER_LOG_LEVEL_STANDARD, "Loading prerequisite bootstrapper application."); | ||
78 | |||
79 | hr = CreatePrerequisiteBA(&vstate, pEngine, pArgs, pResults); | ||
80 | BalExitOnFailure(hr, "Failed to create the pre-requisite bootstrapper application."); | ||
81 | } | ||
82 | else | ||
83 | { | ||
84 | hr = CreateBootstrapperApplication(vstate.hInstance, &vstate.prereqData, pEngine, pArgs, pResults, &vstate.pApplication); | ||
85 | BalExitOnFailure(hr, "Failed to create bootstrapper application interface."); | ||
86 | } | ||
87 | |||
88 | LExit: | ||
89 | ReleaseNullObject(pEngine); | ||
90 | |||
91 | return hr; | ||
92 | } | ||
93 | |||
94 | extern "C" void WINAPI BootstrapperApplicationDestroy( | ||
95 | __in const BOOTSTRAPPER_DESTROY_ARGS* pArgs, | ||
96 | __in BOOTSTRAPPER_DESTROY_RESULTS* pResults | ||
97 | ) | ||
98 | { | ||
99 | BOOTSTRAPPER_DESTROY_RESULTS childResults = { }; | ||
100 | |||
101 | if (vstate.hPrereqModule) | ||
102 | { | ||
103 | PFN_BOOTSTRAPPER_APPLICATION_DESTROY pfnDestroy = reinterpret_cast<PFN_BOOTSTRAPPER_APPLICATION_DESTROY>(::GetProcAddress(vstate.hPrereqModule, "PrereqBootstrapperApplicationDestroy")); | ||
104 | if (pfnDestroy) | ||
105 | { | ||
106 | (*pfnDestroy)(pArgs, &childResults); | ||
107 | } | ||
108 | |||
109 | ::FreeLibrary(vstate.hPrereqModule); | ||
110 | vstate.hPrereqModule = NULL; | ||
111 | } | ||
112 | |||
113 | if (vstate.pApplication) | ||
114 | { | ||
115 | DestroyBootstrapperApplication(vstate.pApplication, pArgs, pResults); | ||
116 | ReleaseNullObject(vstate.pApplication); | ||
117 | } | ||
118 | |||
119 | BalUninitialize(); | ||
120 | |||
121 | // Need to keep track of state between reloads. | ||
122 | pResults->fDisableUnloading = TRUE; | ||
123 | } | ||
124 | |||
125 | static HRESULT LoadModulePaths( | ||
126 | __in INTERNAL_UI_BA_STATE* pState | ||
127 | ) | ||
128 | { | ||
129 | HRESULT hr = S_OK; | ||
130 | LPWSTR sczFullPath = NULL; | ||
131 | |||
132 | hr = PathForCurrentProcess(&sczFullPath, pState->hInstance); | ||
133 | ExitOnFailure(hr, "Failed to get the full host path."); | ||
134 | |||
135 | hr = PathGetDirectory(sczFullPath, &pState->sczAppBase); | ||
136 | ExitOnFailure(hr, "Failed to get the directory of the full process path."); | ||
137 | |||
138 | LExit: | ||
139 | ReleaseStr(sczFullPath); | ||
140 | |||
141 | return hr; | ||
142 | } | ||
143 | |||
144 | static HRESULT LoadInternalUIBAConfiguration( | ||
145 | __in INTERNAL_UI_BA_STATE* pState, | ||
146 | __in const BOOTSTRAPPER_CREATE_ARGS* /*pArgs*/ | ||
147 | ) | 13 | ) |
148 | { | 14 | { |
149 | HRESULT hr = S_OK; | 15 | HRESULT hr = S_OK; |
16 | IBootstrapperApplication* pApplication = NULL; | ||
150 | 17 | ||
151 | pState->prereqData.fAlwaysInstallPrereqs = TRUE; | 18 | hr = CreateWixInternalUIBootstrapperApplication(hInstance, &pApplication); |
152 | pState->prereqData.fPerformHelp = TRUE; | 19 | ExitOnFailure(hr, "Failed to create WiX internal UI bootstrapper application."); |
153 | pState->prereqData.fPerformLayout = TRUE; | ||
154 | |||
155 | return hr; | ||
156 | } | ||
157 | |||
158 | static HRESULT CreatePrerequisiteBA( | ||
159 | __in INTERNAL_UI_BA_STATE* pState, | ||
160 | __in IBootstrapperEngine* pEngine, | ||
161 | __in const BOOTSTRAPPER_CREATE_ARGS* pArgs, | ||
162 | __inout BOOTSTRAPPER_CREATE_RESULTS* pResults | ||
163 | ) | ||
164 | { | ||
165 | HRESULT hr = S_OK; | ||
166 | LPWSTR sczPrereqPath = NULL; | ||
167 | HMODULE hModule = NULL; | ||
168 | |||
169 | hr = PathConcat(pState->sczAppBase, L"prereqba.dll", &sczPrereqPath); | ||
170 | BalExitOnFailure(hr, "Failed to get path to pre-requisite BA."); | ||
171 | |||
172 | hModule = ::LoadLibraryExW(sczPrereqPath, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); | ||
173 | ExitOnNullWithLastError(hModule, hr, "Failed to load pre-requisite BA DLL."); | ||
174 | |||
175 | PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE pfnCreate = reinterpret_cast<PFN_PREQ_BOOTSTRAPPER_APPLICATION_CREATE>(::GetProcAddress(hModule, "PrereqBootstrapperApplicationCreate")); | ||
176 | ExitOnNullWithLastError(pfnCreate, hr, "Failed to get PrereqBootstrapperApplicationCreate entry-point from: %ls", sczPrereqPath); | ||
177 | |||
178 | hr = pfnCreate(&pState->prereqData, pEngine, pArgs, pResults); | ||
179 | ExitOnFailure(hr, "Failed to create prequisite bootstrapper app."); | ||
180 | 20 | ||
181 | pState->hPrereqModule = hModule; | 21 | hr = BootstrapperApplicationRun(pApplication); |
182 | hModule = NULL; | 22 | ExitOnFailure(hr, "Failed to run WiX internal UI bootstrapper application."); |
183 | 23 | ||
184 | LExit: | 24 | LExit: |
185 | if (hModule) | 25 | ReleaseObject(pApplication); |
186 | { | ||
187 | ::FreeLibrary(hModule); | ||
188 | } | ||
189 | ReleaseStr(sczPrereqPath); | ||
190 | 26 | ||
191 | return hr; | 27 | return 0; |
192 | } | 28 | } |