refactor game_manager::run() to accept Option<launch_option> and use it instead of Proton::run()

This commit is contained in:
ALEZ-DEV 2024-08-25 17:24:13 +02:00
parent 175d6c6a9b
commit b0b76354fa

View File

@ -186,17 +186,16 @@ impl GameManager {
debug!("Wine version : {:?}", proton_version); debug!("Wine version : {:?}", proton_version);
let mut child = if let Some(custom_command) = options { let mut child = if let Some(custom_command) = options {
Self::run(proton, binary_path, custom_command) Self::run(proton, binary_path, Some(custom_command))
.await .await
.unwrap() .unwrap()
} else { } else {
if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() { if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() {
Self::run(proton, binary_path, custom_command) Self::run(proton, binary_path, Some(custom_command))
.await .await
.unwrap() .unwrap()
} else { } else {
debug!("Starting game without --options"); Self::run(proton, binary_path, None).await.unwrap()
proton.run(binary_path).unwrap()
} }
}; };
@ -304,10 +303,25 @@ impl GameManager {
async fn run( async fn run(
proton: &Proton, proton: &Proton,
binary_path: PathBuf, binary_path: PathBuf,
custom_command: String, custom_command: Option<String>,
) -> Result<Child, std::io::Error> { ) -> Result<Child, std::io::Error> {
debug!("Starting game with --options -> {}", custom_command); let mut command: Vec<&str> = vec![];
let tokens: Vec<&str> = custom_command.split_whitespace().collect();
let proton_path = GameConfig::get_config_directory()
.await
.join("proton")
.join("proton");
command.push(proton.python.to_str().unwrap());
command.push(proton_path.to_str().unwrap());
command.push("run");
command.push(binary_path.to_str().unwrap());
let launch_option;
if custom_command.is_some() {
launch_option = custom_command.unwrap();
debug!("Starting game with --options -> {}", launch_option.clone());
let tokens: Vec<&str> = launch_option.split_whitespace().collect();
// position of the %command% // position of the %command%
let index = tokens let index = tokens
@ -315,18 +329,21 @@ impl GameManager {
.position(|&s| s == "%command%") .position(|&s| s == "%command%")
.expect("You forget to put %command% in your custom launch command"); .expect("You forget to put %command% in your custom launch command");
Command::new(tokens.get(0).unwrap()) let start_command = tokens[0..index].to_vec();
.args(&tokens[0..(index - 1)]) let mut end_command = tokens[(index + 1)..tokens.len()].to_vec();
.arg(proton.python.as_os_str())
.arg( start_command.iter().rev().for_each(|str| {
GameConfig::get_config_directory() command.insert(0, str);
.await });
.join("proton") command.append(&mut end_command);
.join("proton"), } else {
) debug!("Starting game without --options");
.arg("run") }
.arg(binary_path)
.args(&tokens[(index + 1)..tokens.len()]) debug!("Command preview -> {}", command.join(" "));
Command::new(command[0])
.args(&command[1..command.len()])
.envs(proton.get_envs()) .envs(proton.get_envs())
.env("PROTON_LOG", "1") .env("PROTON_LOG", "1")
.stdin(Stdio::piped()) .stdin(Stdio::piped())