diff options
author | FxQnLr <[email protected]> | 2022-12-19 16:48:21 +0100 |
---|---|---|
committer | FxQnLr <[email protected]> | 2022-12-19 16:48:21 +0100 |
commit | f87ac1a38af96087e8a6927a6cad7ca19b48d76d (patch) | |
tree | a7d2e9e18beeaab35007ca7510137f0f9b3b557b /src/commands/modification.rs | |
parent | 28706f6edf10a135a67334d7035948bab4064bef (diff) | |
download | modlist-f87ac1a38af96087e8a6927a6cad7ca19b48d76d.tar modlist-f87ac1a38af96087e8a6927a6cad7ca19b48d76d.tar.gz modlist-f87ac1a38af96087e8a6927a6cad7ca19b48d76d.zip |
basic io implementation finished
Diffstat (limited to 'src/commands/modification.rs')
-rw-r--r-- | src/commands/modification.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 91243fc..f66ce28 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, Version}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, mods_get_all_ids, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, files::{delete_version, 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, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, Subcmd}, get_current_list, files::{delete_version, download_versions}, List}; |
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 | ||
@@ -22,10 +22,19 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
22 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; | 22 | if args.is_empty() { return Err(Box::new(Error::new(ErrorKind::InvalidInput, "TOO_FEW_ARGUMENTS"))); }; |
23 | 23 | ||
24 | let current_list = get_current_list(config.clone())?; | 24 | let current_list = get_current_list(config.clone())?; |
25 | |||
26 | mod_add(config, &args[0], current_list, input.disable_download).await?; | ||
27 | |||
28 | Ok(()) | ||
29 | } | ||
25 | 30 | ||
26 | let project = project(String::from(&config.apis.modrinth), &args[0]).await; | 31 | pub async fn mod_add(config: Cfg, mod_id: &str, list: List, disable_download: bool) -> Result<(), Box<dyn std::error::Error>> { |
32 | |||
33 | println!("Adding mod {}", mod_id); | ||
34 | |||
35 | let project = project(String::from(&config.apis.modrinth), &mod_id).await; | ||
27 | 36 | ||
28 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), current_list.clone()).await; | 37 | let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; |
29 | 38 | ||
30 | let mut available_versions_vec: Vec<String> = Vec::new(); | 39 | let mut available_versions_vec: Vec<String> = Vec::new(); |
31 | let current_version: Option<Version>; | 40 | let current_version: Option<Version>; |
@@ -52,15 +61,15 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
52 | } | 61 | } |
53 | 62 | ||
54 | //add to current list and mod table | 63 | //add to current list and mod table |
55 | match userlist_get_all_ids(config.clone(), current_list.clone().id) { | 64 | match userlist_get_all_ids(config.clone(), list.clone().id) { |
56 | Ok(mods) => { | 65 | Ok(mods) => { |
57 | if mods.contains(&project.id) { | 66 | if mods.contains(&project.id) { |
58 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } | 67 | return Err(Box::new(Error::new(ErrorKind::Other, "MOD_ALREADY_ON_LIST"))); } |
59 | else { | 68 | else { |
60 | userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; | 69 | userlist_insert(config.clone(), String::from(&list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?; |
61 | } | 70 | } |
62 | }, | 71 | }, |
63 | Err(..) => userlist_insert(config.clone(), String::from(¤t_list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, | 72 | Err(..) => userlist_insert(config.clone(), String::from(&list.id), String::from(&project.id), String::from(¤t_version_id), available_versions_vec, file)?, |
64 | }; | 73 | }; |
65 | 74 | ||
66 | match mods_get_all_ids(config.clone()) { | 75 | match mods_get_all_ids(config.clone()) { |
@@ -75,8 +84,8 @@ async fn add(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error> | |||
75 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; | 84 | mods_insert(config.clone(), String::from(&project.id), String::from(&project.title), project.versions)?; |
76 | }, | 85 | }, |
77 | }; | 86 | }; |
78 | 87 | ||
79 | if !input.disable_download && current_version.is_some() { download_versions(current_list, vec![current_version.unwrap()]).await?; } | 88 | if !disable_download && current_version.is_some() { download_versions(list, vec![current_version.unwrap()]).await?; }; |
80 | 89 | ||
81 | Ok(()) | 90 | Ok(()) |
82 | } | 91 | } |