diff --git a/Cargo.toml b/Cargo.toml index cdbc1f0..6d3a376 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] reqwest = { version = "0.11.18", features = ["blocking"] } +serde_json = "1.0.103" diff --git a/config.json b/config.json new file mode 100644 index 0000000..c02059c --- /dev/null +++ b/config.json @@ -0,0 +1,6 @@ +{ + "proton_installations": { + "Proton - Experimental": "/home/wav/.steam/steam/steamapps/common/Proton - Experimental", + "Proton 6.3": "/home/wav/.steam/steam/steamapps/common/Proton 6.3" + } +} \ No newline at end of file diff --git a/src/args/initialise.rs b/src/args/initialise.rs index b775980..2f8aeda 100644 --- a/src/args/initialise.rs +++ b/src/args/initialise.rs @@ -1,7 +1,12 @@ +use std::fs; + use crate::utils::setup; use crate::utils::terminal::*; +use crate::utils::proton; pub fn main() { + status("Initialising Applejuice..."); + if setup::confirm_applejuice_data_folder_existence() { warning("Configuration directory already exists!"); } else { @@ -28,6 +33,20 @@ pub fn main() { success("Created Roblox directory"); } + status("Finding a Proton installation..."); + let detected_installations = proton::discover_proton_directory(); + if detected_installations == "null" { + error("Failed to find a Proton installation!"); + } else { + status("Found the following Proton installations: "); + for (key, _value) in detected_installations["proton_installations"].as_object().unwrap() { + statusprogress(key); + } + + fs::write(format!("{}/config.json", setup::get_applejuice_dir()), serde_json::to_string_pretty(&detected_installations).unwrap()).expect("Failed to write to config.json"); + success("config.json updated with Proton paths"); + } + println!(); // "Print a newline (for aesthetics" -GitHub copilot, providing dumb crap since 2022 success("Applejuice has been initialised!\nTo get started, run 'applejuicecli --help'\nOr to dive right in, run 'applejuicecli --install client'"); } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 14066de..28d38cd 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,4 @@ pub mod installation; pub mod setup; pub mod terminal; +pub mod proton; diff --git a/src/utils/proton.rs b/src/utils/proton.rs new file mode 100644 index 0000000..6930c0a --- /dev/null +++ b/src/utils/proton.rs @@ -0,0 +1,33 @@ +use std::fs; +use crate::utils::terminal::*; +use serde_json; + +pub fn discover_proton_directory() -> serde_json::Value { // Try to automatically find where Proton is installed to + let potental_path = format!("{}/.steam/steam/steamapps/common/", env!("HOME")); + let mut installations = serde_json::json!({ + "proton_installations": { } + }); + + match fs::read_dir(potental_path.clone()) { + Ok(_) => { + status(format!("Found Steam directory at '{}'", potental_path)); + + for entry in fs::read_dir(potental_path.clone()).unwrap() { + let unwrapped_entry = entry.unwrap(); + let path = unwrapped_entry.path(); + let fsname = path.file_name().unwrap().to_str().unwrap(); + + if fsname.contains("Proton") { + success(format!("Found '{}' at '{}'", fsname, path.to_str().unwrap())); + installations["proton_installations"][fsname] = serde_json::Value::String(path.to_str().unwrap().to_string()); + } + } + + return installations; + }, + Err(_) => { + warning(format!("Failed to find the Steam directory at '{}'", potental_path)); + return "null".parse().unwrap(); + } + } +}