summaryrefslogtreecommitdiff
path: root/src/commands/setup.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-02-05 09:23:29 +0100
committerfxqnlr <[email protected]>2023-02-05 09:23:29 +0100
commitff23a11e632812b685f594324e6004c6da81cd4d (patch)
tree2b503cb25d8ebfbc33d449860e1903a4c6c9513f /src/commands/setup.rs
parent2f4b5f1584f88491ea4a6902d69382a0e73aa76d (diff)
downloadmodlist-ff23a11e632812b685f594324e6004c6da81cd4d.tar
modlist-ff23a11e632812b685f594324e6004c6da81cd4d.tar.gz
modlist-ff23a11e632812b685f594324e6004c6da81cd4d.zip
Fixed update shit not correctly updating
Diffstat (limited to 'src/commands/setup.rs')
-rw-r--r--src/commands/setup.rs86
1 files changed, 46 insertions, 40 deletions
diff --git a/src/commands/setup.rs b/src/commands/setup.rs
index cc7472c..0161bd7 100644
--- a/src/commands/setup.rs
+++ b/src/commands/setup.rs
@@ -1,66 +1,72 @@
1use std::{fs::File, path::Path, io::{Error, ErrorKind}}; 1use std::{fs::File, path::Path};
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, devdir}; 3use crate::{config::Cfg, db::db_setup, error::MLE, devdir};
4 4
5pub async fn setup(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 5pub async fn setup(config: Cfg) -> MLE<()> {
6 let db_file = devdir(format!("{}/data.db", config.data).as_str()); 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 create(config, db_file)?;
10 } 10 }
11 11
12 /*
12 match s_config_get_version(config.clone()) { 13 match s_config_get_version(config.clone()) {
13 Ok(ver) => { 14 Ok(ver) => {
14 match ver.as_str() { 15 match ver.as_str() {
15 "0.2" => to_03(config)?, 16 "0.2" => to_03(config)?,
16 "0.3" => to_04(config)?, 17 "0.3" => to_04(config)?,
17 _ => return Err(Box::new(Error::new(ErrorKind::Other, "UNKNOWN_VERSION"))) 18 _ => return Err(MLError::new(ErrorType::Other, "UNKNOWN_VERSION"))
18 } 19 }
19 }, 20 },
20 Err(..) => to_02(config).await? 21 Err(..) => to_02(config).await?
21 }; 22 };
23 */
22 24
23 Ok(()) 25 Ok(())
24} 26}
25 27
26fn create(config: Cfg, db_file: String) -> Result<(), Box<dyn std::error::Error>> { 28fn create(config: Cfg, db_file: String) -> MLE<()> {
27 File::create(db_file)?;
28 db_setup(config)?;
29 Ok(())
30}
31
32async fn to_02(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
33 let lists = lists_get_all_ids(config.clone())?;
34
35 for list in lists {
36 println!("Updating {}", list);
37 s_insert_column(config.clone(), String::from(&list), String::from("current_download"), String::from("TEXT"), None)?;
38
39 let full_list = lists_get(config.clone(), String::from(&list))?;
40 29
41 let versions = userlist_get_all_current_version_ids(config.clone(), full_list.clone().id)?; 30 println!("Create database");
42
43 let raw_versions = get_raw_versions(String::from(&config.apis.modrinth), versions).await;
44
45 for ver in raw_versions {
46 println!("Adding link for {}", ver.project_id);
47 let file = ver.files.into_iter().find(|f| f.primary).unwrap();
48 s_userlist_update_download(config.clone(), String::from(&full_list.id), ver.project_id, file.url)?;
49 }
50 };
51 s_config_create_version(config)?;
52 31
32 File::create(db_file)?;
33 db_setup(config)?;
53 Ok(()) 34 Ok(())
54} 35}
55 36
56fn to_03(config: Cfg) -> Result<(), Box<dyn std::error::Error>> { 37//async fn to_02(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
57 s_insert_column(config.clone(), String::from("lists"), String::from("download_folder"), String::from("TEXT"), None)?; 38// let lists = lists_get_all_ids(config.clone())?;
58 s_config_update_version(config, String::from("0.3")) 39//
59} 40// for list in lists {
41// println!("Updating {}", list);
42// s_insert_column(config.clone(), String::from(&list), String::from("current_download"), String::from("TEXT"), None)?;
43//
44// let full_list = lists_get(config.clone(), String::from(&list))?;
45//
46// let versions = userlist_get_all_current_version_ids(config.clone(), full_list.clone().id)?;
47//
48// let raw_versions = get_raw_versions(String::from(&config.apis.modrinth), versions).await;
49//
50// for ver in raw_versions {
51// println!("Adding link for {}", ver.project_id);
52// let file = ver.files.into_iter().find(|f| f.primary).unwrap();
53// s_userlist_update_download(config.clone(), String::from(&full_list.id), ver.project_id, file.url)?;
54// }
55// };
56// s_config_create_version(config)?;
57//
58// Ok(())
59//}
60//
61//fn to_03(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
62// s_insert_column(config.clone(), String::from("lists"), String::from("download_folder"), String::from("TEXT"), None)?;
63// s_config_update_version(config, String::from("0.3"))
64//}
65//
66//fn to_04(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
67// for list_id in lists_get_all_ids(config.clone())? {
68// s_insert_column(config.clone(), list_id, String::from("disabled_versions"), String::from("TEXT"), Some(String::from("NONE")))?;
69// }
70// s_config_update_version(config, String::from("0.4"))
71//}
60 72
61fn to_04(config: Cfg) -> Result<(), Box<dyn std::error::Error>> {
62 for list_id in lists_get_all_ids(config.clone())? {
63 s_insert_column(config.clone(), list_id, String::from("disabled_versions"), String::from("TEXT"), Some(String::from("NONE")))?;
64 }
65 s_config_update_version(config, String::from("0.4"))
66} \ No newline at end of file