use crate::steam; use crate::tool::*; use crate::vdf::preset; use crate::vdf::preset::VideoConfig; use crate::wrap_err; use anyhow::Result; // pub type Result = Result; #[tauri::command] pub fn greet(name: &str) -> Result { Ok(format!("Hello, {}! You've been greeted from Rust!", name)) } // 工具 #[tauri::command] pub fn launch_game(steam_path: &str, launch_option: &str, server: &str) -> Result { println!("{}: launching game on server: {}, with launch Option {}", steam_path, server, launch_option); // wrap_err!(steam::launch_game(steam_path, launch_option, server)); // 如果有错误,打印出来 if let Err(e) = steam::launch_game(steam_path, launch_option, server) { println!("Error: {}", e); return Err(e.to_string()); } // steam::launch_game(steam_path, launch_option, server); Ok(format!( "Launching game on server: {}, with launch Option {}", server, launch_option )) } #[tauri::command] pub fn kill_game() -> Result { Ok(common::kill("cs2.exe")) } #[tauri::command] pub fn kill_steam() -> Result { Ok(common::kill("steam.exe")) } // Steam #[tauri::command] pub fn get_steam_path() -> Result { wrap_err!(steam::path::get_steam_path()) } #[tauri::command] pub fn get_cs_path(name: &str, steam_dir: &str) -> Result { wrap_err!(steam::path::get_cs_path(name, steam_dir)) } #[tauri::command] pub fn open_path(path: &str) -> Result<(), String> { wrap_err!(common::open_path(path)) } #[tauri::command] pub fn get_powerplan() -> Result { #[cfg(target_os = "windows")] let powerplan = powerplan::get_powerplan()?; #[cfg(not(target_os = "windows"))] let powerplan = powerplan::PowerPlanMode::Other as i32; Ok(powerplan) } #[tauri::command] pub fn set_powerplan(plan: i32) -> Result<(), String> { #[cfg(target_os = "windows")] powerplan::set_powerplan(plan)?; Ok(()) } #[tauri::command] pub fn get_steam_users(steam_dir: &str) -> Result, String> { wrap_err!(preset::get_users(steam_dir)) } #[tauri::command] pub fn set_auto_login_user(user: &str) -> Result { #[cfg(target_os = "windows")] steam::reg::set_auto_login_user(user)?; Ok(format!("Set auto login user to {}", user)) } #[tauri::command] pub fn get_cs2_video_config(steam_dir: &str, steam_id32: u32) -> Result { let p = format!( "{}/userdata/{}/730/local/cfg/cs2_video.txt", steam_dir, steam_id32 ); let video = preset::get_cs2_video(p.as_str()).map_err(|e| e.to_string())?; Ok(video) } #[tauri::command] pub fn set_cs2_video_config( steam_dir: &str, steam_id32: u32, video_config: VideoConfig, ) -> Result<(), String> { let p = format!( "{}/userdata/{}/730/local/cfg/cs2_video.txt", steam_dir, steam_id32 ); preset::set_cs2_video(p.as_str(), video_config).map_err(|e| e.to_string())?; Ok(()) } #[tauri::command] pub fn check_path(path: &str) -> Result { Ok(std::path::Path::new(&path).exists()) }