From 48393b209396db9ddd44251b2bb445d3ad7533fb Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 25 May 2023 17:23:52 +0200 Subject: changed a whole lot og references, fuck rust --- src/commands/download.rs | 6 ++-- src/commands/io.rs | 34 ++++++++++----------- src/commands/list.rs | 33 +++++++++++---------- src/commands/modification.rs | 30 +++++++++---------- src/commands/update.rs | 32 ++++++++++---------- src/config.rs | 1 + src/db.rs | 70 ++++++++++++++++++++++---------------------- src/files.rs | 8 ++--- src/lib.rs | 2 +- src/main.rs | 56 +++++++++++++++++------------------ 10 files changed, 134 insertions(+), 138 deletions(-) (limited to 'src') diff --git a/src/commands/download.rs b/src/commands/download.rs index 6831714..fea3f34 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -9,13 +9,13 @@ use crate::{ modrinth::get_raw_versions, }; -pub async fn download(config: Cfg, liststack: Vec, clean: bool, delete_old: bool) -> MLE<()> { +pub async fn download(config: &Cfg, liststack: Vec, clean: bool, delete_old: bool) -> MLE<()> { for current_list in liststack { println!("Downloading current versions of mods in {}", current_list.id); let downloaded_versions = get_downloaded_versions(current_list.clone())?; // println!("To download: {:#?}", downloaded_versions); let current_version_ids = match userlist_get_all_current_versions_with_mods( - config.clone(), + config, String::from(¤t_list.id), ) { Ok(i) => Ok(i), @@ -66,7 +66,7 @@ pub async fn download(config: Cfg, liststack: Vec, clean: bool, delete_old // println!("Deleting version {} for mod {}", ver.1, ver.0); delete_version(current_list.clone(), ver.1)?; } else { - disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; + disable_version(config, current_list.clone(), ver.1, ver.0)?; }; } } diff --git a/src/commands/io.rs b/src/commands/io.rs index 2a26f1d..43e642a 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -21,9 +21,9 @@ struct ExportVersion { } impl ExportVersion { - fn from(config: Cfg, list_id: &str, mod_id: &str) -> MLE { + fn from(config: &Cfg, list_id: &str, mod_id: &str) -> MLE { Ok(Self { - version: userlist_get_current_version(config.clone(), list_id, mod_id)?, + version: userlist_get_current_version(config, list_id, mod_id)?, set: userlist_get_set_version(config, list_id, mod_id)? }) } @@ -39,18 +39,18 @@ struct ExportList { } impl ExportList { - pub fn from(config: Cfg, list_id: String, download: bool) -> MLE { - let list = lists_get(config.clone(), String::from(&list_id))?; + pub fn from(config: &Cfg, list_id: String, download: bool) -> MLE { + let list = lists_get(config, String::from(&list_id))?; let mut dl_folder = None; if download { dl_folder = Some(list.download_folder) }; - let mods = userlist_get_all_ids(config.clone(), &list_id)?; + let mods = userlist_get_all_ids(config, &list_id)?; let mut versions = vec![]; for m in mods { - versions.push(ExportVersion::from(config.clone(), &list_id, &m)?) + versions.push(ExportVersion::from(config, &list_id, &m)?) } Ok(Self { @@ -63,16 +63,16 @@ impl ExportList { } } -pub fn export(config: Cfg, list: Option) -> MLE<()> { +pub fn export(config: &Cfg, list: Option) -> MLE<()> { let mut list_ids: Vec = vec![]; if list.is_none() { - list_ids = lists_get_all_ids(config.clone())?; + list_ids = lists_get_all_ids(config)?; } else { - list_ids.push(lists_get(config.clone(), list.unwrap())?.id); + list_ids.push(lists_get(config, list.unwrap())?.id); } let mut lists: Vec = vec![]; for list_id in list_ids { - lists.push(ExportList::from(config.clone(), list_id, true)?); + lists.push(ExportList::from(config, list_id, true)?); } let toml = toml::to_string(&Export { lists })?; @@ -85,7 +85,7 @@ pub fn export(config: Cfg, list: Option) -> MLE<()> { Ok(()) } -pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE<()> { +pub async fn import(config: &Cfg, file_str: String, direct_download: bool) -> MLE<()> { let mut file = File::open(file_str)?; let mut content = String::new(); file.read_to_string(&mut content)?; @@ -99,18 +99,18 @@ pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE download_folder: exportlist.download_folder.ok_or("NO_DL").unwrap(), }; lists_insert( - config.clone(), - list.id.clone(), - list.mc_version.clone(), - list.modloader.clone(), - String::from(&list.download_folder), + config, + &list.id, + &list.mc_version, + &list.modloader, + &list.download_folder, )?; let mut ver_ids = vec![]; for id in exportlist.versions { ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} ); } - mod_add(config.clone(), ver_ids, list, direct_download).await?; + mod_add(config, ver_ids, list, direct_download).await?; } Ok(()) } diff --git a/src/commands/list.rs b/src/commands/list.rs index c07823b..95f9927 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -16,30 +16,31 @@ pub struct List { pub download_folder: String, } -pub fn get_current_list(config: Cfg) -> MLE { - let id = config_get_current_list(config.clone())?; +pub fn get_current_list(config: &Cfg) -> MLE { + let id = config_get_current_list(config)?; lists_get(config, id) } pub fn list_add( - config: Cfg, - id: String, - mc_version: String, - modloader: Modloader, - directory: String, + config: &Cfg, + id: &str, + mc_version: &str, + modloader: &Modloader, + directory: &str, ) -> MLE<()> { lists_insert(config, id, mc_version, modloader, directory) } -pub fn list_change(config: Cfg, id: String) -> MLE<()> { - if !lists_get_all_ids(config.clone())?.into_iter().any(|l| l == id) { +pub fn list_change(config: &Cfg, id: String) -> MLE<()> { + if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { return Err(MLError::new(ErrorType::ArgumentError, "List not found")); }; println!("Change default list to: {}", id); config_change_current_list(config, id) } -pub fn list_remove(config: Cfg, id: String) -> MLE<()> { +pub fn list_remove(config: &Cfg, id: String) -> MLE<()> { + //TODO add logging lists_remove(config, id) } @@ -50,7 +51,7 @@ pub fn list_remove(config: Cfg, id: String) -> MLE<()> { /// * `config` - The current config /// * `args` - All args, to extract the new version pub async fn list_version( - config: Cfg, + config: &Cfg, id: String, mc_version: String, download: bool, @@ -61,20 +62,20 @@ pub async fn list_version( id, mc_version ); - lists_version(config.clone(), &id, &mc_version)?; + lists_version(config, &id, &mc_version)?; println!( "\nCheck for updates for new minecraft version in list {}", id ); - let list = lists_get(config.clone(), id)?; + let list = lists_get(config, id)?; update(config, vec![list], true, download, delete).await } -pub fn list_list(config: Cfg) -> MLE<()> { - let lists = lists_get_all_ids(config.clone())?; +pub fn list_list(config: &Cfg) -> MLE<()> { + let lists = lists_get_all_ids(config)?; for list in lists { - let l = lists_get(config.clone(), list)?; + let l = lists_get(config, list)?; println!("{}: | {} | {}", l.id, l.mc_version, l.modloader) } Ok(()) diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 730583d..31931f8 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -11,11 +11,9 @@ use crate::{ error::{ErrorType, MLError, MLE}, files::{delete_version, download_versions}, modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, - List, + List, PROGRESS_CHARS, }; -const PROGRESS_CHARS: &str = "#>-"; - #[derive(Debug, Clone)] pub struct AddMod { pub id: IDSelector, @@ -40,7 +38,7 @@ pub struct ProjectInfo { } pub async fn mod_add( - config: Cfg, + config: &Cfg, mods: Vec, list: List, direct_download: bool, @@ -74,11 +72,11 @@ pub async fn mod_add( info_p.set_style(bar_style.clone()); let mut projectinfo: Vec = Vec::new(); if !mod_ids.is_empty() { - projectinfo.append(&mut get_mod_infos(config.clone(), mod_ids, list.clone()).await?); + projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); info_p.inc(1); }; if !ver_ids.is_empty() { - projectinfo.append(&mut get_ver_info(config.clone(), ver_ids).await?); + projectinfo.append(&mut get_ver_info(config, ver_ids).await?); info_p.inc(1); }; @@ -105,7 +103,7 @@ pub async fn mod_add( }; match userlist_insert( - config.clone(), + config, &list.id, &project.mod_id, ¤t_version_id, @@ -128,7 +126,7 @@ pub async fn mod_add( }?; match mods_insert( - config.clone(), + config, &project.mod_id, &project.slug, &project.title, @@ -161,7 +159,7 @@ pub async fn mod_add( Ok(()) } -async fn get_mod_infos(config: Cfg, mod_ids: Vec<(String, bool)>, list: List) -> MLE> { +async fn get_mod_infos(config: &Cfg, mod_ids: Vec<(String, bool)>, list: List) -> MLE> { let mut setmap: HashMap = HashMap::new(); @@ -255,7 +253,7 @@ async fn get_mod_infos(config: Cfg, mod_ids: Vec<(String, bool)>, list: List) -> Ok(projectinfo) } -async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE> { +async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE> { let mut setmap: HashMap = HashMap::new(); @@ -306,16 +304,16 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec<(String, bool)>) -> MLE MLE<()> { +pub fn mod_remove(config: &Cfg, id: &str, list: List) -> MLE<()> { let mod_id = mods_get_id(&config.data, id)?; - println!("Remove mod {} from {}", mods_get_info(&config, &mod_id)?.title, list.id); - let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; + println!("Remove mod {} from {}", mods_get_info(config, &mod_id)?.title, list.id); + let version = userlist_get_current_version(config, &list.id, &mod_id)?; print!(" └Remove from list"); //Force flush of stdout, else print! doesn't print instantly std::io::stdout().flush()?; - userlist_remove(config.clone(), &list.id, &mod_id)?; + userlist_remove(config, &list.id, &mod_id)?; println!(" ✓"); print!(" └Delete file"); @@ -334,12 +332,12 @@ pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { print!(" └Clean main db table"); //Force flush of stdout, else print! doesn't print instantly std::io::stdout().flush()?; - let list_ids = lists_get_all_ids(config.clone())?; + let list_ids = lists_get_all_ids(config)?; // Remove mod from main list if not used elsewhere let mut mod_used = false; for id in list_ids { - let mods = match userlist_get_all_ids(config.clone(), &id) { + let mods = match userlist_get_all_ids(config, &id) { Ok(m) => m, Err(err) => { if err.to_string() == "Database: NO_MODS_USERLIST" { diff --git a/src/commands/update.rs b/src/commands/update.rs index 2de13f3..7482e43 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -9,13 +9,11 @@ use crate::{ error::{ErrorType, MLError, MLE}, files::{clean_list_dir, delete_version, disable_version, download_versions}, modrinth::{extract_current_version, versions, Version}, - List, + List, PROGRESS_CHARS, }; -const PROGRESS_CHARS: &str = "#>-"; - pub async fn update( - config: Cfg, + config: &Cfg, liststack: Vec, clean: bool, direct_download: bool, @@ -33,7 +31,7 @@ pub async fn update( for current_list in liststack { // println!("Update mods in {}", current_list.id); - let mods = userlist_get_all_ids(config.clone(), ¤t_list.id)?; + let mods = userlist_get_all_ids(config, ¤t_list.id)?; let list_p = mp.insert_before(&update_p, ProgressBar::new(mods.len().try_into().unwrap())); list_p.set_style(bar_style.clone()); @@ -47,11 +45,11 @@ pub async fn update( let mod_p = mp.insert_before(&list_p, ProgressBar::new(1)); mod_p.set_style(spinner_style.clone()); - let info = mods_get_info(&config, &id)?; + let info = mods_get_info(config, &id)?; mod_p.set_message(format!("Update {}", info.title)); // println!(" ├{}", info.title); - if userlist_get_set_version(config.clone(), ¤t_list.id, &id)? { + if userlist_get_set_version(config, ¤t_list.id, &id)? { // println!(" │ └Set version, skipping update"); list_p.inc(1); continue; @@ -59,16 +57,16 @@ pub async fn update( //Getting current installed version for disable or delete let disable_version = - userlist_get_current_version(config.clone(), ¤t_list.id, &id)?; + userlist_get_current_version(config, ¤t_list.id, &id)?; mod_p.inc(1); updatestack.push( match specific_update( - config.clone(), + config, clean, current_list.clone(), - String::from(&id), + &id, &mod_p ) .await @@ -112,7 +110,7 @@ pub async fn update( delete_version(current_list.clone(), ver.0)?; } else if ver.0 != "NONE" { println!(" └Disable version {}", ver.0); - disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?; + disable_version(config, current_list.clone(), ver.0, ver.1)?; }; } } @@ -126,9 +124,9 @@ pub async fn update( Ok(()) } -async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progress: &ProgressBar) -> MLE { +async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progress: &ProgressBar) -> MLE { let applicable_versions = - versions(&config.apis.modrinth, String::from(&id), list.clone()).await; + versions(&config.apis.modrinth, String::from(id), list.clone()).await; let mut versions: Vec = vec![]; @@ -144,9 +142,9 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progr if clean || (versions.join("|") != userlist_get_applicable_versions( - config.clone(), + config, String::from(&list.id), - String::from(&id), + String::from(id), )?) { let current_str = extract_current_version(applicable_versions.clone())?; @@ -154,7 +152,7 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progr if clean { // println!("\t └Add version to downloadstack"); } else { - progress.println(format!("Found new version for {}", mods_get_info(&config, &id).unwrap().title)); + progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title)); // println!("\t └Get versions for specified minecraft versions"); // println!("\t └New current version: {}", current_str); }; @@ -178,7 +176,7 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progr } .url; - userlist_change_versions(config, list.id, current_str, versions.join("|"), link, id)?; + userlist_change_versions(config, list.id, current_str, versions.join("|"), link, id.to_string())?; } if current.is_empty() { diff --git a/src/config.rs b/src/config.rs index 0cb1891..a952d40 100644 --- a/src/config.rs +++ b/src/config.rs @@ -73,6 +73,7 @@ impl Cfg { check_game_versions(&versionfile, true).await?; }, } + Ok(config) } } diff --git a/src/db.rs b/src/db.rs index dde00ab..3409298 100644 --- a/src/db.rs +++ b/src/db.rs @@ -9,7 +9,7 @@ use crate::{ }; //MODS -pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { +pub fn mods_insert(config: &Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -21,7 +21,7 @@ pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { Ok(()) } -pub fn mods_get_all_ids(config: Cfg) -> Result, Box> { +pub fn mods_get_all_ids(config: &Cfg) -> Result, Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -120,7 +120,7 @@ pub fn mods_get_info(config: &Cfg, id: &str) -> MLE { } } -pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { +pub fn mods_remove(config: &Cfg, id: String) -> MLE<()> { println!("Removing mod {} from database", id); let data = format!("{}/data.db", config.data); @@ -137,7 +137,7 @@ pub struct DBModlistVersions { pub versions: String, } -pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE> { +pub fn mods_get_versions(config: &Cfg, mods: Vec) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -186,7 +186,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE MLE> { +pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -239,7 +239,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: &str) -> MLE> { } } -pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { +pub fn userlist_remove(config: &Cfg, list_id: &str, mod_id: &str) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -251,7 +251,7 @@ pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { } pub fn userlist_get_applicable_versions( - config: Cfg, + config: &Cfg, list_id: String, mod_id: String, ) -> MLE { @@ -279,7 +279,7 @@ pub fn userlist_get_applicable_versions( } pub fn userlist_get_all_applicable_versions_with_mods( - config: Cfg, + config: &Cfg, list_id: String, ) -> MLE> { let data = format!("{}/data.db", config.data); @@ -307,7 +307,7 @@ pub fn userlist_get_all_applicable_versions_with_mods( Ok(versions) } -pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE { +pub fn userlist_get_current_version(config: &Cfg, list_id: &str, mod_id: &str) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -327,7 +327,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> } pub fn userlist_get_all_current_version_ids( - config: Cfg, + config: &Cfg, list_id: String, ) -> MLE> { let data = format!("{}/data.db", config.data); @@ -353,7 +353,7 @@ pub fn userlist_get_all_current_version_ids( } pub fn userlist_get_all_current_versions_with_mods( - config: Cfg, + config: &Cfg, list_id: String, ) -> Result, Box> { let data = format!("{}/data.db", config.data); @@ -384,7 +384,7 @@ pub fn userlist_get_all_current_versions_with_mods( Ok(versions) } -pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE { +pub fn userlist_get_set_version(config: &Cfg, list_id: &str, mod_id: &str) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -401,7 +401,7 @@ pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE } pub fn userlist_change_versions( - config: Cfg, + config: &Cfg, list_id: String, current_version: String, versions: String, @@ -416,7 +416,7 @@ pub fn userlist_change_versions( } pub fn userlist_add_disabled_versions( - config: Cfg, + config: &Cfg, list_id: String, disabled_version: String, mod_id: String, @@ -442,7 +442,7 @@ pub fn userlist_add_disabled_versions( Ok(()) } -pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: String) -> MLE { +pub fn userlist_get_disabled_versions(config: &Cfg, list_id: String, mod_id: String) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -462,7 +462,7 @@ pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: Stri } pub fn userlist_get_all_downloads( - config: Cfg, + config: &Cfg, list_id: String, ) -> Result, Box> { let data = format!("{}/data.db", config.data); @@ -492,11 +492,11 @@ pub fn userlist_get_all_downloads( //lists ///Inserts into lists table and creates new table pub fn lists_insert( - config: Cfg, - id: String, - mc_version: String, - mod_loader: Modloader, - download_folder: String, + config: &Cfg, + id: &str, + mc_version: &str, + mod_loader: &Modloader, + download_folder: &str, ) -> MLE<()> { println!("Creating list {}", id); @@ -506,9 +506,9 @@ pub fn lists_insert( connection.execute( "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [ - id.clone(), + id, mc_version, - mod_loader.to_string(), + &mod_loader.to_string(), download_folder, ], )?; @@ -517,7 +517,7 @@ pub fn lists_insert( Ok(()) } -pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { +pub fn lists_remove(config: &Cfg, id: String) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -526,7 +526,7 @@ pub fn lists_remove(config: Cfg, id: String) -> MLE<()> { Ok(()) } -pub fn lists_get(config: Cfg, list_id: String) -> MLE { +pub fn lists_get(config: &Cfg, list_id: String) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -564,7 +564,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE { Ok(list) } -pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { +pub fn lists_version(config: &Cfg, list_id: &str, version: &str) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -575,7 +575,7 @@ pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { Ok(()) } -pub fn lists_get_all_ids(config: Cfg) -> MLE> { +pub fn lists_get_all_ids(config: &Cfg) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -594,7 +594,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE> { } //config -pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { +pub fn config_change_current_list(config: &Cfg, id: String) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -605,7 +605,7 @@ pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { Ok(()) } -pub fn config_get_current_list(config: Cfg) -> MLE { +pub fn config_get_current_list(config: &Cfg) -> MLE { let data = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -626,7 +626,7 @@ pub fn config_get_current_list(config: Cfg) -> MLE { //SETUP(UPDATES) pub fn s_userlist_update_download( - config: Cfg, + config: &Cfg, list_id: String, mod_id: String, link: String, @@ -645,7 +645,7 @@ pub fn s_userlist_update_download( Ok(()) } -pub fn s_config_create_version(config: Cfg) -> Result<(), Box> { +pub fn s_config_create_version(config: &Cfg) -> Result<(), Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -656,7 +656,7 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box Result<(), Box> { +pub fn s_config_update_version(config: &Cfg, ver: String) -> Result<(), Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -667,7 +667,7 @@ pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box Result> { +pub fn s_config_get_version(config: &Cfg) -> Result> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -689,7 +689,7 @@ pub fn s_config_get_version(config: Cfg) -> Result) -> MLE<()> { let cached = get_cached_versions(&config.cache); @@ -89,7 +87,7 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: progress.set_message(format!("Copy {} to cache", version.id)); let dl_path_file = format!("{}/{}", list.download_folder, filename); - let cache_path = format!("{}/{}", &config.clone().cache, filename); + let cache_path = format!("{}/{}", &config.cache, filename); copy(dl_path_file, cache_path)?; } @@ -135,7 +133,7 @@ async fn download_file(url: &str, path: &str, name: &str, progress: &ProgressBar } pub fn disable_version( - config: Cfg, + config: &Cfg, current_list: List, versionid: String, mod_id: String, diff --git a/src/lib.rs b/src/lib.rs index f59ba89..69cc650 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ pub use commands::*; use error::{ErrorType, MLError, MLE}; use serde::{Deserialize, Serialize}; -pub static TICK_CHARS: &str = "#>-"; +pub static PROGRESS_CHARS: &str = "#>-"; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] pub enum Modloader { diff --git a/src/main.rs b/src/main.rs index 31a320b..0e040b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,7 +162,6 @@ async fn main() { match cli.command { Commands::Mod { command } => { match command { - #[allow(unused_variables)] ModCommands::Add { id, version, @@ -171,10 +170,10 @@ async fn main() { lock, } => { let listf = match list { - Some(list) => lists_get(config.clone(), list).unwrap(), + Some(list) => lists_get(&config, list).unwrap(), None => lists_get( - config.clone(), - config_get_current_list(config.clone()).unwrap(), + &config, + config_get_current_list(&config).unwrap(), ) .unwrap(), }; @@ -186,18 +185,18 @@ async fn main() { let add_id = AddMod { id: marked_id, set_version: lock }; - mod_add(config, vec![add_id], listf, download).await + mod_add(&config, vec![add_id], listf, download).await } ModCommands::Remove { id, list } => { let listf = match list { - Some(list) => lists_get(config.clone(), list).unwrap(), + Some(list) => lists_get(&config, list).unwrap(), None => lists_get( - config.clone(), - config_get_current_list(config.clone()).unwrap(), + &config, + config_get_current_list(&config).unwrap(), ) .unwrap(), }; - mod_remove(config, &id, listf) + mod_remove(&config, &id, listf) } } } @@ -211,28 +210,28 @@ async fn main() { } => { let ml = match modloader { Some(ml) => Modloader::from(&ml).unwrap(), - None => config.clone().defaults.modloader, + None => config.defaults.modloader.clone(), }; let versions_path = &config.versions; let ver = match version { Some(ver) => VersionLevel::from(&ver).get(versions_path, cli.force_gameupdate).await.unwrap(), - None => config.clone().defaults.version.get(versions_path, cli.force_gameupdate).await.unwrap(), + None => config.defaults.version.clone().get(versions_path, cli.force_gameupdate).await.unwrap(), }; - list_add(config, id, ver, ml, directory) + list_add(&config, &id, &ver, &ml, &directory) } - ListCommands::Remove { id } => list_remove(config, id), + ListCommands::Remove { id } => list_remove(&config, id), ListCommands::List => { - list_list(config) + list_list(&config) } - ListCommands::Change { id } => list_change(config, id), + ListCommands::Change { id } => list_change(&config, id), ListCommands::Version { id, version, download, remove, - } => list_version(config, id, version, download, remove).await, + } => list_version(&config, id, version, download, remove).await, } } Commands::Update { @@ -244,34 +243,35 @@ async fn main() { } => { let mut liststack: Vec = vec![]; if all { - let list_ids = lists_get_all_ids(config.clone()).unwrap(); + let list_ids = lists_get_all_ids(&config).unwrap(); for id in list_ids { - liststack.push(lists_get(config.clone(), id).unwrap()); + liststack.push(lists_get(&config, id).unwrap()); } } else { let current = match list { - Some(l) => lists_get(config.clone(), l).unwrap(), - None => get_current_list(config.clone()).unwrap(), + Some(l) => lists_get(&config, l).unwrap(), + None => get_current_list(&config).unwrap(), }; liststack.push(current) } - update(config, liststack, clean, download, remove).await + update(&config, liststack, clean, download, remove).await } Commands::Download { all, clean, remove, list } => { let mut liststack: Vec = vec![]; if all { - let list_ids = lists_get_all_ids(config.clone()).unwrap(); + let list_ids = lists_get_all_ids(&config).unwrap(); for id in list_ids { - liststack.push(lists_get(config.clone(), id).unwrap()); + liststack.push(lists_get(&config, id).unwrap()); } } else { let current = match list { - Some(l) => lists_get(config.clone(), l).unwrap(), - None => get_current_list(config.clone()).unwrap(), + Some(l) => lists_get(&config, l).unwrap(), + None => get_current_list(&config).unwrap(), }; liststack.push(current) } - download(config, liststack, clean, remove).await + + download(&config, liststack, clean, remove).await }, Commands::Import { file, download } => { let filestr: String = match file { @@ -284,9 +284,9 @@ async fn main() { .unwrap(), }; - import(config, filestr, download).await + import(&config, filestr, download).await } - Commands::Export { list } => export(config, list), + Commands::Export { list } => export(&config, list), Commands::Test => Ok(()), } .unwrap(); -- cgit v1.2.3