summaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs41
1 files changed, 19 insertions, 22 deletions
diff --git a/src/db.rs b/src/db.rs
index 1f3ad4c..f627ef4 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -120,9 +120,7 @@ pub fn mods_get_info(config: &Cfg, id: &str) -> MLE<ModInfo> {
120 } 120 }
121} 121}
122 122
123pub fn mods_remove(config: &Cfg, id: String) -> MLE<()> { 123pub fn mods_remove(config: &Cfg, id: &str) -> MLE<()> {
124 // println!("Removing mod {} from database", id);
125
126 let data = format!("{}/data.db", config.data); 124 let data = format!("{}/data.db", config.data);
127 let connection = Connection::open(data)?; 125 let connection = Connection::open(data)?;
128 126
@@ -233,7 +231,10 @@ pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE<Vec<String>> {
233 } 231 }
234 232
235 match mod_ids.is_empty() { 233 match mod_ids.is_empty() {
236 true => Err(MLError::new(ErrorType::DBError, &format!("NO_MODS_USERLIST{}", list_id))), 234 true => Err(MLError::new(
235 ErrorType::DBError,
236 &format!("NO_MODS_USERLIST{}", list_id),
237 )),
237 false => Ok(mod_ids), 238 false => Ok(mod_ids),
238 } 239 }
239} 240}
@@ -325,10 +326,7 @@ pub fn userlist_get_current_version(config: &Cfg, list_id: &str, mod_id: &str) -
325 } 326 }
326} 327}
327 328
328pub fn userlist_get_all_current_version_ids( 329pub fn userlist_get_all_current_version_ids(config: &Cfg, list_id: String) -> MLE<Vec<String>> {
329 config: &Cfg,
330 list_id: String,
331) -> MLE<Vec<String>> {
332 let data = format!("{}/data.db", config.data); 330 let data = format!("{}/data.db", config.data);
333 let connection = Connection::open(data)?; 331 let connection = Connection::open(data)?;
334 332
@@ -342,10 +340,7 @@ pub fn userlist_get_all_current_version_ids(
342 } 340 }
343 341
344 if versions.is_empty() { 342 if versions.is_empty() {
345 return Err(MLError::new( 343 return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST"));
346 ErrorType::DBError,
347 "NO_MODS_ON_LIST",
348 ));
349 }; 344 };
350 345
351 Ok(versions) 346 Ok(versions)
@@ -441,7 +436,11 @@ pub fn userlist_add_disabled_versions(
441 Ok(()) 436 Ok(())
442} 437}
443 438
444pub fn userlist_get_disabled_versions(config: &Cfg, list_id: String, mod_id: String) -> MLE<String> { 439pub fn userlist_get_disabled_versions(
440 config: &Cfg,
441 list_id: String,
442 mod_id: String,
443) -> MLE<String> {
445 let data = format!("{}/data.db", config.data); 444 let data = format!("{}/data.db", config.data);
446 let connection = Connection::open(data).unwrap(); 445 let connection = Connection::open(data).unwrap();
447 446
@@ -504,19 +503,14 @@ pub fn lists_insert(
504 503
505 connection.execute( 504 connection.execute(
506 "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", 505 "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)",
507 [ 506 [id, mc_version, &mod_loader.to_string(), download_folder],
508 id,
509 mc_version,
510 &mod_loader.to_string(),
511 download_folder,
512 ],
513 )?; 507 )?;
514 connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?; 508 connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?;
515 509
516 Ok(()) 510 Ok(())
517} 511}
518 512
519pub fn lists_remove(config: &Cfg, id: String) -> MLE<()> { 513pub fn lists_remove(config: &Cfg, id: &str) -> MLE<()> {
520 let data = format!("{}/data.db", config.data); 514 let data = format!("{}/data.db", config.data);
521 let connection = Connection::open(data)?; 515 let connection = Connection::open(data)?;
522 516
@@ -593,7 +587,7 @@ pub fn lists_get_all_ids(config: &Cfg) -> MLE<Vec<String>> {
593} 587}
594 588
595//config 589//config
596pub fn config_change_current_list(config: &Cfg, id: String) -> MLE<()> { 590pub fn config_change_current_list(config: &Cfg, id: &str) -> MLE<()> {
597 let data = format!("{}/data.db", config.data); 591 let data = format!("{}/data.db", config.data);
598 let connection = Connection::open(data)?; 592 let connection = Connection::open(data)?;
599 593
@@ -655,7 +649,10 @@ pub fn s_config_create_version(config: &Cfg) -> Result<(), Box<dyn std::error::E
655 Ok(()) 649 Ok(())
656} 650}
657 651
658pub fn s_config_update_version(config: &Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { 652pub fn s_config_update_version(
653 config: &Cfg,
654 ver: String,
655) -> Result<(), Box<dyn std::error::Error>> {
659 let data = format!("{}/data.db", config.data); 656 let data = format!("{}/data.db", config.data);
660 let connection = Connection::open(data)?; 657 let connection = Connection::open(data)?;
661 658