diff options
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 37 |
1 files changed, 19 insertions, 18 deletions
@@ -5,7 +5,7 @@ use rusqlite::Connection; | |||
5 | use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}}; | 5 | use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}}; |
6 | 6 | ||
7 | //mods | 7 | //mods |
8 | pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { | 8 | pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec<String>) -> MLE<()> { |
9 | 9 | ||
10 | println!("Inserting mod {}({}) into database", name, id); | 10 | println!("Inserting mod {}({}) into database", name, id); |
11 | 11 | ||
@@ -41,7 +41,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error:: | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::error::Error>> { | 44 | pub fn mods_get_id(config: Cfg, name: String) -> MLE<String> { |
45 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 45 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
46 | let connection = Connection::open(data)?; | 46 | let connection = Connection::open(data)?; |
47 | 47 | ||
@@ -56,12 +56,12 @@ pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::err | |||
56 | }; | 56 | }; |
57 | 57 | ||
58 | match mod_id.is_empty() { | 58 | match mod_id.is_empty() { |
59 | true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), | 59 | true => Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")), |
60 | false => Ok(mod_id), | 60 | false => Ok(mod_id), |
61 | } | 61 | } |
62 | } | 62 | } |
63 | 63 | ||
64 | pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> { | 64 | pub fn mods_get_name(config: Cfg, id: &str) -> MLE<String> { |
65 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 65 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
66 | let connection = Connection::open(data)?; | 66 | let connection = Connection::open(data)?; |
67 | 67 | ||
@@ -76,14 +76,14 @@ pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::err | |||
76 | }; | 76 | }; |
77 | 77 | ||
78 | match mod_name.is_empty() { | 78 | match mod_name.is_empty() { |
79 | true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), | 79 | true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")), |
80 | false => Ok(mod_name), | 80 | false => Ok(mod_name), |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> MLE<()> { | 84 | pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> MLE<()> { |
85 | 85 | ||
86 | println!("Updating versions for {} with \n {}", mod_id, versions); | 86 | //println!("Updating versions for {} with \n {}", mod_id, versions); |
87 | 87 | ||
88 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 88 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
89 | let connection = Connection::open(data)?; | 89 | let connection = Connection::open(data)?; |
@@ -92,7 +92,7 @@ pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> ML | |||
92 | Ok(()) | 92 | Ok(()) |
93 | } | 93 | } |
94 | 94 | ||
95 | pub fn mods_remove(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { | 95 | pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { |
96 | 96 | ||
97 | println!("Removing mod {} from database", id); | 97 | println!("Removing mod {} from database", id); |
98 | 98 | ||
@@ -131,7 +131,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer | |||
131 | 131 | ||
132 | for ver in id_iter { | 132 | for ver in id_iter { |
133 | let version = ver?; | 133 | let version = ver?; |
134 | println!("Getting versions for {} from the database", String::from(&version[2])); | 134 | println!("\t({}) Get versions from the database", String::from(&version[2])); |
135 | //println!("Found versions {} for mod {}", version[1], version[0]); | 135 | //println!("Found versions {} for mod {}", version[1], version[0]); |
136 | versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]) }) | 136 | versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]) }) |
137 | }; | 137 | }; |
@@ -143,7 +143,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> MLE<Vec<DBModlistVer | |||
143 | } | 143 | } |
144 | 144 | ||
145 | //userlist | 145 | //userlist |
146 | pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_version: String, applicable_versions: Vec<String>, current_link: String) -> Result<(), Box<dyn std::error::Error>> { | 146 | pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_version: String, applicable_versions: Vec<String>, current_link: String) -> MLE<()> { |
147 | println!("Inserting {} into current list({})", mod_id, list_id); | 147 | println!("Inserting {} into current list({})", mod_id, list_id); |
148 | 148 | ||
149 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 149 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
@@ -177,7 +177,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE<Vec<String>> { | |||
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { | 180 | pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> MLE<()> { |
181 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 181 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
182 | let connection = Connection::open(data)?; | 182 | let connection = Connection::open(data)?; |
183 | 183 | ||
@@ -186,7 +186,7 @@ pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<( | |||
186 | } | 186 | } |
187 | 187 | ||
188 | 188 | ||
189 | pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { | 189 | pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> MLE<String> { |
190 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 190 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
191 | let connection = Connection::open(data).unwrap(); | 191 | let connection = Connection::open(data).unwrap(); |
192 | 192 | ||
@@ -201,12 +201,12 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St | |||
201 | }; | 201 | }; |
202 | 202 | ||
203 | match version.is_empty() { | 203 | match version.is_empty() { |
204 | true => Err(Box::new(Error::new(ErrorKind::NotFound, "MOD_NOT_FOUND"))), | 204 | true => Err(MLError::new(ErrorType::DBError, "GAV_MOD_NOT_FOUND")), |
205 | false => Ok(version), | 205 | false => Ok(version), |
206 | } | 206 | } |
207 | } | 207 | } |
208 | 208 | ||
209 | pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { | 209 | pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> MLE<Vec<(String, String)>> { |
210 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 210 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
211 | let connection = Connection::open(data)?; | 211 | let connection = Connection::open(data)?; |
212 | 212 | ||
@@ -221,7 +221,7 @@ pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: Stri | |||
221 | versions.push((out[0].to_owned(), out[1].to_owned())); | 221 | versions.push((out[0].to_owned(), out[1].to_owned())); |
222 | }; | 222 | }; |
223 | 223 | ||
224 | if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; | 224 | if versions.is_empty() { return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); }; |
225 | 225 | ||
226 | Ok(versions) | 226 | Ok(versions) |
227 | } | 227 | } |
@@ -241,7 +241,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String | |||
241 | }; | 241 | }; |
242 | 242 | ||
243 | match version.is_empty() { | 243 | match version.is_empty() { |
244 | true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), | 244 | true => Err(MLError::new(ErrorType::DBError, "GCV_MOD_NOT_FOUND")), |
245 | false => Ok(version), | 245 | false => Ok(version), |
246 | } | 246 | } |
247 | } | 247 | } |
@@ -285,7 +285,7 @@ pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) | |||
285 | Ok(versions) | 285 | Ok(versions) |
286 | } | 286 | } |
287 | 287 | ||
288 | pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { | 288 | pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> MLE<()> { |
289 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 289 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
290 | let connection = Connection::open(data)?; | 290 | let connection = Connection::open(data)?; |
291 | 291 | ||
@@ -322,7 +322,7 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin | |||
322 | }; | 322 | }; |
323 | 323 | ||
324 | match version.is_empty() { | 324 | match version.is_empty() { |
325 | true => Err(MLError::new(ErrorType::DBError, "MOD_NOT_FOUND")), | 325 | true => Err(MLError::new(ErrorType::DBError, "GDV_MOD_NOT_FOUND")), |
326 | false => Ok(version), | 326 | false => Ok(version), |
327 | } | 327 | } |
328 | } | 328 | } |
@@ -349,6 +349,7 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<St | |||
349 | } | 349 | } |
350 | 350 | ||
351 | //lists | 351 | //lists |
352 | ///Inserts into lists table and creates new table | ||
352 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> MLE<()> { | 353 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> MLE<()> { |
353 | println!("Creating list {}", id); | 354 | println!("Creating list {}", id); |
354 | 355 | ||
@@ -420,7 +421,7 @@ pub fn lists_get_all_ids(config: Cfg) -> MLE<Vec<String>> { | |||
420 | } | 421 | } |
421 | 422 | ||
422 | //config | 423 | //config |
423 | pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { | 424 | pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { |
424 | let data = devdir(format!("{}/data.db", config.data).as_str()); | 425 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
425 | let connection = Connection::open(data)?; | 426 | let connection = Connection::open(data)?; |
426 | 427 | ||