From 015cbf51de2cb111037bb33c639d282a097b629b Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Thu, 17 Oct 2024 17:48:28 -0600 Subject: [PATCH] fix launch with Linux when using native steam (#799) --- bin/src/commands/launch/mod.rs | 23 +++++++++----- .../common/src/config/project/hemtt/launch.rs | 31 ++++++------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/bin/src/commands/launch/mod.rs b/bin/src/commands/launch/mod.rs index 4e700660..8a9e5a6c 100644 --- a/bin/src/commands/launch/mod.rs +++ b/bin/src/commands/launch/mod.rs @@ -353,9 +353,7 @@ pub fn execute(matches: &ArgMatches) -> Result { } else { path.push(exe); } - if cfg!(windows) { - path.set_extension("exe"); - } + path.set_extension("exe"); } else { path.push(launch.executable()); } @@ -363,8 +361,11 @@ pub fn execute(matches: &ArgMatches) -> Result { windows_launch(&arma3dir, &path, &instance)?; } } else { + if launch.executable() != "arma3_x64.exe" { + warn!("Currently, only Windows supports specifying the executable"); + } for instance in instances { - linux_launch(&arma3dir, &launch.executable(), &instance)?; + linux_launch(&instance)?; } } @@ -420,7 +421,7 @@ fn windows_launch(arma3dir: &Path, executable: &PathBuf, args: &[String]) -> Res Ok(()) } -fn linux_launch(arma3dir: &Path, executable: &str, args: &[String]) -> Result<(), Error> { +fn linux_launch(args: &[String]) -> Result<(), Error> { // check if flatpak steam is installed let flatpak = std::process::Command::new("flatpak") .arg("list") @@ -428,9 +429,10 @@ fn linux_launch(arma3dir: &Path, executable: &str, args: &[String]) -> Result<() .output() .map(|o| String::from_utf8_lossy(&o.stdout).contains("com.valvesoftware.Steam"))?; if flatpak { - warn!("A flatpak override will be created to grant access to the .hemttout directory"); + warn!( + "A flatpak override will be created to grant Steam access to the .hemttout directory" + ); info!("Using flatpak steam with:\n {}", args.join("\n ")); - trace!("using flatpak override to grant access to the mod"); std::process::Command::new("flatpak") .arg("override") .arg("--user") @@ -454,8 +456,13 @@ fn linux_launch(arma3dir: &Path, executable: &str, args: &[String]) -> Result<() .spawn()?; } else { info!("Using native steam with:\n {}", args.join("\n ")); - std::process::Command::new(arma3dir.join(executable)) + std::process::Command::new("steam") + .arg("-applaunch") + .arg("107410") + .arg("-nolauncher") .args(args) + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) .spawn()?; } Ok(()) diff --git a/libs/common/src/config/project/hemtt/launch.rs b/libs/common/src/config/project/hemtt/launch.rs index c00fd82d..88a95072 100644 --- a/libs/common/src/config/project/hemtt/launch.rs +++ b/libs/common/src/config/project/hemtt/launch.rs @@ -78,17 +78,20 @@ impl LaunchOptions { } #[must_use] - /// Binary to launch, `.exe` is appended on Windows - /// Defaults to `arma3_x64` + /// Binary to launch, with `.exe` + /// Defaults to `arma3_x64.exe` pub fn executable(&self) -> String { let executable = &self .executable .as_ref() .map_or_else(|| "arma3_x64", |e| e.as_str()); - if cfg!(target_os = "windows") { - format!("{executable}.exe") - } else { + if std::path::Path::new(executable) + .extension() + .map_or(false, |ext| ext.eq_ignore_ascii_case("exe")) + { (*executable).to_string() + } else { + format!("{executable}.exe") } } @@ -281,14 +284,7 @@ rapify = false assert_eq!(config.optionals(), &["test"]); assert_eq!(config.mission(), Some(&"test".to_string())); assert_eq!(config.parameters(), &["test"]); - assert_eq!( - config.executable(), - if cfg!(target_os = "windows") { - "test.exe" - } else { - "test" - } - ); + assert_eq!(config.executable(), "test.exe"); assert!(config.binarize()); assert!(!config.file_patching()); assert_eq!(config.instances(), 2); @@ -306,14 +302,7 @@ rapify = false assert!(config.optionals().is_empty()); assert!(config.mission().is_none()); assert!(config.parameters().is_empty()); - assert_eq!( - config.executable(), - if cfg!(target_os = "windows") { - "arma3_x64.exe" - } else { - "arma3_x64" - } - ); + assert_eq!(config.executable(), "arma3_x64.exe"); assert!(!config.binarize()); assert!(config.file_patching()); assert_eq!(config.instances(), 1);