summaryrefslogtreecommitdiff
path: root/src/commands/download.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r--src/commands/download.rs44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 269d5d3..bb946b0 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -1,10 +1,11 @@
1use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 1use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
2 2
3use crate::apis::modrinth::get_raw_versions; 3use crate::apis::modrinth::get_raw_versions;
4use crate::errors::Error;
4use crate::{config::Cfg, List}; 5use crate::{config::Cfg, List};
5use crate::{ 6use crate::{
6 db::userlist_get_all_current_versions_with_mods, 7 db::userlist_get_all_current_versions_with_mods,
7 error::{EType, MLErr, MLE}, 8 errors::MLE,
8 files::{ 9 files::{
9 clean_list_dir, delete_version, disable_version, download_versions, 10 clean_list_dir, delete_version, disable_version, download_versions,
10 get_downloaded_versions, 11 get_downloaded_versions,
@@ -20,20 +21,22 @@ pub async fn download(
20 delete_old: bool, 21 delete_old: bool,
21) -> MLE<()> { 22) -> MLE<()> {
22 let mp = MultiProgress::new(); 23 let mp = MultiProgress::new();
23 let download_p = mp.add(ProgressBar::new( 24 let download_p = mp.add(ProgressBar::new(liststack.len().try_into()?));
24 liststack
25 .len()
26 .try_into()
27 .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?,
28 ));
29 download_p.set_style( 25 download_p.set_style(
30 ProgressStyle::with_template(STYLE_BAR_POS) 26 ProgressStyle::with_template(STYLE_BAR_POS)?
31 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?
32 .progress_chars(PROGRESS_CHARS), 27 .progress_chars(PROGRESS_CHARS),
33 ); 28 );
34 29
35 for current_list in liststack { 30 for current_list in liststack {
36 download_list(config, mp.clone(), download_p.clone(), current_list, clean, delete_old).await?; 31 download_list(
32 config,
33 mp.clone(),
34 download_p.clone(),
35 current_list,
36 clean,
37 delete_old,
38 )
39 .await?;
37 } 40 }
38 41
39 download_p.finish_with_message("Downloaded all lists"); 42 download_p.finish_with_message("Downloaded all lists");
@@ -52,13 +55,8 @@ async fn download_list(
52 download_p.set_message(format!("Download in {}", current_list.id)); 55 download_p.set_message(format!("Download in {}", current_list.id));
53 56
54 let downloaded_versions = get_downloaded_versions(&current_list)?; 57 let downloaded_versions = get_downloaded_versions(&current_list)?;
55 let current_version_ids = match userlist_get_all_current_versions_with_mods( 58 let current_version_ids =
56 config, 59 userlist_get_all_current_versions_with_mods(config, &current_list.id)?;
57 &current_list.id,
58 ) {
59 Ok(i) => Ok(i),
60 Err(e) => Err(MLErr::new(EType::DBError, e.to_string().as_str())),
61 }?;
62 60
63 let mut to_download: Vec<String> = vec![]; 61 let mut to_download: Vec<String> = vec![];
64 //(mod_id, version_id) 62 //(mod_id, version_id)
@@ -74,7 +72,7 @@ async fn download_list(
74 to_download.push(current_version); 72 to_download.push(current_version);
75 } else { 73 } else {
76 let downloaded_version = 74 let downloaded_version =
77 current_download.ok_or(MLErr::new(EType::Other, "IDK, WTF"))?; 75 current_download.ok_or(Error::NoDownload)?;
78 if &current_version != downloaded_version { 76 if &current_version != downloaded_version {
79 to_disable 77 to_disable
80 .push((mod_id.clone(), String::from(downloaded_version))); 78 .push((mod_id.clone(), String::from(downloaded_version)));
@@ -106,16 +104,10 @@ async fn download_list(
106 if !to_disable.is_empty() { 104 if !to_disable.is_empty() {
107 let d_p = mp.insert_before( 105 let d_p = mp.insert_before(
108 &download_p, 106 &download_p,
109 ProgressBar::new( 107 ProgressBar::new(to_disable.len().try_into()?),
110 to_disable
111 .len()
112 .try_into()
113 .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?,
114 ),
115 ); 108 );
116 d_p.set_style( 109 d_p.set_style(
117 ProgressStyle::with_template(STYLE_BAR_POS) 110 ProgressStyle::with_template(STYLE_BAR_POS)?
118 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?
119 .progress_chars(PROGRESS_CHARS), 111 .progress_chars(PROGRESS_CHARS),
120 ); 112 );
121 for ver in to_disable { 113 for ver in to_disable {