| 348 | |
| 349 | |
| 350 | static nfdresult_t SetDefaultPath( IFileDialog *dialog, const char *defaultPath ) |
| 351 | { |
| 352 | if ( !defaultPath || strlen(defaultPath) == 0 ) |
| 353 | return NFD_OKAY; |
| 354 | |
| 355 | wchar_t *defaultPathW = {0}; |
| 356 | CopyNFDCharToWChar( defaultPath, &defaultPathW ); |
| 357 | |
| 358 | IShellItem *folder; |
| 359 | HRESULT result = SHCreateItemFromParsingName( defaultPathW, NULL, IID_PPV_ARGS(&folder) ); |
| 360 | |
| 361 | // Valid non results. |
| 362 | if ( result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE) ) |
| 363 | { |
| 364 | NFDi_Free( defaultPathW ); |
| 365 | return NFD_OKAY; |
| 366 | } |
| 367 | |
| 368 | if ( !SUCCEEDED(result) ) |
| 369 | { |
| 370 | NFDi_SetError("Error creating ShellItem"); |
| 371 | NFDi_Free( defaultPathW ); |
| 372 | return NFD_ERROR; |
| 373 | } |
| 374 | |
| 375 | // Could also call SetDefaultFolder(), but this guarantees defaultPath -- more consistency across API. |
| 376 | dialog->SetFolder( folder ); |
| 377 | |
| 378 | NFDi_Free( defaultPathW ); |
| 379 | folder->Release(); |
| 380 | |
| 381 | return NFD_OKAY; |
| 382 | } |
| 383 | |
| 384 | /* public */ |
| 385 |
no test coverage detected