Skip to content

Commit

Permalink
specify platform on profile creation
Browse files Browse the repository at this point in the history
  • Loading branch information
altalk23 committed Apr 3, 2024
1 parent 7d114ed commit b15d315
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 2 additions & 7 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 33 additions & 3 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,\
Expand All @@ -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"
{
Expand All @@ -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;
Expand All @@ -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");
}
Expand Down
34 changes: 28 additions & 6 deletions src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ pub enum Profile {
/// New profile name
#[clap(short, long)]
name: String,

/// Platform of the target
platform: Option<String>,
},

/// Remove profile
Expand Down Expand Up @@ -99,17 +102,17 @@ pub fn run_profile(
background: RunBackground,
launch_args: Vec<String>,
) {
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());
Expand Down Expand Up @@ -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())));
}
}

Expand Down
25 changes: 22 additions & 3 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Value>,
}
Expand Down Expand Up @@ -48,6 +51,16 @@ pub struct OldConfig {
pub default_developer: Option<String>,
}

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 {
Expand All @@ -65,6 +78,7 @@ impl OldConfig {
.unwrap_or(&inst.executable)
.into(),
gd_path: inst.path.clone(),
platform: String::from("win"),
other: HashMap::new(),
})
})
Expand Down Expand Up @@ -131,24 +145,25 @@ 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::<String, Value>::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()
}
}

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")
Expand All @@ -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 {
Expand Down

0 comments on commit b15d315

Please sign in to comment.