diff options
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r-- | src/commands/download.rs | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 2714630..9434591 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,10 +1,16 @@ | |||
1 | use 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}}; | 1 | use crate::{config::Cfg, get_current_list, List}; |
2 | use crate::{List, get_current_list, config::Cfg, input::Input}; | 2 | use crate::{ |
3 | 3 | db::{lists_get, lists_get_all_ids, userlist_get_all_current_versions_with_mods}, | |
4 | pub async fn download(config: Cfg, input: Input) -> MLE<()> { | 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 | }; | ||
5 | 10 | ||
11 | pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> { | ||
6 | let mut liststack: Vec<List> = vec![]; | 12 | let mut liststack: Vec<List> = vec![]; |
7 | if input.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())?; |
9 | for id in list_ids { | 15 | for id in list_ids { |
10 | liststack.push(lists_get(config.clone(), id)?); | 16 | liststack.push(lists_get(config.clone(), id)?); |
@@ -18,7 +24,10 @@ pub async fn download(config: Cfg, input: Input) -> MLE<()> { | |||
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(¤t_list.id)) { | 27 | let current_version_ids = match userlist_get_all_current_versions_with_mods( |
28 | config.clone(), | ||
29 | String::from(¤t_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 | }?; |
@@ -33,31 +42,40 @@ pub async fn download(config: Cfg, input: Input) -> MLE<()> { | |||
33 | 42 | ||
34 | let current_download = downloaded_versions.get(&mod_id); | 43 | let current_download = downloaded_versions.get(&mod_id); |
35 | 44 | ||
36 | if current_download.is_none() || input.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 ¤t_version != downloaded_version { | 51 | if ¤t_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 input.clean { clean_list_dir(¤t_list)? }; | 58 | if clean { |
59 | clean_list_dir(¤t_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 input.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 | } |