pub(crate) mod remote; use crate::config::remote::{FTPConfig, SFTPConfig, FileConfig}; use config::{Config, ConfigError, File}; use serde::Deserialize; use std::path::PathBuf; /// World types supported #[derive(Debug, Deserialize, Clone)] pub enum WorldType { /// The End (DIM1) END, /// Nether (DIM-1) NETHER, /// Overworld OVERWORLD, } impl From for WorldType { /// Convert config strings to WorldType fn from(string: String) -> Self { match string.as_str() { "END" => WorldType::END, "NETHER" => WorldType::NETHER, _ => WorldType::OVERWORLD, } } } /// Config for individual world configuration #[derive(Debug, Deserialize, Clone)] pub struct WorldConfig { pub world_name: String, pub save_radius: u64, pub world_type: Option, } /// Config for doing backups #[derive(Debug, Deserialize, Clone)] pub struct BackupConfig { pub minecraft_dir: PathBuf, pub backups_to_keep: usize, pub discord_webhook: Option, pub output_config: FileConfig, } /// Config for remote_backup backups #[derive(Debug, Deserialize, Clone)] pub struct RemoteBackupConfig { pub backups_to_keep: usize, pub sftp: Option, pub ftp: Option, pub file: Option } /// Configs #[derive(Debug, Deserialize, Clone)] pub struct AlbatrossConfig { pub backup: BackupConfig, pub world_config: Option>, pub remote: Option, } impl AlbatrossConfig { /// Create new backup from file pub fn new(config_path: &str) -> Result { let mut cfg = Config::new(); cfg.merge(File::with_name(config_path))?; cfg.try_into() } }