aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/WixToolset.DUtil/wndutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/WixToolset.DUtil/wndutil.cpp')
-rw-r--r--src/libs/dutil/WixToolset.DUtil/wndutil.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/wndutil.cpp b/src/libs/dutil/WixToolset.DUtil/wndutil.cpp
index b75b0491..5d832e50 100644
--- a/src/libs/dutil/WixToolset.DUtil/wndutil.cpp
+++ b/src/libs/dutil/WixToolset.DUtil/wndutil.cpp
@@ -161,6 +161,163 @@ LExit:
161} 161}
162 162
163 163
164DAPI_(HRESULT) WnduShowOpenFileDialog(
165 __in_opt HWND hwndParent,
166 __in BOOL fForcePathExists,
167 __in BOOL fForceFileExists,
168 __in_opt LPCWSTR wzTitle,
169 __in COMDLG_FILTERSPEC* rgFilters,
170 __in DWORD cFilters,
171 __in DWORD dwDefaultFilter,
172 __in_opt LPCWSTR wzDefaultPath,
173 __inout LPWSTR* psczPath
174 )
175{
176 HRESULT hr = S_OK;
177 IFileOpenDialog* pFileOpenDialog = NULL;
178 FILEOPENDIALOGOPTIONS fos = 0;
179 FILEOPENDIALOGOPTIONS additionalFlags = FOS_NOCHANGEDIR;
180 IShellItem* psi = NULL;
181 LPWSTR sczDefaultDirectory = NULL;
182 LPWSTR sczPath = NULL;
183
184 hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpenDialog));
185 WnduExitOnFailure(hr, "Failed to create FileOpenDialog object.");
186
187 hr = pFileOpenDialog->SetTitle(wzTitle);
188 WnduExitOnFailure(hr, "Failed to set FileOpenDialog title.");
189
190 hr = pFileOpenDialog->GetOptions(&fos);
191 WnduExitOnFailure(hr, "Failed to get FileOpenDialog options.");
192
193 if (fForcePathExists)
194 {
195 additionalFlags |= FOS_PATHMUSTEXIST;
196 }
197
198 if (fForceFileExists)
199 {
200 additionalFlags |= FOS_FILEMUSTEXIST;
201 }
202
203 hr = pFileOpenDialog->SetOptions(fos | additionalFlags);
204 WnduExitOnFailure(hr, "Failed to set FileOpenDialog options.");
205
206 hr = pFileOpenDialog->SetFileTypes(cFilters, rgFilters);
207 WnduExitOnFailure(hr, "Failed to set FileOpenDialog file types.");
208
209 hr = pFileOpenDialog->SetFileTypeIndex(dwDefaultFilter);
210 WnduExitOnFailure(hr, "Failed to set FileOpenDialog default file type.");
211
212 if (wzDefaultPath && *wzDefaultPath)
213 {
214 hr = PathGetDirectory(wzDefaultPath, &sczDefaultDirectory);
215 if (SUCCEEDED(hr))
216 {
217 hr = ::SHCreateItemFromParsingName(sczDefaultDirectory, NULL, IID_PPV_ARGS(&psi));
218 if (SUCCEEDED(hr))
219 {
220 hr = pFileOpenDialog->SetFolder(psi);
221 WnduExitOnFailure(hr, "Failed to set FileOpenDialog folder.");
222 }
223
224 ReleaseNullObject(psi);
225 }
226
227 hr = pFileOpenDialog->SetFileName(wzDefaultPath);
228 WnduExitOnFailure(hr, "Failed to set FileOpenDialog file name.");
229 }
230
231 hr = pFileOpenDialog->Show(hwndParent);
232 if (HRESULT_FROM_WIN32(ERROR_CANCELLED) == hr)
233 {
234 ExitFunction();
235 }
236 WnduExitOnFailure(hr, "Failed to show FileOpenDialog for file.");
237
238 hr = pFileOpenDialog->GetResult(&psi);
239 WnduExitOnFailure(hr, "Failed to get FileOpenDialog result.");
240
241 hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &sczPath);
242 WnduExitOnFailure(hr, "Failed to get FileOpenDialog result path.");
243
244 hr = StrAllocString(psczPath, sczPath, 0);
245 WnduExitOnFailure(hr, "Failed to copy FileOpenDialog result path.");
246
247LExit:
248 if (sczPath)
249 {
250 ::CoTaskMemFree(sczPath);
251 }
252
253 ReleaseStr(sczDefaultDirectory);
254 ReleaseObject(psi);
255 ReleaseObject(pFileOpenDialog);
256
257 return hr;
258}
259
260
261DAPI_(HRESULT) WnduShowOpenFolderDialog(
262 __in_opt HWND hwndParent,
263 __in BOOL fForceFileSystem,
264 __in_opt LPCWSTR wzTitle,
265 __inout LPWSTR* psczPath
266 )
267{
268 HRESULT hr = S_OK;
269 IFileOpenDialog* pFileOpenDialog = NULL;
270 FILEOPENDIALOGOPTIONS fos = 0;
271 FILEOPENDIALOGOPTIONS additionalFlags = FOS_PICKFOLDERS | FOS_NOCHANGEDIR;
272 IShellItem* psi = NULL;
273 LPWSTR sczPath = NULL;
274
275 hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpenDialog));
276 WnduExitOnFailure(hr, "Failed to create FileOpenDialog object.");
277
278 hr = pFileOpenDialog->SetTitle(wzTitle);
279 WnduExitOnFailure(hr, "Failed to set FileOpenDialog title.");
280
281 hr = pFileOpenDialog->GetOptions(&fos);
282 WnduExitOnFailure(hr, "Failed to get FileOpenDialog options.");
283
284 if (fForceFileSystem)
285 {
286 additionalFlags |= FOS_FORCEFILESYSTEM;
287 }
288
289 hr = pFileOpenDialog->SetOptions(fos | additionalFlags);
290 WnduExitOnFailure(hr, "Failed to set FileOpenDialog options.");
291
292 hr = pFileOpenDialog->Show(hwndParent);
293 if (HRESULT_FROM_WIN32(ERROR_CANCELLED) == hr)
294 {
295 ExitFunction();
296 }
297 WnduExitOnFailure(hr, "Failed to show FileOpenDialog for folder.");
298
299 hr = pFileOpenDialog->GetResult(&psi);
300 WnduExitOnFailure(hr, "Failed to get FileOpenDialog result.");
301
302 hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &sczPath);
303 WnduExitOnFailure(hr, "Failed to get FileOpenDialog result path.");
304
305 hr = StrAllocString(psczPath, sczPath, 0);
306 WnduExitOnFailure(hr, "Failed to copy FileOpenDialog result path.");
307
308LExit:
309 if (sczPath)
310 {
311 ::CoTaskMemFree(sczPath);
312 }
313
314 ReleaseObject(psi);
315 ReleaseObject(pFileOpenDialog);
316
317 return hr;
318}
319
320
164static DWORD CALLBACK RichEditStreamFromFileHandleCallback( 321static DWORD CALLBACK RichEditStreamFromFileHandleCallback(
165 __in DWORD_PTR dwCookie, 322 __in DWORD_PTR dwCookie,
166 __in_bcount(cb) LPBYTE pbBuff, 323 __in_bcount(cb) LPBYTE pbBuff,