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)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct RootConfig {
|
pub struct RootConfig {
|
||||||
/// Available games
|
/// Available games
|
||||||
|
#[serde(default)]
|
||||||
games: HashMap<String, Game>,
|
games: HashMap<String, Game>,
|
||||||
|
|
||||||
/// Where all mods are stored
|
/// Where all mods are stored
|
||||||
@@ -23,6 +24,9 @@ pub struct RootConfig {
|
|||||||
/// All available mods
|
/// All available mods
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
mods: Vec<ModConfig>,
|
mods: Vec<ModConfig>,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
self_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RootConfig {
|
impl RootConfig {
|
||||||
@@ -32,8 +36,14 @@ impl RootConfig {
|
|||||||
path.as_ref().to_string_lossy()
|
path.as_ref().to_string_lossy()
|
||||||
);
|
);
|
||||||
|
|
||||||
let data = read_to_string(path)?;
|
let data = read_to_string(&path)?;
|
||||||
let config = toml::from_str(&data)?;
|
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)
|
Ok(config)
|
||||||
}
|
}
|
||||||
@@ -52,8 +62,12 @@ impl RootConfig {
|
|||||||
.get(id)
|
.get(id)
|
||||||
.ok_or(ConfigReadWriteError::IDNotFound)?;
|
.ok_or(ConfigReadWriteError::IDNotFound)?;
|
||||||
|
|
||||||
|
if conf.path.is_relative() {
|
||||||
|
ModdedInstance::load_from_file(self.self_path.join(&conf.path))
|
||||||
|
} else {
|
||||||
ModdedInstance::load_from_file(&conf.path)
|
ModdedInstance::load_from_file(&conf.path)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mod_location(&self) -> &Path {
|
pub fn mod_location(&self) -> &Path {
|
||||||
&self.mod_location
|
&self.mod_location
|
||||||
|
|||||||
Reference in New Issue
Block a user