diff options
author | RaindropsSys <raindrops@equestria.dev> | 2024-05-10 21:51:39 +0200 |
---|---|---|
committer | RaindropsSys <raindrops@equestria.dev> | 2024-05-10 21:51:39 +0200 |
commit | 24781e5ffff7641437dde6cecb33a292e43554f8 (patch) | |
tree | 155e717f97135a23ba7940b7c198ef964401646e /launcher/src/main.rs | |
parent | b0d44bdc9321306a7b473e3d2a60428966f106b1 (diff) | |
download | atomic-24781e5ffff7641437dde6cecb33a292e43554f8.tar.gz atomic-24781e5ffff7641437dde6cecb33a292e43554f8.tar.bz2 atomic-24781e5ffff7641437dde6cecb33a292e43554f8.zip |
Crappy code fix 9/?
Diffstat (limited to 'launcher/src/main.rs')
-rw-r--r-- | launcher/src/main.rs | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/launcher/src/main.rs b/launcher/src/main.rs index 8d1d6c5..22617af 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::process; fn get_home() -> PathBuf { @@ -88,7 +88,8 @@ fn get_search_paths() -> [PathBuf; 29] { fn show_system_info() { println!( - "atomic-launcher: Starting atomic-launcher on {} ({})", + "atomic-launcher: Starting atomic-launcher {} on {} ({})", + VERSION, std::env::consts::OS, std::env::consts::ARCH ); @@ -111,6 +112,19 @@ const APP_DATA_PATH: &str = "../Resources/app"; #[cfg(any(target_os = "linux", target_os = "windows"))] const APP_DATA_PATH: &str = "./resources/app"; +const VERSION: &str = env!("CARGO_PKG_VERSION"); + +fn is_valid_path(mut path: PathBuf) -> Option<PathBuf> { + path.push(BINARY_PATH); + let as_path = path.as_path(); + + if as_path.is_file() { + Some(path) + } else { + None + } +} + fn main() { show_system_info(); println!( @@ -141,38 +155,36 @@ fn main() { } let runtime_search_paths = get_search_paths(); + let runtime_search_paths_string = runtime_search_paths + .iter() + .map(|i| i.to_str().unwrap()) + .collect::<Vec<&str>>() + .join(", "); println!( "atomic-launcher: Looking for atomic-runtime in: {}", - runtime_search_paths - .iter() - .map(|i| i.to_str().unwrap()) - .collect::<Vec<&str>>() - .join(", ") - .as_str() + runtime_search_paths_string ); - let mut valid_path: Option<PathBuf> = None; - for path in runtime_search_paths { + /*for path in runtime_search_paths { let path_str = path.to_str().unwrap(); if path.as_path().exists() && Path::new(&format!("{}/{}", path_str, BINARY_PATH)).exists() { valid_path = Some(path); break; } - } + }*/ + + let runtime_path = runtime_search_paths.into_iter() + .filter_map(is_valid_path) + .next(); - if let Some(path) = valid_path { + if let Some(path) = runtime_path { println!( "atomic-launcher: Found atomic-runtime at {}", - Path::new(&format!("{}/{}", path.to_str().unwrap(), BINARY_PATH)) - .to_str() - .unwrap() + path.to_str().unwrap() ); - let mut cmd = process::Command::new(Path::new(&format!( - "{}/{}", - path.to_str().unwrap(), - BINARY_PATH - ))); + let mut cmd = process::Command::new(path) + .env("ATOMIC_LAUNCHER_VERSION", VERSION); println!("atomic-launcher: Executing: {:?}", cmd); if found_app { |