mirror of
https://github.com/alterware/alterware-launcher.git
synced 2025-12-04 07:17:50 +00:00
(unix) launch using wine if found
This commit is contained in:
@@ -4,4 +4,4 @@ fn main() {
|
||||
res.set_icon("res/icon.ico").set_language(0x0409);
|
||||
res.compile().unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
30
src/main.rs
30
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| {
|
||||
|
||||
13
src/misc.rs
13
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)*) => {{
|
||||
|
||||
Reference in New Issue
Block a user