diff --git a/src/types/root_config.rs b/src/types/root_config.rs index efbe6f0..e4cc6a8 100644 --- a/src/types/root_config.rs +++ b/src/types/root_config.rs @@ -12,6 +12,7 @@ use crate::types::{ConfigReadWriteError, ModConfig, game::Game, modded_instance: #[derive(Debug, Clone, Deserialize)] pub struct RootConfig { /// Available games + #[serde(default)] games: HashMap, /// Where all mods are stored @@ -23,6 +24,9 @@ pub struct RootConfig { /// All available mods #[serde(default)] mods: Vec, + + #[serde(skip)] + self_path: PathBuf, } impl RootConfig { @@ -32,8 +36,14 @@ impl RootConfig { path.as_ref().to_string_lossy() ); - let data = read_to_string(path)?; - let config = toml::from_str(&data)?; + let data = read_to_string(&path)?; + let mut config: Self = toml::from_str(&data)?; + + config.self_path = path.as_ref().to_owned(); + + if config.mod_location.is_relative() { + config.mod_location = path.as_ref().join(config.mod_location).to_owned(); + } Ok(config) } @@ -52,7 +62,11 @@ impl RootConfig { .get(id) .ok_or(ConfigReadWriteError::IDNotFound)?; - ModdedInstance::load_from_file(&conf.path) + if conf.path.is_relative() { + ModdedInstance::load_from_file(self.self_path.join(&conf.path)) + } else { + ModdedInstance::load_from_file(&conf.path) + } } pub fn mod_location(&self) -> &Path {