paths in config can now be relative to the file
This commit is contained in:
@@ -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<String, Game>,
|
||||
|
||||
/// Where all mods are stored
|
||||
@@ -23,6 +24,9 @@ pub struct RootConfig {
|
||||
/// All available mods
|
||||
#[serde(default)]
|
||||
mods: Vec<ModConfig>,
|
||||
|
||||
#[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 {
|
||||
|
||||
Reference in New Issue
Block a user