BootLoader下载支持
This commit is contained in:
@@ -35,11 +35,22 @@ static DOWNLOAD_STATE: std::sync::Mutex<DownloadState> = std::sync::Mutex::new(D
|
|||||||
});
|
});
|
||||||
|
|
||||||
// ===================== 版本比较与下载 =====================
|
// ===================== 版本比较与下载 =====================
|
||||||
|
/// 获取 Updater 数据目录(X:\AppData\,存放 BootLoader.exe 等)
|
||||||
|
fn get_updater_data_dir() -> PathBuf {
|
||||||
|
let exe_path = std::env::current_exe().expect("Failed to get executable path");
|
||||||
|
let drive = exe_path
|
||||||
|
.parent()
|
||||||
|
.and_then(|p| p.as_os_str().to_str())
|
||||||
|
.and_then(|s| s.split('\\').next())
|
||||||
|
.unwrap_or("C:");
|
||||||
|
let appdata = PathBuf::from(format!("{}/AppData", drive));
|
||||||
|
let _ = fs::create_dir_all(&appdata);
|
||||||
|
appdata
|
||||||
|
}
|
||||||
|
|
||||||
/// 获取本地文件版本号(使用 PowerShell 获取 PE 文件版本信息)
|
/// 获取本地文件版本号(使用 PowerShell 获取 PE 文件版本信息)
|
||||||
fn get_local_file_version(filename: &str) -> String {
|
fn get_local_file_version(filename: &str) -> String {
|
||||||
let exe_path = std::env::current_exe().expect("Failed to get executable path");
|
let file_path = get_updater_data_dir().join(filename);
|
||||||
let base_dir = exe_path.parent().unwrap_or(std::path::Path::new(""));
|
|
||||||
let file_path = base_dir.join(filename);
|
|
||||||
|
|
||||||
if !file_path.exists() {
|
if !file_path.exists() {
|
||||||
return "0.0.0".to_string();
|
return "0.0.0".to_string();
|
||||||
@@ -141,10 +152,9 @@ fn handle_file_chunk(data: &serde_json::Map<std::string::String, serde_json::Val
|
|||||||
let _ = fs::remove_file(tp);
|
let _ = fs::remove_file(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取可执行文件目录
|
// 使用 AppData/Updater/ 作为数据目录
|
||||||
let exe_path = std::env::current_exe().expect("Failed to get executable path");
|
let data_dir = get_updater_data_dir();
|
||||||
let base_dir = exe_path.parent().unwrap_or(std::path::Path::new(""));
|
let temp_path = data_dir.join(format!("{}.tmp", filename));
|
||||||
let temp_path = base_dir.join(format!("{}.tmp", filename));
|
|
||||||
|
|
||||||
// 创建临时文件(截断)
|
// 创建临时文件(截断)
|
||||||
match File::create(&temp_path) {
|
match File::create(&temp_path) {
|
||||||
@@ -205,9 +215,8 @@ fn handle_file_chunk(data: &serde_json::Map<std::string::String, serde_json::Val
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref temp) = temp_path {
|
if let Some(ref temp) = temp_path {
|
||||||
let exe_path = std::env::current_exe().expect("Failed to get executable path");
|
let data_dir = get_updater_data_dir();
|
||||||
let base_dir = exe_path.parent().unwrap_or(std::path::Path::new(""));
|
let final_path = data_dir.join(filename);
|
||||||
let final_path = base_dir.join(filename);
|
|
||||||
|
|
||||||
// 原子重命名
|
// 原子重命名
|
||||||
if let Err(e) = fs::rename(temp, &final_path) {
|
if let Err(e) = fs::rename(temp, &final_path) {
|
||||||
@@ -266,16 +275,7 @@ impl Default for Config {
|
|||||||
|
|
||||||
/// 获取 Updater 自身配置路径 AppData/Updater/config.json
|
/// 获取 Updater 自身配置路径 AppData/Updater/config.json
|
||||||
fn get_updater_config_path() -> PathBuf {
|
fn get_updater_config_path() -> PathBuf {
|
||||||
let exe_path = std::env::current_exe().expect("Failed to get executable path");
|
get_updater_data_dir().join("Updater").join("config.json")
|
||||||
let drive = exe_path
|
|
||||||
.parent()
|
|
||||||
.and_then(|p| p.as_os_str().to_str())
|
|
||||||
.and_then(|s| s.split('\\').next())
|
|
||||||
.unwrap_or("C:");
|
|
||||||
let appdata = PathBuf::from(format!("{}/AppData", drive));
|
|
||||||
let updater_dir = appdata.join("Updater");
|
|
||||||
let _ = fs::create_dir_all(&updater_dir);
|
|
||||||
updater_dir.join("config.json")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 获取公共配置路径 AppData/config.json(与 BootLoader 同级)
|
/// 获取公共配置路径 AppData/config.json(与 BootLoader 同级)
|
||||||
|
|||||||
Reference in New Issue
Block a user