optim fpstest ui and try to fix steam path related crash

This commit is contained in:
2025-11-06 23:11:41 +08:00
parent 9f29857fd3
commit f7c9e455f7
9 changed files with 354 additions and 183 deletions

View File

@@ -156,6 +156,22 @@ pub fn check_path(path: &str) -> Result<bool, String> {
Ok(std::path::Path::new(&path).exists())
}
#[tauri::command]
pub fn check_steam_dir_valid(steam_dir: &str) -> Result<bool, String> {
use std::path::Path;
let path = Path::new(steam_dir);
if !path.exists() {
return Ok(false);
}
// 检查是否存在 steam.exe 或 config 目录(至少有一个即可)
let steam_exe = path.join("steam.exe");
let config_dir = path.join("config");
Ok(steam_exe.exists() || config_dir.exists())
}
///// 录像
#[tauri::command]
pub async fn analyze_replay(app: tauri::AppHandle, path: &str) -> Result<String, String> {

View File

@@ -162,6 +162,7 @@ fn main() {
cmds::get_cs2_video_config,
cmds::set_cs2_video_config,
cmds::check_path,
cmds::check_steam_dir_valid,
cmds::analyze_replay,
cmds::get_console_log_path,
cmds::read_vprof_report,

View File

@@ -134,7 +134,10 @@ pub fn parse_login_users(steam_dir: &str) -> Result<Vec<LoginUser>> {
let mut users = Vec::new();
for (k, v) in kv {
let props = v.as_object().unwrap();
let props = match v.as_object() {
Some(p) => p,
None => continue, // 跳过非对象类型的值
};
let avatar = if let Some(img) = read_avatar(&steam_dir, &k) {
img
@@ -142,7 +145,11 @@ pub fn parse_login_users(steam_dir: &str) -> Result<Vec<LoginUser>> {
String::new()
};
let id64 = k.parse::<u64>()?;
// 跳过无法解析为 u64 的键
let id64 = match k.parse::<u64>() {
Ok(id) => id,
Err(_) => continue,
};
let user = LoginUser {
steam_id32: steam::id::id64_to_32(id64),
@@ -216,7 +223,11 @@ pub fn parse_local_users(steam_dir: &str) -> Result<Vec<LocalUser>> {
// 只处理目录
if entry.file_type().is_dir() {
let id = path.file_name().unwrap().to_str().unwrap();
// 安全获取文件名
let id = match path.file_name().and_then(|n| n.to_str()) {
Some(id_str) => id_str,
None => continue, // 跳过无法获取文件名的路径
};
// 检查 localconfig.vdf 文件是否存在
let local_config_path = path.join("config/localconfig.vdf");
@@ -224,21 +235,26 @@ pub fn parse_local_users(steam_dir: &str) -> Result<Vec<LocalUser>> {
continue;
}
// 读取并解析 localconfig.vdf 文件
let data = fs::read_to_string(local_config_path)?;
// 读取并解析 localconfig.vdf 文件,如果失败则跳过
let data = match fs::read_to_string(&local_config_path) {
Ok(d) => d,
Err(_) => continue, // 跳过无法读取的文件
};
let json_data = super::parse::to_json(&data);
let kv: HashMap<String, Value> = serde_json::from_str(&json_data)?;
let kv = match serde_json::from_str::<HashMap<String, Value>>(&json_data) {
Ok(kv) => kv,
Err(_) => continue, // 跳过无法解析的 JSON
};
// 剥离顶层 UserLocalConfigStore
// let kv = kv.get("UserLocalConfigStore").and_then(|v| v.as_object()).unwrap();
// 获取 friends 节点
let friends = kv.get("friends").and_then(|v| v.as_object());
if friends.is_none() {
continue;
}
let friends = friends.unwrap();
let friends = match kv.get("friends").and_then(|v| v.as_object()) {
Some(f) => f,
None => continue,
};
// 获取 PersonaName
let persona_name = friends
@@ -256,9 +272,15 @@ pub fn parse_local_users(steam_dir: &str) -> Result<Vec<LocalUser>> {
.unwrap_or("")
.to_string();
// 安全解析 ID如果失败则跳过
let steam_id32 = match id.parse::<u32>() {
Ok(id) => id,
Err(_) => continue, // 跳过无法解析为 u32 的 ID
};
// 创建 LocalUser 并加入列表
local_users.push(LocalUser {
steam_id32: id.parse::<u32>().unwrap(),
steam_id32,
persona_name,
avatar_key,
});