diff --git a/res/build.rs b/res/build.rs index 78438a1..8aa9e51 100644 --- a/res/build.rs +++ b/res/build.rs @@ -4,4 +4,4 @@ fn main() { res.set_icon("res/icon.ico").set_language(0x0409); res.compile().unwrap(); } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index ab09564..63e5e96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -467,6 +467,7 @@ async fn update( fs::write(dir.join(".sha-sums"), hash_file_content).unwrap(); } +#[cfg(windows)] fn launch(file_path: &PathBuf, args: &str) { println!("\n\nJoin the AlterWare Discord server:\nhttps://discord.gg/2ETE8engZM\n\n"); crate::println_info!("Launching {} {}", file_path.display(), args); @@ -484,6 +485,35 @@ fn launch(file_path: &PathBuf, args: &str) { } } +#[cfg(unix)] +fn launch(file_path: &PathBuf, args: &str) { + println!("\n\nJoin the AlterWare Discord server:\nhttps://discord.gg/2ETE8engZM\n\n"); + crate::println_info!("Launching {} {}", file_path.display(), args); + let exit_status = if misc::is_program_in_path("wine") { + println!("Found wine, launching game using wine.\nIf you run into issues or want to launch a different way, run {} manually.", file_path.display()); + std::process::Command::new("wine") + .args([file_path.to_str().unwrap(), args.trim()]) + .current_dir(file_path.parent().unwrap()) + .spawn() + .expect("Failed to launch the game") + .wait() + .expect("Failed to wait for the game process to finish") + } else { + std::process::Command::new(file_path) + .args(args.trim().split(' ')) + .current_dir(file_path.parent().unwrap()) + .spawn() + .expect("Failed to launch the game") + .wait() + .expect("Failed to wait for the game process to finish") + }; + + crate::println_error!("Game exited with status: {}", exit_status); + if !exit_status.success() { + misc::stdin(); + } +} + #[cfg(windows)] fn setup_env() { colored::control::set_virtual_terminal(true).unwrap_or_else(|error| { diff --git a/src/misc.rs b/src/misc.rs index 6344906..9c026e7 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -57,6 +57,19 @@ pub fn cute_path(path: &Path) -> String { path.to_str().unwrap().replace('\\', "/") } +#[cfg(unix)] +pub fn is_program_in_path(program: &str) -> bool { + if let Ok(path) = std::env::var("PATH") { + for p in path.split(':') { + let p_str = format!("{}/{}", p, program); + if fs::metadata(p_str).is_ok() { + return true; + } + } + } + false +} + #[macro_export] macro_rules! println_info { ($($arg:tt)*) => {{