不允许重入

This commit is contained in:
zqm
2026-04-07 11:10:40 +08:00
parent c41b5ff145
commit bd3420e4ed

View File

@@ -18,6 +18,11 @@ fn main() {
// 隐藏控制台窗口
hide_console();
// 检查是否已有 BootLoader 进程在运行
if is_process_running("BootLoader.exe") {
return;
}
// 获取 BootLoader 启动目录所在盘的 AppData 目录
let appdata_dir = get_appdata_dir();
@@ -25,14 +30,16 @@ fn main() {
let updater_exe = appdata_dir.join("Updater.exe");
let updater_new_exe = appdata_dir.join("Updater.new.exe");
// 检查 Updater.new.exe 是否存在
if !updater_new_exe.exists() {
return;
}
// 等待 Updater 进程退出
wait_for_process_exit("Updater.exe");
// 检查 Updater.new.exe 是否存在
if updater_new_exe.exists() {
// 直接覆盖 Updater.exefs::rename 在 Windows 上会自动替换已存在的文件)
fs::rename(&updater_new_exe, &updater_exe).expect("Failed to rename Updater.new.exe to Updater.exe");
}
// 启动 Updater.exe
Command::new(updater_exe)
@@ -40,6 +47,16 @@ fn main() {
.expect("Failed to start Updater.exe");
}
fn is_process_running(process_name: &str) -> bool {
let output = Command::new("tasklist")
.args(["/FI", &format!("IMAGENAME eq {}", process_name)])
.output()
.expect("Failed to execute tasklist");
let output_str = String::from_utf8_lossy(&output.stdout);
output_str.contains(process_name)
}
fn get_appdata_dir() -> std::path::PathBuf {
let exe_path = std::env::current_exe().expect("Failed to get executable path");
let drive = if let Some(parent) = exe_path.parent() {