Skip to content

Commit

Permalink
fix launch with Linux when using native steam (#799)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettMayson authored Oct 17, 2024
1 parent f533f07 commit 015cbf5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
23 changes: 15 additions & 8 deletions bin/src/commands/launch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,19 @@ pub fn execute(matches: &ArgMatches) -> Result<Report, Error> {
} else {
path.push(exe);
}
if cfg!(windows) {
path.set_extension("exe");
}
path.set_extension("exe");
} else {
path.push(launch.executable());
}
for instance in instances {
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)?;
}
}

Expand Down Expand Up @@ -420,17 +421,18 @@ 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")
.arg("--app")
.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")
Expand All @@ -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(())
Expand Down
31 changes: 10 additions & 21 deletions libs/common/src/config/project/hemtt/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 015cbf5

Please sign in to comment.