diff options
author | FxQnLr <[email protected]> | 2022-11-25 15:52:20 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2022-11-25 15:52:20 +0100 |
commit | d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca (patch) | |
tree | dcb68d55e52f71dbac6d9c10c9a09a8b0cab9c85 /src/commands | |
parent | c00673fd0e01d1438798dbb1635a761a76a2b559 (diff) | |
download | modlist-d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca.tar modlist-d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca.tar.gz modlist-d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca.zip |
added direct download
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/download.rs | 8 | ||||
-rw-r--r-- | src/commands/update.rs | 88 |
2 files changed, 55 insertions, 41 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 82d6b02..13ba0e1 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,15 +1,19 @@ | |||
1 | #[allow(unused_imports)] | ||
1 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; | 2 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
2 | 3 | ||
3 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 4 | pub async fn download(_config: Cfg, _input: Input) -> Result<(), Box<dyn std::error::Error>> { |
5 | println!("NO IMPLEMENTATION FOR DOWNLOAD YET"); | ||
6 | /* | ||
4 | let list = get_current_list(config.clone())?; | 7 | let list = get_current_list(config.clone())?; |
5 | 8 | ||
6 | let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; | 9 | let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; |
7 | 10 | ||
8 | download_links(config, input, list, links).await?; | 11 | download_links(config, input, list, links).await?; |
9 | 12 | */ | |
10 | Ok(()) | 13 | Ok(()) |
11 | } | 14 | } |
12 | 15 | ||
16 | #[allow(dead_code)] | ||
13 | async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { | 17 | async fn download_links(_config: Cfg, _input: Input, _current_list: List, _links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { |
14 | println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET"); | 18 | println!("NO DL IMPLEMENTATION FOR DOWNLOAD YET"); |
15 | //TODO copy dl from update if possible | 19 | //TODO copy dl from update if possible |
diff --git a/src/commands/update.rs b/src/commands/update.rs index eba5e91..42d19aa 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -1,50 +1,60 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions}, List, input::Input, download_file}; | 3 | use crate::{config::Cfg, modrinth::{projects, Project, versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, mods_get_versions, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get}, List, input::Input, download_file}; |
4 | 4 | ||
5 | pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | |||
7 | let current_list = get_current_list(config.clone())?; | ||
8 | |||
9 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; | ||
10 | |||
11 | let mut versions = mods_get_versions(config.clone(), mods.clone())?; | ||
12 | versions.sort_by_key(|ver| ver.mod_id.clone()); | ||
13 | |||
14 | let mut projects = projects(String::from(&config.apis.modrinth), mods).await; | ||
15 | projects.sort_by_key(|pro| pro.id.clone()); | ||
16 | 6 | ||
17 | let mut updatestack: Vec<Version> = vec![]; | 7 | let mut liststack: Vec<List> = vec![]; |
18 | for (index, project) in projects.into_iter().enumerate() { | 8 | if input.all_lists { |
19 | //Get versions for project and check if they match up | 9 | let list_ids = lists_get_all_ids(config.clone())?; |
20 | let current_version = &versions[index]; | 10 | for id in list_ids { |
21 | let p_id = String::from(&project.id); | 11 | liststack.push(lists_get(config.clone(), id)?); |
22 | let v_id = ¤t_version.mod_id; | 12 | } |
23 | if &p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "SORTING_ERROR"))) }; | 13 | } else { |
24 | 14 | liststack.push(get_current_list(config.clone())?) | |
25 | 15 | } | |
26 | //Adding to stack if not the same versions in the list OR if clean == true | 16 | |
27 | if input.clone().clean || (project.versions.join("|") != current_version.versions) { | 17 | for current_list in liststack { |
28 | updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { | 18 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; |
29 | Ok(ver) => ver, | 19 | |
30 | //TODO handle errors (only continue on "NO_UPDATE_AVAILABLE") | 20 | let mut versions = mods_get_versions(config.clone(), mods.clone())?; |
31 | Err(_) => { println!("({}) No new version found for the specified minecraft version", project.title); continue; }, | 21 | versions.sort_by_key(|ver| ver.mod_id.clone()); |
32 | }); | 22 | |
33 | } else { | 23 | let mut projects = projects(String::from(&config.apis.modrinth), mods).await; |
34 | println!("({}) No new version found", project.title); | 24 | projects.sort_by_key(|pro| pro.id.clone()); |
25 | |||
26 | let mut updatestack: Vec<Version> = vec![]; | ||
27 | for (index, project) in projects.into_iter().enumerate() { | ||
28 | //Get versions for project and check if they match up | ||
29 | let current_version = &versions[index]; | ||
30 | let p_id = String::from(&project.id); | ||
31 | let v_id = ¤t_version.mod_id; | ||
32 | if &p_id != v_id { return Err(Box::new(Error::new(ErrorKind::Other, "SORTING_ERROR"))) }; | ||
33 | |||
34 | |||
35 | //Adding to stack if not the same versions in the list OR if clean == true | ||
36 | if input.clone().clean || (project.versions.join("|") != current_version.versions) { | ||
37 | updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { | ||
38 | Ok(ver) => ver, | ||
39 | //TODO handle errors (only continue on "NO_UPDATE_AVAILABLE") | ||
40 | Err(_) => { println!("({}) No new version found for the specified minecraft version", project.title); continue; }, | ||
41 | }); | ||
42 | } else { | ||
43 | println!("({}) No new version found", project.title); | ||
44 | }; | ||
35 | }; | 45 | }; |
36 | }; | 46 | |
37 | 47 | if input.clean { | |
38 | if input.clean { | 48 | let dl_path = ¤t_list.download_folder; |
39 | let dl_path = ¤t_list.download_folder; | 49 | println!("Cleaning {}", dl_path); |
40 | println!("Cleaning {}", dl_path); | 50 | for entry in std::fs::read_dir(dl_path)? { |
41 | for entry in std::fs::read_dir(dl_path)? { | 51 | let entry = entry?; |
42 | let entry = entry?; | 52 | std::fs::remove_file(entry.path())?; |
43 | std::fs::remove_file(entry.path())?; | 53 | } |
44 | } | 54 | } |
55 | |||
56 | if input.direct_download { download_updates(current_list, updatestack).await?; }; | ||
45 | } | 57 | } |
46 | |||
47 | if input.direct_download { download_updates(current_list, updatestack).await?; }; | ||
48 | 58 | ||
49 | Ok(()) | 59 | Ok(()) |
50 | } | 60 | } |