From a393e0a2f2c3678a3ea869dc1417fa269f2b1040 Mon Sep 17 00:00:00 2001 From: Filip Wandzio Date: Sat, 24 Jan 2026 08:29:14 +0100 Subject: Resolve audio not loading bug Ensure all assets are downloading for each version Temporarily disable minecraft versions older than 1.8 because of the asset/manifest loading issues Implement basic documentation of modules Implement basic async/multithreading for downloading assets --- src/config/loader.rs | 23 +++++++++-------------- src/config/mod.rs | 11 ++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) (limited to 'src/config') diff --git a/src/config/loader.rs b/src/config/loader.rs index 81a4351..d4b142e 100644 --- a/src/config/loader.rs +++ b/src/config/loader.rs @@ -1,9 +1,9 @@ -use std::{env, path::PathBuf}; +use std::{env::var, fs::read_to_string, path::PathBuf}; +use directories::ProjectDirs; use serde::Deserialize; use crate::{constants::*, errors::McError}; - #[allow(dead_code)] #[derive(Debug, Deserialize)] pub struct Config { @@ -18,37 +18,33 @@ pub struct Config { #[serde(default)] pub jvm_args: Vec, } - impl Config { pub fn load() -> Result { let cfg_path = default_config_path()?; let mut cfg: Config = if cfg_path.exists() { - let txt = std::fs::read_to_string(&cfg_path)?; + let txt = read_to_string(&cfg_path)?; toml::from_str(&txt).map_err(|e| McError::Config(e.to_string()))? } else { Self::default() }; - - if let Ok(v) = env::var("MC_USERNAME") { + if let Ok(v) = var("MC_USERNAME") { cfg.username = v; } - if let Ok(v) = env::var("MC_VERSION") { + if let Ok(v) = var("MC_VERSION") { cfg.version = v; } - if let Ok(v) = env::var("MC_JAVA_PATH") { + if let Ok(v) = var("MC_JAVA_PATH") { cfg.java_path = v; } - if let Ok(v) = env::var("MC_MAX_MEMORY_MB") { + if let Ok(v) = var("MC_MAX_MEMORY_MB") { cfg.max_memory_mb = v.parse().unwrap_or(cfg.max_memory_mb); } - Ok(cfg) } fn default() -> Self { let base = - directories::ProjectDirs::from("com", "example", "mccl").expect("platform dirs"); - + ProjectDirs::from("com", "example", "dml").expect("platform dirs"); Self { username: "Player".into(), uuid: uuid::Uuid::new_v4().to_string(), @@ -62,9 +58,8 @@ impl Config { } } } - fn default_config_path() -> Result { - let base = directories::ProjectDirs::from("com", "example", "mccl") + let base = ProjectDirs::from("com", "example", "dml") .ok_or_else(|| McError::Config("cannot determine config dir".into()))?; Ok(base.config_dir().join("config.toml")) } diff --git a/src/config/mod.rs b/src/config/mod.rs index c5fc004..066154a 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,3 +1,12 @@ -pub mod loader; +//! Configuration module for the DML launcher. +//! +//! This module contains submodules and helpers for loading, parsing, and +//! managing configuration files and settings. It abstracts the details +//! of where configuration is stored and how it is represented in memory. +//! +//! # Submodules +//! - `loader`: Functions to load and parse configuration from disk or +//! environment variables. +pub mod loader; pub use loader::Config; -- cgit v1.2.3