summaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/download.rs2
-rw-r--r--src/commands/io.rs5
-rw-r--r--src/commands/mod.rs2
-rw-r--r--src/commands/setup.rs70
-rw-r--r--src/commands/update.rs98
5 files changed, 51 insertions, 126 deletions
diff --git a/src/commands/download.rs b/src/commands/download.rs
index 9434591..1a8eb8f 100644
--- a/src/commands/download.rs
+++ b/src/commands/download.rs
@@ -23,7 +23,7 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo
23 23
24 for current_list in liststack { 24 for current_list in liststack {
25 let downloaded_versions = get_downloaded_versions(current_list.clone())?; 25 let downloaded_versions = get_downloaded_versions(current_list.clone())?;
26 println!("To download: {:#?}", downloaded_versions); 26 // println!("To download: {:#?}", downloaded_versions);
27 let current_version_ids = match userlist_get_all_current_versions_with_mods( 27 let current_version_ids = match userlist_get_all_current_versions_with_mods(
28 config.clone(), 28 config.clone(),
29 String::from(&current_list.id), 29 String::from(&current_list.id),
diff --git a/src/commands/io.rs b/src/commands/io.rs
index 7f03eec..82b30ce 100644
--- a/src/commands/io.rs
+++ b/src/commands/io.rs
@@ -5,7 +5,6 @@ use std::io::prelude::*;
5use crate::{ 5use crate::{
6 config::Cfg, 6 config::Cfg,
7 db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids}, 7 db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids},
8 devdir,
9 error::MLE, 8 error::MLE,
10 mod_add, IDSelector, List, Modloader, 9 mod_add, IDSelector, List, Modloader,
11}; 10};
@@ -61,9 +60,7 @@ pub fn export(config: Cfg, list: Option<String>) -> MLE<()> {
61 60
62 let filestr = dirs::home_dir().unwrap().join("mlexport.toml"); 61 let filestr = dirs::home_dir().unwrap().join("mlexport.toml");
63 62
64 let mut file = File::create(devdir( 63 let mut file = File::create(filestr.into_os_string().into_string().unwrap().as_str())?;
65 filestr.into_os_string().into_string().unwrap().as_str(),
66 ))?;
67 file.write_all(toml.as_bytes())?; 64 file.write_all(toml.as_bytes())?;
68 65
69 Ok(()) 66 Ok(())
diff --git a/src/commands/mod.rs b/src/commands/mod.rs
index 1c7c012..0f13056 100644
--- a/src/commands/mod.rs
+++ b/src/commands/mod.rs
@@ -2,12 +2,10 @@ pub mod download;
2pub mod io; 2pub mod io;
3pub mod list; 3pub mod list;
4pub mod modification; 4pub mod modification;
5pub mod setup;
6pub mod update; 5pub mod update;
7 6
8pub use download::*; 7pub use download::*;
9pub use io::*; 8pub use io::*;
10pub use list::*; 9pub use list::*;
11pub use modification::*; 10pub use modification::*;
12pub use setup::*;
13pub use update::*; 11pub use update::*;
diff --git a/src/commands/setup.rs b/src/commands/setup.rs
deleted file mode 100644
index 40e8c0a..0000000
--- a/src/commands/setup.rs
+++ /dev/null
@@ -1,70 +0,0 @@
1use std::{fs::File, path::Path};
2
3use crate::{config::Cfg, db::db_setup, devdir, error::MLE};
4
5pub async fn setup(config: Cfg) -> MLE<()> {
6 let db_file = devdir(format!("{}/data.db", config.data).as_str());
7
8 if !Path::new(&db_file).exists() {
9 create(config, db_file)?;
10 }
11
12 /*
13 match s_config_get_version(config.clone()) {
14 Ok(ver) => {
15 match ver.as_str() {
16 "0.2" => to_03(config)?,
17 "0.3" => to_04(config)?,
18 _ => return Err(MLError::new(ErrorType::Other, "UNKNOWN_VERSION"))
19 }
20 },
21 Err(..) => to_02(config).await?
22 };
23 */
24
25 Ok(())
26}
27
28fn create(config: Cfg, db_file: String) -> MLE<()> {
29 println!("Create database");
30
31 File::create(db_file)?;
32 db_setup(config)?;
33 Ok(())
34}
35
36//async fn to_02(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
37// let lists = lists_get_all_ids(config.clone())?;
38//
39// for list in lists {
40// println!("Updating {}", list);
41// s_insert_column(config.clone(), String::from(&list), String::from("current_download"), String::from("TEXT"), None)?;
42//
43// let full_list = lists_get(config.clone(), String::from(&list))?;
44//
45// let versions = userlist_get_all_current_version_ids(config.clone(), full_list.clone().id)?;
46//
47// let raw_versions = get_raw_versions(String::from(&config.apis.modrinth), versions).await;
48//
49// for ver in raw_versions {
50// println!("Adding link for {}", ver.project_id);
51// let file = ver.files.into_iter().find(|f| f.primary).unwrap();
52// s_userlist_update_download(config.clone(), String::from(&full_list.id), ver.project_id, file.url)?;
53// }
54// };
55// s_config_create_version(config)?;
56//
57// Ok(())
58//}
59//
60//fn to_03(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
61// s_insert_column(config.clone(), String::from("lists"), String::from("download_folder"), String::from("TEXT"), None)?;
62// s_config_update_version(config, String::from("0.3"))
63//}
64//
65//fn to_04(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
66// for list_id in lists_get_all_ids(config.clone())? {
67// s_insert_column(config.clone(), list_id, String::from("disabled_versions"), String::from("TEXT"), Some(String::from("NONE")))?;
68// }
69// s_config_update_version(config, String::from("0.4"))
70//}
diff --git a/src/commands/update.rs b/src/commands/update.rs
index 3d9578b..4bc3ac0 100644
--- a/src/commands/update.rs
+++ b/src/commands/update.rs
@@ -156,52 +156,52 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML
156 Ok(current[0].clone()) 156 Ok(current[0].clone())
157} 157}
158 158
159#[tokio::test] 159// #[tokio::test]
160async fn download_updates_test() { 160// async fn download_updates_test() {
161 use crate::{ 161// use crate::{
162 modrinth::{Hash, Version, VersionFile, VersionType}, 162// modrinth::{Hash, Version, VersionFile, VersionType},
163 List, Modloader, 163// List, Modloader,
164 }; 164// };
165 165//
166 let config = Cfg::init("modlist.toml").unwrap(); 166// let config = Cfg::init().unwrap();
167 let current_list = List { 167// let current_list = List {
168 id: String::from("..."), 168// id: String::from("..."),
169 mc_version: String::from("..."), 169// mc_version: String::from("..."),
170 modloader: Modloader::Fabric, 170// modloader: Modloader::Fabric,
171 download_folder: String::from("./dev/tests/dl"), 171// download_folder: String::from("./dev/tests/dl"),
172 }; 172// };
173 173//
174 let versions = vec![Version { 174// let versions = vec![Version {
175 id: "dEqtGnT9".to_string(), 175// id: "dEqtGnT9".to_string(),
176 project_id: "kYuIpRLv".to_string(), 176// project_id: "kYuIpRLv".to_string(),
177 author_id: "Qnt13hO8".to_string(), 177// author_id: "Qnt13hO8".to_string(),
178 featured: true, 178// featured: true,
179 name: "1.2.2-1.19 - Fabric".to_string(), 179// name: "1.2.2-1.19 - Fabric".to_string(),
180 version_number: "1.2.2-1.19".to_string(), 180// version_number: "1.2.2-1.19".to_string(),
181 changelog: None, 181// changelog: None,
182 date_published: "2022-11-02T17:41:43.072267Z".to_string(), 182// date_published: "2022-11-02T17:41:43.072267Z".to_string(),
183 downloads: 58, 183// downloads: 58,
184 version_type: VersionType::release, 184// version_type: VersionType::release,
185 files: vec![VersionFile { 185// files: vec![VersionFile {
186 hashes: Hash { 186// hashes: Hash {
187 sha1: "fdc6dc39427fc92cc1d7ad8b275b5b83325e712b".to_string(), 187// sha1: "fdc6dc39427fc92cc1d7ad8b275b5b83325e712b".to_string(),
188 sha512: "5b372f00d6e5d6a5ef225c3897826b9f6a2be5506905f7f71b9e939779765b41be6f2a9b029cfc752ad0751d0d2d5f8bb4544408df1363eebdde15641e99a849".to_string() 188// sha512: "5b372f00d6e5d6a5ef225c3897826b9f6a2be5506905f7f71b9e939779765b41be6f2a9b029cfc752ad0751d0d2d5f8bb4544408df1363eebdde15641e99a849".to_string()
189 }, 189// },
190 url: "https://cdn.modrinth.com/data/kYuIpRLv/versions/dEqtGnT9/waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(), 190// url: "https://cdn.modrinth.com/data/kYuIpRLv/versions/dEqtGnT9/waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(),
191 filename: "waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(), 191// filename: "waveycapes-fabric-1.2.2-mc1.19.2.jar".to_string(),
192 primary: true, 192// primary: true,
193 size: 323176 193// size: 323176
194 }], 194// }],
195 game_versions: vec![ 195// game_versions: vec![
196 "1.19".to_string(), 196// "1.19".to_string(),
197 "1.19.1".to_string(), 197// "1.19.1".to_string(),
198 "1.19.2".to_string() 198// "1.19.2".to_string()
199 ], 199// ],
200 loaders: vec![ 200// loaders: vec![
201 "fabric".to_string() 201// "fabric".to_string()
202 ] 202// ]
203 }]; 203// }];
204 assert!(download_versions(current_list, config, versions) 204// assert!(download_versions(current_list, config, versions)
205 .await 205// .await
206 .is_ok()) 206// .is_ok())
207} 207// }