From 5326d48f6e0a88ad42005c39b73f7baaf91c9b86 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 28 Dec 2022 13:15:10 +0100 Subject: added devdir; better config dir --- src/db.rs | 64 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index cd32d1f..3f05772 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,14 +2,14 @@ use std::io::{Error, ErrorKind}; use rusqlite::Connection; -use crate::{Modloader, config::Cfg, List}; +use crate::{Modloader, config::Cfg, List, devdir}; //mods pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec) -> Result<(), Box> { println!("Inserting mod {}({}) into database", name, id); - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute( @@ -21,7 +21,7 @@ pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec) } pub fn mods_get_all_ids(config: Cfg) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut mods: Vec = Vec::new(); @@ -43,7 +43,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut mod_id = String::new(); @@ -64,7 +64,7 @@ pub fn mods_get_id(config: Cfg, name: String) -> Result Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut mod_name = String::new(); @@ -88,7 +88,7 @@ pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> Re println!("Updating versions for {} with \n {}", mod_id, versions); - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute("UPDATE mods SET versions = ?1 WHERE id = ?2", [versions, mod_id])?; @@ -99,7 +99,7 @@ pub fn mods_remove(config: Cfg, id: String) -> Result<(), Box) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; if mods.is_empty() { return Err(Box::new(Error::new(ErrorKind::Other, "MODS_NO_INPUT"))); } @@ -149,7 +149,7 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> Result, current_link: String) -> Result<(), Box> { println!("Inserting {} into current list({})", mod_id, list_id); - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -159,7 +159,7 @@ pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_ver } pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut mod_ids: Vec = Vec::new(); @@ -181,7 +181,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> Result, pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute(format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), [mod_id])?; @@ -190,7 +190,7 @@ pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<( pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); @@ -210,7 +210,7 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St } pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut versions: Vec<(String, String)> = Vec::new(); @@ -230,7 +230,7 @@ pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: Stri } pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); @@ -250,7 +250,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String } pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut versions: Vec = Vec::new(); @@ -269,7 +269,7 @@ pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Res } pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut versions: Vec<(String, String)> = Vec::new(); @@ -289,7 +289,7 @@ pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) } pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute(format!("UPDATE {} SET current_version = ?1, applicable_versions = ?2, current_download = ?3 WHERE mod_id = ?4", list_id).as_str(), [current_version, versions, link, mod_id])?; @@ -297,7 +297,7 @@ pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: S } pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_version: String, mod_id: String) -> Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let currently_disabled_versions = userlist_get_disabled_versions(config, String::from(&list_id), String::from(&mod_id))?; @@ -311,7 +311,7 @@ pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_ver } pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: String) -> Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); @@ -331,7 +331,7 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin } pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut links: Vec = Vec::new(); @@ -355,7 +355,7 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result Result<(), Box> { println!("Creating list {}", id); - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id.clone(), mc_version, mod_loader.stringify(), download_folder])?; @@ -365,7 +365,7 @@ pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Mod } pub fn lists_remove(config: Cfg, id: String) -> Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; @@ -374,7 +374,7 @@ pub fn lists_remove(config: Cfg, id: String) -> Result<(), Box Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut list = List { id: String::new(), mc_version: String::new(), modloader: Modloader::Fabric, download_folder: String::new() }; @@ -395,7 +395,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> Result Result, Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut list_ids: Vec = Vec::new(); @@ -416,7 +416,7 @@ pub fn lists_get_all_ids(config: Cfg) -> Result, Box Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute("UPDATE user_config SET value = ? WHERE id = 'current_list'", [id])?; @@ -424,7 +424,7 @@ pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut list_id = String::new(); @@ -444,7 +444,7 @@ pub fn config_get_current_list(config: Cfg) -> Result Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute(format!("UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", list_id).as_str(), [link, mod_id])?; @@ -452,7 +452,7 @@ pub fn s_userlist_update_download(config: Cfg, list_id: String, mod_id: String, } pub fn s_config_create_version(config: Cfg) -> Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute("INSERT INTO 'user_config' VALUES ( 'db_version', '0.2' )", ())?; @@ -460,7 +460,7 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute("UPDATE user_config SET value = ? WHERE id = 'db_version'", [ver])?; @@ -468,7 +468,7 @@ pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box Result> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut version: String = String::new(); @@ -486,7 +486,7 @@ pub fn s_config_get_version(config: Cfg) -> Result) -> Result<(), Box> { - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); @@ -503,7 +503,7 @@ pub fn db_setup(config: Cfg) -> Result<(), Box> { println!("Initiating database"); - let data = format!("{}/data.db", config.data); + let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute_batch( -- cgit v1.2.3