Skip to content

Commit

Permalink
Fix: Install missing args warning, change strs to json! and more
Browse files Browse the repository at this point in the history
  • Loading branch information
WaviestBalloon committed Aug 25, 2023
1 parent 59539b0 commit fd6af70
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/args/initialise.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::fs;
use serde_json::json;

use crate::utils::setup;
use crate::utils::terminal::*;
use crate::utils::proton;
Expand Down Expand Up @@ -71,6 +73,8 @@ pub fn main() {
success("config.json updated with Proton paths");
}

configuration::update_config(json!({ "global": {} }), "global");

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'");
}
13 changes: 8 additions & 5 deletions src/args/install.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{fs, env::var};
use serde_json::json;

use crate::utils::{terminal::*, installation, setup, configuration, argparse};

const HELP_TEXT: &str = "\nUsage: --install [type] [?removeolder] [?migratefflags] \nInstalls Roblox Client or Roblox Studio\n\nOptions:\n\tclient\tInstalls the Roblox Client\n\tstudio\tInstalls Roblox Studio\n\nExample: --install client zcanary --removeolder --migratefflags";
Expand Down Expand Up @@ -34,6 +36,10 @@ fn download_and_install(version_hash: &str, channel: &str, raw_args: Vec<Vec<(St
installation::extract_deployment_zips(binary_type, cache_path, folder_path.clone());
success("Extracted deployment successfully!");

status("Creating ClientSettings for FFlag configuration...");
fs::create_dir(format!("{}/ClientSettings", folder_path)).expect("Failed to create ClientSettings directory");
fs::write(format!("{}/ClientSettings/ClientAppSettings.json", folder_path), json!({}).to_string()).expect("Failed to create the config file!");

status("Reading available Proton instances from configuration...");
let proton_instances = configuration::get_config("proton_installations");
let mut proton_instance: String = "".to_string();
Expand All @@ -44,7 +50,7 @@ fn download_and_install(version_hash: &str, channel: &str, raw_args: Vec<Vec<(St
break;
}
}
success(format!("Setting \"preferred_proton\" to '{}'", proton_instance));
success(format!("Setting \"preferred_proton\" to {}", proton_instance));
} else {
warning("Failed to find a Proton instance! Do you have one specified in your config.json file?");
}
Expand All @@ -61,7 +67,6 @@ Type=Application
Categories=Game;");
fs::write(desktop_shortcut_path.clone(), desktop_shortcut_contents).expect("Failed to write desktop shortcut");

status("Updating configuration file...");
configuration::update_config(serde_json::json!({
format!("{}", version_hash): {
"version": version_hash,
Expand All @@ -79,8 +84,6 @@ Categories=Game;");
fn install_client(channel_arg: Option<String>, version_hash_arg: Option<String>, raw_args: Vec<Vec<(String, String)>>) {
let version_hash: String;
let mut channel: String = "LIVE".to_string();
let mut _protocol: bool = false;
let mut _uncap_fps_fflag: bool = false;

if !channel_arg.is_some() {
status("Defaulting to LIVE channel...");
Expand Down Expand Up @@ -110,7 +113,7 @@ fn install_studio(channel_arg: Option<String>, version_hash_arg: Option<String>,
pub fn main(args: Vec<Vec<(String, String)>>) {
let binding = argparse::get_param_value(args.clone(), "install");
let parsed_args = binding.split(" ").collect::<Vec<&str>>();
if parsed_args.len() == 0 {
if parsed_args.len() == 0 || parsed_args[0] == "blank" {
error(format!("No command line arguments provided for install!{}", HELP_TEXT));
}
let install_type: &str = &parsed_args[0];
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::env;
use std::{env, process};
mod utils; // Import utilities that are not necessarily commands
mod args; // Import modules which act as a handler for certain command parameters
use crate::utils::{terminal::*, *};

fn main() {
if env::consts::OS != "linux" {
error(format!("Applejuice is a Linux-only application and is not designed to be ran on any operating system other than a Linux-based system.\nYour OS identifies itself as {}!\n{}", env::consts::OS, if env::consts::OS == "windows" { "Since you are using Windows, consider using Bloxstrap: https://github.com/pizzaboxer/bloxstrap/\n" } else { "" }));
process::exit(1);
}
let args: Vec<String> = env::args().collect();
if !setup::confirm_applejuice_data_folder_existence() { // Initialisation warning
warning("Applejuice has not been initialised yet! Attempting to initialise...");
Expand Down
2 changes: 1 addition & 1 deletion src/utils/argparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub fn get_param_value(command_vector: Vec<Vec<(String, String)>>, value_to_find
for command in command_vector.iter() {
if command[0].0 == value_to_find.to_string() {
if command[0].1.is_empty() {
return "true".to_string();
return "blank".to_string();
} else {
return command[0].1.to_string();
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn get_binary_type(package_manifest: Vec<&str>) -> &str {
break;
}
}
if binary == "" {
if binary.is_empty() {
error("Could not determine binary type for provided package menifest!");
}

Expand Down
6 changes: 5 additions & 1 deletion src/utils/setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::{fs, env::var};
use serde_json::json;

use crate::utils::terminal::*;

pub fn confirm_applejuice_data_folder_existence() -> bool { // Check whether the .applejuice data folder exists under $HOME/.applejuice
Expand Down Expand Up @@ -29,8 +31,10 @@ pub fn construct_applejuice_data_folder() { // Construct the .applejuice data fo
}
}

status("Creating README.txt...");
fs::write(format!("{}/{}", path, "README.txt"), "Hey! Welcome to the cool zone...\n\n\tIf you want a fresh start, delete this folder and Applejuice will forget everything!").expect("Failed to create the README file!");
fs::write(format!("{}/{}", path, "config.json"), "{}").expect("Failed to create the config file!");
status("Creating config.json...");
fs::write(format!("{}/{}", path, "config.json"), json!({}).to_string()).expect("Failed to create the config file!");
}

pub fn confirm_existence(providedpath: &str) -> bool { // Check whether a item exists in the .applejuice data folder or a ancestor to it
Expand Down

0 comments on commit fd6af70

Please sign in to comment.