| 331 | } |
| 332 | |
| 333 | nfdresult_t NFD_OpenDialogN(nfdnchar_t** outPath, |
| 334 | const nfdnfilteritem_t* filterList, |
| 335 | nfdfiltersize_t filterCount, |
| 336 | const nfdnchar_t* defaultPath) { |
| 337 | ::IFileOpenDialog* fileOpenDialog; |
| 338 | |
| 339 | // Create dialog |
| 340 | HRESULT result = ::CoCreateInstance(::CLSID_FileOpenDialog, |
| 341 | nullptr, |
| 342 | CLSCTX_ALL, |
| 343 | ::IID_IFileOpenDialog, |
| 344 | reinterpret_cast<void**>(&fileOpenDialog)); |
| 345 | |
| 346 | if (!SUCCEEDED(result)) { |
| 347 | NFDi_SetError("Could not create dialog."); |
| 348 | return NFD_ERROR; |
| 349 | } |
| 350 | |
| 351 | // make sure we remember to free the dialog |
| 352 | Release_Guard<::IFileOpenDialog> fileOpenDialogGuard(fileOpenDialog); |
| 353 | |
| 354 | // Build the filter list |
| 355 | if (!AddFiltersToDialog(fileOpenDialog, filterList, filterCount)) { |
| 356 | return NFD_ERROR; |
| 357 | } |
| 358 | |
| 359 | // Set auto-completed default extension |
| 360 | if (!SetDefaultExtension(fileOpenDialog, filterList, filterCount)) { |
| 361 | return NFD_ERROR; |
| 362 | } |
| 363 | |
| 364 | // Set the default path |
| 365 | if (!SetDefaultPath(fileOpenDialog, defaultPath)) { |
| 366 | return NFD_ERROR; |
| 367 | } |
| 368 | |
| 369 | // Only show file system items |
| 370 | if (!AddOptions(fileOpenDialog, ::FOS_FORCEFILESYSTEM)) { |
| 371 | return NFD_ERROR; |
| 372 | } |
| 373 | |
| 374 | // Show the dialog. |
| 375 | result = fileOpenDialog->Show(nullptr); |
| 376 | if (SUCCEEDED(result)) { |
| 377 | // Get the file name |
| 378 | ::IShellItem* psiResult; |
| 379 | result = fileOpenDialog->GetResult(&psiResult); |
| 380 | if (!SUCCEEDED(result)) { |
| 381 | NFDi_SetError("Could not get shell item from dialog."); |
| 382 | return NFD_ERROR; |
| 383 | } |
| 384 | Release_Guard<::IShellItem> psiResultGuard(psiResult); |
| 385 | |
| 386 | nfdnchar_t* filePath; |
| 387 | result = psiResult->GetDisplayName(::SIGDN_FILESYSPATH, &filePath); |
| 388 | if (!SUCCEEDED(result)) { |
| 389 | NFDi_SetError("Could not get file path from shell item returned by dialog."); |
| 390 | return NFD_ERROR; |
no test coverage detected