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.rs38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 4baecee..9434591 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -1,8 +1,14 @@
1use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version, clean_list_dir}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions, error::{MLE, ErrorType, MLError}}; 1use crate::{config::Cfg, get_current_list, List};
2use crate::{List, get_current_list, config::Cfg}; 2use crate::{
3 db::{lists_get, lists_get_all_ids, userlist_get_all_current_versions_with_mods},
4 error::{ErrorType, MLError, MLE},
5 files::{
6 clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions,
7 },
8 modrinth::get_raw_versions,
9};
3 10
4pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> { 11pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> {
5
6 let mut liststack: Vec<List> = vec![]; 12 let mut liststack: Vec<List> = vec![];
7 if all_lists { 13 if all_lists {
8 let list_ids = lists_get_all_ids(config.clone())?; 14 let list_ids = lists_get_all_ids(config.clone())?;
@@ -18,7 +24,10 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo
18 for current_list in liststack { 24 for current_list in liststack {
19 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 25 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
20 println!("To download: {:#?}", downloaded_versions); 26 println!("To download: {:#?}", downloaded_versions);
21 let current_version_ids = match userlist_get_all_current_versions_with_mods(config.clone(), String::from(&current_list.id)) { 27 let current_version_ids = match userlist_get_all_current_versions_with_mods(
28 config.clone(),
29 String::from(&current_list.id),
30 ) {
22 Ok(i) => Ok(i), 31 Ok(i) => Ok(i),
23 Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), 32 Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())),
24 }?; 33 }?;
@@ -36,28 +45,37 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo
36 if current_download.is_none() || clean { 45 if current_download.is_none() || clean {
37 to_download.push(current_version); 46 to_download.push(current_version);
38 } else { 47 } else {
39 let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG").unwrap(); 48 let downloaded_version = current_download
49 .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")
50 .unwrap();
40 if &current_version != downloaded_version { 51 if &current_version != downloaded_version {
41 to_disable.push((mod_id.clone(), String::from(downloaded_version))); 52 to_disable.push((mod_id.clone(), String::from(downloaded_version)));
42 to_download.push(current_version); 53 to_download.push(current_version);
43 } 54 }
44 } 55 }
45 } 56 }
46 57
47 if clean { clean_list_dir(&current_list)? }; 58 if clean {
59 clean_list_dir(&current_list)?
60 };
48 61
49 if !to_download.is_empty() { 62 if !to_download.is_empty() {
50 download_versions(current_list.clone(), config.clone(), get_raw_versions(&config.apis.modrinth, to_download).await).await?; 63 download_versions(
64 current_list.clone(),
65 config.clone(),
66 get_raw_versions(&config.apis.modrinth, to_download).await,
67 )
68 .await?;
51 } else { 69 } else {
52 println!("There are no new versions to download"); 70 println!("There are no new versions to download");
53 } 71 }
54 72
55 if !to_disable.is_empty() { 73 if !to_disable.is_empty() {
56 for ver in to_disable { 74 for ver in to_disable {
57 if delete_old { 75 if delete_old {
58 println!("Deleting version {} for mod {}", ver.1, ver.0); 76 println!("Deleting version {} for mod {}", ver.1, ver.0);
59 delete_version(current_list.clone(), ver.1)?; 77 delete_version(current_list.clone(), ver.1)?;
60 } else { 78 } else {
61 disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; 79 disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?;
62 }; 80 };
63 } 81 }