From b15d3157a50768e9d36c4d2d09f55901959fb448 Mon Sep 17 00:00:00 2001 From: altalk23 <45172705+altalk23@users.noreply.github.com> Date: Wed, 3 Apr 2024 21:53:41 +0300 Subject: [PATCH] specify platform on profile creation --- Cargo.toml | 10 +++++----- src/index.rs | 9 ++------- src/info.rs | 36 +++++++++++++++++++++++++++++++++--- src/profile.rs | 34 ++++++++++++++++++++++++++++------ src/util/config.rs | 25 ++++++++++++++++++++++--- 5 files changed, 90 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 00c8637..7066fb8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,23 +16,23 @@ build = "build.rs" clap = { version = "4.1.4", features = ["derive"] } colored = "2" dirs = "5.0.1" -fontdue = "0.7.2" +fontdue = "0.8.0" git2 = "0.18.0" glob = "0.3.0" image = "0.24.3" imageproc = "0.23.0" signed-distance-field = "0.6.3" path-absolutize = "3.0.11" -plist = "1.3.1" +plist = "1.6.1" rustyline = "12.0.0" -serde = { version = "1.0.136", features = ["derive"] } -serde_json = { version = "1.0", features = ["preserve_order"] } +serde = { version = "1.0.197", features = ["derive"] } +serde_json = { version = "1.0.115", features = ["preserve_order"] } sha256 = "1.0.3" texture_packer = "0.25.0" walkdir = "2" zip = "0.6.6" semver = "1.0.14" -reqwest = { version = "0.11.12", features = ["json", "blocking"] } +reqwest = { version = "0.12.2", features = ["json", "blocking"] } cfg-if = "1.0.0" regex = "1.6.0" sha3 = "0.10.6" diff --git a/src/index.rs b/src/index.rs index cb64ef5..4f46c99 100644 --- a/src/index.rs +++ b/src/index.rs @@ -209,13 +209,8 @@ pub fn install_mod( let entry = get_entry(config, id, version) .nice_unwrap(format!("Unable to find '{id}' version '{version}'")); - let plat = if cfg!(windows) || cfg!(target_os = "linux") { - "windows" - } else if cfg!(target_os = "macos") { - "macos" - } else { - fatal!("This platform doesn't support installing mods"); - }; + let curr_profile = config.get_current_profile(); + let plat = curr_profile.platform_str(); if !entry.platforms.contains(plat) { if ignore_platform { diff --git a/src/info.rs b/src/info.rs index 4d52eb1..d6d899e 100644 --- a/src/info.rs +++ b/src/info.rs @@ -110,6 +110,34 @@ pub fn subcommand(config: &mut Config, cmd: Info) { Info::Setup {} => { if config.profiles.is_empty() { + info!("Please enter the platform you are using (win, mac, android32, android64), empty for host platform:"); + + let platform = loop { + let mut buf = String::new(); + match std::io::stdin().lock().read_line(&mut buf) { + Ok(_) => {} + Err(e) => { + fail!("Unable to read input: {}", e); + continue; + } + }; + + let platform = buf.trim().to_lowercase(); + if platform.is_empty() { + break std::env::consts::OS; + } else if platform == "win" { + break "win"; + } else if platform == "mac" { + break "mac"; + } else if platform == "android32" { + break "android32"; + } else if platform == "android64" { + break "android64"; + } else { + fail!("Invalid platform"); + } + }; + info!("Please enter the path to the Geometry Dash app:"); let path = loop { @@ -126,7 +154,7 @@ pub fn subcommand(config: &mut Config, cmd: Info) { let path = PathBuf::from(buf.trim()); #[allow(clippy::collapsible_else_if)] - if cfg!(windows) || cfg!(target_os = "linux") { + if platform == "win" { if path.is_dir() { fail!( "The path must point to the Geometry Dash exe,\ @@ -137,7 +165,7 @@ pub fn subcommand(config: &mut Config, cmd: Info) { fail!("The path must point to a .exe file"); continue; } - } else { + } else if platform == "mac" { if !path.is_dir() || path.extension().and_then(|p| p.to_str()).unwrap_or("") != "app" { @@ -147,6 +175,8 @@ pub fn subcommand(config: &mut Config, cmd: Info) { fail!("The path must point to the Geometry Dash app, not a Steam shortcut"); continue; } + } else { + break path; } break path; @@ -165,7 +195,7 @@ pub fn subcommand(config: &mut Config, cmd: Info) { config .profiles - .push(RefCell::new(Profile::new(name.trim().into(), path))); + .push(RefCell::new(Profile::new(name.trim().into(), path, platform.to_string()))); config.current_profile = Some(name.trim().into()); done!("Profile added"); } diff --git a/src/profile.rs b/src/profile.rs index 67f0ffb..968636e 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -45,6 +45,9 @@ pub enum Profile { /// New profile name #[clap(short, long)] name: String, + + /// Platform of the target + platform: Option, }, /// Remove profile @@ -99,17 +102,17 @@ pub fn run_profile( background: RunBackground, launch_args: Vec, ) { - let path = &profile + let profile = &profile .clone() .map(|p| config.get_profile(&Some(p)).map(|p| p.borrow())) .unwrap_or(Some(config.get_current_profile())) .nice_unwrap(format!( "Profile '{}' does not exist", profile.unwrap_or_default() - )) - .gd_path; + )); + let path = &profile.gd_path; - let mut cmd = if cfg!(target_os = "windows") || cfg!(target_os = "linux") { + let mut cmd = if profile.platform_str().to_string() == "win".to_string() { let mut out = Command::new(path); out.args(launch_args); out.current_dir(path.parent().unwrap()); @@ -208,16 +211,35 @@ pub fn subcommand(config: &mut Config, cmd: Profile) { } } - Profile::Add { name, location } => { + Profile::Add { name, location, platform } => { if config.get_profile(&Some(name.to_owned())).is_some() { fail!("A profile named '{}' already exists", name); } else if !is_valid_geode_dir(&location) { fail!("The specified path does not point to a valid Geode installation"); } else { done!("A new profile named '{}' has been created", &name); + let profile = match platform { + Some(platform) => match platform.as_str() { + "win" | "windows" => "win", + "mac" | "macos" => "mac", + "android32" => "android32", + "android64" => "android64", + _ => "", + }, + None => if cfg!(target_os = "windows") { + "win" + } else if cfg!(target_os = "macos") { + "mac" + } else { + "" + }, + }; + if profile.is_empty() { + fail!("Platform must be specified for this system"); + } config .profiles - .push(RefCell::new(CfgProfile::new(name, location))); + .push(RefCell::new(CfgProfile::new(name, location, profile.to_string()))); } } diff --git a/src/util/config.rs b/src/util/config.rs index 7f588f0..6035c65 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -13,6 +13,9 @@ pub struct Profile { pub name: String, pub gd_path: PathBuf, + #[serde(default = "profile_platform_default")] + pub platform: String, + #[serde(flatten)] other: HashMap, } @@ -48,6 +51,16 @@ pub struct OldConfig { pub default_developer: Option, } +fn profile_platform_default() -> String { + if cfg!(target_os = "windows") { + "win".to_owned() + } else if cfg!(target_os = "macos") { + "mac".to_owned() + } else { + "win".to_owned() + } +} + // TODO: remove this in 3.0 impl OldConfig { pub fn migrate(&self) -> Config { @@ -65,6 +78,7 @@ impl OldConfig { .unwrap_or(&inst.executable) .into(), gd_path: inst.path.clone(), + platform: String::from("win"), other: HashMap::new(), }) }) @@ -131,16 +145,17 @@ fn migrate_location(name: &str, mut path: PathBuf) -> PathBuf { } impl Profile { - pub fn new(name: String, location: PathBuf) -> Profile { + pub fn new(name: String, location: PathBuf, platform: String) -> Profile { Profile { gd_path: migrate_location(&name, location), name, + platform, other: HashMap::::new(), } } pub fn gd_dir(&self) -> PathBuf { - if cfg!(target_os = "windows") || cfg!(target_os = "linux") { + if self.platform == "win" { self.gd_path.parent().unwrap().to_path_buf() } else { self.gd_path.clone() @@ -148,7 +163,7 @@ impl Profile { } pub fn geode_dir(&self) -> PathBuf { - if cfg!(target_os = "windows") || cfg!(target_os = "linux") { + if self.platform == "win" { self.gd_path.parent().unwrap().join("geode") } else { self.gd_path.join("Contents/geode") @@ -162,6 +177,10 @@ impl Profile { pub fn mods_dir(&self) -> PathBuf { self.geode_dir().join("mods") } + + pub fn platform_str(&self) -> &str { + self.platform.as_str() + } } impl Config {