From f0ecaa1513471245e12110759a84571beaa119c2 Mon Sep 17 00:00:00 2001 From: zoumi Date: Thu, 5 Oct 2017 21:13:56 +0800 Subject: [PATCH 1/2] delete_subkey_all() does not delete itself when subkey's path is empty. --- src/lib.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c48a5cf..341b309 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -443,8 +443,8 @@ impl RegKey { EnumValues{key: self, index: 0} } - /// Delete key. Cannot delete if it has subkeys. - /// Will delete itself if `path` is an empty string. + /// Delete key.Key names are not case sensitive. + /// Cannot delete if it has subkeys. /// Use `delete_subkey_all` for that. /// /// # Examples @@ -460,7 +460,7 @@ impl RegKey { match unsafe { advapi32::RegDeleteKeyW( self.hkey, - c_path.as_ptr(), + c_path.as_ptr(), //This parameter cannot be NULL. ) as DWORD } { 0 => Ok(()), @@ -475,11 +475,11 @@ impl RegKey { match unsafe { advapi32::RegDeleteKeyTransactedW( self.hkey, - c_path.as_ptr(), + c_path.as_ptr(), //The value of this parameter cannot be NULL. 0, 0, t.handle, - ptr::null_mut(), + ptr::null_mut(), ) as DWORD } { 0 => Ok(()), @@ -489,6 +489,7 @@ impl RegKey { /// Recursively delete subkey with all its subkeys and values. /// Will delete itself if `path` is an empty string. + /// If `path` is an empty string, the subkeys and values of this key are deleted. /// /// # Examples /// @@ -499,11 +500,18 @@ impl RegKey { /// .delete_subkey_all("Software\\MyProduct").unwrap(); /// ``` pub fn delete_subkey_all>(&self, path: P) -> io::Result<()> { - let c_path = to_utf16(path); + let c_path; + let path_ptr; + if path.as_ref().is_empty(){ + path_ptr = ptr::null(); + }else{ + c_path = to_utf16(path); + path_ptr = c_path.as_ptr(); + } match unsafe{ advapi32::RegDeleteTreeW( self.hkey, - c_path.as_ptr(), + path_ptr,//If this parameter is NULL, the subkeys and values of this key are deleted. ) as DWORD } { 0 => Ok(()), From c57393f3933e5ce93b65777aca163b3baa502270 Mon Sep 17 00:00:00 2001 From: zoumi Date: Thu, 5 Oct 2017 21:16:55 +0800 Subject: [PATCH 2/2] Update lib.rs --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 341b309..2732fbf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -488,7 +488,6 @@ impl RegKey { } /// Recursively delete subkey with all its subkeys and values. - /// Will delete itself if `path` is an empty string. /// If `path` is an empty string, the subkeys and values of this key are deleted. /// /// # Examples