summaryrefslogtreecommitdiff
path: root/gnu/packages/patches/rust-trash-2-update-windows.patch
blob: f6b13a4658c1a4f95fdb8278aa1ef94207351985 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
This patch is taken from upstream so we can use an already packaged
version of the windows crate.

diff --git a/Cargo.toml b/Cargo.toml
index 2c28dfe..6b61771 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -87,9 +87,8 @@ version = "0.2.7"
 version = "1.0.0"
 
 [target."cfg(windows)".dependencies.windows]
-version = "0.37.0"
+version = "0.44.0"
 features = [
-    "alloc",
     "Win32_Foundation",
     "Win32_System_Com_StructuredStorage",
     "Win32_UI_Shell_PropertiesSystem",
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 894a78c..c17fc02 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -44,7 +44,7 @@ once_cell = "1.7.2"
 once_cell = "1.7.2"
 
 [target.'cfg(windows)'.dependencies]
-windows = { version = "0.37.0", features = [ "alloc",
+windows = { version = "0.44.0", features = [
     "Win32_Foundation",
     "Win32_System_Com_StructuredStorage",
     "Win32_UI_Shell_PropertiesSystem",
diff --git a/src/windows.rs b/src/windows.rs
index c1379d3..3f4426b 100644
--- a/src/windows.rs
+++ b/src/windows.rs
@@ -1,7 +1,6 @@
 use crate::{Error, TrashContext, TrashItem};
 use std::{
-    ffi::{OsStr, OsString},
-    mem::MaybeUninit,
+    ffi::{c_void, OsStr, OsString},
     os::windows::{ffi::OsStrExt, prelude::*},
     path::PathBuf,
 };
@@ -66,7 +65,7 @@ impl TrashContext {
                 let shi: IShellItem =
                     SHCreateItemFromParsingName(PCWSTR(wide_path_slice.as_ptr()), None)?;
 
-                pfo.DeleteItem(shi, None)?;
+                pfo.DeleteItem(&shi, None)?;
             }
             pfo.PerformOperations()?;
             Ok(())
@@ -78,28 +77,18 @@ pub fn list() -> Result<Vec<TrashItem>, Error> {
     ensure_com_initialized();
     unsafe {
         let mut item_vec = Vec::new();
-        let mut recycle_bin = MaybeUninit::<Option<IShellItem>>::uninit();
 
-        SHGetKnownFolderItem(
-            &FOLDERID_RecycleBinFolder,
-            KF_FLAG_DEFAULT,
-            HANDLE::default(),
-            &IShellItem::IID,
-            recycle_bin.as_mut_ptr() as _,
-        )?;
-
-        let recycle_bin = recycle_bin.assume_init().ok_or(Error::Unknown {
-            description: "SHGetKnownFolderItem gave NULL for FOLDERID_RecycleBinFolder".into(),
-        })?;
+        let recycle_bin: IShellItem =
+            SHGetKnownFolderItem(&FOLDERID_RecycleBinFolder, KF_FLAG_DEFAULT, HANDLE::default())?;
 
         let pesi: IEnumShellItems = recycle_bin.BindToHandler(None, &BHID_EnumItems)?;
-        let mut fetched: u32 = 0;
 
         loop {
+            let mut fetched_count: u32 = 0;
             let mut arr = [None];
-            pesi.Next(&mut arr, &mut fetched)?;
+            pesi.Next(&mut arr, Some(&mut fetched_count as *mut u32))?;
 
-            if fetched == 0 {
+            if fetched_count == 0 {
                 break;
             }
 
@@ -145,7 +134,7 @@ where
             at_least_one = true;
             let id_as_wide: Vec<u16> = item.id.encode_wide().chain(std::iter::once(0)).collect();
             let parsing_name = PCWSTR(id_as_wide.as_ptr());
-            let trash_item: IShellItem = SHCreateItemFromParsingName(&parsing_name, None)?;
+            let trash_item: IShellItem = SHCreateItemFromParsingName(parsing_name, None)?;
             pfo.DeleteItem(&trash_item, None)?;
         }
         if at_least_one {
@@ -181,7 +170,7 @@ where
         for item in items.iter() {
             let id_as_wide: Vec<u16> = item.id.encode_wide().chain(std::iter::once(0)).collect();
             let parsing_name = PCWSTR(id_as_wide.as_ptr());
-            let trash_item: IShellItem = SHCreateItemFromParsingName(&parsing_name, None)?;
+            let trash_item: IShellItem = SHCreateItemFromParsingName(parsing_name, None)?;
             let parent_path_wide: Vec<_> =
                 item.original_parent.as_os_str().encode_wide().chain(std::iter::once(0)).collect();
             let orig_folder_shi: IShellItem =
@@ -191,7 +180,7 @@ where
                 .chain(std::iter::once(0))
                 .collect();
 
-            pfo.MoveItem(trash_item, orig_folder_shi, PCWSTR(name_wstr.as_ptr()), None)?;
+            pfo.MoveItem(&trash_item, &orig_folder_shi, PCWSTR(name_wstr.as_ptr()), None)?;
         }
         if !items.is_empty() {
             pfo.PerformOperations()?;
@@ -203,7 +192,7 @@ where
 unsafe fn get_display_name(psi: &IShellItem, sigdnname: SIGDN) -> Result<OsString, Error> {
     let name = psi.GetDisplayName(sigdnname)?;
     let result = wstr_to_os_string(name);
-    CoTaskMemFree(name.0 as _);
+    CoTaskMemFree(Some(name.0 as *const c_void));
     Ok(result)
 }
 
@@ -257,7 +246,7 @@ impl CoInitializer {
         if cfg!(feature = "coinit_speed_over_memory") {
             init_mode |= COINIT_SPEED_OVER_MEMORY;
         }
-        let hr = unsafe { CoInitializeEx(std::ptr::null_mut(), init_mode) };
+        let hr = unsafe { CoInitializeEx(None, init_mode) };
         if hr.is_err() {
             panic!("Call to CoInitializeEx failed. HRESULT: {:?}. Consider using `trash` with the feature `coinit_multithreaded`", hr);
         }