diff options
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r-- | src/commands/download.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index b958bf3..7748d15 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions}; | 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}}; |
2 | use crate::{List, get_current_list, config::Cfg, input::Input}; | 2 | use crate::{List, get_current_list, config::Cfg, input::Input}; |
3 | 3 | ||
4 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 4 | pub async fn download(config: Cfg, input: Input) -> MLE<()> { |
5 | 5 | ||
6 | let mut liststack: Vec<List> = vec![]; | 6 | let mut liststack: Vec<List> = vec![]; |
7 | if input.all_lists { | 7 | if input.all_lists { |
@@ -18,7 +18,10 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro | |||
18 | for current_list in liststack { | 18 | for current_list in liststack { |
19 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 19 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; |
20 | println!("To download: {:#?}", downloaded_versions); | 20 | println!("To download: {:#?}", downloaded_versions); |
21 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; | 21 | let current_version_ids = match userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id)) { |
22 | Ok(i) => Ok(i), | ||
23 | Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), | ||
24 | }?; | ||
22 | 25 | ||
23 | let mut to_download: Vec<String> = vec![]; | 26 | let mut to_download: Vec<String> = vec![]; |
24 | //(mod_id, version_id) | 27 | //(mod_id, version_id) |
@@ -33,7 +36,7 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro | |||
33 | if current_download.is_none() || input.clean { | 36 | if current_download.is_none() || input.clean { |
34 | to_download.push(current_version); | 37 | to_download.push(current_version); |
35 | } else { | 38 | } else { |
36 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?; | 39 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG").unwrap(); |
37 | if ¤t_version != downloaded_version { | 40 | if ¤t_version != downloaded_version { |
38 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); | 41 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); |
39 | to_download.push(current_version); | 42 | to_download.push(current_version); |
@@ -41,17 +44,10 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro | |||
41 | } | 44 | } |
42 | } | 45 | } |
43 | 46 | ||
44 | if input.clean { | 47 | if input.clean { clean_list_dir(¤t_list)? }; |
45 | let dl_path = ¤t_list.download_folder; | ||
46 | println!("Cleaning {}", dl_path); | ||
47 | for entry in std::fs::read_dir(dl_path)? { | ||
48 | let entry = entry?; | ||
49 | std::fs::remove_file(entry.path())?; | ||
50 | } | ||
51 | } | ||
52 | 48 | ||
53 | if !to_download.is_empty() { | 49 | if !to_download.is_empty() { |
54 | download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; | 50 | download_versions(current_list.clone(), config.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; |
55 | } else { | 51 | } else { |
56 | println!("There are no new versions to download"); | 52 | println!("There are no new versions to download"); |
57 | } | 53 | } |