From fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 17 Nov 2022 21:20:09 +0100 Subject: added --clean for update && list downloadfolder --- src/db.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'src/db.rs') diff --git a/src/db.rs b/src/db.rs index 5d82271..6b1e3ab 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,7 +2,7 @@ use std::io::{Error, ErrorKind}; use rusqlite::Connection; -use crate::{Modloader, config::Cfg, List, get_modloader}; +use crate::{Modloader, config::Cfg, List}; //mods pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec) -> Result<(), Box> { @@ -226,14 +226,14 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result Result<(), Box> { +pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> Result<(), Box> { println!("Creating list {}", id); let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; - connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3)", [id.clone(), mc_version, mod_loader.stringify()])?; - connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT)", id).as_str(), [])?; + connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id.clone(), mc_version, mod_loader.stringify(), download_folder])?; + connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT )", id).as_str(), [])?; Ok(()) } @@ -251,16 +251,16 @@ pub fn lists_get(config: Cfg, list_id: String) -> Result(0)?, row.get::(1)?]) + Ok(vec![row.get::(0)?, row.get::(1)?, row.get::(2)?]) })?; for l in list_iter { let li = l?; - list = List { id: String::from(&list_id), mc_version: String::from(&li[0]), modloader: get_modloader(String::from(&li[1]))? }; + list = List { id: String::from(&list_id), mc_version: String::from(&li[0]), modloader: Modloader::from(&li[1])?, download_folder: String::from(&li[2]) }; }; if list.id.is_empty() { return Err(Box::new(Error::new(ErrorKind::Other, "LIST_NOT_FOUND"))); } @@ -378,11 +378,10 @@ pub fn db_setup(config: Cfg) -> Result<(), Box> { connection.execute_batch( "CREATE TABLE 'user_config' ( 'id' TEXT, 'value' TEXT ); CREATE TABLE 'mods' ( 'id' TEXT, 'name' TEXT, 'versions' TEXT ); - CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT ); - INSERT INTO 'user_config' VALUES ( 'db_version', '0.2' ); + CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT, 'download_folder' TEXT ); + INSERT INTO 'user_config' VALUES ( 'db_version', '0.3' ); INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", )?; Ok(()) } - -- cgit v1.2.3