From 202ed4fcaa69e7de23e83fab0bae4ced6209eee4 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 2 May 2023 20:37:23 +0200 Subject: added config option for default mc version changed version input system --- src/config.rs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/config.rs') 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::{ use serde::{Deserialize, Serialize}; -use crate::{db::db_setup, error::MLE, Modloader}; +use crate::{db::db_setup, error::MLE, Modloader, VersionLevel, check_game_versions}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Cfg { pub data: String, pub cache: String, + pub versions: String, pub defaults: Defaults, pub apis: Apis, } @@ -24,10 +25,11 @@ pub struct Apis { #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Defaults { pub modloader: Modloader, + pub version: VersionLevel, } impl Cfg { - pub fn init(path: Option) -> MLE { + pub async fn init(path: Option) -> MLE { let configfile = match path.clone() { Some(p) => String::from(p), None => dirs::config_dir() @@ -62,6 +64,15 @@ impl Cfg { Ok(..) => (), Err(..) => create_database(&datafile)?, }; + //Check versions + let versionfile = format!("{}/versions.json", config.versions); + match File::open(&versionfile) { + Ok(..) => (), + Err(..) => { + create_versions_dummy(&versionfile).await?; + check_game_versions(&versionfile, true).await?; + }, + } Ok(config) } } @@ -78,8 +89,10 @@ fn create_config(path: &str) -> MLE<()> { let default_cfg = Cfg { data: cache_dir.clone(), cache: format!("{}/cache", cache_dir), + versions: cache_dir.clone(), defaults: Defaults { - modloader: Modloader::Fabric + modloader: Modloader::Fabric, + version: VersionLevel::Release }, apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/"), @@ -112,3 +125,13 @@ fn create_cache(path: &str) -> MLE<()> { println!(" ✓"); Ok(()) } + +async fn create_versions_dummy(path: &str) -> MLE<()> { + print!("No version file found, create dummy"); + //Force flush of stdout, else print! doesn't print instantly + std::io::stdout().flush()?; + + File::create(path)?; + println!(" ✓"); + Ok(()) +} -- cgit v1.2.3