From 1435c3d566970f5366e990cdea512e1d0a6c738d Mon Sep 17 00:00:00 2001 From: emmalexandria Date: Mon, 11 Mar 2024 23:36:58 +0200 Subject: [PATCH] Attempt to fix second argument issue --- src/windows.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/windows.rs b/src/windows.rs index 7622e8f..1deecde 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -51,25 +51,26 @@ impl PlatformTrashContext { } impl TrashContext { /// See https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-_shfileopstructa - pub(crate) fn delete_specified_canonicalized(&self, full_path: PathBuf) -> Result<(), Error> { + pub(crate) fn delete_specified_canonicalized(&self, full_paths: Vec) -> Result<(), Error> { ensure_com_initialized(); unsafe { let pfo: IFileOperation = CoCreateInstance(&FileOperation as *const _, None, CLSCTX_ALL).unwrap(); pfo.SetOperationFlags(FOF_NO_UI | FOF_ALLOWUNDO | FOF_WANTNUKEWARNING)?; - let path_prefix = ['\\' as u16, '\\' as u16, '?' as u16, '\\' as u16]; - let wide_path_container = to_wide_path(full_path); - let wide_path_slice = if wide_path_container.starts_with(&path_prefix) { - &wide_path_container[path_prefix.len()..] - } else { - &wide_path_container[0..] - }; - - let shi: IShellItem = SHCreateItemFromParsingName(PCWSTR(wide_path_slice.as_ptr()), None)?; + for full_path in full_paths.iter() { + let path_prefix = ['\\' as u16, '\\' as u16, '?' as u16, '\\' as u16]; + let wide_path_container = to_wide_path(full_path); + let wide_path_slice = if wide_path_container.starts_with(&path_prefix) { + &wide_path_container[path_prefix.len()..] + } else { + &wide_path_container[0..] + }; - pfo.DeleteItem(&shi, None)?; + let shi: IShellItem = SHCreateItemFromParsingName(PCWSTR(wide_path_slice.as_ptr()), None)?; + pfo.DeleteItem(&shi, None)?; + } pfo.PerformOperations()?; Ok(()) } @@ -77,9 +78,7 @@ impl TrashContext { /// Removes all files and folder paths recursively. pub(crate) fn delete_all_canonicalized(&self, full_paths: Vec) -> Result<(), Error> { - for path in full_paths { - self.delete_specified_canonicalized(path)?; - } + self.delete_specified_canonicalized(full_paths)?; Ok(()) } }