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 | |
parent | c00673fd0e01d1438798dbb1635a761a76a2b559 (diff) | |
download | modlist-d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca.tar modlist-d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca.tar.gz modlist-d8cb7bc5f9c2e01c82f954427a60da6eaf0610ca.zip |
added direct download
-rw-r--r-- | data.db | bin | 24576 -> 16384 bytes | |||
-rw-r--r-- | src/commands/download.rs | 8 | ||||
-rw-r--r-- | src/commands/update.rs | 88 | ||||
-rw-r--r-- | src/input.rs | 15 |
4 files changed, 61 insertions, 50 deletions
Binary files differ | |||
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 | } |
diff --git a/src/input.rs b/src/input.rs index 0b616d4..0946971 100644 --- a/src/input.rs +++ b/src/input.rs | |||
@@ -7,18 +7,16 @@ pub struct Input { | |||
7 | pub subcommand: Option<Subcmd>, | 7 | pub subcommand: Option<Subcmd>, |
8 | pub args: Option<Vec<String>>, | 8 | pub args: Option<Vec<String>>, |
9 | pub direct_download: bool, | 9 | pub direct_download: bool, |
10 | pub force_download: bool, | ||
11 | pub all_lists: bool, | 10 | pub all_lists: bool, |
12 | pub delete_old: bool, | 11 | pub delete_old: bool, |
13 | pub clean: bool, | 12 | pub clean: bool, |
14 | } | 13 | } |
15 | 14 | ||
16 | impl Input { | 15 | impl Input { |
17 | pub fn from(string: &str) -> MLE<Self> { | 16 | fn from(string: &str) -> MLE<Self> { |
18 | let mut split: Vec<&str> = string.split(' ').collect(); | 17 | let mut split: Vec<&str> = string.split(' ').collect(); |
19 | 18 | ||
20 | let mut direct_download = false; | 19 | let mut direct_download = false; |
21 | let mut force_download = false; | ||
22 | let mut all_lists = false; | 20 | let mut all_lists = false; |
23 | let mut delete_old = false; | 21 | let mut delete_old = false; |
24 | let mut clean = false; | 22 | let mut clean = false; |
@@ -27,9 +25,8 @@ impl Input { | |||
27 | if input.starts_with("--") { | 25 | if input.starts_with("--") { |
28 | match input { | 26 | match input { |
29 | "--direct-download" => direct_download = true, | 27 | "--direct-download" => direct_download = true, |
30 | "--force-download" => force_download = true, | 28 | "--all-lists" => all_lists = true, |
31 | "--all_lists" => all_lists = true, | 29 | "--delete-old" => delete_old = true, |
32 | "--delete_old" => delete_old = true, | ||
33 | "--clean" => clean = true, | 30 | "--clean" => clean = true, |
34 | _ => continue, | 31 | _ => continue, |
35 | } | 32 | } |
@@ -54,7 +51,7 @@ impl Input { | |||
54 | } | 51 | } |
55 | }; | 52 | }; |
56 | 53 | ||
57 | Ok(Self { command, subcommand, args, direct_download, force_download, all_lists, delete_old, clean }) | 54 | Ok(Self { command, subcommand, args, direct_download, all_lists, delete_old, clean }) |
58 | } | 55 | } |
59 | } | 56 | } |
60 | 57 | ||
@@ -68,7 +65,7 @@ pub enum Cmd { | |||
68 | } | 65 | } |
69 | 66 | ||
70 | impl Cmd { | 67 | impl Cmd { |
71 | pub fn from(string: &str) -> MLE<Self> { | 68 | fn from(string: &str) -> MLE<Self> { |
72 | let cmd = match string { | 69 | let cmd = match string { |
73 | "mod" => Self::Mod, | 70 | "mod" => Self::Mod, |
74 | "list" => Self::List, | 71 | "list" => Self::List, |
@@ -130,6 +127,6 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
130 | #[test] | 127 | #[test] |
131 | fn input_from() { | 128 | fn input_from() { |
132 | let string = "list add test 1.19.2 fabric"; | 129 | let string = "list add test 1.19.2 fabric"; |
133 | let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), force_download: false, direct_download: false, all_lists: false, clean: false, delete_old: false }; | 130 | let input = Input{ command: Cmd::List, subcommand: Some(Subcmd::Add), args: Some(vec![String::from("test"), String::from("1.19.2"), String::from("fabric")]), direct_download: false, all_lists: false, clean: false, delete_old: false }; |
134 | assert_eq!(Input::from(string).unwrap(), input); | 131 | assert_eq!(Input::from(string).unwrap(), input); |
135 | } | 132 | } |