Skip to content

Commit

Permalink
change the way paths are stored, added smooth migration
Browse files Browse the repository at this point in the history
  • Loading branch information
c314m committed Aug 16, 2023
1 parent 6423806 commit d3101f9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 24 deletions.
43 changes: 27 additions & 16 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use clap::Subcommand;
use colored::Colorize;
use std::cell::RefCell;
use std::io::BufRead;

/**
* geode info
*/
Expand Down Expand Up @@ -109,7 +110,7 @@ pub fn subcommand(config: &mut Config, cmd: Info) {

Info::Setup {} => {
if config.profiles.is_empty() {
info!("Please enter the path to the Geometry Dash folder:");
info!("Please enter the path to the Geometry Dash app:");

let path = loop {
let mut buf = String::new();
Expand All @@ -123,24 +124,34 @@ pub fn subcommand(config: &mut Config, cmd: Info) {

// Verify path is valid
let path = PathBuf::from(buf.trim());
if !path.is_dir() {
fail!(
"The path must point to the Geometry Dash \
folder, not the executable"
);
continue;
}
if path
.read_dir()
.map(|mut files| files.next().is_none())
.unwrap_or(false)
{
fail!("Given path appears to be empty");
continue;

if cfg!(windows) {
if path.is_dir() {
fail!(
"The path must point to the Geometry Dash exe,\
not the folder it's in"
);
continue;
} else if path.extension().and_then(|p| p.to_str()).unwrap_or("") != "exe" {
fail!("The path must point to a .exe file");
continue;
}
} else {
if !path.is_dir() ||
path.extension().and_then(|p| p.to_str()).unwrap_or("") != "app"
{
fail!("The path must point to the Geometry Dash app");
continue;
} else if path.join("Contents/MacOS/Geometry Dash").exists()
{
fail!("The path must point to the Geometry Dash app, not a Steam shortcut");
continue;
}
}

break path;
// todo: maybe do some checksum verification
// to make sure GD 2.113 is in the folder
break path;
};

info!("Please enter a name for the profile:");
Expand Down
9 changes: 4 additions & 5 deletions src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,20 @@ pub fn run_profile(config: &Config, profile: Option<String>, background: bool) {
.gd_path;

let mut cmd = if cfg!(windows) {
let mut out = Command::new(path.join("GeometryDash.exe"));
out.current_dir(path);
let mut out = Command::new(path);
out.current_dir(path.parent().unwrap());
out
} else {
let mut out = Command::new(path.join("MacOS").join("Geometry Dash"));
let mut out = Command::new(path.join("Contents/MacOS/Geometry Dash"));

if path.join("MacOS").join("steam_appid.txt").exists() {
if path.join("Contents/MacOS/steam_appid.txt").exists() {
warn!("Steam version detected. Output may not be available.");

out.env("DYLD_INSERT_LIBRARIES", path
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.parent().unwrap()
.join("Steam.AppBundle")
.join("Steam")
.join("Contents")
Expand Down
29 changes: 26 additions & 3 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ pub struct Config {
}

// old config.json structures for migration

// TODO: remove this in 3.0
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct OldConfigInstallation {
pub path: PathBuf,
pub executable: String,
}

// TODO: remove this in 3.0
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "kebab-case")]
pub struct OldConfig {
Expand All @@ -46,6 +47,7 @@ pub struct OldConfig {
pub default_developer: Option<String>,
}

// TODO: remove this in 3.0
impl OldConfig {
pub fn migrate(&self) -> Config {
let profiles = self
Expand Down Expand Up @@ -102,17 +104,37 @@ pub fn geode_root() -> PathBuf {
data_dir
}

fn migrate_location(name: &str, mut path: PathBuf) -> PathBuf {
// Migrate folder to executable
if cfg!(windows) && path.is_dir() {
path.push("GeometryDash.exe");

if !path.exists() {
warn!("Unable to find GeometryDash.exe in profile \
'{}', please update the GD path for it", name);
}
} else if path.file_name().unwrap() == "Contents" {
path = path.parent().unwrap().to_path_buf();
}

path
}

impl Profile {
pub fn new(name: String, location: PathBuf) -> Profile {
Profile {
gd_path: migrate_location(&name, location),
name,
gd_path: location,
other: HashMap::<String, Value>::new(),
}
}

pub fn geode_dir(&self) -> PathBuf {
self.gd_path.join("geode")
if cfg!(windows) {
self.gd_path.parent().unwrap().join("geode")
} else {
self.gd_path.join("Contents/geode")
}
}

pub fn index_dir(&self) -> PathBuf {
Expand Down Expand Up @@ -207,6 +229,7 @@ impl Config {
Ok(json) => json,
Err(e) => {
// Try migrating old config
// TODO: remove this in 3.0
let json = serde_json::from_str::<OldConfig>(config_json_str)
.ok()
.nice_unwrap(format!("Unable to parse config.json: {}", e));
Expand Down

0 comments on commit d3101f9

Please sign in to comment.