diff options
author | fxqnlr <[email protected]> | 2022-12-28 13:15:10 +0100 |
---|---|---|
committer | fxqnlr <[email protected]> | 2022-12-28 13:15:10 +0100 |
commit | 5326d48f6e0a88ad42005c39b73f7baaf91c9b86 (patch) | |
tree | 154ff8715a2e0f121b285870d52c50f1737f7abc /src/db.rs | |
parent | e1c79889d3bf02c8d131d642fed8ba7ef9521bf4 (diff) | |
download | modlist-5326d48f6e0a88ad42005c39b73f7baaf91c9b86.tar modlist-5326d48f6e0a88ad42005c39b73f7baaf91c9b86.tar.gz modlist-5326d48f6e0a88ad42005c39b73f7baaf91c9b86.zip |
added devdir; better config dir
Diffstat (limited to 'src/db.rs')
-rw-r--r-- | src/db.rs | 64 |
1 files changed, 32 insertions, 32 deletions
@@ -2,14 +2,14 @@ use std::io::{Error, ErrorKind}; | |||
2 | 2 | ||
3 | use rusqlite::Connection; | 3 | use rusqlite::Connection; |
4 | 4 | ||
5 | use crate::{Modloader, config::Cfg, List}; | 5 | use crate::{Modloader, config::Cfg, List, devdir}; |
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>> { |
9 | 9 | ||
10 | println!("Inserting mod {}({}) into database", name, id); | 10 | println!("Inserting mod {}({}) into database", name, id); |
11 | 11 | ||
12 | let data = format!("{}/data.db", config.data); | 12 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
13 | let connection = Connection::open(data)?; | 13 | let connection = Connection::open(data)?; |
14 | 14 | ||
15 | connection.execute( | 15 | connection.execute( |
@@ -21,7 +21,7 @@ pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec<String>) | |||
21 | } | 21 | } |
22 | 22 | ||
23 | pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 23 | pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
24 | let data = format!("{}/data.db", config.data); | 24 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
25 | let connection = Connection::open(data).unwrap(); | 25 | let connection = Connection::open(data).unwrap(); |
26 | 26 | ||
27 | let mut mods: Vec<String> = Vec::new(); | 27 | let mut mods: Vec<String> = Vec::new(); |
@@ -43,7 +43,7 @@ pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error:: | |||
43 | } | 43 | } |
44 | 44 | ||
45 | pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::error::Error>> { | 45 | pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::error::Error>> { |
46 | let data = format!("{}/data.db", config.data); | 46 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
47 | let connection = Connection::open(data)?; | 47 | let connection = Connection::open(data)?; |
48 | 48 | ||
49 | let mut mod_id = String::new(); | 49 | let mut mod_id = String::new(); |
@@ -64,7 +64,7 @@ pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::err | |||
64 | } | 64 | } |
65 | 65 | ||
66 | pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> { | 66 | pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> { |
67 | let data = format!("{}/data.db", config.data); | 67 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
68 | let connection = Connection::open(data)?; | 68 | let connection = Connection::open(data)?; |
69 | 69 | ||
70 | let mut mod_name = String::new(); | 70 | let mut mod_name = String::new(); |
@@ -88,7 +88,7 @@ pub fn mods_change_versions(config: Cfg, versions: String, mod_id: String) -> Re | |||
88 | 88 | ||
89 | println!("Updating versions for {} with \n {}", mod_id, versions); | 89 | println!("Updating versions for {} with \n {}", mod_id, versions); |
90 | 90 | ||
91 | let data = format!("{}/data.db", config.data); | 91 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
92 | let connection = Connection::open(data)?; | 92 | let connection = Connection::open(data)?; |
93 | 93 | ||
94 | connection.execute("UPDATE mods SET versions = ?1 WHERE id = ?2", [versions, mod_id])?; | 94 | 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<dyn std::error::Er | |||
99 | 99 | ||
100 | println!("Removing mod {} from database", id); | 100 | println!("Removing mod {} from database", id); |
101 | 101 | ||
102 | let data = format!("{}/data.db", config.data); | 102 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
103 | let connection = Connection::open(data)?; | 103 | let connection = Connection::open(data)?; |
104 | 104 | ||
105 | connection.execute("DELETE FROM mods WHERE id = ?", [id])?; | 105 | connection.execute("DELETE FROM mods WHERE id = ?", [id])?; |
@@ -114,7 +114,7 @@ pub struct DBModlistVersions { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> Result<Vec<DBModlistVersions>, Box<dyn std::error::Error>> { | 116 | pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> Result<Vec<DBModlistVersions>, Box<dyn std::error::Error>> { |
117 | let data = format!("{}/data.db", config.data); | 117 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
118 | let connection = Connection::open(data)?; | 118 | let connection = Connection::open(data)?; |
119 | 119 | ||
120 | if mods.is_empty() { return Err(Box::new(Error::new(ErrorKind::Other, "MODS_NO_INPUT"))); } | 120 | 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<String>) -> Result<Vec<DBModlist | |||
149 | 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>> { | 149 | 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>> { |
150 | println!("Inserting {} into current list({})", mod_id, list_id); | 150 | println!("Inserting {} into current list({})", mod_id, list_id); |
151 | 151 | ||
152 | let data = format!("{}/data.db", config.data); | 152 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
153 | let connection = Connection::open(data)?; | 153 | let connection = Connection::open(data)?; |
154 | 154 | ||
155 | 155 | ||
@@ -159,7 +159,7 @@ pub fn userlist_insert(config: Cfg, list_id: String, mod_id: String, current_ver | |||
159 | } | 159 | } |
160 | 160 | ||
161 | pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 161 | pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
162 | let data = format!("{}/data.db", config.data); | 162 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
163 | let connection = Connection::open(data).unwrap(); | 163 | let connection = Connection::open(data).unwrap(); |
164 | 164 | ||
165 | let mut mod_ids: Vec<String> = Vec::new(); | 165 | let mut mod_ids: Vec<String> = Vec::new(); |
@@ -181,7 +181,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> Result<Vec<String>, | |||
181 | 181 | ||
182 | 182 | ||
183 | pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { | 183 | pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { |
184 | let data = format!("{}/data.db", config.data); | 184 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
185 | let connection = Connection::open(data)?; | 185 | let connection = Connection::open(data)?; |
186 | 186 | ||
187 | connection.execute(format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), [mod_id])?; | 187 | 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<( | |||
190 | 190 | ||
191 | 191 | ||
192 | pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { | 192 | pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { |
193 | let data = format!("{}/data.db", config.data); | 193 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
194 | let connection = Connection::open(data).unwrap(); | 194 | let connection = Connection::open(data).unwrap(); |
195 | 195 | ||
196 | let mut version: String = String::new(); | 196 | let mut version: String = String::new(); |
@@ -210,7 +210,7 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St | |||
210 | } | 210 | } |
211 | 211 | ||
212 | pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { | 212 | pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { |
213 | let data = format!("{}/data.db", config.data); | 213 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
214 | let connection = Connection::open(data)?; | 214 | let connection = Connection::open(data)?; |
215 | 215 | ||
216 | let mut versions: Vec<(String, String)> = Vec::new(); | 216 | 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 | |||
230 | } | 230 | } |
231 | 231 | ||
232 | pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { | 232 | pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { |
233 | let data = format!("{}/data.db", config.data); | 233 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
234 | let connection = Connection::open(data).unwrap(); | 234 | let connection = Connection::open(data).unwrap(); |
235 | 235 | ||
236 | let mut version: String = String::new(); | 236 | let mut version: String = String::new(); |
@@ -250,7 +250,7 @@ pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String | |||
250 | } | 250 | } |
251 | 251 | ||
252 | pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 252 | pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
253 | let data = format!("{}/data.db", config.data); | 253 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
254 | let connection = Connection::open(data)?; | 254 | let connection = Connection::open(data)?; |
255 | 255 | ||
256 | let mut versions: Vec<String> = Vec::new(); | 256 | let mut versions: Vec<String> = Vec::new(); |
@@ -269,7 +269,7 @@ pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Res | |||
269 | } | 269 | } |
270 | 270 | ||
271 | pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { | 271 | pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { |
272 | let data = format!("{}/data.db", config.data); | 272 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
273 | let connection = Connection::open(data)?; | 273 | let connection = Connection::open(data)?; |
274 | 274 | ||
275 | let mut versions: Vec<(String, String)> = Vec::new(); | 275 | 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) | |||
289 | } | 289 | } |
290 | 290 | ||
291 | 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>> { | 291 | 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>> { |
292 | let data = format!("{}/data.db", config.data); | 292 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
293 | let connection = Connection::open(data)?; | 293 | let connection = Connection::open(data)?; |
294 | 294 | ||
295 | 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])?; | 295 | 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 | |||
297 | } | 297 | } |
298 | 298 | ||
299 | pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_version: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { | 299 | pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_version: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { |
300 | let data = format!("{}/data.db", config.data); | 300 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
301 | let connection = Connection::open(data)?; | 301 | let connection = Connection::open(data)?; |
302 | 302 | ||
303 | let currently_disabled_versions = userlist_get_disabled_versions(config, String::from(&list_id), String::from(&mod_id))?; | 303 | 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 | |||
311 | } | 311 | } |
312 | 312 | ||
313 | pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { | 313 | pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { |
314 | let data = format!("{}/data.db", config.data); | 314 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
315 | let connection = Connection::open(data).unwrap(); | 315 | let connection = Connection::open(data).unwrap(); |
316 | 316 | ||
317 | let mut version: String = String::new(); | 317 | let mut version: String = String::new(); |
@@ -331,7 +331,7 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin | |||
331 | } | 331 | } |
332 | 332 | ||
333 | pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 333 | pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
334 | let data = format!("{}/data.db", config.data); | 334 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
335 | let connection = Connection::open(data).unwrap(); | 335 | let connection = Connection::open(data).unwrap(); |
336 | 336 | ||
337 | let mut links: Vec<String> = Vec::new(); | 337 | let mut links: Vec<String> = Vec::new(); |
@@ -355,7 +355,7 @@ pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<St | |||
355 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> Result<(), Box<dyn std::error::Error>> { | 355 | pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> Result<(), Box<dyn std::error::Error>> { |
356 | println!("Creating list {}", id); | 356 | println!("Creating list {}", id); |
357 | 357 | ||
358 | let data = format!("{}/data.db", config.data); | 358 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
359 | let connection = Connection::open(data)?; | 359 | let connection = Connection::open(data)?; |
360 | 360 | ||
361 | connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id.clone(), mc_version, mod_loader.stringify(), download_folder])?; | 361 | 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 | |||
365 | } | 365 | } |
366 | 366 | ||
367 | pub fn lists_remove(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { | 367 | pub fn lists_remove(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { |
368 | let data = format!("{}/data.db", config.data); | 368 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
369 | let connection = Connection::open(data)?; | 369 | let connection = Connection::open(data)?; |
370 | 370 | ||
371 | connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; | 371 | connection.execute("DELETE FROM lists WHERE id = ?", [&id])?; |
@@ -374,7 +374,7 @@ pub fn lists_remove(config: Cfg, id: String) -> Result<(), Box<dyn std::error::E | |||
374 | } | 374 | } |
375 | 375 | ||
376 | pub fn lists_get(config: Cfg, list_id: String) -> Result<List, Box<dyn std::error::Error>> { | 376 | pub fn lists_get(config: Cfg, list_id: String) -> Result<List, Box<dyn std::error::Error>> { |
377 | let data = format!("{}/data.db", config.data); | 377 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
378 | let connection = Connection::open(data).unwrap(); | 378 | let connection = Connection::open(data).unwrap(); |
379 | 379 | ||
380 | let mut list = List { id: String::new(), mc_version: String::new(), modloader: Modloader::Fabric, download_folder: String::new() }; | 380 | 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<List, Box<dyn std::erro | |||
395 | } | 395 | } |
396 | 396 | ||
397 | pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { | 397 | pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { |
398 | let data = format!("{}/data.db", config.data); | 398 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
399 | let connection = Connection::open(data).unwrap(); | 399 | let connection = Connection::open(data).unwrap(); |
400 | 400 | ||
401 | let mut list_ids: Vec<String> = Vec::new(); | 401 | let mut list_ids: Vec<String> = Vec::new(); |
@@ -416,7 +416,7 @@ pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error: | |||
416 | 416 | ||
417 | //config | 417 | //config |
418 | pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { | 418 | pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { |
419 | let data = format!("{}/data.db", config.data); | 419 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
420 | let connection = Connection::open(data)?; | 420 | let connection = Connection::open(data)?; |
421 | 421 | ||
422 | connection.execute("UPDATE user_config SET value = ? WHERE id = 'current_list'", [id])?; | 422 | 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<dyn | |||
424 | } | 424 | } |
425 | 425 | ||
426 | pub fn config_get_current_list(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { | 426 | pub fn config_get_current_list(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { |
427 | let data = format!("{}/data.db", config.data); | 427 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
428 | let connection = Connection::open(data).unwrap(); | 428 | let connection = Connection::open(data).unwrap(); |
429 | 429 | ||
430 | let mut list_id = String::new(); | 430 | let mut list_id = String::new(); |
@@ -444,7 +444,7 @@ pub fn config_get_current_list(config: Cfg) -> Result<String, Box<dyn std::error | |||
444 | 444 | ||
445 | //SETUP(UPDATES) | 445 | //SETUP(UPDATES) |
446 | pub fn s_userlist_update_download(config: Cfg, list_id: String, mod_id: String, link: String) -> Result<(), Box<dyn std::error::Error>> { | 446 | pub fn s_userlist_update_download(config: Cfg, list_id: String, mod_id: String, link: String) -> Result<(), Box<dyn std::error::Error>> { |
447 | let data = format!("{}/data.db", config.data); | 447 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
448 | let connection = Connection::open(data)?; | 448 | let connection = Connection::open(data)?; |
449 | 449 | ||
450 | connection.execute(format!("UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", list_id).as_str(), [link, mod_id])?; | 450 | 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, | |||
452 | } | 452 | } |
453 | 453 | ||
454 | pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | 454 | pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { |
455 | let data = format!("{}/data.db", config.data); | 455 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
456 | let connection = Connection::open(data)?; | 456 | let connection = Connection::open(data)?; |
457 | 457 | ||
458 | connection.execute("INSERT INTO 'user_config' VALUES ( 'db_version', '0.2' )", ())?; | 458 | 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<dyn std::error::Er | |||
460 | } | 460 | } |
461 | 461 | ||
462 | pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { | 462 | pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { |
463 | let data = format!("{}/data.db", config.data); | 463 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
464 | let connection = Connection::open(data)?; | 464 | let connection = Connection::open(data)?; |
465 | 465 | ||
466 | connection.execute("UPDATE user_config SET value = ? WHERE id = 'db_version'", [ver])?; | 466 | 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<dyn s | |||
468 | } | 468 | } |
469 | 469 | ||
470 | pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { | 470 | pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { |
471 | let data = format!("{}/data.db", config.data); | 471 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
472 | let connection = Connection::open(data)?; | 472 | let connection = Connection::open(data)?; |
473 | 473 | ||
474 | let mut version: String = String::new(); | 474 | let mut version: String = String::new(); |
@@ -486,7 +486,7 @@ pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::E | |||
486 | } | 486 | } |
487 | 487 | ||
488 | pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: String, default: Option<String>) -> Result<(), Box<dyn std::error::Error>> { | 488 | pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: String, default: Option<String>) -> Result<(), Box<dyn std::error::Error>> { |
489 | let data = format!("{}/data.db", config.data); | 489 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
490 | let connection = Connection::open(data)?; | 490 | let connection = Connection::open(data)?; |
491 | 491 | ||
492 | let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); | 492 | let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); |
@@ -503,7 +503,7 @@ pub fn db_setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { | |||
503 | 503 | ||
504 | println!("Initiating database"); | 504 | println!("Initiating database"); |
505 | 505 | ||
506 | let data = format!("{}/data.db", config.data); | 506 | let data = devdir(format!("{}/data.db", config.data).as_str()); |
507 | let connection = Connection::open(data)?; | 507 | let connection = Connection::open(data)?; |
508 | 508 | ||
509 | connection.execute_batch( | 509 | connection.execute_batch( |