diff options
author | fxqnlr <[email protected]> | 2022-11-17 21:20:09 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-11-17 21:20:09 +0100 |
commit | fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113 (patch) | |
tree | ec7c7c80434b339f9442882f1e2dce6f60cc9edd /src/db.rs | |
parent | 5145dd23f1777180d8003e76f59af57643796516 (diff) | |
download | modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.tar modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.tar.gz modlist-fdd7525e5a0d298ebb8a9aa81cc19ec79e8cd113.zip |
added --clean for update && list downloadfolder
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 21 |
1 files changed, 10 insertions, 11 deletions
@@ -2,7 +2,7 @@ use std::io::{Error, ErrorKind}; | |||
2 | 2 | ||
3 | use rusqlite::Connection; | 3 | use rusqlite::Connection; |
4 | 4 | ||
5 | use crate::{Modloader, config::Cfg, List, get_modloader}; | 5 | use crate::{Modloader, config::Cfg, List}; |
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>) -> Result<(), Box<dyn std::error::Error>> { |
@@ -226,14 +226,14 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<St | |||
226 | } | 226 | } |
227 | 227 | ||
228 | //lists | 228 | //lists |
229 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader) -> Result<(), Box<dyn std::error::Error>> { | 229 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> Result<(), Box<dyn std::error::Error>> { |
230 | println!("Creating list {}", id); | 230 | println!("Creating list {}", id); |
231 | 231 | ||
232 | let data = format!("{}/data.db", config.data); | 232 | let data = format!("{}/data.db", config.data); |
233 | let connection = Connection::open(data)?; | 233 | let connection = Connection::open(data)?; |
234 | 234 | ||
235 | connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3)", [id.clone(), mc_version, mod_loader.stringify()])?; | 235 | connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id.clone(), mc_version, mod_loader.stringify(), download_folder])?; |
236 | connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT)", id).as_str(), [])?; | 236 | connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT )", id).as_str(), [])?; |
237 | 237 | ||
238 | Ok(()) | 238 | Ok(()) |
239 | } | 239 | } |
@@ -251,16 +251,16 @@ pub fn lists_get(config: Cfg, list_id: String) -> Result<List, Box<dyn std::erro | |||
251 | let data = format!("{}/data.db", config.data); | 251 | let data = format!("{}/data.db", config.data); |
252 | let connection = Connection::open(data).unwrap(); | 252 | let connection = Connection::open(data).unwrap(); |
253 | 253 | ||
254 | let mut list = List { id: String::new(), mc_version: String::new(), modloader: Modloader::Fabric }; | 254 | let mut list = List { id: String::new(), mc_version: String::new(), modloader: Modloader::Fabric, download_folder: String::new() }; |
255 | let mut stmt = connection.prepare("SELECT mc_version, modloader FROM lists WHERE id = ?")?; | 255 | let mut stmt = connection.prepare("SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?")?; |
256 | 256 | ||
257 | let list_iter = stmt.query_map([&list_id], |row| { | 257 | let list_iter = stmt.query_map([&list_id], |row| { |
258 | Ok(vec![row.get::<usize, String>(0)?, row.get::<usize, String>(1)?]) | 258 | Ok(vec![row.get::<usize, String>(0)?, row.get::<usize, String>(1)?, row.get::<usize, String>(2)?]) |
259 | })?; | 259 | })?; |
260 | 260 | ||
261 | for l in list_iter { | 261 | for l in list_iter { |
262 | let li = l?; | 262 | let li = l?; |
263 | list = List { id: String::from(&list_id), mc_version: String::from(&li[0]), modloader: get_modloader(String::from(&li[1]))? }; | 263 | list = List { id: String::from(&list_id), mc_version: String::from(&li[0]), modloader: Modloader::from(&li[1])?, download_folder: String::from(&li[2]) }; |
264 | }; | 264 | }; |
265 | 265 | ||
266 | if list.id.is_empty() { return Err(Box::new(Error::new(ErrorKind::Other, "LIST_NOT_FOUND"))); } | 266 | 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<dyn std::error::Error>> { | |||
378 | connection.execute_batch( | 378 | connection.execute_batch( |
379 | "CREATE TABLE 'user_config' ( 'id' TEXT, 'value' TEXT ); | 379 | "CREATE TABLE 'user_config' ( 'id' TEXT, 'value' TEXT ); |
380 | CREATE TABLE 'mods' ( 'id' TEXT, 'name' TEXT, 'versions' TEXT ); | 380 | CREATE TABLE 'mods' ( 'id' TEXT, 'name' TEXT, 'versions' TEXT ); |
381 | CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT ); | 381 | CREATE TABLE 'lists' ( 'id' TEXT, 'mc_version' TEXT, 'modloader' TEXT, 'download_folder' TEXT ); |
382 | INSERT INTO 'user_config' VALUES ( 'db_version', '0.2' ); | 382 | INSERT INTO 'user_config' VALUES ( 'db_version', '0.3' ); |
383 | INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", | 383 | INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", |
384 | )?; | 384 | )?; |
385 | 385 | ||
386 | Ok(()) | 386 | Ok(()) |
387 | } | 387 | } |
388 | |||