[feat] launch game code optim + open path after mkdir

This commit is contained in:
2025-08-06 17:59:57 +08:00
parent 0c306b658e
commit 84d0cd7473
2 changed files with 17 additions and 13 deletions

View File

@@ -24,11 +24,11 @@ pub fn launch_game(
let mut opt = launch_option.replace("\n", " "); let mut opt = launch_option.replace("\n", " ");
if server == "perfectworld" { opt = match server {
opt = opt.replace("-worldwide", "") + " -perfectworld"; "perfectworld" => opt.replace("-worldwide", "") + " -perfectworld",
} else if server == "worldwide" { "worldwide" => opt.replace("-perfectworld", "") + " -worldwide",
opt = opt.replace("-perfectworld", "") + " -worldwide"; _ => opt,
} };
let opts = format!("-applaunch 730 {}", opt); let opts = format!("-applaunch 730 {}", opt);
let opts_split = opts.split_whitespace().collect::<Vec<&str>>(); let opts_split = opts.split_whitespace().collect::<Vec<&str>>();

View File

@@ -1,3 +1,4 @@
use std::fs;
use std::process::Command; use std::process::Command;
#[cfg(windows)] #[cfg(windows)]
@@ -23,10 +24,8 @@ pub fn run_steam() -> std::io::Result<std::process::Output> {
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.output(); .output();
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
Command::new("open") Command::new("open").args(&["-a", "Steam"]).output()
.args(&["-a", "Steam"])
.output()
} }
pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> { pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
@@ -44,10 +43,13 @@ pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
.creation_flags(CREATE_NO_WINDOW) .creation_flags(CREATE_NO_WINDOW)
.output()?; .output()?;
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
let output = Command::new("osascript") let output = Command::new("osascript")
.args(&["-e", &format!("tell application \"{}\" to get path to me", name)]) .args(&[
.output()?; "-e",
&format!("tell application \"{}\" to get path to me", name),
])
.output()?;
let out = String::from_utf8_lossy(&output.stdout).to_string(); let out = String::from_utf8_lossy(&output.stdout).to_string();
@@ -68,6 +70,8 @@ pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
pub fn open_path(path: &str) -> Result<(), std::io::Error> { pub fn open_path(path: &str) -> Result<(), std::io::Error> {
// path中所有/ 转换为 \ // path中所有/ 转换为 \
let path = path.replace("/", "\\"); let path = path.replace("/", "\\");
fs::create_dir_all(path)?;
#[cfg(windows)] #[cfg(windows)]
Command::new("cmd.exe") Command::new("cmd.exe")
.args(["/c", "start", "", &path]) .args(["/c", "start", "", &path])