disable all dev logs
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
use crate::steam;
|
||||
use crate::tool::*;
|
||||
use crate::tool::updater::{check_update, download_update, install_update, UpdateInfo};
|
||||
use crate::tool::*;
|
||||
use crate::vdf::preset;
|
||||
use crate::vdf::preset::VideoConfig;
|
||||
use crate::wrap_err;
|
||||
use anyhow::Result;
|
||||
use std::fs::File;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::Path;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Arc, OnceLock};
|
||||
use tauri::path::BaseDirectory;
|
||||
use tauri::Manager;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// use tauri_plugin_shell::ShellExt;
|
||||
|
||||
@@ -23,7 +23,9 @@ use serde::{Deserialize, Serialize};
|
||||
static DOWNLOAD_CANCELLED: OnceLock<Arc<AtomicBool>> = OnceLock::new();
|
||||
|
||||
fn get_download_cancelled() -> Arc<AtomicBool> {
|
||||
DOWNLOAD_CANCELLED.get_or_init(|| Arc::new(AtomicBool::new(false))).clone()
|
||||
DOWNLOAD_CANCELLED
|
||||
.get_or_init(|| Arc::new(AtomicBool::new(false)))
|
||||
.clone()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -127,7 +129,9 @@ pub fn start_watch_cs2_video(
|
||||
steam_dir: String,
|
||||
steam_id32: u32,
|
||||
) -> Result<(), String> {
|
||||
wrap_err!(steam::watch::start_watch_cs2_video(app, steam_dir, steam_id32))
|
||||
wrap_err!(steam::watch::start_watch_cs2_video(
|
||||
app, steam_dir, steam_id32
|
||||
))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -169,16 +173,16 @@ pub fn check_path(path: &str) -> Result<bool, String> {
|
||||
#[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())
|
||||
}
|
||||
|
||||
@@ -201,14 +205,14 @@ pub async fn analyze_replay(app: tauri::AppHandle, path: &str) -> Result<String,
|
||||
fs::create_dir_all(&config_dir).expect("无法创建 metadata 文件夹");
|
||||
}
|
||||
|
||||
// 提取文件名部分
|
||||
let file_name = std::path::Path::new(path)
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.unwrap_or("default_filename");
|
||||
// 提取文件名部分
|
||||
let file_name = std::path::Path::new(path)
|
||||
.file_name()
|
||||
.and_then(|name| name.to_str())
|
||||
.unwrap_or("default_filename");
|
||||
|
||||
// 拼接输出文件路径
|
||||
let output_path = config_dir.join(format!("{}.json", file_name));
|
||||
// 拼接输出文件路径
|
||||
let output_path = config_dir.join(format!("{}.json", file_name));
|
||||
|
||||
// 确保输出文件存在,如果不存在则创建空文件
|
||||
if !output_path.exists() {
|
||||
@@ -265,21 +269,21 @@ pub fn get_console_log_path(cs_path: &str) -> Result<String, String> {
|
||||
#[tauri::command]
|
||||
pub fn read_vprof_report(console_log_path: &str) -> Result<String, String> {
|
||||
let path = Path::new(console_log_path);
|
||||
|
||||
|
||||
if !path.exists() {
|
||||
return Err("console.log 文件不存在".to_string());
|
||||
}
|
||||
|
||||
let file = File::open(path).map_err(|e| format!("无法打开文件: {}", e))?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
|
||||
let mut vprof_lines = Vec::new();
|
||||
let mut in_vprof_section = false;
|
||||
let mut empty_line_count = 0;
|
||||
|
||||
|
||||
for line_result in reader.lines() {
|
||||
let line = line_result.map_err(|e| format!("读取行错误: {}", e))?;
|
||||
|
||||
|
||||
// 检测 [VProf] 标记
|
||||
if line.contains("[VProf]") {
|
||||
in_vprof_section = true;
|
||||
@@ -300,11 +304,11 @@ pub fn read_vprof_report(console_log_path: &str) -> Result<String, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if vprof_lines.is_empty() {
|
||||
return Err("未找到 [VProf] 报告".to_string());
|
||||
}
|
||||
|
||||
|
||||
Ok(vprof_lines.join("\n"))
|
||||
}
|
||||
|
||||
@@ -321,34 +325,22 @@ pub async fn check_app_update(
|
||||
let current_version = app.package_info().version.to_string();
|
||||
let use_mirror = use_mirror.unwrap_or(false);
|
||||
let include_prerelease = include_prerelease.unwrap_or(false);
|
||||
|
||||
// println!("[检查更新命令] 当前应用版本: {}", current_version);
|
||||
// println!("[检查更新命令] 使用镜像: {}", use_mirror);
|
||||
// println!("[检查更新命令] 包含预发布版本: {}", include_prerelease);
|
||||
// if let Some(ref ep) = endpoint {
|
||||
// println!("[检查更新命令] 自定义端点: {}", ep);
|
||||
// }
|
||||
|
||||
|
||||
// 从环境变量获取 GitHub 仓库信息,如果没有则使用默认值
|
||||
const DEFAULT_GITHUB_REPO: &str = "plsgo/cstb";
|
||||
let github_repo_str = std::env::var("GITHUB_REPO").ok();
|
||||
let github_repo = github_repo_str.as_deref().unwrap_or(DEFAULT_GITHUB_REPO);
|
||||
// println!("[检查更新命令] GitHub 仓库: {}", github_repo);
|
||||
|
||||
let result = wrap_err!(check_update(
|
||||
endpoint.as_deref(),
|
||||
¤t_version,
|
||||
use_mirror,
|
||||
Some(github_repo),
|
||||
include_prerelease
|
||||
).await)?;
|
||||
|
||||
// if result.is_some() {
|
||||
// println!("[检查更新命令] ✓ 返回更新信息");
|
||||
// } else {
|
||||
// println!("[检查更新命令] ✗ 无更新可用");
|
||||
// }
|
||||
|
||||
let result = wrap_err!(
|
||||
check_update(
|
||||
endpoint.as_deref(),
|
||||
¤t_version,
|
||||
use_mirror,
|
||||
Some(github_repo),
|
||||
include_prerelease
|
||||
)
|
||||
.await
|
||||
)?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
@@ -361,7 +353,7 @@ pub async fn download_app_update(
|
||||
// 重置取消标志
|
||||
let cancelled = get_download_cancelled();
|
||||
cancelled.store(false, Ordering::Relaxed);
|
||||
|
||||
|
||||
let path = wrap_err!(download_update(&app, &download_url, cancelled).await)?;
|
||||
Ok(path.to_string_lossy().to_string())
|
||||
}
|
||||
@@ -385,7 +377,7 @@ pub fn install_app_update(installer_path: String) -> Result<(), String> {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn get_computer_info() -> Result<serde_json::Value, String> {
|
||||
use tokio::process::Command;
|
||||
|
||||
|
||||
// 异步执行 PowerShell 命令获取计算机信息并转换为 JSON
|
||||
let output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -396,24 +388,24 @@ pub async fn get_computer_info() -> Result<serde_json::Value, String> {
|
||||
.output()
|
||||
.await
|
||||
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(format!("PowerShell 命令执行失败: {}", stderr));
|
||||
}
|
||||
|
||||
|
||||
// 处理 PowerShell 输出,移除 BOM 和空白字符
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let cleaned = stdout.trim().trim_start_matches('\u{feff}'); // 移除 BOM
|
||||
|
||||
|
||||
// 如果输出为空,返回空对象
|
||||
if cleaned.is_empty() {
|
||||
return Ok(serde_json::json!({}));
|
||||
}
|
||||
|
||||
|
||||
let mut json: serde_json::Value = serde_json::from_str(cleaned)
|
||||
.map_err(|e| format!("解析 JSON 失败: {},原始输出: {}", e, cleaned))?;
|
||||
|
||||
|
||||
// 对于 Windows 11,优先使用 OSDisplayVersion 获取版本代码(如 25H2)
|
||||
// 如果 OSDisplayVersion 存在且包含版本代码,提取它
|
||||
if let Some(os_display_version) = json.get("OSDisplayVersion").and_then(|v| v.as_str()) {
|
||||
@@ -428,7 +420,7 @@ pub async fn get_computer_info() -> Result<serde_json::Value, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 如果没有从 OSDisplayVersion 获取到版本代码,尝试从注册表获取 ReleaseId
|
||||
if !json.get("ReleaseId").and_then(|v| v.as_str()).is_some() {
|
||||
let release_id_output = Command::new("powershell")
|
||||
@@ -439,17 +431,19 @@ pub async fn get_computer_info() -> Result<serde_json::Value, String> {
|
||||
])
|
||||
.output()
|
||||
.await;
|
||||
|
||||
|
||||
if let Ok(release_output) = release_id_output {
|
||||
if release_output.status.success() {
|
||||
let release_str = String::from_utf8_lossy(&release_output.stdout).trim().to_string();
|
||||
let release_str = String::from_utf8_lossy(&release_output.stdout)
|
||||
.trim()
|
||||
.to_string();
|
||||
if !release_str.is_empty() {
|
||||
json["ReleaseId"] = serde_json::Value::String(release_str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(json)
|
||||
}
|
||||
|
||||
@@ -488,12 +482,12 @@ fn format_bytes(bytes: u64) -> String {
|
||||
#[tauri::command]
|
||||
pub fn get_gpu_info() -> Result<Option<GpuInfo>, String> {
|
||||
use gfxinfo::active_gpu;
|
||||
|
||||
|
||||
match active_gpu() {
|
||||
Ok(gpu) => {
|
||||
let info = gpu.info();
|
||||
let temp = info.temperature() as f64 / 1000.0;
|
||||
|
||||
|
||||
Ok(Some(GpuInfo {
|
||||
vendor: gpu.vendor().to_string(),
|
||||
model: gpu.model().to_string(),
|
||||
@@ -558,7 +552,7 @@ pub struct MotherboardInfo {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn get_memory_info() -> Result<Vec<MemoryInfo>, String> {
|
||||
use tokio::process::Command;
|
||||
|
||||
|
||||
// 执行 PowerShell 命令获取内存信息
|
||||
let output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -569,25 +563,25 @@ pub async fn get_memory_info() -> Result<Vec<MemoryInfo>, String> {
|
||||
.output()
|
||||
.await
|
||||
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(format!("PowerShell 命令执行失败: {}", stderr));
|
||||
}
|
||||
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let cleaned = stdout.trim().trim_start_matches('\u{feff}');
|
||||
|
||||
|
||||
if cleaned.is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
|
||||
// PowerShell 可能返回数组或单个对象
|
||||
let json: serde_json::Value = serde_json::from_str(cleaned)
|
||||
.map_err(|e| format!("解析 JSON 失败: {},原始输出: {}", e, cleaned))?;
|
||||
|
||||
|
||||
let mut memory_list = Vec::new();
|
||||
|
||||
|
||||
if let Some(array) = json.as_array() {
|
||||
// 如果是数组
|
||||
for item in array {
|
||||
@@ -597,31 +591,30 @@ pub async fn get_memory_info() -> Result<Vec<MemoryInfo>, String> {
|
||||
// 如果是单个对象
|
||||
memory_list.push(parse_memory_info(&json));
|
||||
}
|
||||
|
||||
|
||||
Ok(memory_list)
|
||||
}
|
||||
|
||||
/// 解析内存信息
|
||||
fn parse_memory_info(json: &serde_json::Value) -> MemoryInfo {
|
||||
// 容量(字节)
|
||||
let capacity = json.get("Capacity")
|
||||
.and_then(|v| v.as_u64());
|
||||
|
||||
let manufacturer = json.get("Manufacturer")
|
||||
let capacity = json.get("Capacity").and_then(|v| v.as_u64());
|
||||
|
||||
let manufacturer = json
|
||||
.get("Manufacturer")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
|
||||
// 实际频率:优先使用 ConfiguredClockSpeed
|
||||
let speed = json.get("ConfiguredClockSpeed")
|
||||
let speed = json
|
||||
.get("ConfiguredClockSpeed")
|
||||
.and_then(|v| v.as_u64())
|
||||
.map(|v| v as u32);
|
||||
|
||||
|
||||
// 默认频率:Speed(如果存在)
|
||||
let default_speed = json.get("Speed")
|
||||
.and_then(|v| v.as_u64())
|
||||
.map(|v| v as u32);
|
||||
|
||||
let default_speed = json.get("Speed").and_then(|v| v.as_u64()).map(|v| v as u32);
|
||||
|
||||
MemoryInfo {
|
||||
capacity,
|
||||
manufacturer,
|
||||
@@ -642,7 +635,7 @@ pub async fn get_memory_info() -> Result<Vec<MemoryInfo>, String> {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
use tokio::process::Command;
|
||||
|
||||
|
||||
// 执行 PowerShell 命令获取显示器信息
|
||||
let output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -653,24 +646,24 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
.output()
|
||||
.await
|
||||
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(format!("PowerShell 命令执行失败: {}", stderr));
|
||||
}
|
||||
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let cleaned = stdout.trim().trim_start_matches('\u{feff}');
|
||||
|
||||
|
||||
if cleaned.is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
|
||||
|
||||
let json: serde_json::Value = serde_json::from_str(cleaned)
|
||||
.map_err(|e| format!("解析 JSON 失败: {},原始输出: {}", e, cleaned))?;
|
||||
|
||||
|
||||
let mut monitor_list = Vec::new();
|
||||
|
||||
|
||||
if let Some(array) = json.as_array() {
|
||||
for item in array {
|
||||
monitor_list.push(parse_monitor_info(item));
|
||||
@@ -678,7 +671,7 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
} else {
|
||||
monitor_list.push(parse_monitor_info(&json));
|
||||
}
|
||||
|
||||
|
||||
// 尝试获取刷新率和分辨率信息
|
||||
let _display_output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -688,7 +681,7 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
])
|
||||
.output()
|
||||
.await;
|
||||
|
||||
|
||||
// 获取刷新率信息
|
||||
let _refresh_output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -698,7 +691,7 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
])
|
||||
.output()
|
||||
.await;
|
||||
|
||||
|
||||
// 获取当前显示器的分辨率和刷新率
|
||||
let current_display_output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -708,12 +701,15 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
])
|
||||
.output()
|
||||
.await;
|
||||
|
||||
|
||||
// 合并显示器信息
|
||||
if let Ok(display_result) = current_display_output {
|
||||
if display_result.status.success() {
|
||||
let display_str = String::from_utf8_lossy(&display_result.stdout).to_string();
|
||||
let display_str = display_str.trim().trim_start_matches('\u{feff}').to_string();
|
||||
let display_str = display_str
|
||||
.trim()
|
||||
.trim_start_matches('\u{feff}')
|
||||
.to_string();
|
||||
if let Ok(display_json) = serde_json::from_str::<serde_json::Value>(&display_str) {
|
||||
if let Some(displays) = display_json.as_array() {
|
||||
for (i, display) in displays.iter().enumerate() {
|
||||
@@ -739,22 +735,24 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ok(monitor_list)
|
||||
}
|
||||
|
||||
/// 解析显示器信息
|
||||
fn parse_monitor_info(json: &serde_json::Value) -> MonitorInfo {
|
||||
let manufacturer = json.get("Manufacturer")
|
||||
let manufacturer = json
|
||||
.get("Manufacturer")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
let model = json.get("Model")
|
||||
|
||||
let model = json
|
||||
.get("Model")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
|
||||
// 组合制造商和型号作为名称
|
||||
let name = match (&manufacturer, &model) {
|
||||
(Some(mfg), Some(model_name)) => Some(format!("{} {}", mfg, model_name)),
|
||||
@@ -762,7 +760,7 @@ fn parse_monitor_info(json: &serde_json::Value) -> MonitorInfo {
|
||||
(None, Some(model_name)) => Some(model_name.clone()),
|
||||
(None, None) => None,
|
||||
};
|
||||
|
||||
|
||||
MonitorInfo {
|
||||
manufacturer,
|
||||
model,
|
||||
@@ -785,7 +783,7 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
|
||||
#[cfg(target_os = "windows")]
|
||||
pub async fn get_motherboard_info() -> Result<MotherboardInfo, String> {
|
||||
use tokio::process::Command;
|
||||
|
||||
|
||||
// 执行 PowerShell 命令获取主板信息
|
||||
let output = Command::new("powershell")
|
||||
.args(&[
|
||||
@@ -796,15 +794,15 @@ pub async fn get_motherboard_info() -> Result<MotherboardInfo, String> {
|
||||
.output()
|
||||
.await
|
||||
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
|
||||
|
||||
|
||||
if !output.status.success() {
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
return Err(format!("PowerShell 命令执行失败: {}", stderr));
|
||||
}
|
||||
|
||||
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let cleaned = stdout.trim().trim_start_matches('\u{feff}');
|
||||
|
||||
|
||||
if cleaned.is_empty() {
|
||||
return Ok(MotherboardInfo {
|
||||
manufacturer: None,
|
||||
@@ -812,25 +810,28 @@ pub async fn get_motherboard_info() -> Result<MotherboardInfo, String> {
|
||||
version: None,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
let json: serde_json::Value = serde_json::from_str(cleaned)
|
||||
.map_err(|e| format!("解析 JSON 失败: {},原始输出: {}", e, cleaned))?;
|
||||
|
||||
|
||||
// 分别获取制造商和型号
|
||||
let manufacturer = json.get("Manufacturer")
|
||||
let manufacturer = json
|
||||
.get("Manufacturer")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
let model = json.get("Product")
|
||||
|
||||
let model = json
|
||||
.get("Product")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty());
|
||||
|
||||
|
||||
Ok(MotherboardInfo {
|
||||
manufacturer,
|
||||
model,
|
||||
version: json.get("Version")
|
||||
version: json
|
||||
.get("Version")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.trim().to_string())
|
||||
.filter(|s| !s.is_empty()),
|
||||
@@ -846,4 +847,4 @@ pub async fn get_motherboard_info() -> Result<MotherboardInfo, String> {
|
||||
model: None,
|
||||
version: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user