49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
// Manage sub modules
|
|
pub mod id;
|
|
pub mod path;
|
|
pub mod reg;
|
|
pub mod user;
|
|
|
|
// common steam utils
|
|
use anyhow::Result;
|
|
use std::error::Error;
|
|
use std::process::{Command, Output};
|
|
|
|
pub fn launch_game(
|
|
steam_path: &str,
|
|
launch_option: &str,
|
|
server: &str,
|
|
) -> Result<(), Box<dyn Error>> {
|
|
// 判断路径是否存在
|
|
if !std::path::Path::new(steam_path).exists() {
|
|
return Err(Box::new(std::io::Error::new(
|
|
std::io::ErrorKind::NotFound,
|
|
"Steam path not found",
|
|
)));
|
|
}
|
|
|
|
let mut opt = launch_option.replace("\n", " ");
|
|
|
|
if server == "perfectworld" {
|
|
opt = opt.replace("-worldwide", "") + " -perfectworld";
|
|
} else if server == "worldwide" {
|
|
opt = opt.replace("-perfectworld", "") + " -worldwide";
|
|
}
|
|
|
|
let opts = format!("-applaunch 730 {}", opt);
|
|
let opts_split = opts.split_whitespace().collect::<Vec<&str>>();
|
|
|
|
let output: Output = Command::new(steam_path).args(opts_split).output()?;
|
|
|
|
if !output.status.success() {
|
|
let error_message = String::from_utf8_lossy(&output.stderr);
|
|
println!("Error: {}", error_message);
|
|
return Err(Box::new(std::io::Error::new(
|
|
std::io::ErrorKind::Other,
|
|
"Failed to launch game",
|
|
)));
|
|
}
|
|
|
|
Ok(())
|
|
}
|