diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/download.rs | 90 | ||||
-rw-r--r-- | src/commands/io.rs | 12 | ||||
-rw-r--r-- | src/commands/list.rs | 3 | ||||
-rw-r--r-- | src/commands/mod.rs | 2 | ||||
-rw-r--r-- | src/commands/update.rs | 2 |
5 files changed, 73 insertions, 36 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs index 9f70499..0f9011c 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs | |||
@@ -1,49 +1,69 @@ | |||
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}; | 1 | use 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}; |
2 | #[allow(unused_imports)] | 2 | use crate::{List, get_current_list, config::Cfg, input::Input}; |
3 | use crate::{List, get_current_list, config::Cfg, db::userlist_get_all_downloads, input::Input}; | ||
4 | 3 | ||
5 | 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>> { |
6 | 5 | ||
7 | let current_list = get_current_list(config.clone())?; | 6 | let mut liststack: Vec<List> = vec![]; |
7 | if input.all_lists { | ||
8 | let list_ids = lists_get_all_ids(config.clone())?; | ||
9 | for id in list_ids { | ||
10 | liststack.push(lists_get(config.clone(), id)?); | ||
11 | } | ||
12 | } else { | ||
13 | let current = get_current_list(config.clone())?; | ||
14 | println!("Checking for updates of mods in {}", current.id); | ||
15 | liststack.push(current) | ||
16 | } | ||
8 | 17 | ||
9 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; | 18 | for current_list in liststack { |
10 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; | 19 | let downloaded_versions = get_downloaded_versions(current_list.clone())?; |
20 | let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id))?; | ||
11 | 21 | ||
12 | let mut to_download: Vec<String> = vec![]; | 22 | let mut to_download: Vec<String> = vec![]; |
13 | //(mod_id, version_id) | 23 | //(mod_id, version_id) |
14 | let mut to_disable: Vec<(String, String)> = vec![]; | 24 | let mut to_disable: Vec<(String, String)> = vec![]; |
15 | 25 | ||
16 | for version in current_version_ids { | 26 | for version in current_version_ids { |
17 | let mod_id = version.0; | 27 | let mod_id = version.0; |
18 | let current_version = version.1; | 28 | let current_version = version.1; |
19 | 29 | ||
20 | let current_download = downloaded_versions.get(&mod_id); | 30 | let current_download = downloaded_versions.get(&mod_id); |
21 | 31 | ||
22 | if current_download.is_none() { | 32 | if current_download.is_none() || input.clean { |
23 | to_download.push(current_version); | ||
24 | } else { | ||
25 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?; | ||
26 | if ¤t_version != downloaded_version { | ||
27 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); | ||
28 | to_download.push(current_version); | 33 | to_download.push(current_version); |
34 | } else { | ||
35 | let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG")?; | ||
36 | if ¤t_version != downloaded_version { | ||
37 | to_disable.push((mod_id.clone(), String::from(downloaded_version))); | ||
38 | to_download.push(current_version); | ||
39 | } | ||
29 | } | 40 | } |
30 | } | 41 | } |
31 | } | 42 | |
32 | 43 | if input.clean { | |
33 | if !to_download.is_empty() { | 44 | let dl_path = ¤t_list.download_folder; |
34 | download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; | 45 | println!("Cleaning {}", dl_path); |
35 | } else { | 46 | for entry in std::fs::read_dir(dl_path)? { |
36 | println!("There are no new versions to download"); | 47 | let entry = entry?; |
37 | } | 48 | std::fs::remove_file(entry.path())?; |
38 | 49 | } | |
39 | if !to_disable.is_empty() { | 50 | } |
40 | for ver in to_disable { | 51 | |
41 | if input.delete_old { | 52 | if !to_download.is_empty() { |
42 | println!("Deleting version {} for mod {}", ver.1, ver.0); | 53 | download_versions(current_list.clone(), get_raw_versions(String::from(&config.apis.modrinth), to_download).await).await?; |
43 | delete_version(current_list.clone(), ver.1)?; | 54 | } else { |
44 | } else { | 55 | println!("There are no new versions to download"); |
45 | disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; | 56 | } |
46 | }; | 57 | |
58 | if !to_disable.is_empty() { | ||
59 | for ver in to_disable { | ||
60 | if input.delete_old { | ||
61 | println!("Deleting version {} for mod {}", ver.1, ver.0); | ||
62 | delete_version(current_list.clone(), ver.1)?; | ||
63 | } else { | ||
64 | disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; | ||
65 | }; | ||
66 | } | ||
47 | } | 67 | } |
48 | } | 68 | } |
49 | 69 | ||
diff --git a/src/commands/io.rs b/src/commands/io.rs new file mode 100644 index 0000000..dc1f408 --- /dev/null +++ b/src/commands/io.rs | |||
@@ -0,0 +1,12 @@ | |||
1 | use crate::{input::{Input, Subcmd}, config::Cfg}; | ||
2 | |||
3 | pub fn io(_config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | ||
4 | |||
5 | match input.subcommand.ok_or("INVALID_INPUT")? { | ||
6 | Subcmd::Export => {}, | ||
7 | Subcmd::Import => {}, | ||
8 | _ => {}, | ||
9 | } | ||
10 | |||
11 | Ok(()) | ||
12 | } | ||
diff --git a/src/commands/list.rs b/src/commands/list.rs index 76965df..096ce65 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs | |||
@@ -21,6 +21,9 @@ pub fn list(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> | |||
21 | }, | 21 | }, |
22 | Subcmd::Remove => { | 22 | Subcmd::Remove => { |
23 | remove(config, input.args.ok_or("")?) | 23 | remove(config, input.args.ok_or("")?) |
24 | }, | ||
25 | _ => { | ||
26 | Err(Box::new(Error::new(ErrorKind::InvalidInput, "WRONG_SUBCOMMAND"))) | ||
24 | } | 27 | } |
25 | } | 28 | } |
26 | } | 29 | } |
diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 20badcb..0d5bd00 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs | |||
@@ -3,9 +3,11 @@ pub mod list; | |||
3 | pub mod update; | 3 | pub mod update; |
4 | pub mod setup; | 4 | pub mod setup; |
5 | pub mod download; | 5 | pub mod download; |
6 | pub mod io; | ||
6 | 7 | ||
7 | pub use modification::*; | 8 | pub use modification::*; |
8 | pub use list::*; | 9 | pub use list::*; |
9 | pub use update::*; | 10 | pub use update::*; |
10 | pub use setup::*; | 11 | pub use setup::*; |
11 | pub use download::*; | 12 | pub use download::*; |
13 | pub use io::*; | ||
diff --git a/src/commands/update.rs b/src/commands/update.rs index 498b6a9..0895efb 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -41,7 +41,7 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
41 | let version_db_string = project.versions.join("|"); | 41 | let version_db_string = project.versions.join("|"); |
42 | 42 | ||
43 | //Adding to stack if not the same versions in the list OR if clean == true | 43 | //Adding to stack if not the same versions in the list OR if clean == true |
44 | if input.clone().clean || (version_db_string != current_version.versions) { | 44 | if input.clean || (version_db_string != current_version.versions) { |
45 | updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { | 45 | updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { |
46 | Ok(ver) => { | 46 | Ok(ver) => { |
47 | current_versions.push((disable_version, p_id)); | 47 | current_versions.push((disable_version, p_id)); |