2021-09-19 19:56:30 +00:00
|
|
|
pub(crate) mod remote;
|
2021-02-10 02:47:40 +00:00
|
|
|
|
2021-09-19 19:56:30 +00:00
|
|
|
use crate::config::remote::{FTPConfig, SFTPConfig, FileConfig};
|
2020-06-06 19:41:42 +00:00
|
|
|
use config::{Config, ConfigError, File};
|
2020-10-24 01:40:32 +00:00
|
|
|
use serde::Deserialize;
|
2020-06-06 19:41:42 +00:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2020-06-07 00:59:02 +00:00
|
|
|
/// World types supported
|
2020-06-06 19:41:42 +00:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub enum WorldType {
|
2020-06-07 00:59:02 +00:00
|
|
|
/// The End (DIM1)
|
2020-06-06 19:41:42 +00:00
|
|
|
END,
|
2020-06-07 00:59:02 +00:00
|
|
|
/// Nether (DIM-1)
|
2020-06-06 19:41:42 +00:00
|
|
|
NETHER,
|
2020-06-07 00:59:02 +00:00
|
|
|
/// Overworld
|
2020-06-06 19:41:42 +00:00
|
|
|
OVERWORLD,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<String> for WorldType {
|
2020-06-07 00:59:02 +00:00
|
|
|
/// Convert config strings to WorldType
|
2020-06-06 19:41:42 +00:00
|
|
|
fn from(string: String) -> Self {
|
|
|
|
match string.as_str() {
|
|
|
|
"END" => WorldType::END,
|
|
|
|
"NETHER" => WorldType::NETHER,
|
|
|
|
_ => WorldType::OVERWORLD,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-03 03:21:55 +00:00
|
|
|
/// Config for individual world configuration
|
2020-06-06 19:41:42 +00:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub struct WorldConfig {
|
|
|
|
pub world_name: String,
|
|
|
|
pub save_radius: u64,
|
|
|
|
pub world_type: Option<WorldType>,
|
|
|
|
}
|
|
|
|
|
2020-06-07 00:59:02 +00:00
|
|
|
/// Config for doing backups
|
2020-06-06 19:41:42 +00:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub struct BackupConfig {
|
|
|
|
pub minecraft_dir: PathBuf,
|
2021-09-19 19:56:30 +00:00
|
|
|
pub backups_to_keep: usize,
|
2020-06-07 19:21:26 +00:00
|
|
|
pub discord_webhook: Option<String>,
|
2021-09-19 19:56:30 +00:00
|
|
|
pub output_config: FileConfig,
|
2020-06-06 19:41:42 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 19:56:30 +00:00
|
|
|
/// Config for remote_backup backups
|
2021-02-03 03:21:55 +00:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub struct RemoteBackupConfig {
|
2021-09-19 19:56:30 +00:00
|
|
|
pub backups_to_keep: usize,
|
2021-02-10 02:47:40 +00:00
|
|
|
pub sftp: Option<SFTPConfig>,
|
2021-02-13 02:02:57 +00:00
|
|
|
pub ftp: Option<FTPConfig>,
|
2021-09-19 19:56:30 +00:00
|
|
|
pub file: Option<FileConfig>
|
2021-02-03 03:21:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-07 00:59:02 +00:00
|
|
|
/// Configs
|
2020-06-06 19:41:42 +00:00
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
pub struct AlbatrossConfig {
|
|
|
|
pub backup: BackupConfig,
|
|
|
|
pub world_config: Option<Vec<WorldConfig>>,
|
2021-02-03 03:21:55 +00:00
|
|
|
pub remote: Option<RemoteBackupConfig>,
|
2020-06-06 19:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl AlbatrossConfig {
|
2020-06-07 00:59:02 +00:00
|
|
|
/// Create new backup from file
|
2020-06-06 19:41:42 +00:00
|
|
|
pub fn new(config_path: &str) -> Result<Self, ConfigError> {
|
|
|
|
let mut cfg = Config::new();
|
|
|
|
cfg.merge(File::with_name(config_path))?;
|
|
|
|
|
|
|
|
cfg.try_into()
|
|
|
|
}
|
|
|
|
}
|