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.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 7321832..7af1066 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -15,7 +15,6 @@ use crate::{
15use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; 15use crate::{PROGRESS_CHARS, STYLE_BAR_POS};
16 16
17/// # Errors 17/// # Errors
18/// # Panics
19pub async fn download( 18pub async fn download(
20 config: &Cfg, 19 config: &Cfg,
21 liststack: Vec<List>, 20 liststack: Vec<List>,
@@ -23,29 +22,31 @@ pub async fn download(
23 delete_old: bool, 22 delete_old: bool,
24) -> MLE<()> { 23) -> MLE<()> {
25 let mp = MultiProgress::new(); 24 let mp = MultiProgress::new();
26 let download_p = 25 let download_p = mp.add(ProgressBar::new(
27 mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); 26 liststack
27 .len()
28 .try_into()
29 .map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?,
30 ));
28 download_p.set_style( 31 download_p.set_style(
29 ProgressStyle::with_template(STYLE_BAR_POS) 32 ProgressStyle::with_template(STYLE_BAR_POS)
30 .unwrap() 33 .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?
31 .progress_chars(PROGRESS_CHARS), 34 .progress_chars(PROGRESS_CHARS),
32 ); 35 );
33 36
34 for current_list in liststack { 37 for current_list in liststack {
35 download_p.set_message(format!("Download in {}", current_list.id)); 38 download_p.set_message(format!("Download in {}", current_list.id));
36 39
37 let downloaded_versions = 40 let downloaded_versions = get_downloaded_versions(&current_list)?;
38 get_downloaded_versions(&current_list)?;
39 let current_version_ids = 41 let current_version_ids =
40 match userlist_get_all_current_versions_with_mods( 42 match userlist_get_all_current_versions_with_mods(
41 config, 43 config,
42 &current_list.id, 44 &current_list.id,
43 ) { 45 ) {
44 Ok(i) => Ok(i), 46 Ok(i) => Ok(i),
45 Err(e) => Err(MLErr::new( 47 Err(e) => {
46 EType::DBError, 48 Err(MLErr::new(EType::DBError, e.to_string().as_str()))
47 e.to_string().as_str(), 49 }
48 )),
49 }?; 50 }?;
50 51
51 let mut to_download: Vec<String> = vec![]; 52 let mut to_download: Vec<String> = vec![];
@@ -62,8 +63,7 @@ pub async fn download(
62 to_download.push(current_version); 63 to_download.push(current_version);
63 } else { 64 } else {
64 let downloaded_version = current_download 65 let downloaded_version = current_download
65 .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") 66 .ok_or(MLErr::new(EType::Other, "IDK, WTF"))?;
66 .unwrap();
67 if &current_version != downloaded_version { 67 if &current_version != downloaded_version {
68 to_disable.push(( 68 to_disable.push((
69 mod_id.clone(), 69 mod_id.clone(),
@@ -87,7 +87,7 @@ pub async fn download(
87 download_versions( 87 download_versions(
88 current_list.clone(), 88 current_list.clone(),
89 config.clone(), 89 config.clone(),
90 get_raw_versions(&config.apis.modrinth, to_download).await, 90 get_raw_versions(&config.apis.modrinth, to_download).await?,
91 &mp, 91 &mp,
92 &download_p, 92 &download_p,
93 ) 93 )
@@ -95,13 +95,18 @@ pub async fn download(
95 } 95 }
96 96
97 if !to_disable.is_empty() { 97 if !to_disable.is_empty() {
98 let d_p = mp.insert_before( 98 let d_p =
99 &download_p, 99 mp.insert_before(
100 ProgressBar::new(to_disable.len().try_into().unwrap()), 100 &download_p,
101 ); 101 ProgressBar::new(to_disable.len().try_into().map_err(
102 |_| MLErr::new(EType::Other, "ListStackLen"),
103 )?),
104 );
102 d_p.set_style( 105 d_p.set_style(
103 ProgressStyle::with_template(STYLE_BAR_POS) 106 ProgressStyle::with_template(STYLE_BAR_POS)
104 .unwrap() 107 .map_err(|_| {
108 MLErr::new(EType::LibIndicatif, "template error")
109 })?
105 .progress_chars(PROGRESS_CHARS), 110 .progress_chars(PROGRESS_CHARS),
106 ); 111 );
107 for ver in to_disable { 112 for ver in to_disable {
@@ -112,12 +117,7 @@ pub async fn download(
112 } else { 117 } else {
113 d_p.set_message(format!("Disable version {}", ver.1)); 118 d_p.set_message(format!("Disable version {}", ver.1));
114 d_p.inc(1); 119 d_p.inc(1);
115 disable_version( 120 disable_version(config, &current_list, ver.1, ver.0)?;
116 config,
117 &current_list,
118 ver.1,
119 ver.0,
120 )?;
121 }; 121 };
122 } 122 }
123 123