windows: Fix can not set folder for FileSaveDialog (#17708)

Closes #17622
Closes #17682

The story here is that `SHCreateItemFromParsingName` dose not accept UNC
path.

Video:



https://github.com/user-attachments/assets/f4f7f671-5ab5-4965-9158-e7a79ac02654



Release Notes:

- N/A
This commit is contained in:
Junkui Zhang 2024-10-01 07:26:20 +08:00 committed by GitHub
parent 837756198f
commit ecb7144b95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -664,10 +664,11 @@ fn file_save_dialog(directory: PathBuf) -> Result<Option<PathBuf>> {
let dialog: IFileSaveDialog = unsafe { CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)? }; let dialog: IFileSaveDialog = unsafe { CoCreateInstance(&FileSaveDialog, None, CLSCTX_ALL)? };
if !directory.to_string_lossy().is_empty() { if !directory.to_string_lossy().is_empty() {
if let Some(full_path) = directory.canonicalize().log_err() { if let Some(full_path) = directory.canonicalize().log_err() {
let full_path = full_path.to_string_lossy().to_string(); let full_path = full_path.to_string_lossy();
if !full_path.is_empty() { let full_path_str = full_path.trim_start_matches("\\\\?\\");
if !full_path_str.is_empty() {
let path_item: IShellItem = let path_item: IShellItem =
unsafe { SHCreateItemFromParsingName(&HSTRING::from(&full_path), None)? }; unsafe { SHCreateItemFromParsingName(&HSTRING::from(full_path_str), None)? };
unsafe { dialog.SetFolder(&path_item).log_err() }; unsafe { dialog.SetFolder(&path_item).log_err() };
} }
} }