summaryrefslogtreecommitdiff
path: root/src/commands/download.rs
diff options
context:
space:
mode:
authorFxQnLr <[email protected]>2023-01-29 14:14:43 +0100
committerGitHub <[email protected]>2023-01-29 14:14:43 +0100
commit35d9e091b9b6f68e51a79c1a10e0a95cd2ae974e (patch)
tree68a63f39a5bf6241e4ca9499d03ea148ec9737c4 /src/commands/download.rs
parent8f3c77986b36d7653fd44e16ef986f0ad284e0c4 (diff)
parentd7d0c904bff665ab5c8355f2381a0628ebbf7a30 (diff)
downloadmodlist-35d9e091b9b6f68e51a79c1a10e0a95cd2ae974e.tar
modlist-35d9e091b9b6f68e51a79c1a10e0a95cd2ae974e.tar.gz
modlist-35d9e091b9b6f68e51a79c1a10e0a95cd2ae974e.zip
Merge pull request #3 from FxQnLr/new_input
New input, fuck it
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r--src/commands/download.rs22
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 @@
1use 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}; 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}};
2use crate::{List, get_current_list, config::Cfg, input::Input}; 2use crate::{List, get_current_list, config::Cfg, input::Input};
3 3
4pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { 4pub 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(&current_list.id))?; 21 let current_version_ids = match userlist_get_all_current_versions_with_mods(config.clone(), String::from(&current_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 &current_version != downloaded_version { 40 if &current_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(&current_list)? };
45 let dl_path = &current_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 }