diff options
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/commands/update.rs | 24 |
3 files changed, 16 insertions, 12 deletions
@@ -615,7 +615,7 @@ dependencies = [ | |||
615 | 615 | ||
616 | [[package]] | 616 | [[package]] |
617 | name = "modlist" | 617 | name = "modlist" |
618 | version = "0.8.0" | 618 | version = "0.8.1" |
619 | dependencies = [ | 619 | dependencies = [ |
620 | "chrono", | 620 | "chrono", |
621 | "dirs", | 621 | "dirs", |
@@ -1,6 +1,6 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "modlist" | 2 | name = "modlist" |
3 | version = "0.8.0" | 3 | version = "0.8.1" |
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/src/commands/update.rs b/src/commands/update.rs index 0895efb..11f283e 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -3,7 +3,7 @@ use std::io::{Error, ErrorKind}; | |||
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, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}}; | 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, userlist_get_current_version, mods_change_versions}, List, input::Input, files::{delete_version, download_versions, disable_version}}; |
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 | 6 | ||
7 | let mut liststack: Vec<List> = vec![]; | 7 | let mut liststack: Vec<List> = vec![]; |
8 | if input.all_lists { | 8 | if input.all_lists { |
9 | let list_ids = lists_get_all_ids(config.clone())?; | 9 | let list_ids = lists_get_all_ids(config.clone())?; |
@@ -15,7 +15,11 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
15 | println!("Checking for updates of mods in {}", current.id); | 15 | println!("Checking for updates of mods in {}", current.id); |
16 | liststack.push(current) | 16 | liststack.push(current) |
17 | } | 17 | } |
18 | |||
19 | cmd_update(config, liststack, input.clean, input.direct_download, input.delete_old).await | ||
20 | } | ||
18 | 21 | ||
22 | pub async fn cmd_update(config: Cfg, liststack: Vec<List>, clean: bool, direct_download: bool, delete_old: bool) -> Result<(), Box<dyn std::error::Error>> { | ||
19 | for current_list in liststack { | 23 | for current_list in liststack { |
20 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; | 24 | let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; |
21 | 25 | ||
@@ -41,17 +45,17 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
41 | let version_db_string = project.versions.join("|"); | 45 | let version_db_string = project.versions.join("|"); |
42 | 46 | ||
43 | //Adding to stack if not the same versions in the list OR if clean == true | 47 | //Adding to stack if not the same versions in the list OR if clean == true |
44 | if input.clean || (version_db_string != current_version.versions) { | 48 | if clean || (version_db_string != current_version.versions) { |
45 | updatestack.push(match specific_update(config.clone(), input.clone(), current_list.clone(), project.clone()).await { | 49 | updatestack.push(match specific_update(config.clone(), clean, current_list.clone(), project.clone()).await { |
46 | Ok(ver) => { | 50 | Ok(ver) => { |
47 | current_versions.push((disable_version, p_id)); | 51 | current_versions.push((disable_version, p_id)); |
48 | ver | 52 | ver |
49 | }, | 53 | }, |
50 | //TODO handle errors (only continue on "NO_UPDATE_AVAILABLE") | 54 | //TODO handle errors (only continue on "NO_UPDATE_AVAILABLE") |
51 | Err(e) => { | 55 | Err(..) => { |
52 | //Updating versions in modlist for no repeating version calls | 56 | //Updating versions in modlist for no repeating version calls |
53 | mods_change_versions(config.clone(), version_db_string, project.id)?; | 57 | mods_change_versions(config.clone(), version_db_string, project.id)?; |
54 | println!("({}) No new version found for the specified minecraft version({})", project.title, e); | 58 | println!("({}) No new version found for the specified", project.title); |
55 | continue; | 59 | continue; |
56 | }, | 60 | }, |
57 | }); | 61 | }); |
@@ -60,7 +64,7 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
60 | }; | 64 | }; |
61 | }; | 65 | }; |
62 | 66 | ||
63 | if input.clean { | 67 | if clean { |
64 | let dl_path = ¤t_list.download_folder; | 68 | let dl_path = ¤t_list.download_folder; |
65 | println!("Cleaning {}", dl_path); | 69 | println!("Cleaning {}", dl_path); |
66 | for entry in std::fs::read_dir(dl_path)? { | 70 | for entry in std::fs::read_dir(dl_path)? { |
@@ -69,12 +73,12 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
69 | } | 73 | } |
70 | } | 74 | } |
71 | 75 | ||
72 | if input.direct_download { | 76 | if direct_download { |
73 | download_versions(current_list.clone(), updatestack).await?; | 77 | download_versions(current_list.clone(), updatestack).await?; |
74 | 78 | ||
75 | //Disable old versions | 79 | //Disable old versions |
76 | for ver in current_versions { | 80 | for ver in current_versions { |
77 | if input.delete_old { | 81 | if delete_old { |
78 | println!("Deleting version {} for mod {}", ver.0, ver.1); | 82 | println!("Deleting version {} for mod {}", ver.0, ver.1); |
79 | delete_version(current_list.clone(), ver.0)?; | 83 | delete_version(current_list.clone(), ver.0)?; |
80 | } else if ver.0 != "NONE" { | 84 | } else if ver.0 != "NONE" { |
@@ -89,7 +93,7 @@ pub async fn update(config: Cfg, input: Input) -> Result<(), Box<dyn std::error: | |||
89 | Ok(()) | 93 | Ok(()) |
90 | } | 94 | } |
91 | 95 | ||
92 | async fn specific_update(config: Cfg, input: Input, list: List, project: Project) -> Result<Version, Box<dyn std::error::Error>> { | 96 | async fn specific_update(config: Cfg, clean: bool, list: List, project: Project) -> Result<Version, Box<dyn std::error::Error>> { |
93 | println!("Checking update for '{}' in {}", project.title, list.id); | 97 | println!("Checking update for '{}' in {}", project.title, list.id); |
94 | 98 | ||
95 | let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; | 99 | let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; |
@@ -106,7 +110,7 @@ async fn specific_update(config: Cfg, input: Input, list: List, project: Project | |||
106 | 110 | ||
107 | 111 | ||
108 | let mut current: Vec<Version> = vec![]; | 112 | let mut current: Vec<Version> = vec![]; |
109 | if input.clean || (versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&project.id))?) { | 113 | if clean || (versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&project.id))?) { |
110 | //get new versions | 114 | //get new versions |
111 | print!(" | getting new version"); | 115 | print!(" | getting new version"); |
112 | let current_str = extract_current_version(applicable_versions.clone())?; | 116 | let current_str = extract_current_version(applicable_versions.clone())?; |