fix fallback

pull/2019/head
amrbashir 8 months ago
parent ac467fe636
commit 3a54f2f82e
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

@ -71,18 +71,22 @@ mod imp {
unsafe {
if let Err(e) = SHOpenFolderAndSelectItems(dir_item, Some(&[file_item]), 0) {
// from https://github.com/electron/electron/blob/10d967028af2e72382d16b7e2025d243b9e204ae/shell/common/platform_util_win.cc#L302
// On some systems, the above call mysteriously fails with "file not
// found" even though the file is there. In these cases, ShellExecute()
// seems to work as a fallback (although it won't select the file).
if e.code().0 == ERROR_FILE_NOT_FOUND.0 as i32 {
let is_dir = std::fs::metadata(file).map(|f| f.is_dir()).unwrap_or(false);
let is_dir = file.is_dir();
let mut info = SHELLEXECUTEINFOW {
cbSize: std::mem::size_of::<SHELLEXECUTEINFOW>() as _,
nShow: SW_SHOWNORMAL.0,
lpFile: PCWSTR(dir.as_ptr()),
lpClass: if is_dir { w!("folder") } else { PCWSTR::null() },
lpVerb: if is_dir {
w!("explore")
} else {
PCWSTR::null()
},
lpClass: if is_dir { w!("folder") } else { PCWSTR::null() },
lpFile: PCWSTR(file_h.as_ptr()),
..std::mem::zeroed()
};

Loading…
Cancel
Save