summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock54
-rw-r--r--Cargo.toml3
-rw-r--r--src/commands/download.rs3
-rw-r--r--src/commands/io.rs8
-rw-r--r--src/commands/setup.rs4
-rw-r--r--src/config.rs14
-rw-r--r--src/db.rs64
-rw-r--r--src/files.rs4
-rw-r--r--src/lib.rs16
-rw-r--r--src/main.rs3
10 files changed, 124 insertions, 49 deletions
diff --git a/Cargo.lock b/Cargo.lock
index f7a63d6..788f68c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -180,6 +180,26 @@ dependencies = [
180] 180]
181 181
182[[package]] 182[[package]]
183name = "dirs"
184version = "4.0.0"
185source = "registry+https://github.com/rust-lang/crates.io-index"
186checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059"
187dependencies = [
188 "dirs-sys",
189]
190
191[[package]]
192name = "dirs-sys"
193version = "0.3.7"
194source = "registry+https://github.com/rust-lang/crates.io-index"
195checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6"
196dependencies = [
197 "libc",
198 "redox_users",
199 "winapi",
200]
201
202[[package]]
183name = "encoding_rs" 203name = "encoding_rs"
184version = "0.8.31" 204version = "0.8.31"
185source = "registry+https://github.com/rust-lang/crates.io-index" 205source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -595,9 +615,10 @@ dependencies = [
595 615
596[[package]] 616[[package]]
597name = "modlist" 617name = "modlist"
598version = "0.6.2" 618version = "0.8.0"
599dependencies = [ 619dependencies = [
600 "chrono", 620 "chrono",
621 "dirs",
601 "error-chain", 622 "error-chain",
602 "futures-util", 623 "futures-util",
603 "reqwest", 624 "reqwest",
@@ -790,6 +811,17 @@ dependencies = [
790] 811]
791 812
792[[package]] 813[[package]]
814name = "redox_users"
815version = "0.4.3"
816source = "registry+https://github.com/rust-lang/crates.io-index"
817checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b"
818dependencies = [
819 "getrandom",
820 "redox_syscall",
821 "thiserror",
822]
823
824[[package]]
793name = "remove_dir_all" 825name = "remove_dir_all"
794version = "0.5.3" 826version = "0.5.3"
795source = "registry+https://github.com/rust-lang/crates.io-index" 827source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1019,6 +1051,26 @@ dependencies = [
1019] 1051]
1020 1052
1021[[package]] 1053[[package]]
1054name = "thiserror"
1055version = "1.0.38"
1056source = "registry+https://github.com/rust-lang/crates.io-index"
1057checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0"
1058dependencies = [
1059 "thiserror-impl",
1060]
1061
1062[[package]]
1063name = "thiserror-impl"
1064version = "1.0.38"
1065source = "registry+https://github.com/rust-lang/crates.io-index"
1066checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f"
1067dependencies = [
1068 "proc-macro2",
1069 "quote",
1070 "syn",
1071]
1072
1073[[package]]
1022name = "time" 1074name = "time"
1023version = "0.1.45" 1075version = "0.1.45"
1024source = "registry+https://github.com/rust-lang/crates.io-index" 1076source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 124c084..6e9c282 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
1[package] 1[package]
2name = "modlist" 2name = "modlist"
3version = "0.7.0" 3version = "0.8.0"
4edition = "2021" 4edition = "2021"
5 5
6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 6# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -15,3 +15,4 @@ futures-util = "0.3.14"
15chrono = "0.4.22" 15chrono = "0.4.22"
16toml = "0.5.10" 16toml = "0.5.10"
17error-chain = "0.12.4" 17error-chain = "0.12.4"
18dirs = "4.0.0"
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 0f9011c..b958bf3 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -11,12 +11,13 @@ pub async fn download(config: Cfg, input: Input) -> Result<(), Box<dyn std::erro
11 } 11 }
12 } else { 12 } else {
13 let current = get_current_list(config.clone())?; 13 let current = get_current_list(config.clone())?;
14 println!("Checking for updates of mods in {}", current.id); 14 println!("Downloading current versions of mods in {}", current.id);
15 liststack.push(current) 15 liststack.push(current)
16 } 16 }
17 17
18 for current_list in liststack { 18 for current_list in liststack {
19 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 19 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
20 println!("To download: {:#?}", downloaded_versions);
20 let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(&current_list.id))?; 21 let current_version_ids = userlist_get_all_current_versions_with_mods(config.clone(), String::from(&current_list.id))?;
21 22
22 let mut to_download: Vec<String> = vec![]; 23 let mut to_download: Vec<String> = vec![];
diff --git a/src/commands/io.rs b/src/commands/io.rs
index 2edb95d..39f92d5 100644
--- a/src/commands/io.rs
+++ b/src/commands/io.rs
@@ -2,7 +2,7 @@ use std::fs::File;
2use std::io::prelude::*; 2use std::io::prelude::*;
3use serde::{Serialize, Deserialize}; 3use serde::{Serialize, Deserialize};
4 4
5use crate::{input::{Input, Subcmd}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, mod_add, List}; 5use crate::{input::{Input, Subcmd}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, mod_add, List, devdir};
6 6
7#[derive(Debug, Serialize, Deserialize)] 7#[derive(Debug, Serialize, Deserialize)]
8struct Export { 8struct Export {
@@ -60,7 +60,9 @@ fn export(config: Cfg, input: Input) -> Result<(), Box<dyn std::error::Error>> {
60 60
61 let toml = toml::to_string( &Export { lists } )?; 61 let toml = toml::to_string( &Export { lists } )?;
62 62
63 let mut file = File::create("export.toml")?; 63 let filestr = dirs::home_dir().unwrap().join("mlexport.toml");
64
65 let mut file = File::create(devdir(filestr.into_os_string().into_string().unwrap().as_str()))?;
64 file.write_all(&toml.as_bytes())?; 66 file.write_all(&toml.as_bytes())?;
65 67
66 Ok(()) 68 Ok(())
@@ -70,7 +72,7 @@ async fn import(config: Cfg, args: Option<Vec<String>>) -> Result<(), Box<dyn st
70 72
71 let filestr: String = match args { 73 let filestr: String = match args {
72 Some(args) => String::from(&args[0]), 74 Some(args) => String::from(&args[0]),
73 None => String::from("export.toml"), 75 None => String::from(devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str())),
74 }; 76 };
75 77
76 let mut file = File::open(filestr)?; 78 let mut file = File::open(filestr)?;
diff --git a/src/commands/setup.rs b/src/commands/setup.rs
index c7f1bed..e4fa801 100644
--- a/src/commands/setup.rs
+++ b/src/commands/setup.rs
@@ -1,9 +1,9 @@
1use std::{fs::File, path::Path, io::{Error, ErrorKind}}; 1use std::{fs::File, path::Path, io::{Error, ErrorKind}};
2 2
3use crate::{config::Cfg, db::{db_setup, s_config_get_version, s_config_create_version, s_insert_column, lists_get_all_ids, lists_get, userlist_get_all_current_version_ids, s_userlist_update_download, s_config_update_version}, modrinth::get_raw_versions}; 3use crate::{config::Cfg, db::{db_setup, s_config_get_version, s_config_create_version, s_insert_column, lists_get_all_ids, lists_get, userlist_get_all_current_version_ids, s_userlist_update_download, s_config_update_version}, modrinth::get_raw_versions, devdir};
4 4
5pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 5pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
6 let db_file = format!("{}/data.db", String::from(&config.data)); 6 let db_file = devdir(format!("{}/data.db", config.data).as_str());
7 7
8 if !Path::new(&db_file).exists() { 8 if !Path::new(&db_file).exists() {
9 return create(config, db_file); 9 return create(config, db_file);
diff --git a/src/config.rs b/src/config.rs
index 99d2ec2..383e7ee 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -2,7 +2,7 @@ use std::{fs::File, io::{Read, Write}};
2 2
3use serde::{Serialize, Deserialize}; 3use serde::{Serialize, Deserialize};
4 4
5use crate::error::MLE; 5use crate::{error::MLE, devdir};
6 6
7#[derive(Debug, Clone, Serialize, Deserialize)] 7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Cfg { 8pub struct Cfg {
@@ -16,16 +16,20 @@ pub struct Apis {
16} 16}
17 17
18impl Cfg { 18impl Cfg {
19 pub fn init(path: &str) -> MLE<Self> { 19 pub fn init(filename: &str) -> MLE<Self> {
20 let mut file = match File::open(path) { 20 let configfile = dirs::config_dir().unwrap().join(filename);
21
22 let mut file = match File::open(devdir(configfile.to_str().unwrap())) {
21 Ok(file) => file, 23 Ok(file) => file,
22 Err(err) => { 24 Err(err) => {
23 if err.kind() == std::io::ErrorKind::NotFound { 25 if err.kind() == std::io::ErrorKind::NotFound {
24 println!("No config file found, creating one"); 26 println!("No config file found, creating one");
25 let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } }; 27 let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } };
26 let mut file = File::create(path)?; 28 //TODO Error
29 let mut file = File::create(devdir(configfile.to_str().unwrap()))?;
30 println!("Created config file");
27 file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?; 31 file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?;
28 File::open(path)? 32 File::open(devdir(configfile.to_str().unwrap()))?
29 } else { 33 } else {
30 return Err(err.into()); 34 return Err(err.into());
31 } 35 }
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};
2 2
3use rusqlite::Connection; 3use rusqlite::Connection;
4 4
5use crate::{Modloader, config::Cfg, List}; 5use crate::{Modloader, config::Cfg, List, devdir};
6 6
7//mods 7//mods
8pub fn mods_insert(config: Cfg, id: String, name: String, versions: Vec<String>) -> Result<(), Box<dyn std::error::Error>> { 8pub 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
23pub fn mods_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { 23pub 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
45pub fn mods_get_id(config: Cfg, name: String) -> Result<String, Box<dyn std::error::Error>> { 45pub 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
66pub fn mods_get_name(config: Cfg, id: String) -> Result<String, Box<dyn std::error::Error>> { 66pub 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
116pub fn mods_get_versions(config: Cfg, mods: Vec<String>) -> Result<Vec<DBModlistVersions>, Box<dyn std::error::Error>> { 116pub 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
149pub 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>> { 149pub 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
161pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { 161pub 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
183pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { 183pub 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
192pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { 192pub 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
212pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { 212pub 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
232pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { 232pub 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
252pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { 252pub 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
271pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result<Vec<(String, String)>, Box<dyn std::error::Error>> { 271pub 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
291pub 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>> { 291pub 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
299pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_version: String, mod_id: String) -> Result<(), Box<dyn std::error::Error>> { 299pub 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
313pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: String) -> Result<String, Box<dyn std::error::Error>> { 313pub 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
333pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result<Vec<String>, Box<dyn std::error::Error>> { 333pub 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
355pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> Result<(), Box<dyn std::error::Error>> { 355pub 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
367pub fn lists_remove(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { 367pub 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
376pub fn lists_get(config: Cfg, list_id: String) -> Result<List, Box<dyn std::error::Error>> { 376pub 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
397pub fn lists_get_all_ids(config: Cfg) -> Result<Vec<String>, Box<dyn std::error::Error>> { 397pub 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
418pub fn config_change_current_list(config: Cfg, id: String) -> Result<(), Box<dyn std::error::Error>> { 418pub 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
426pub fn config_get_current_list(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { 426pub 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)
446pub fn s_userlist_update_download(config: Cfg, list_id: String, mod_id: String, link: String) -> Result<(), Box<dyn std::error::Error>> { 446pub 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
454pub fn s_config_create_version(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 454pub 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
462pub fn s_config_update_version(config: Cfg, ver: String) -> Result<(), Box<dyn std::error::Error>> { 462pub 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
470pub fn s_config_get_version(config: Cfg) -> Result<String, Box<dyn std::error::Error>> { 470pub 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
488pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: String, default: Option<String>) -> Result<(), Box<dyn std::error::Error>> { 488pub 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(
diff --git a/src/files.rs b/src/files.rs
index b1e537c..a3f838a 100644
--- a/src/files.rs
+++ b/src/files.rs
@@ -28,7 +28,7 @@ async fn download_file(url: String, path: String, name: String) -> Result<(), Bo
28 .await?; 28 .await?;
29 29
30 // download chunks 30 // download chunks
31 let mut file = File::create(String::from(&dl_path_file))?; 31 let mut file = File::create(&dl_path_file)?;
32 let mut stream = res.bytes_stream(); 32 let mut stream = res.bytes_stream();
33 33
34 while let Some(item) = stream.next().await { 34 while let Some(item) = stream.next().await {
@@ -78,7 +78,7 @@ pub fn get_file_path(list: List, versionid: String) -> Result<String, Box<dyn st
78 78
79pub fn get_downloaded_versions(list: List) -> Result<HashMap<String, String>, Box<dyn std::error::Error>> { 79pub fn get_downloaded_versions(list: List) -> Result<HashMap<String, String>, Box<dyn std::error::Error>> {
80 let mut versions: HashMap<String, String> = HashMap::new(); 80 let mut versions: HashMap<String, String> = HashMap::new();
81 for file in read_dir(list.download_folder)? { 81 for file in read_dir(&list.download_folder)? {
82 let path = file?.path(); 82 let path = file?.path();
83 if path.is_file() && path.extension().ok_or("BAH")? == "jar" { 83 if path.is_file() && path.extension().ok_or("BAH")? == "jar" {
84 let pathstr = path.to_str().ok_or("BAH")?; 84 let pathstr = path.to_str().ok_or("BAH")?;
diff --git a/src/lib.rs b/src/lib.rs
index 971f544..17ad6b9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,7 +6,7 @@ pub mod db;
6pub mod error; 6pub mod error;
7pub mod files; 7pub mod files;
8 8
9use std::io::{Error, ErrorKind}; 9use std::{io::{Error, ErrorKind}, path::Path};
10 10
11pub use apis::*; 11pub use apis::*;
12pub use commands::*; 12pub use commands::*;
@@ -33,3 +33,17 @@ impl Modloader {
33 } 33 }
34 } 34 }
35} 35}
36
37pub fn devdir(path: &str) -> String {
38 let p = Path::new(path);
39 let dev = std::env::var("DEV");
40 let lvl = match dev {
41 Ok(dev) => dev.parse::<i32>().unwrap(),
42 Err(..) => 0,
43 };
44 if lvl >= 1 {
45 format!("./dev/{}", p.file_name().unwrap().to_str().unwrap())
46 } else {
47 String::from(path)
48 }
49}
diff --git a/src/main.rs b/src/main.rs
index a8aa15d..59d41c5 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,7 +2,8 @@ use modlist::{config::Cfg, input::get_input};
2 2
3#[tokio::main] 3#[tokio::main]
4async fn main() { 4async fn main() {
5 let config = Cfg::init("config.toml").unwrap(); 5 let config = Cfg::init("modlist.toml").unwrap();
6
6 match get_input(config).await { 7 match get_input(config).await {
7 Ok(..) => (), 8 Ok(..) => (),
8 Err(e) => { 9 Err(e) => {