summaryrefslogtreecommitdiff
path: root/src/commands/update.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-25 17:23:52 +0200
committerfxqnlr <[email protected]>2023-05-25 17:23:52 +0200
commit48393b209396db9ddd44251b2bb445d3ad7533fb (patch)
tree264b459bacc0f6c62f26c3fd45c83ee9946babe2 /src/commands/update.rs
parent529d52534c300aec4a6e3e9e08f9762a401f7086 (diff)
downloadmodlist-48393b209396db9ddd44251b2bb445d3ad7533fb.tar
modlist-48393b209396db9ddd44251b2bb445d3ad7533fb.tar.gz
modlist-48393b209396db9ddd44251b2bb445d3ad7533fb.zip
changed a whole lot og references, fuck rust
Diffstat (limited to 'src/commands/update.rs')
-rw-r--r--src/commands/update.rs32
1 files changed, 15 insertions, 17 deletions
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::{
9 error::{ErrorType, MLError, MLE}, 9 error::{ErrorType, MLError, MLE},
10 files::{clean_list_dir, delete_version, disable_version, download_versions}, 10 files::{clean_list_dir, delete_version, disable_version, download_versions},
11 modrinth::{extract_current_version, versions, Version}, 11 modrinth::{extract_current_version, versions, Version},
12 List, 12 List, PROGRESS_CHARS,
13}; 13};
14 14
15const PROGRESS_CHARS: &str = "#>-";
16
17pub async fn update( 15pub async fn update(
18 config: Cfg, 16 config: &Cfg,
19 liststack: Vec<List>, 17 liststack: Vec<List>,
20 clean: bool, 18 clean: bool,
21 direct_download: bool, 19 direct_download: bool,
@@ -33,7 +31,7 @@ pub async fn update(
33 for current_list in liststack { 31 for current_list in liststack {
34 32
35 // println!("Update mods in {}", current_list.id); 33 // println!("Update mods in {}", current_list.id);
36 let mods = userlist_get_all_ids(config.clone(), &current_list.id)?; 34 let mods = userlist_get_all_ids(config, &current_list.id)?;
37 35
38 let list_p = mp.insert_before(&update_p, ProgressBar::new(mods.len().try_into().unwrap())); 36 let list_p = mp.insert_before(&update_p, ProgressBar::new(mods.len().try_into().unwrap()));
39 list_p.set_style(bar_style.clone()); 37 list_p.set_style(bar_style.clone());
@@ -47,11 +45,11 @@ pub async fn update(
47 let mod_p = mp.insert_before(&list_p, ProgressBar::new(1)); 45 let mod_p = mp.insert_before(&list_p, ProgressBar::new(1));
48 mod_p.set_style(spinner_style.clone()); 46 mod_p.set_style(spinner_style.clone());
49 47
50 let info = mods_get_info(&config, &id)?; 48 let info = mods_get_info(config, &id)?;
51 mod_p.set_message(format!("Update {}", info.title)); 49 mod_p.set_message(format!("Update {}", info.title));
52 // println!(" ├{}", info.title); 50 // println!(" ├{}", info.title);
53 51
54 if userlist_get_set_version(config.clone(), &current_list.id, &id)? { 52 if userlist_get_set_version(config, &current_list.id, &id)? {
55 // println!(" │ └Set version, skipping update"); 53 // println!(" │ └Set version, skipping update");
56 list_p.inc(1); 54 list_p.inc(1);
57 continue; 55 continue;
@@ -59,16 +57,16 @@ pub async fn update(
59 57
60 //Getting current installed version for disable or delete 58 //Getting current installed version for disable or delete
61 let disable_version = 59 let disable_version =
62 userlist_get_current_version(config.clone(), &current_list.id, &id)?; 60 userlist_get_current_version(config, &current_list.id, &id)?;
63 61
64 mod_p.inc(1); 62 mod_p.inc(1);
65 63
66 updatestack.push( 64 updatestack.push(
67 match specific_update( 65 match specific_update(
68 config.clone(), 66 config,
69 clean, 67 clean,
70 current_list.clone(), 68 current_list.clone(),
71 String::from(&id), 69 &id,
72 &mod_p 70 &mod_p
73 ) 71 )
74 .await 72 .await
@@ -112,7 +110,7 @@ pub async fn update(
112 delete_version(current_list.clone(), ver.0)?; 110 delete_version(current_list.clone(), ver.0)?;
113 } else if ver.0 != "NONE" { 111 } else if ver.0 != "NONE" {
114 println!(" └Disable version {}", ver.0); 112 println!(" └Disable version {}", ver.0);
115 disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?; 113 disable_version(config, current_list.clone(), ver.0, ver.1)?;
116 }; 114 };
117 } 115 }
118 } 116 }
@@ -126,9 +124,9 @@ pub async fn update(
126 Ok(()) 124 Ok(())
127} 125}
128 126
129async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progress: &ProgressBar) -> MLE<Version> { 127async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progress: &ProgressBar) -> MLE<Version> {
130 let applicable_versions = 128 let applicable_versions =
131 versions(&config.apis.modrinth, String::from(&id), list.clone()).await; 129 versions(&config.apis.modrinth, String::from(id), list.clone()).await;
132 130
133 let mut versions: Vec<String> = vec![]; 131 let mut versions: Vec<String> = vec![];
134 132
@@ -144,9 +142,9 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progr
144 if clean 142 if clean
145 || (versions.join("|") 143 || (versions.join("|")
146 != userlist_get_applicable_versions( 144 != userlist_get_applicable_versions(
147 config.clone(), 145 config,
148 String::from(&list.id), 146 String::from(&list.id),
149 String::from(&id), 147 String::from(id),
150 )?) 148 )?)
151 { 149 {
152 let current_str = extract_current_version(applicable_versions.clone())?; 150 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
154 if clean { 152 if clean {
155 // println!("\t └Add version to downloadstack"); 153 // println!("\t └Add version to downloadstack");
156 } else { 154 } else {
157 progress.println(format!("Found new version for {}", mods_get_info(&config, &id).unwrap().title)); 155 progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title));
158 // println!("\t └Get versions for specified minecraft versions"); 156 // println!("\t └Get versions for specified minecraft versions");
159 // println!("\t └New current version: {}", current_str); 157 // println!("\t └New current version: {}", current_str);
160 }; 158 };
@@ -178,7 +176,7 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String, progr
178 } 176 }
179 .url; 177 .url;
180 178
181 userlist_change_versions(config, list.id, current_str, versions.join("|"), link, id)?; 179 userlist_change_versions(config, list.id, current_str, versions.join("|"), link, id.to_string())?;
182 } 180 }
183 181
184 if current.is_empty() { 182 if current.is_empty() {