From 3455eee4cc59ccbc770da11bb9f86423303941ec Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Fri, 27 Dec 2024 20:12:58 +0800 Subject: [PATCH] make winreg as optional --- Cargo.toml | 9 +++++++-- src/adapter.rs | 6 ++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c63339a..f229086 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,12 @@ features = ["async"] [features] default = [] -# default = ["verify_binary_signature", "panic_on_unsent_packets", "async"] +# default = [ +# "verify_binary_signature", +# "panic_on_unsent_packets", +# "async", +# "winreg", +# ] async = ["blocking", "futures"] panic_on_unsent_packets = [] verify_binary_signature = [] @@ -55,7 +60,7 @@ windows-sys = { version = "0.59", features = [ "Win32_System_LibraryLoader", "Win32_Security_WinTrust", ] } -winreg = "0.52.0" +winreg = { version = "0.52.0", optional = true } [dev-dependencies] dotenvy = "0.15" diff --git a/src/adapter.rs b/src/adapter.rs index e7e1c01..ee3db75 100644 --- a/src/adapter.rs +++ b/src/adapter.rs @@ -403,12 +403,13 @@ impl Adapter { impl Drop for Adapter { fn drop(&mut self) { - let name = self.get_name(); + let _name = self.get_name(); //Close adapter on drop //This is why we need an Arc of wintun unsafe { self.wintun.WintunCloseAdapter(self.adapter.0) }; self.adapter = UnsafeHandle(ptr::null_mut()); - if let Ok(name) = name { + #[cfg(feature = "winreg")] + if let Ok(name) = _name { // Delete registry related to network card _ = delete_adapter_info_from_reg(&name); } @@ -416,6 +417,7 @@ impl Drop for Adapter { } /// This function is used to avoid the adapter name and guid being recorded in the registry +#[cfg(feature = "winreg")] pub(crate) fn delete_adapter_info_from_reg(dev_name: &str) -> std::io::Result<()> { use winreg::{enums::HKEY_LOCAL_MACHINE, enums::KEY_ALL_ACCESS, RegKey}; let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);