(unix) launch using wine if found

This commit is contained in:
2024-06-26 15:08:21 +02:00
parent 30c6d568b8
commit 6173fb218e
3 changed files with 44 additions and 1 deletions

View File

@@ -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| {

View File

@@ -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)*) => {{