Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push experimental changes that improve RPC, error message changes, bug fixes and more #15

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 118 additions & 134 deletions src/args/purge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@ use std::{fs::{read_dir, remove_dir_all, remove_file, metadata}, process::exit,

const HELP_TEXT: &str = "\nUsage: --purge [type]\nPurges cache or installs, useful for a fresh start or if you are having issues\n\nOptions:\n\tcache\tDeletes all compressed files that were downloaded from the CDN\n\tinstalls\tNukes every install of Roblox you have\n\tinstall\tDeletes a specific version of Roblox, can purge multiple versions at once";

fn check_location(folder: &str) {
if !setup::confirm_existence(folder) {
error!("{folder} directory does not exist! Did you forget to initialise?");
exit(1);
}

let paths = read_dir(format!("{}/cache", setup::get_applejuice_dir())).unwrap();
if paths.count() == 0 {
error!("{folder} directory is empty!");
exit(1);
}
}

fn get_all_valid_installations() {
// Vec format: (location, size, installation_date, special_mods)
let mut valid_player_versions: Vec<(String, String, String, String)> = vec![];
let mut valid_studio_versions: Vec<(String, String, String, String)> = vec![];

let paths = read_dir(format!("{}/roblox", setup::get_applejuice_dir())).unwrap();
for deployment_path in paths { // "roblox/<DEPLOYMENT_CHANNEL>"
let studio_player = read_dir(deployment_path.unwrap().path()).unwrap();

for binary_type in studio_player { // "roblox/<DEPLOYMENT_CHANNEL>/<STUDIO/PLAYER>"
let version = read_dir(binary_type.unwrap().path()).unwrap();

for version_path in version { // "roblox/<DEPLOYMENT_CHANNEL>/<STUDIO/PLAYER>/<VERSION>"
//let path_unwrap = version_path.unwrap().path().to_str().unwrap();

//println!("{}", path_unwrap);
println!("{:?}", version_path.unwrap().path());
}
}
}
}

pub fn main(args: Vec<Vec<(String, String)>>) {
let binding = argparse::get_param_value(args, "purge");
let parsed_args = binding.split(' ').collect::<Vec<&str>>();
Expand All @@ -16,168 +51,117 @@ pub fn main(args: Vec<Vec<(String, String)>>) {
match install_type {
"cache" => {
status!("Purging cache...");

if setup::confirm_existence("cache") {
let paths = read_dir(format!("{}/cache", setup::get_applejuice_dir())).unwrap();
if paths.count() == 0 {
error!("Cache directory is empty!");

match remove_dir_all(format!("{}/cache", setup::get_applejuice_dir())) {
Ok(_) => {
success!("Removed cache directory");
},
Err(errmsg) => {
error!("Failed to remove the cache directory!\nError: {}", errmsg);
exit(1);
}

match remove_dir_all(format!("{}/cache", setup::get_applejuice_dir())) {
Ok(_) => {
success!("Removed cache directory");
},
Err(errmsg) => {
error!("Failed to remove the cache directory!\nError: {}", errmsg);
exit(1);
}
}

setup::create_dir("cache");
success!("Created cache directory");
} else {
error!("Cache directory does not exist! Did you forget to initialise?");
exit(1);
}

setup::create_dir("cache");
success!("Created cache directory");

success!("Purged cache successfully");
},
"installs" => {
status!("Purging Roblox installations...");

if setup::confirm_existence("roblox") {
let paths = read_dir(format!("{}/roblox", setup::get_applejuice_dir())).unwrap();
if paths.count() == 0 {
error!("Roblox directory is empty!");
exit(1);
}

let mut removing = Vec::new();
match read_dir(format!("{}/roblox", setup::get_applejuice_dir())) {
Ok(paths) => {
for deployment_path in paths {
let path_unwrap = deployment_path.unwrap();
match read_dir(path_unwrap.path()) {
Ok(paths) => {
for binary_type in paths {
let path_unwrap = binary_type.unwrap();

check_location("roblox");

let mut removing = Vec::new();
match read_dir(format!("{}/roblox", setup::get_applejuice_dir())) {
Ok(paths) => {
for deployment_path in paths {
let path_unwrap = deployment_path.unwrap();
match read_dir(path_unwrap.path()) {
Ok(paths) => {
for binary_type in paths {
let path_unwrap = binary_type.unwrap();
match read_dir(path_unwrap.path()) {
Ok(paths) => {
for version_path in paths {
let path_unwrap = version_path.unwrap();
let binding = path_unwrap.path();
removing.push(path_unwrap.file_name().into_string().unwrap());

status!("Removing {:?}...", binding.clone());
match remove_dir_all(binding.clone()) {
Ok(_) => {
success!("Removed Roblox directory for version {}", binding.to_str().unwrap());
Ok(paths) => {
for version_path in paths {
let path_unwrap = version_path.unwrap();
let binding = path_unwrap.path();
removing.push(path_unwrap.file_name().into_string().unwrap());

status!("Removing {:?}...", binding.clone());
match remove_dir_all(binding.clone()) {
Ok(_) => {
success!("Removed Roblox directory for version {}", binding.to_str().unwrap());
},
Err(errmsg) => {
error!("Failed to remove the Roblox directory for version {}!\nError: {}", path_unwrap.path().to_str().unwrap(), errmsg);
exit(1);
}
Err(errmsg) => {
error!("Failed to remove the Roblox directory for version {}!\nError: {}", path_unwrap.path().to_str().unwrap(), errmsg);
exit(1);
}
}
},
Err(errmsg) => {
error!("Failed to read the Roblox directory!\nError: {}", errmsg);
exit(1);
}
},
Err(errmsg) => {
error!("Failed to read the Roblox directory!\nError: {}", errmsg);
exit(1);
}
}
},
Err(errmsg) => {
error!("Failed to read the Roblox directory!\nError: {}", errmsg);
exit(1);
}
},
Err(errmsg) => {
error!("Failed to read the Roblox directory!\nError: {}", errmsg);
exit(1);
}
}
},
Err(errmsg) => {
error!("Failed to read the Roblox directory!\nError: {}", errmsg);
exit(1);
}
}

status!("Cleaning up...");
match remove_dir_all(format!("{}/roblox", setup::get_applejuice_dir())) {
Ok(_) => {
success!("Removed Roblox directory");
},
Err(errmsg) => {
format!("Failed to remove the Roblox directory!\nError: {}", errmsg);
exit(1);
}
},
Err(errmsg) => {
error!("Failed to read the Roblox directory!\nError: {}", errmsg);
exit(1);
}

status!("Removing shortcuts to deployments...");
removing.iter().for_each(|version| {
let config = get_config(version);
let binary_type = config.get("binary_type").unwrap().as_str().unwrap();
let clean_version_hash = version.replace("version-", "");
let desktop_shortcut_path = format!("{}/.local/share/applications/roblox-{}-{}.desktop", var("HOME").expect("$HOME not set"), binary_type.to_lowercase(), clean_version_hash);
if metadata(desktop_shortcut_path.clone()).is_ok() {
remove_file(desktop_shortcut_path).unwrap();
}
});
status!("Updating desktop database...");
process::Command::new("update-desktop-database")
.arg(format!("{}/.local/share/applications", var("HOME").expect("$HOME not set")))
.spawn()
.expect("Failed to execute update-desktop-database");

status!("Removing installation entires from configuration file...");
removing.iter().for_each(|version| {
update_config(serde_json::Value::Null, version);
});

setup::create_dir("roblox");
success!("Created Roblox directory");
} else {
error!("Roblox directory does not exist! Did you forget to initialise?");
exit(1);
}

success!("Purged Roblox installations successfully");
},
"install" => {
// status("Searching for remnant entries in config...");
/*status(format!("Purging Roblox installation(s) for version(s) {}...", parsed_args[1..].join(", ")));

if setup::confirm_existence("roblox") {
let paths = read_dir(format!("{}/roblox", setup::get_applejuice_dir())).unwrap();
if paths.count() == 0 {
error("Roblox directory is empty!");
status!("Cleaning up...");
match remove_dir_all(format!("{}/roblox", setup::get_applejuice_dir())) {
Ok(_) => {
success!("Removed Roblox directory");
},
Err(errmsg) => {
format!("Failed to remove the Roblox directory!\nError: {}", errmsg);
exit(1);
}
}

for version in parsed_args[1..].iter() {
for path in read_dir(format!("{}/roblox", setup::get_applejuice_dir())).unwrap() {
let path_unwrap = path.unwrap();
if path_unwrap.path().to_str().unwrap().contains(version) {
match remove_dir_all(path_unwrap.path()) {
Ok(_) => {
success(format!("Removed Roblox directory for version {}", version));
},
Err(errmsg) => {
error(format!("Failed to remove the Roblox directory for version {}!\nError: {}", version, errmsg));
exit(1);
}
}
}
}
status!("Removing shortcuts to deployments...");
removing.iter().for_each(|version| {
let config = get_config(version);
let binary_type = config.get("binary_type").unwrap().as_str().unwrap();
let clean_version_hash = version.replace("version-", "");
let desktop_shortcut_path = format!("{}/.local/share/applications/roblox-{}-{}.desktop", var("HOME").expect("$HOME not set"), binary_type.to_lowercase(), clean_version_hash);
if metadata(desktop_shortcut_path.clone()).is_ok() {
remove_file(desktop_shortcut_path).unwrap();
}
});
status!("Updating desktop database...");
process::Command::new("update-desktop-database")
.arg(format!("{}/.local/share/applications", var("HOME").expect("$HOME not set")))
.spawn()
.expect("Failed to execute update-desktop-database");

status("Searching for remnant entries in config...");
} else {
error("Roblox directory does not exist! Did you forget to initialise?");
exit(1);
}
status!("Removing installation entires from configuration file...");
removing.iter().for_each(|version| {
update_config(serde_json::Value::Null, version);
});

setup::create_dir("roblox");
success!("Created Roblox directory");

success!("Purged Roblox installations successfully");
},
"install" => {
status!("Discovering Roblox installations...");
check_location("roblox");

get_all_valid_installations();

success("Purged Roblox installation(s) successfully");*/
error!("Not implemented yet!");
},
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/argparse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub fn get_param_value(command_vector: Vec<Vec<(String, String)>>, value_to_find: &str) -> String {
pub fn get_param_value(command_vector: Vec<Vec<(String, String)>>, value_to_find: &str) -> String { // TODO: Replace all `get_param_value` calls with `get_param_value_new`
for command in command_vector.iter() {
if command[0].0 == *value_to_find {
if command[0].1.is_empty() {
Expand Down
3 changes: 1 addition & 2 deletions src/utils/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ struct Response {
#[serde(rename_all = "camelCase")]
struct ResponseErrorMeat {
code: i32,
message: String
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -164,7 +163,7 @@ pub fn fetch_latest_version(version: LatestVersion) -> ExactVersion {
match errors[0].code {
1 => { error!("Could not find version details for channel {}, make sure you have spelt the deployment channel name correctly.", channel); },
5 => { error!("The deployment channel {} is restricted by Roblox!", channel); },
_ => { error!("Unknown error response.\nResponse: {}\nError: {}", output, error); }
_ => { error!("Unknown error response when attempting to resolve channel {}!\nResponse: {}\nError: {}", channel, output, error); }
}

exit(1);
Expand Down
9 changes: 7 additions & 2 deletions src/utils/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utils::terminal::*;
pub fn create_notification(icon: &str, expire_time: &str, title: &str, body: &str) {
let output = process::Command::new("notify-send")
.arg("--app-name=Applejuice")
.arg(format!("--icon={}", icon))
.arg(format!("--icon={}", "aaaaa"))
.arg("--urgency=normal")
.arg(format!("--expire-time={}", expire_time))
.arg(title)
Expand All @@ -14,8 +14,13 @@ pub fn create_notification(icon: &str, expire_time: &str, title: &str, body: &st
match output {
Ok(_) => { },
Err(errmsg) => { // Do not quit or panic here, since it's a non-critical error
warning!("Failed to create notification, raw: '{}'\nError: {}", icon, errmsg);
warning!("Failed to create notification, icon: '{}'\nError: {}", icon, errmsg);

if icon.is_empty() {
warning!("Failed to create notification twice; You may not have libnotify installed on your system, ignoring...");
return;
}

if errmsg.to_string().contains("No such file or directory (os error 2)") { // Fallback to default/no icon if we detect a missing file error
warning!("Assuming a asset was missing; falling back to no icon...");
create_notification("", expire_time, title, body);
Expand Down
Loading