diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | planmodlist.xopp | bin | 197609 -> 197651 bytes | |||
-rw-r--r-- | src/commands/download.rs | 19 | ||||
-rw-r--r-- | src/input.rs | 4 |
5 files changed, 18 insertions, 9 deletions
@@ -647,7 +647,7 @@ dependencies = [ | |||
647 | 647 | ||
648 | [[package]] | 648 | [[package]] |
649 | name = "modlist" | 649 | name = "modlist" |
650 | version = "0.2.1" | 650 | version = "0.2.2" |
651 | dependencies = [ | 651 | dependencies = [ |
652 | "chrono", | 652 | "chrono", |
653 | "config", | 653 | "config", |
@@ -1,6 +1,6 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "modlist" | 2 | name = "modlist" |
3 | version = "0.2.1" | 3 | version = "0.2.2" |
4 | edition = "2021" | 4 | edition = "2021" |
5 | 5 | ||
6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
diff --git a/planmodlist.xopp b/planmodlist.xopp index 7dbf105..a1fd2fa 100644 --- a/planmodlist.xopp +++ b/planmodlist.xopp | |||
Binary files differ | |||
diff --git a/src/commands/download.rs b/src/commands/download.rs index 993294b..db0fc93 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -4,22 +4,31 @@ use reqwest::Client; | |||
4 | 4 | ||
5 | use futures_util::StreamExt; | 5 | use futures_util::StreamExt; |
6 | 6 | ||
7 | use crate::{get_current_list, config::Cfg, db::userlist_get_all_downloads}; | 7 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; |
8 | 8 | ||
9 | pub async fn download(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 9 | pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
10 | let list = get_current_list(config.clone())?; | 10 | let list = get_current_list(config.clone())?; |
11 | 11 | ||
12 | let links = userlist_get_all_downloads(config.clone(), list.id)?; | 12 | let links = userlist_get_all_downloads(config.clone(), list.clone().id)?; |
13 | 13 | ||
14 | download_links(config, links).await?; | 14 | download_links(config, input, list, links).await?; |
15 | 15 | ||
16 | Ok(()) | 16 | Ok(()) |
17 | } | 17 | } |
18 | 18 | ||
19 | async fn download_links(config: Cfg, links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { | 19 | async fn download_links(config: Cfg, input: Input, current_list: List, links: Vec<String>) -> Result<String, Box<dyn std::error::Error>> { |
20 | 20 | ||
21 | let dl_path = String::from(&config.downloads); | 21 | let dl_path = String::from(&config.downloads); |
22 | 22 | ||
23 | if input.clean { | ||
24 | let dl_path = ¤t_list.download_folder; | ||
25 | println!("Cleaning {}", dl_path); | ||
26 | for entry in std::fs::read_dir(dl_path)? { | ||
27 | let entry = entry?; | ||
28 | std::fs::remove_file(entry.path())?; | ||
29 | } | ||
30 | } | ||
31 | |||
23 | for link in links { | 32 | for link in links { |
24 | let filename = link.split('/').last().unwrap(); | 33 | let filename = link.split('/').last().unwrap(); |
25 | let dl_path_file = format!("{}/{}", config.downloads, filename); | 34 | let dl_path_file = format!("{}/{}", config.downloads, filename); |
diff --git a/src/input.rs b/src/input.rs index 109fa0c..19aa2c2 100644 --- a/src/input.rs +++ b/src/input.rs | |||
@@ -122,7 +122,7 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
122 | setup(config).await | 122 | setup(config).await |
123 | }, | 123 | }, |
124 | Cmd::Download => { | 124 | Cmd::Download => { |
125 | download(config).await | 125 | download(config, input).await |
126 | } | 126 | } |
127 | } | 127 | } |
128 | } | 128 | } |
@@ -130,6 +130,6 @@ pub async fn get_input(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
130 | #[test] | 130 | #[test] |
131 | fn input_from() { | 131 | fn input_from() { |
132 | let string = "lis add test 1.19.2 fabric"; | 132 | let string = "lis 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 }; | 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 }; |
134 | assert_eq!(Input::from(string).unwrap(), input); | 134 | assert_eq!(Input::from(string).unwrap(), input); |
135 | } | 135 | } |