summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2023-05-02 20:37:23 +0200
committerfxqnlr <[email protected]>2023-05-02 20:37:23 +0200
commit202ed4fcaa69e7de23e83fab0bae4ced6209eee4 (patch)
tree94c907a04f357f71f35e0d4a27b7e272dc00c476 /src/config.rs
parente8cac6786bc2e91382316ef1023a494c3e812013 (diff)
downloadmodlist-202ed4fcaa69e7de23e83fab0bae4ced6209eee4.tar
modlist-202ed4fcaa69e7de23e83fab0bae4ced6209eee4.tar.gz
modlist-202ed4fcaa69e7de23e83fab0bae4ced6209eee4.zip
added config option for default mc version
changed version input system
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/config.rs b/src/config.rs
index cf27257..e1049d1 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -6,12 +6,13 @@ use std::{
6 6
7use serde::{Deserialize, Serialize}; 7use serde::{Deserialize, Serialize};
8 8
9use crate::{db::db_setup, error::MLE, Modloader}; 9use crate::{db::db_setup, error::MLE, Modloader, VersionLevel, check_game_versions};
10 10
11#[derive(Debug, Clone, Serialize, Deserialize)] 11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Cfg { 12pub struct Cfg {
13 pub data: String, 13 pub data: String,
14 pub cache: String, 14 pub cache: String,
15 pub versions: String,
15 pub defaults: Defaults, 16 pub defaults: Defaults,
16 pub apis: Apis, 17 pub apis: Apis,
17} 18}
@@ -24,10 +25,11 @@ pub struct Apis {
24#[derive(Debug, Clone, Serialize, Deserialize)] 25#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Defaults { 26pub struct Defaults {
26 pub modloader: Modloader, 27 pub modloader: Modloader,
28 pub version: VersionLevel,
27} 29}
28 30
29impl Cfg { 31impl Cfg {
30 pub fn init(path: Option<String>) -> MLE<Self> { 32 pub async fn init(path: Option<String>) -> MLE<Self> {
31 let configfile = match path.clone() { 33 let configfile = match path.clone() {
32 Some(p) => String::from(p), 34 Some(p) => String::from(p),
33 None => dirs::config_dir() 35 None => dirs::config_dir()
@@ -62,6 +64,15 @@ impl Cfg {
62 Ok(..) => (), 64 Ok(..) => (),
63 Err(..) => create_database(&datafile)?, 65 Err(..) => create_database(&datafile)?,
64 }; 66 };
67 //Check versions
68 let versionfile = format!("{}/versions.json", config.versions);
69 match File::open(&versionfile) {
70 Ok(..) => (),
71 Err(..) => {
72 create_versions_dummy(&versionfile).await?;
73 check_game_versions(&versionfile, true).await?;
74 },
75 }
65 Ok(config) 76 Ok(config)
66 } 77 }
67} 78}
@@ -78,8 +89,10 @@ fn create_config(path: &str) -> MLE<()> {
78 let default_cfg = Cfg { 89 let default_cfg = Cfg {
79 data: cache_dir.clone(), 90 data: cache_dir.clone(),
80 cache: format!("{}/cache", cache_dir), 91 cache: format!("{}/cache", cache_dir),
92 versions: cache_dir.clone(),
81 defaults: Defaults { 93 defaults: Defaults {
82 modloader: Modloader::Fabric 94 modloader: Modloader::Fabric,
95 version: VersionLevel::Release
83 }, 96 },
84 apis: Apis { 97 apis: Apis {
85 modrinth: String::from("https://api.modrinth.com/v2/"), 98 modrinth: String::from("https://api.modrinth.com/v2/"),
@@ -112,3 +125,13 @@ fn create_cache(path: &str) -> MLE<()> {
112 println!(" ✓"); 125 println!(" ✓");
113 Ok(()) 126 Ok(())
114} 127}
128
129async fn create_versions_dummy(path: &str) -> MLE<()> {
130 print!("No version file found, create dummy");
131 //Force flush of stdout, else print! doesn't print instantly
132 std::io::stdout().flush()?;
133
134 File::create(path)?;
135 println!(" ✓");
136 Ok(())
137}