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,29 +303,47 @@ 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();
// position of the %command% let proton_path = GameConfig::get_config_directory()
let index = tokens .await
.iter() .join("proton")
.position(|&s| s == "%command%") .join("proton");
.expect("You forget to put %command% in your custom launch command");
Command::new(tokens.get(0).unwrap()) command.push(proton.python.to_str().unwrap());
.args(&tokens[0..(index - 1)]) command.push(proton_path.to_str().unwrap());
.arg(proton.python.as_os_str()) command.push("run");
.arg( command.push(binary_path.to_str().unwrap());
GameConfig::get_config_directory()
.await let launch_option;
.join("proton") if custom_command.is_some() {
.join("proton"), launch_option = custom_command.unwrap();
) debug!("Starting game with --options -> {}", launch_option.clone());
.arg("run") let tokens: Vec<&str> = launch_option.split_whitespace().collect();
.arg(binary_path)
.args(&tokens[(index + 1)..tokens.len()]) // position of the %command%
let index = tokens
.iter()
.position(|&s| s == "%command%")
.expect("You forget to put %command% in your custom launch command");
let start_command = tokens[0..index].to_vec();
let mut end_command = tokens[(index + 1)..tokens.len()].to_vec();
start_command.iter().rev().for_each(|str| {
command.insert(0, str);
});
command.append(&mut end_command);
} else {
debug!("Starting game without --options");
}
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())