diff options
author | FxQnLr <[email protected]> | 2022-11-29 22:59:19 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2022-11-29 22:59:19 +0100 |
commit | 575d2493e8e5747bf65321f7277e52211d73e387 (patch) | |
tree | 11b20e371316047110ffd36d1fe5bfefd2183c07 /src/commands | |
parent | ddde9204c72dd867f920f07f6483be03dda7cf68 (diff) | |
download | modlist-575d2493e8e5747bf65321f7277e52211d73e387.tar modlist-575d2493e8e5747bf65321f7277e52211d73e387.tar.gz modlist-575d2493e8e5747bf65321f7277e52211d73e387.zip |
fixed mod without matching specific version
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/modification.rs | 38 | ||||
-rw-r--r-- | src/commands/update.rs | 11 |
2 files changed, 34 insertions, 15 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 8e39d11..ac23970 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | use std::io::{Error, ErrorKind}; | 1 | use std::io::{Error, ErrorKind}; |
2 | 2 | ||
3 | use crate::{modrinth::{project, versions, extract_current_version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::{Input, Subcmd}, get_current_list, download_versions}; | 3 | use crate::{modrinth::{project, versions, extract_current_version, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids}, input::{Input, Subcmd}, get_current_list, download_versions}; |
4 | 4 | ||
5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { | 5 | pub async fn modification(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> { |
6 | 6 | ||
@@ -26,27 +26,41 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
26 | let project = project(String::from(&config.apis.modrinth), &args[0]).await; | 26 | let project = project(String::from(&config.apis.modrinth), &args[0]).await; |
27 | 27 | ||
28 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; | 28 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; |
29 | |||
30 | let current_id = extract_current_version(available_versions.clone())?; | ||
31 | |||
32 | let current_version = available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap(); | ||
33 | 29 | ||
34 | let file = current_version.clone().files.into_iter().find(|f| f.primary).unwrap().url; | ||
35 | |||
36 | let mut available_versions_vec: Vec<String> = Vec::new(); | 30 | let mut available_versions_vec: Vec<String> = Vec::new(); |
37 | for ver in available_versions { | 31 | let current_version: Option<Version>; |
38 | available_versions_vec.push(ver.id); | 32 | let current_version_id: String; |
33 | let file: String; | ||
34 | if !available_versions.is_empty() { | ||
35 | let current_id = extract_current_version(available_versions.clone())?; | ||
36 | |||
37 | current_version = Some(available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap()); | ||
38 | |||
39 | current_version_id = current_version.clone().unwrap().id; | ||
40 | |||
41 | file = current_version.clone().ok_or("VERSION_CORRUPTED")?.files.into_iter().find(|f| f.primary).unwrap().url; | ||
42 | |||
43 | for ver in available_versions { | ||
44 | available_versions_vec.push(ver.id); | ||
45 | }; | ||
46 | } else { | ||
47 | println!("There's currently no mod version for your specified target"); | ||
48 | current_version = None; | ||
49 | current_version_id = String::from("NONE"); | ||
50 | file = String::from("NONE"); | ||
51 | available_versions_vec.push(String::from("NONE")); | ||
39 | } | 52 | } |
53 | |||
40 | //add to current list and mod table | 54 | //add to current list and mod table |
41 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { | 55 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { |
42 | Ok(mods) => { | 56 | Ok(mods) => { |
43 | if mods.contains(&project.id) { | 57 | if mods.contains(&project.id) { |
44 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } | 58 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } |
45 | else { | 59 | else { |
46 | userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version.id), available_versions_vec, file)?; | 60 | userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; |
47 | } | 61 | } |
48 | }, | 62 | }, |
49 | Err(..) => userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version.id), available_versions_vec, file)?, | 63 | Err(..) => userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, |
50 | }; | 64 | }; |
51 | 65 | ||
52 | match mods_get_all_ids(config.clone()) { | 66 | match mods_get_all_ids(config.clone()) { |
@@ -62,7 +76,7 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
62 | }, | 76 | }, |
63 | }; | 77 | }; |
64 | 78 | ||
65 | if !input.disable_download { download_versions(current_list, vec![current_version]).await?; } | 79 | if !input.disable_download && current_version.is_some() { download_versions(current_list, vec![current_version.unwrap()]).await?; } |
66 | 80 | ||
67 | Ok(()) | 81 | Ok(()) |
68 | } | 82 | } |
diff --git a/src/commands/update.rs b/src/commands/update.rs index c8f0880..be15cfa 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs | |||
@@ -86,10 +86,15 @@ async fn specific_update(config: Cfg, input: Input, list: List, project: Project | |||
86 | let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; | 86 | let applicable_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; |
87 | 87 | ||
88 | let mut versions: Vec<String> = vec![]; | 88 | let mut versions: Vec<String> = vec![]; |
89 | 89 | ||
90 | for ver in &applicable_versions { | 90 | if !applicable_versions.is_empty() { |
91 | versions.push(String::from(&ver.id)); | 91 | for ver in &applicable_versions { |
92 | versions.push(String::from(&ver.id)); | ||
93 | } | ||
94 | } else { | ||
95 | versions.push(String::from("NONE")); | ||
92 | } | 96 | } |
97 | |||
93 | 98 | ||
94 | let mut current: Vec<Version> = vec![]; | 99 | let mut current: Vec<Version> = vec![]; |
95 | if input.clean || (versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&project.id))?) { | 100 | if input.clean || (versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&project.id))?) { |