use dunce

This commit is contained in:
amrbashir
2024-10-30 01:38:01 +03:00
parent 1ec8844b0e
commit 539d41ace7
4 changed files with 47 additions and 86 deletions
+1
View File
@@ -37,6 +37,7 @@ regex = "1"
open = { version = "5", features = ["shellexecute-on-windows"] }
encoding_rs = "0.8"
os_pipe = "1"
dunce = { workspace = true }
[target."cfg(windows)".dependencies.windows]
version = "0.54"
+3 -2
View File
@@ -139,10 +139,11 @@ pub fn open<P: AsRef<str>>(scope: &OpenScope, path: P, with: Option<Program>) ->
pub fn show_item_in_directory<P: AsRef<std::path::Path>>(p: P) -> crate::Result<()> {
let p = p.as_ref().canonicalize()?;
let p = dunce::simplified(&p);
#[cfg(any(
windows,
target_os = "maco",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
@@ -153,7 +154,7 @@ pub fn show_item_in_directory<P: AsRef<std::path::Path>>(p: P) -> crate::Result<
#[cfg(not(any(
windows,
target_os = "maco",
target_os = "macos",
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
+3 -5
View File
@@ -1,4 +1,4 @@
use std::{ffi::OsString, path::PathBuf};
use std::path::Path;
use windows::{
core::{w, HSTRING, PCWSTR},
@@ -12,18 +12,16 @@ use windows::{
},
};
pub fn show_item_in_directory(file: PathBuf) -> crate::Result<()> {
pub fn show_item_in_directory(file: &Path) -> crate::Result<()> {
let _ = unsafe { CoInitialize(None) };
let dir = file
.parent()
.ok_or_else(|| crate::Error::NoParent(file.clone()))?;
.ok_or_else(|| crate::Error::NoParent(file.to_path_buf()))?;
let dir = OsString::from(dir);
let dir = HSTRING::from(dir);
let dir_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(dir.as_ptr())) };
let file = OsString::from(file);
let file = HSTRING::from(file);
let file_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(file.as_ptr())) };