🐛 修复成就数据读取异常

This commit is contained in:
BTMuli
2025-12-03 18:40:25 +08:00
parent 676ef8e8ee
commit 46cf40734f
6 changed files with 18 additions and 57 deletions

View File

@@ -154,7 +154,7 @@ pub fn run_with_admin() -> Result<(), String> {
return Err(format!("executable not found: {}", exe_path.display()));
}
let elevated_arg = "--elevated-action=post_install";
let elevated_arg = "--elevated";
// /C start "" "<full_path>" --elevated-action=post_install
let params = format!("/C start \"\" \"{}\" {}", exe_path.display(), elevated_arg);

View File

@@ -15,13 +15,7 @@ pub fn build_si_plugin<R: Runtime>() -> TauriPlugin<R> {
let args: Vec<String> = argv.iter().map(|s| s.to_string()).collect();
// 如果包含提升约定参数,发出专门事件并短路退出
if args.iter().any(|a| a.starts_with("--elevated-action"))
|| args.iter().any(|a| a == "--elevated")
{
if let Err(e) = app.emit("elevated_launch", args.clone()) {
// 记录错误但不要 panic
eprintln!("emit elevated_launch failed: {}", e);
}
if args.iter().any(|a| a == "--elevated") {
// 提升实例通常只负责传参或执行一次性任务,退出避免与主实例冲突
std::process::exit(0);
}

View File

@@ -23,7 +23,7 @@ fn read_rva(key: &str) -> i32 {
}
// 读取配置文件
fn read_conf(path: &str) -> i32 {
pub fn read_conf(path: &str) -> i32 {
// 编译时嵌入 JSON 文件值都是32位整数
let data = include_str!("../../lib/conf.json");
let json: Value = serde_json::from_str(data).expect("Invalid JSON");

View File

@@ -1,7 +1,8 @@
//! Yae 成就信息的 Protobuf 定义
//! @since Beta v0.8.7
//! @since Beta v0.7.9
#![cfg(target_os = "windows")]
use crate::yae::read_conf;
use prost::encoding::{decode_key, WireType};
use prost::DecodeError;
use prost::Message;
@@ -140,6 +141,8 @@ pub fn parse_achi_list(bytes: &[u8]) -> Result<Vec<UiafAchiItem>, DecodeError> {
let value = prost::encoding::decode_varint(&mut inner)? as u32;
dict.insert(tag, value);
}
// 输出 dict
println!("{:?}", dict);
// dict 至少需要两个 key
if dict.len() > 2 {
dicts.push(dict)
@@ -147,14 +150,20 @@ pub fn parse_achi_list(bytes: &[u8]) -> Result<Vec<UiafAchiItem>, DecodeError> {
}
}
let _id = read_conf("id") as u32;
let _status = read_conf("status") as u32;
let _cur = read_conf("currentProgress") as u32;
let _ts = read_conf("finishTimestamp") as u32;
let achievements = dicts
.into_iter()
.map(|d| UiafAchiItem {
id: d.get(&15).copied().unwrap_or(0),
status: d.get(&11).copied().unwrap_or(0),
current: d.get(&13).copied().unwrap_or(0),
timestamp: d.get(&7).copied().unwrap_or(0),
id: d.get(&_id).copied().unwrap_or(0),
status: d.get(&_status).copied().unwrap_or(0),
current: d.get(&_cur).copied().unwrap_or(0),
timestamp: d.get(&_ts).copied().unwrap_or(0),
})
.filter(|a| a.status != 0)
.collect();
Ok(achievements)