mirror of
https://mirror.suhoan.cn/https://github.com/EasyTier/EasyTier.git
synced 2025-12-14 13:47:24 +08:00
delete bloated registry items (#200)
* delete bloated registry items --------- Co-authored-by: 荣耀的捍卫者 <1250839773@qq.com>
This commit is contained in:
@@ -41,6 +41,7 @@ tauri-plugin-positioner = { version = "2.0.0-beta", features = ["tray-icon"] }
|
|||||||
tauri-plugin-vpnservice = { path = "../../tauri-plugin-vpnservice" }
|
tauri-plugin-vpnservice = { path = "../../tauri-plugin-vpnservice" }
|
||||||
tauri-plugin-os = "2.0.0-beta.7"
|
tauri-plugin-os = "2.0.0-beta.7"
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
# This feature is used for production builds or when a dev server is not specified, DO NOT REMOVE!!
|
||||||
custom-protocol = ["tauri/custom-protocol"]
|
custom-protocol = ["tauri/custom-protocol"]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
use tauri::Manager as _;
|
use tauri::Manager as _;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||||
enum NetworkingMethod {
|
enum NetworkingMethod {
|
||||||
PublicServer,
|
PublicServer,
|
||||||
@@ -336,6 +337,7 @@ pub fn init_launch(_app_handle: &tauri::AppHandle, enable: bool) -> Result<bool,
|
|||||||
Ok(enabled)
|
Ok(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
#[cfg(not(target_os = "android"))]
|
#[cfg(not(target_os = "android"))]
|
||||||
@@ -343,7 +345,6 @@ pub fn run() {
|
|||||||
use std::process;
|
use std::process;
|
||||||
process::exit(0);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_os::init())
|
.plugin(tauri_plugin_os::init())
|
||||||
.plugin(tauri_plugin_clipboard_manager::init())
|
.plugin(tauri_plugin_clipboard_manager::init())
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ windows-sys = { version = "0.52", features = [
|
|||||||
"Win32_System_IO",
|
"Win32_System_IO",
|
||||||
] }
|
] }
|
||||||
encoding = "0.2"
|
encoding = "0.2"
|
||||||
|
winreg = "0.11"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = "0.10"
|
tonic-build = "0.10"
|
||||||
|
|||||||
@@ -245,6 +245,82 @@ pub struct VirtualNic {
|
|||||||
ifname: Option<String>,
|
ifname: Option<String>,
|
||||||
ifcfg: Box<dyn IfConfiguerTrait + Send + Sync + 'static>,
|
ifcfg: Box<dyn IfConfiguerTrait + Send + Sync + 'static>,
|
||||||
}
|
}
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub fn checkreg() -> io::Result<()> {
|
||||||
|
use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey,enums::KEY_ALL_ACCESS};
|
||||||
|
// 打开根键
|
||||||
|
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
|
||||||
|
// 打开指定的子键
|
||||||
|
let profiles_key = hklm.open_subkey_with_flags(
|
||||||
|
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\Profiles",
|
||||||
|
KEY_ALL_ACCESS,
|
||||||
|
)?;
|
||||||
|
let unmanaged_key = hklm.open_subkey_with_flags(
|
||||||
|
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\Signatures\\Unmanaged",
|
||||||
|
KEY_ALL_ACCESS,
|
||||||
|
)?;
|
||||||
|
// 收集要删除的子键名称
|
||||||
|
let mut keys_to_delete = Vec::new();
|
||||||
|
let mut keys_to_delete_unmanaged = Vec::new();
|
||||||
|
for subkey_name in profiles_key.enum_keys().filter_map(Result::ok) {
|
||||||
|
let subkey = profiles_key.open_subkey(&subkey_name)?;
|
||||||
|
// 尝试读取 ProfileName 值
|
||||||
|
match subkey.get_value::<String, _>("ProfileName") {
|
||||||
|
Ok(profile_name) => {
|
||||||
|
// 检查 ProfileName 是否包含 "et"
|
||||||
|
if profile_name.contains("et_") {
|
||||||
|
keys_to_delete.push(subkey_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// 打印错误信息
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to read ProfileName for subkey {}: {}",
|
||||||
|
subkey_name,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for subkey_name in unmanaged_key.enum_keys().filter_map(Result::ok) {
|
||||||
|
let subkey = unmanaged_key.open_subkey(&subkey_name)?;
|
||||||
|
// 尝试读取 ProfileName 值
|
||||||
|
match subkey.get_value::<String, _>("Description") {
|
||||||
|
Ok(profile_name) => {
|
||||||
|
// 检查 ProfileName 是否包含 "et"
|
||||||
|
if profile_name.contains("et_") {
|
||||||
|
keys_to_delete_unmanaged.push(subkey_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
// 打印错误信息
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to read ProfileName for subkey {}: {}",
|
||||||
|
subkey_name,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//删除收集到的子键
|
||||||
|
if !keys_to_delete.is_empty() {
|
||||||
|
for subkey_name in keys_to_delete {
|
||||||
|
match profiles_key.delete_subkey_all(&subkey_name) {
|
||||||
|
Ok(_) => tracing::trace!("Successfully deleted subkey: {}", subkey_name),
|
||||||
|
Err(e) => tracing::error!("Failed to delete subkey {}: {}", subkey_name, e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !keys_to_delete_unmanaged.is_empty() {
|
||||||
|
for subkey_name in keys_to_delete_unmanaged {
|
||||||
|
match unmanaged_key.delete_subkey_all(&subkey_name) {
|
||||||
|
Ok(_) => tracing::trace!("Successfully deleted subkey: {}", subkey_name),
|
||||||
|
Err(e) => tracing::error!("Failed to delete subkey {}: {}", subkey_name, e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
impl VirtualNic {
|
impl VirtualNic {
|
||||||
pub fn new(global_ctx: ArcGlobalCtx) -> Self {
|
pub fn new(global_ctx: ArcGlobalCtx) -> Self {
|
||||||
@@ -285,6 +361,10 @@ impl VirtualNic {
|
|||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
|
match checkreg(){
|
||||||
|
Ok(_) => tracing::trace!("delete successful!"),
|
||||||
|
Err(e) => tracing::error!("An error occurred: {}", e),
|
||||||
|
}
|
||||||
use rand::distributions::Distribution as _;
|
use rand::distributions::Distribution as _;
|
||||||
use std::net::IpAddr;
|
use std::net::IpAddr;
|
||||||
let c = crate::arch::windows::interface_count()?;
|
let c = crate::arch::windows::interface_count()?;
|
||||||
|
|||||||
Reference in New Issue
Block a user