refactor: 迁移 winapi 到 windows-sys,修复配置解析漏洞

- 依赖替换为 windows-sys 0.61,main.rs 全面适配新 API
  - 配置解析错误显式传播:env/args 类型错误、数组空洞、非法键不再静默
  吞错
  - 修正空环境变量与空参数语义,补充 UTF-8 与路径拼接校验
  - require 容错移至 Rust 侧,模块加载失败记录日志并跳过
  - 新增配置解析与运行时单元测试(19 个)
This commit is contained in:
2026-08-14 20:09:34 +08:00
parent ed5439eaa1
commit 5e69a6a980
13 changed files with 691 additions and 278 deletions

45
src/layout.rs Normal file
View File

@@ -0,0 +1,45 @@
use crate::error::ShimError;
use std::path::{Path, PathBuf};
pub struct ShimLayout {
pub root_dir: PathBuf,
pub bin_dir: PathBuf,
pub tools_dir: PathBuf,
}
impl ShimLayout {
/// 从当前可执行文件解析 shim 安装目录布局
pub fn from_executable(exe_path: impl AsRef<Path>) -> Result<Self, ShimError> {
let exe_path = exe_path.as_ref();
let bin_dir = exe_path
.parent()
.ok_or_else(|| {
ShimError::PathResolution(format!(
"无法获取程序 [{}] 的父级 bin 目录",
exe_path.display()
))
})?
.to_path_buf();
eprintln!("bin_dir目录 {}", bin_dir.display());
let root_dir = bin_dir
.parent()
.ok_or_else(|| {
ShimError::PathResolution(format!(
"无法获取 bin 目录 [{}] 的父级 root 目录",
bin_dir.display()
))
})?
.to_path_buf();
eprintln!("root_dir 目录 {}", root_dir.display());
let tools_dir = root_dir.join("tools");
eprintln!("tools_dir 目录 {}", tools_dir.display());
Ok(Self {
root_dir,
bin_dir,
tools_dir,
})
}
}