use anyhow::{anyhow, Result};
use directories::ProjectDirs;
use std::fs::DirBuilder;
use std::path::PathBuf;
use rpfm_lib::games::{*, supported_games::SupportedGames};
pub struct Config {
pub game: Option<GameInfo>,
pub verbose: bool,
}
impl Config {
pub fn new(game: &str, verbose: bool) -> Self {
let supported_games = SupportedGames::default();
Self {
game: supported_games.game(game).cloned(),
verbose,
}
}
}
#[must_use = "Many things depend on this folder existing. So better check this worked."]
pub fn init_config_path() -> Result<()> {
DirBuilder::new().recursive(true).create(error_path()?)?;
Ok(())
}
pub fn config_path() -> Result<PathBuf> {
if cfg!(debug_assertions) { std::env::current_dir().map_err(From::from) } else {
match ProjectDirs::from("com", "FrodoWazEre", "rpfm") {
Some(proj_dirs) => Ok(proj_dirs.config_dir().to_path_buf()),
None => Err(anyhow!("Failed to get the config path."))
}
}
}
pub fn error_path() -> Result<PathBuf> {
Ok(config_path()?.join("error"))
}