diff options
Diffstat (limited to 'src/commands/download.rs')
-rw-r--r-- | src/commands/download.rs | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 421f058..9f70499 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,50 +1,51 @@ | |||
1 | use crate::{files::get_downloaded_versions, db::{userlist_get_all_applicable_versions_with_mods, userlist_get_all_current_versions_with_mods}}; | 1 | use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version}, db::userlist_get_all_current_versions_with_mods, modrinth::get_raw_versions}; |
2 | #[allow(unused_imports)] | 2 | #[allow(unused_imports)] |
3 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; | 3 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
4 | 4 | ||
5 | pub async fn download(config: Cfg, _input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
7 | let current_list = get_current_list(config.clone())?; | 7 | let current_list = get_current_list(config.clone())?; |
8 | 8 | ||
9 | println!("NO IMPLEMENTATION FOR DOWNLOAD YET"); | ||
10 | |||
11 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 9 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; |
12 | println!("DL: {:?}", downloaded_versions); | ||
13 | |||
14 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; | 10 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; |
15 | println!("CU: {:?}", current_version_ids); | ||
16 | 11 | ||
17 | let applicable_version_ids = userlist_get_all_applicable_versions_with_mods(config, current_list.id)?; | 12 | let mut to_download: Vec<String> = vec![]; |
18 | println!("AP: {:?}", applicable_version_ids); | 13 | //(mod_id, version_id) |
19 | 14 | let mut to_disable: Vec<(String, String)> = vec![]; | |
20 | /* | ||
21 | let list = get_current_list(config.clone())?; | ||
22 | 15 | ||
23 | let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; | 16 | for version in current_version_ids { |
17 | let mod_id = version.0; | ||
18 | let current_version = version.1; | ||
24 | 19 | ||
25 | download_links(config, input, list, links).await?; | 20 | let current_download = downloaded_versions.get(&mod_id); |
26 | */ | ||
27 | Ok(()) | ||
28 | } | ||
29 | 21 | ||
30 | #[allow(dead_code)] | 22 | if current_download.is_none() { |
31 | async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { | 23 | to_download.push(current_version); |
32 | println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET"); | 24 | } else { |
33 | //TODO copy dl from update if possible | 25 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?; |
34 | /* | 26 | if ¤t_version != downloaded_version { |
35 | let dl_path = String::from(¤t_list.download_folder); | 27 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); |
36 | 28 | to_download.push(current_version); | |
37 | if input.clean { | 29 | } |
38 | let dl_path = ¤t_list.download_folder; | 30 | } |
39 | println!("Cleaning {}", dl_path); | 31 | } |
40 | for entry in std::fs::read_dir(dl_path)? { | 32 | |
41 | let entry = entry?; | 33 | if !to_download.is_empty() { |
42 | std::fs::remove_file(entry.path())?; | 34 | download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; |
35 | } else { | ||
36 | println!("There are no new versions to download"); | ||
37 | } | ||
38 | |||
39 | if !to_disable.is_empty() { | ||
40 | for ver in to_disable { | ||
41 | if input.delete_old { | ||
42 | println!("Deleting version {} for mod {}", ver.1, ver.0); | ||
43 | delete_version(current_list.clone(), ver.1)?; | ||
44 | } else { | ||
45 | disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; | ||
46 | }; | ||
43 | } | 47 | } |
44 | } | 48 | } |
45 | */ | ||
46 | 49 | ||
47 | Ok(String::new()) | 50 | Ok(()) |
48 | } | 51 | } |
49 | |||
50 | |||