summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/download.rs8
-rw-r--r--src/commands/modification.rs18
-rw-r--r--src/commands/update.rs123
3 files changed, 52 insertions, 97 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index fea3f34..e9a96b5 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -1,4 +1,6 @@
1 1
2use indicatif::MultiProgress;
3
2use crate::{config::Cfg, List}; 4use crate::{config::Cfg, List};
3use crate::{ 5use crate::{
4 db::userlist_get_all_current_versions_with_mods, 6 db::userlist_get_all_current_versions_with_mods,
@@ -10,10 +12,12 @@ use crate::{
10}; 12};
11 13
12pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> { 14pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_old: bool) -> MLE<()> {
15
16 let mp = MultiProgress::new();
17
13 for current_list in liststack { 18 for current_list in liststack {
14 println!("Downloading current versions of mods in {}", current_list.id); 19 println!("Downloading current versions of mods in {}", current_list.id);
15 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 20 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
16 // println!("To download: {:#?}", downloaded_versions);
17 let current_version_ids = match userlist_get_all_current_versions_with_mods( 21 let current_version_ids = match userlist_get_all_current_versions_with_mods(
18 config, 22 config,
19 String::from(&current_list.id), 23 String::from(&current_list.id),
@@ -54,6 +58,8 @@ pub async fn download(config: &Cfg, liststack: Vec<List>, clean: bool, delete_ol
54 current_list.clone(), 58 current_list.clone(),
55 config.clone(), 59 config.clone(),
56 get_raw_versions(&config.apis.modrinth, to_download).await, 60 get_raw_versions(&config.apis.modrinth, to_download).await,
61 &mp,
62 None
57 ) 63 )
58 .await?; 64 .await?;
59 } else { 65 } else {
diff --git a/src/commands/modification.rs b/src/commands/modification.rs
index 31931f8..d369c4b 100644
--- a/src/commands/modification.rs
+++ b/src/commands/modification.rs
@@ -1,6 +1,6 @@
1use std::{io::Write, collections::HashMap}; 1use std::{io::Write, collections::HashMap};
2 2
3use indicatif::{ProgressBar, ProgressStyle}; 3use indicatif::{ProgressBar, ProgressStyle, MultiProgress};
4 4
5use crate::{ 5use crate::{
6 config::Cfg, 6 config::Cfg,
@@ -11,16 +11,16 @@ use crate::{
11 error::{ErrorType, MLError, MLE}, 11 error::{ErrorType, MLError, MLE},
12 files::{delete_version, download_versions}, 12 files::{delete_version, download_versions},
13 modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, 13 modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version},
14 List, PROGRESS_CHARS, 14 List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_SPINNER,
15}; 15};
16 16
17#[derive(Debug, Clone)] 17#[derive(Debug)]
18pub struct AddMod { 18pub struct AddMod {
19 pub id: IDSelector, 19 pub id: IDSelector,
20 pub set_version: bool 20 pub set_version: bool
21} 21}
22 22
23#[derive(Debug, Clone, PartialEq, Eq)] 23#[derive(Debug, PartialEq, Eq)]
24pub enum IDSelector { 24pub enum IDSelector {
25 ModificationID(String), 25 ModificationID(String),
26 VersionID(String), 26 VersionID(String),
@@ -43,12 +43,11 @@ pub async fn mod_add(
43 list: List, 43 list: List,
44 direct_download: bool, 44 direct_download: bool,
45) -> MLE<()> { 45) -> MLE<()> {
46 let spinner_style = ProgressStyle::with_template("{spinner:.green}{msg}").unwrap();
47 let bar_style = ProgressStyle::with_template("{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]").unwrap().progress_chars(PROGRESS_CHARS);
48 46
49 // println!("Add mods to {}", list.id); 47 //TODO MultiProgress
50 // println!(" └Add mods:");
51 48
49 let spinner_style = ProgressStyle::with_template(STYLE_SPINNER).unwrap();
50 let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS);
52 let mut mod_ids: Vec<(String, bool)> = Vec::new(); 51 let mut mod_ids: Vec<(String, bool)> = Vec::new();
53 let mut ver_ids: Vec<(String, bool)> = Vec::new(); 52 let mut ver_ids: Vec<(String, bool)> = Vec::new();
54 53
@@ -153,7 +152,8 @@ pub async fn mod_add(
153 152
154 //Download all the added mods 153 //Download all the added mods
155 if direct_download { 154 if direct_download {
156 download_versions(list.clone(), config.clone(), downloadstack).await?; 155 let mp = MultiProgress::new();
156 download_versions(list.clone(), config.clone(), downloadstack, &mp, None).await?;
157 }; 157 };
158 158
159 Ok(()) 159 Ok(())
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 7482e43..bde6896 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -9,7 +9,7 @@ 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, PROGRESS_CHARS, 12 List, PROGRESS_CHARS, STYLE_BAR_POS,
13}; 13};
14 14
15pub async fn update( 15pub async fn update(
@@ -23,35 +23,32 @@ pub async fn update(
23 let mp = MultiProgress::new(); 23 let mp = MultiProgress::new();
24 24
25 let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); 25 let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap()));
26 let bar_style = ProgressStyle::with_template("{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]").unwrap().progress_chars(PROGRESS_CHARS); 26 let bar_style = ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS);
27 let spinner_style = ProgressStyle::with_template("{spinner:.green}{msg}").unwrap();
28 update_p.set_style(bar_style.clone()); 27 update_p.set_style(bar_style.clone());
29 update_p.set_message("Update"); 28 update_p.set_message("Update");
30 29
31 for current_list in liststack { 30 for current_list in liststack {
31 let list_p = mp.insert_before(&update_p, ProgressBar::new(2));
32 list_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS));
33 list_p.set_message(format!("Update {}", current_list.id));
32 34
33 // println!("Update mods in {}", current_list.id);
34 let mods = userlist_get_all_ids(config, &current_list.id)?; 35 let mods = userlist_get_all_ids(config, &current_list.id)?;
35 36
36 let list_p = mp.insert_before(&update_p, ProgressBar::new(mods.len().try_into().unwrap())); 37 let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap()));
37 list_p.set_style(bar_style.clone()); 38 list_u_p.set_style(bar_style.clone());
38 list_p.set_message(format!("Update {}", current_list.id)); 39 list_u_p.set_message(format!("Update {}", current_list.id));
39 40
40 let mut current_versions: Vec<(String, String)> = vec![]; 41 let mut current_versions: Vec<(String, String)> = vec![];
41 42
42 let mut updatestack: Vec<Version> = vec![]; 43 let mut updatestack: Vec<Version> = vec![];
43 44
44 for id in mods { 45 for id in mods {
45 let mod_p = mp.insert_before(&list_p, ProgressBar::new(1));
46 mod_p.set_style(spinner_style.clone());
47
48 let info = mods_get_info(config, &id)?; 46 let info = mods_get_info(config, &id)?;
49 mod_p.set_message(format!("Update {}", info.title)); 47 list_u_p.set_message(format!("Update {}", info.title));
50 // println!(" ├{}", info.title); 48
51 49 //Skip check if version is set
52 if userlist_get_set_version(config, &current_list.id, &id)? { 50 if userlist_get_set_version(config, &current_list.id, &id)? {
53 // println!(" │ └Set version, skipping update"); 51 list_u_p.inc(1);
54 list_p.inc(1);
55 continue; 52 continue;
56 } 53 }
57 54
@@ -59,15 +56,13 @@ pub async fn update(
59 let disable_version = 56 let disable_version =
60 userlist_get_current_version(config, &current_list.id, &id)?; 57 userlist_get_current_version(config, &current_list.id, &id)?;
61 58
62 mod_p.inc(1);
63
64 updatestack.push( 59 updatestack.push(
65 match specific_update( 60 match specific_update(
66 config, 61 config,
67 clean, 62 clean,
68 current_list.clone(), 63 current_list.clone(),
69 &id, 64 &id,
70 &mod_p 65 &list_u_p
71 ) 66 )
72 .await 67 .await
73 { 68 {
@@ -77,44 +72,55 @@ pub async fn update(
77 } 72 }
78 Err(e) => { 73 Err(e) => {
79 if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" { 74 if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" {
80 // println!(
81 // " │ └No new version found for the specified minecraft version"
82 // );
83 } else { 75 } else {
84 return Err(e); 76 return Err(e);
85 }; 77 };
86 list_p.inc(1); 78 list_u_p.inc(1);
87 continue; 79 continue;
88 } 80 }
89 }, 81 },
90 ); 82 );
91 list_p.inc(1); 83 list_u_p.inc(1);
92 } 84 }
93 85
94 list_p.finish_with_message(format!("Updated {}", current_list.id)); 86 list_u_p.finish_with_message(format!("Updated mods in {}", current_list.id));
87 list_p.inc(1);
95 88
96 if clean { 89 if clean {
97 update_p.set_message("Cleaning"); 90 list_p.set_message("Cleaning");
98 update_p.inc(1);
99 clean_list_dir(&current_list)?; 91 clean_list_dir(&current_list)?;
100 }; 92 };
101 93
102 if direct_download && !updatestack.is_empty() { 94 if direct_download && !updatestack.is_empty() {
103 download_versions(current_list.clone(), config.clone(), updatestack).await?; 95 download_versions(current_list.clone(), config.clone(), updatestack, &mp, Some(&list_p)).await?;
104 96
105 //Disable old versions 97 //Disable old versions
106 if !clean { 98 if !clean {
99 let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap()));
100 d_p.set_style(bar_style.clone());
107 for ver in current_versions { 101 for ver in current_versions {
108 if delete_old { 102 if delete_old {
109 println!(" └Delete version {}", ver.0); 103 d_p.set_message(format!("Delete version {}", ver.0));
104 d_p.inc(1);
110 delete_version(current_list.clone(), ver.0)?; 105 delete_version(current_list.clone(), ver.0)?;
111 } else if ver.0 != "NONE" { 106 } else if ver.0 != "NONE" {
112 println!(" └Disable version {}", ver.0); 107 d_p.set_message(format!("Disable version {}", ver.0));
108 d_p.inc(1);
113 disable_version(config, current_list.clone(), ver.0, ver.1)?; 109 disable_version(config, current_list.clone(), ver.0, ver.1)?;
114 }; 110 };
115 } 111 }
112
113 let del_msg = if delete_old {
114 "Deleted all old versions"
115 } else {
116 "Disabled all old versions"
117 };
118
119 d_p.finish_with_message(del_msg);
116 } 120 }
117 }; 121 };
122 list_p.inc(1);
123 list_p.finish_with_message(format!("Updated {}", current_list.id));
118 update_p.inc(1); 124 update_p.inc(1);
119 } 125 }
120 126
@@ -149,13 +155,7 @@ async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progre
149 { 155 {
150 let current_str = extract_current_version(applicable_versions.clone())?; 156 let current_str = extract_current_version(applicable_versions.clone())?;
151 157
152 if clean { 158 if !clean { progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title)); }
153 // println!("\t └Add version to downloadstack");
154 } else {
155 progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title));
156 // println!("\t └Get versions for specified minecraft versions");
157 // println!("\t └New current version: {}", current_str);
158 };
159 159
160 //get new versions 160 //get new versions
161 let current_ver = match applicable_versions 161 let current_ver = match applicable_versions
@@ -183,56 +183,5 @@ async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progre
183 return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")); 183 return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE"));
184 }; 184 };
185 185
186 //println!(" └✔️");
187 Ok(current[0].clone()) 186 Ok(current[0].clone())
188} 187}
189
190// #[tokio::test]
191// async fn download_updates_test() {
192// use crate::{
193// modrinth::{Hash, Version, VersionFile, VersionType},
194// List, Modloader,
195// };
196//
197// let config = Cfg::init().unwrap();
198// let current_list = List {
199// id: String::from("..."),
200// mc_version: String::from("..."),
201// modloader: Modloader::Fabric,
202// download_folder: String::from("./dev/tests/dl"),
203// };
204//
205// let versions = vec![Version {
206// id: "dEqtGnT9".to_string(),
207// project_id: "kYuIpRLv".to_string(),
208// author_id: "Qnt13hO8".to_string(),
209// featured: true,
210// name: "1.2.2-1.19 - Fabric".to_string(),
211// version_number: "1.2.2-1.19".to_string(),
212// changelog: None,
213// date_published: "2022-11-02T17:41:43.072267Z".to_string(),
214// downloads: 58,
215// version_type: VersionType::release,
216// files: vec![VersionFile {
217// hashes: Hash {
218// sha1: "fdc6dc39427fc92cc1d7ad8b275b5b83325e712b".to_string(),
219// sha512: "5b372f00d6e5d6a5ef225c3897826b9f6a2be5506905f7f71b9e939779765b41be6f2a9b029cfc752ad0751d0d2d5f8bb4544408df1363eebdde15641e99a849".to_string()
220// },
221// url: "https://cdn.modrinth.com/data/kYuIpRLv/versions/dEqtGnT9/waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(),
222// filename: "waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(),
223// primary: true,
224// size: 323176
225// }],
226// game_versions: vec![
227// "1.19".to_string(),
228// "1.19.1".to_string(),
229// "1.19.2".to_string()
230// ],
231// loaders: vec![
232// "fabric".to_string()
233// ]
234// }];
235// assert!(download_versions(current_list, config, versions)
236// .await
237// .is_ok())
238// }