diff options
author | fxqnlr <[email protected]> | 2023-02-19 12:14:37 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-02-19 12:14:37 +0100 |
commit | 9f2f36eb7ff00d655ab9fb12f10434962b7de1a2 (patch) | |
tree | a45f7334cddaff7e686563b4d8e49bbd3d52ede6 /src/commands | |
parent | ca438e8956f8ce179551d659e3b82d679759707e (diff) | |
download | modlist-9f2f36eb7ff00d655ab9fb12f10434962b7de1a2.tar modlist-9f2f36eb7ff00d655ab9fb12f10434962b7de1a2.tar.gz modlist-9f2f36eb7ff00d655ab9fb12f10434962b7de1a2.zip |
Fixed import output && cleanup
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/modification.rs | 70 |
1 files changed, 6 insertions, 64 deletions
diff --git a/src/commands/modification.rs b/src/commands/modification.rs index c815155..31e50af 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; | 1 | use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; |
2 | 2 | ||
3 | //TODO DO IT | ||
4 | #[derive(Debug, Clone, PartialEq, Eq)] | 3 | #[derive(Debug, Clone, PartialEq, Eq)] |
5 | pub enum IDSelector { | 4 | pub enum IDSelector { |
6 | ModificationID(String), | 5 | ModificationID(String), |
@@ -35,7 +34,6 @@ pub struct ProjectInfo { | |||
35 | pub download_link: String, | 34 | pub download_link: String, |
36 | } | 35 | } |
37 | 36 | ||
38 | //TODO impl specific version... Rewrite yay | ||
39 | pub async fn mods_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_download: bool, set_version: bool) -> MLE<()> { | 37 | pub async fn mods_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_download: bool, set_version: bool) -> MLE<()> { |
40 | println!("Add mods to {}", list.id); | 38 | println!("Add mods to {}", list.id); |
41 | println!(" └Add mods:"); | 39 | println!(" └Add mods:"); |
@@ -60,9 +58,14 @@ pub async fn mods_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_down | |||
60 | let mut downloadstack: Vec<Version> = Vec::new(); | 58 | let mut downloadstack: Vec<Version> = Vec::new(); |
61 | 59 | ||
62 | //Adding each mod to the lists and downloadstack | 60 | //Adding each mod to the lists and downloadstack |
61 | if projectinfo.len() == 1 { | ||
62 | println!(" └Insert mod in list {} and save infos", list.id); | ||
63 | } else { | ||
64 | println!(" └Insert mods in list {} and save infos", list.id); | ||
65 | } | ||
66 | |||
63 | for project in projectinfo { | 67 | for project in projectinfo { |
64 | let current_version_id = if project.current_version.is_none() { String::from("NONE") } else { project.current_version.clone().unwrap().id }; | 68 | let current_version_id = if project.current_version.is_none() { String::from("NONE") } else { project.current_version.clone().unwrap().id }; |
65 | |||
66 | match userlist_insert(config.clone(), &list.id, &project.mod_id, ¤t_version_id, project.clone().applicable_versions, &project.download_link, set_version) { | 69 | match userlist_insert(config.clone(), &list.id, &project.mod_id, ¤t_version_id, project.clone().applicable_versions, &project.download_link, set_version) { |
67 | Err(e) => { | 70 | Err(e) => { |
68 | let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); | 71 | let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); |
@@ -86,67 +89,6 @@ pub async fn mods_add(config: Cfg, ids: Vec<IDSelector>, list: List, direct_down | |||
86 | download_versions(list.clone(), config.clone(), downloadstack).await?; | 89 | download_versions(list.clone(), config.clone(), downloadstack).await?; |
87 | }; | 90 | }; |
88 | 91 | ||
89 | |||
90 | // let projects = if id.len() == 1 { | ||
91 | // vec![project(String::from(&config.apis.modrinth), &mod_id).await] | ||
92 | // } else { | ||
93 | // projects(String::from(&config.apis.modrinth), &mod_id).await | ||
94 | // }; | ||
95 | // | ||
96 | // let mut downloadstack: Vec<Version> = Vec::new(); | ||
97 | // | ||
98 | // for project in projects { | ||
99 | // println!("\t└{}", project.title); | ||
100 | // println!("\t └Get versions"); | ||
101 | // let available_versions = versions(String::from(&config.apis.modrinth), String::from(&project.id), list.clone()).await; | ||
102 | // | ||
103 | // let mut available_versions_vec: Vec<String> = Vec::new(); | ||
104 | // let current_version: Option<Version>; | ||
105 | // let current_version_id: String; | ||
106 | // let file: String; | ||
107 | // if !available_versions.is_empty() { | ||
108 | // let current_id = extract_current_version(available_versions.clone())?; | ||
109 | // println!("\t └Current version: {}", current_id); | ||
110 | // | ||
111 | // current_version = Some(available_versions.clone().into_iter().find(|v| v.id == current_id).unwrap()); | ||
112 | // | ||
113 | // current_version_id = current_version.clone().unwrap().id; | ||
114 | // | ||
115 | // file = current_version.clone().ok_or("").unwrap().files.into_iter().find(|f| f.primary).unwrap().url; | ||
116 | // for ver in available_versions { | ||
117 | // available_versions_vec.push(ver.id); | ||
118 | // }; | ||
119 | // } else { | ||
120 | // println!("\t └There's currently no mod version for your specified target"); | ||
121 | // current_version = None; | ||
122 | // current_version_id = String::from("NONE"); | ||
123 | // file = String::from("NONE"); | ||
124 | // available_versions_vec.push(String::from("NONE")); | ||
125 | // } | ||
126 | // | ||
127 | // match userlist_insert(config.clone(), &list.id, &project.id, ¤t_version_id, available_versions_vec, &file, set_version) { | ||
128 | // Err(e) => { | ||
129 | // let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); | ||
130 | // if e.to_string() == expected_err { Err(MLError::new(ErrorType::ModError, "MOD_ALREADY_ON_SELECTED_LIST")) } else { Err(e) } | ||
131 | // }, | ||
132 | // Ok(..) => { Ok(..) }, | ||
133 | // }?; | ||
134 | // | ||
135 | // match mods_insert(config.clone(), &project.id, &project.slug, &project.title) { | ||
136 | // Err(e) => { | ||
137 | // if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { Ok(..) } else { Err(e) } | ||
138 | // }, | ||
139 | // Ok(..) => Ok(..), | ||
140 | // }?; | ||
141 | // | ||
142 | // downloadstack.push(current_version.unwrap()); | ||
143 | // }; | ||
144 | // | ||
145 | // //Download all the added mods | ||
146 | // if direct_download { | ||
147 | // download_versions(list.clone(), config.clone(), downloadstack).await?; | ||
148 | // }; | ||
149 | // | ||
150 | Ok(()) | 92 | Ok(()) |
151 | } | 93 | } |
152 | 94 | ||