| 232 | } |
| 233 | |
| 234 | nfdresult_t SetDefaultPath(IFileDialog* dialog, const nfdnchar_t* defaultPath) { |
| 235 | if (!defaultPath || !*defaultPath) return NFD_OKAY; |
| 236 | |
| 237 | IShellItem* folder; |
| 238 | HRESULT result = SHCreateItemFromParsingName(defaultPath, nullptr, IID_PPV_ARGS(&folder)); |
| 239 | |
| 240 | // Valid non results. |
| 241 | if (result == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || |
| 242 | result == HRESULT_FROM_WIN32(ERROR_INVALID_DRIVE)) { |
| 243 | return NFD_OKAY; |
| 244 | } |
| 245 | |
| 246 | if (!SUCCEEDED(result)) { |
| 247 | NFDi_SetError("Failed to create ShellItem for setting the default path."); |
| 248 | return NFD_ERROR; |
| 249 | } |
| 250 | |
| 251 | Release_Guard<IShellItem> folderGuard(folder); |
| 252 | |
| 253 | // SetDefaultFolder() might use another recently used folder if available, so the user doesn't |
| 254 | // need to keep navigating back to the default folder (recommended by Windows). change to |
| 255 | // SetFolder() if you always want to use the default folder |
| 256 | if (!SUCCEEDED(dialog->SetFolder(folder))) { |
| 257 | NFDi_SetError("Failed to set default path."); |
| 258 | return NFD_ERROR; |
| 259 | } |
| 260 | |
| 261 | return NFD_OKAY; |
| 262 | } |
| 263 | |
| 264 | nfdresult_t SetDefaultName(IFileDialog* dialog, const nfdnchar_t* defaultName) { |
| 265 | if (!defaultName || !*defaultName) return NFD_OKAY; |
no test coverage detected