diff --git a/Cargo.toml b/Cargo.toml index 0dc07b4..b0a70be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "archive-helper" +name = "cyber-mod-manager" version = "0.1.0" edition = "2021" @@ -8,3 +8,5 @@ edition = "2021" [dependencies] clap = { version = "4.3.11", features = ["derive"] } compress-tools = "0.14.3" +serde = { version = "1.0.170", features = ["derive"] } +serde_json = "1.0.100" diff --git a/README.md b/README.md index 57b7eb9..64c6f7a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ -# archive-helper +# cyberpunk 2077 mod manager -basically does what video game mod managers (vortex, mo2) do but worse \ No newline at end of file +if it works for other games, epic + +if it doesn't, don't yell at me i didn't make it for other games which is why it defaults to cyberpunk diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..4d48166 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,64 @@ +use std::{fs, path::Path}; + +use serde::{Deserialize, Serialize}; + +pub struct ConfigFile { + pub latest_date: String, + pub cache_folder: String, +} + +pub fn get_home() -> String { + let home = match std::env::consts::OS { + "linux" => std::env::var("HOME").expect("how is there not a $HOME"), + "windows" => std::env::var("userprofile") + .expect("yell at me if this doesn't work please i'm not going to touch windows"), + _ => std::env::var("HOME").expect( + "if this doesn't work, you're probably on macos, which i literally cannot test on", + ), + }; + // println!("{home}"); + home +} + +pub fn create_config(file: &String) -> bool { + let replaced = file.replace('~', &get_home()[..]); // replace ~ with $HOME + let mut paths = replaced.split('/').collect::>(); // split path by / + paths.pop(); + let path = paths.join("/"); + let file_path = std::path::Path::new(&path); // Path without the filename + + if let Some(_) = file_path.parent() { + // if the file_path has a parent folder + fs::create_dir_all(&path).expect("couldn't create needed folders") // create folders + }; + + if file_path.exists() && !Path::new(&replaced).exists() { + let file_contents = "{{ \"archives\": \"{{CONFIG}/CyberModManager/Archives\", \"folders\": \"{{CONFIG}/CyberModManager/Mods\", \"game_folder\": \"{{STEAM}/steamapps/common/Cyberpunk 2077\"}"; + fs::write(replaced, file_contents).expect("couldn't write to config file"); + true + } else { + false + } +} + +pub fn get_steam_location() -> () { +} + +pub fn read_config(file: &String) -> Config { + let read = fs::read_to_string(file).expect("couldn't read config file"); + serde_json::from_str(&read[..]).expect("couldn't parse json") +} + +pub fn ensure_exists(path: String) { + let p = Path::new(&path); + if !p.exists() { + fs::create_dir_all(p).expect("couldn't create folder") + } +} + +#[derive(Serialize, Deserialize)] +pub struct Config { + pub latest_date: String, + pub cache_folder: String, +} +