Skip to content

Commit

Permalink
Proton detection added to proton.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
WaviestBalloon committed Jul 16, 2023
1 parent 8d19875 commit 790badd
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"

[dependencies]
reqwest = { version = "0.11.18", features = ["blocking"] }
serde_json = "1.0.103"
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions src/args/initialise.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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'");
}
1 change: 1 addition & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod installation;
pub mod setup;
pub mod terminal;
pub mod proton;
33 changes: 33 additions & 0 deletions src/utils/proton.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

0 comments on commit 790badd

Please sign in to comment.