From a04cd88493fe2eb4f179557e235aab853681fb06 Mon Sep 17 00:00:00 2001 From: FlowerCode Date: Mon, 12 Aug 2024 19:12:32 +0800 Subject: [PATCH 1/3] Replace `winreg` with `windows-registry`. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 022cc11d7..a7108e2c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -181,7 +181,7 @@ futures-util = { version = "0.3.28", default-features = false, features = ["std" rustls = { version = "0.23", default-features = false, features = ["ring"] } [target.'cfg(windows)'.dependencies] -winreg = "0.52.0" +windows-registry = "0.2" [target.'cfg(target_os = "macos")'.dependencies] system-configuration = { version = "0.5.1", optional = true } From 348f2898567e7498f5b9bea1e3222a42adc53be5 Mon Sep 17 00:00:00 2001 From: FlowerCode Date: Mon, 12 Aug 2024 19:13:16 +0800 Subject: [PATCH 2/3] Update `proxy.rs` to use `windows-registry`. --- src/proxy.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/proxy.rs b/src/proxy.rs index 98708c775..262faa2d3 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -29,10 +29,6 @@ use system_configuration::{ sys::schema_definitions::kSCPropNetProxiesHTTPSPort, sys::schema_definitions::kSCPropNetProxiesHTTPSProxy, }; -#[cfg(target_os = "windows")] -use winreg::enums::HKEY_CURRENT_USER; -#[cfg(target_os = "windows")] -use winreg::RegKey; /// Configuration of a proxy that a `Client` should pass requests to. /// @@ -937,12 +933,10 @@ fn is_cgi() -> bool { #[cfg(target_os = "windows")] fn get_from_platform_impl() -> Result, Box> { - let hkcu = RegKey::predef(HKEY_CURRENT_USER); - let internet_setting: RegKey = - hkcu.open_subkey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")?; + let internet_setting = windows_registry::CURRENT_USER.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")?; // ensure the proxy is enable, if the value doesn't exist, an error will returned. - let proxy_enable: u32 = internet_setting.get_value("ProxyEnable")?; - let proxy_server: String = internet_setting.get_value("ProxyServer")?; + let proxy_enable = internet_setting.get_u32("ProxyEnable")?; + let proxy_server = internet_setting.get_string("ProxyServer")?; Ok((proxy_enable == 1).then_some(proxy_server)) } From 5cde7066b06ce624af53477729f71d9fd05d15db Mon Sep 17 00:00:00 2001 From: FlowerCode Date: Mon, 12 Aug 2024 20:35:54 +0800 Subject: [PATCH 3/3] Code style fix. --- src/proxy.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/proxy.rs b/src/proxy.rs index 262faa2d3..5be207a8a 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -933,7 +933,8 @@ fn is_cgi() -> bool { #[cfg(target_os = "windows")] fn get_from_platform_impl() -> Result, Box> { - let internet_setting = windows_registry::CURRENT_USER.open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")?; + let internet_setting = windows_registry::CURRENT_USER + .open("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")?; // ensure the proxy is enable, if the value doesn't exist, an error will returned. let proxy_enable = internet_setting.get_u32("ProxyEnable")?; let proxy_server = internet_setting.get_string("ProxyServer")?;