fix: resolve winreg API compatibility issue on Windows

- Update RegValue.to_string() usage to match current winreg API
  which returns String directly instead of Result
- Add conditional compilation for std::fs import (Unix only)
This commit is contained in:
farion1231
2025-11-19 10:06:52 +08:00
parent 436f0e8e42
commit 1ce007622e

View File

@@ -1,4 +1,5 @@
use serde::{Deserialize, Serialize};
#[cfg(not(target_os = "windows"))]
use std::fs;
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -49,17 +50,15 @@ fn check_system_env(keywords: &[&str]) -> Result<Vec<EnvConflict>, String> {
if let Ok(hkcu) = RegKey::predef(HKEY_CURRENT_USER).open_subkey("Environment") {
for (name, value) in hkcu.enum_values().filter_map(Result::ok) {
if keywords.iter().any(|k| name.to_uppercase().contains(k)) {
if let Ok(val) = value.to_string() {
conflicts.push(EnvConflict {
var_name: name.clone(),
var_value: val,
var_value: value.to_string(),
source_type: "system".to_string(),
source_path: "HKEY_CURRENT_USER\\Environment".to_string(),
});
}
}
}
}
// Check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
if let Ok(hklm) = RegKey::predef(HKEY_LOCAL_MACHINE)
@@ -67,17 +66,15 @@ fn check_system_env(keywords: &[&str]) -> Result<Vec<EnvConflict>, String> {
{
for (name, value) in hklm.enum_values().filter_map(Result::ok) {
if keywords.iter().any(|k| name.to_uppercase().contains(k)) {
if let Ok(val) = value.to_string() {
conflicts.push(EnvConflict {
var_name: name.clone(),
var_value: val,
var_value: value.to_string(),
source_type: "system".to_string(),
source_path: "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment".to_string(),
});
}
}
}
}
Ok(conflicts)
}