93 lines
2.2 KiB
Rust
93 lines
2.2 KiB
Rust
pub(crate) mod remote;
|
|
|
|
use crate::config::remote::{FTPConfig, FileConfig, SFTPConfig};
|
|
use config::{Config, ConfigError, File};
|
|
use serde::Deserialize;
|
|
use std::path::PathBuf;
|
|
|
|
/// World types supported
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub enum WorldType {
|
|
End,
|
|
Nether,
|
|
Overworld,
|
|
}
|
|
|
|
impl From<String> for WorldType {
|
|
/// Convert config strings to WorldType
|
|
fn from(string: String) -> Self {
|
|
match string.as_str() {
|
|
"END" => WorldType::End,
|
|
"NETHER" => WorldType::Nether,
|
|
_ => WorldType::Overworld,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WorldType {
|
|
pub fn dim_number(&self) -> i8 {
|
|
match self {
|
|
WorldType::End => 1,
|
|
WorldType::Nether => -1,
|
|
WorldType::Overworld => 0,
|
|
}
|
|
}
|
|
|
|
pub fn dim_name(&self) -> String {
|
|
format!("DIM{}", self.dim_number())
|
|
}
|
|
}
|
|
|
|
/// Config for individual world configuration
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct WorldConfig {
|
|
pub world_name: String,
|
|
pub save_radius: u64,
|
|
pub world_type: Option<WorldType>,
|
|
}
|
|
|
|
/// Config for doing backups
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct BackupConfig {
|
|
pub minecraft_dir: PathBuf,
|
|
pub backups_to_keep: usize,
|
|
pub discord_webhook: Option<String>,
|
|
pub output_config: FileConfig,
|
|
}
|
|
|
|
/// Config for remote_backup backups
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct RemoteBackupConfig {
|
|
pub backups_to_keep: usize,
|
|
pub sftp: Option<SFTPConfig>,
|
|
pub ftp: Option<FTPConfig>,
|
|
pub file: Option<FileConfig>,
|
|
}
|
|
|
|
/// Config for individual world configuration
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct World26PlusConfig {
|
|
pub world_name: String,
|
|
pub dimensions: Vec<WorldConfig>,
|
|
}
|
|
|
|
/// Configs
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
pub struct AlbatrossConfig {
|
|
pub backup: BackupConfig,
|
|
pub world_config: Option<Vec<WorldConfig>>,
|
|
pub world_26_plus_config: Option<World26PlusConfig>,
|
|
pub remote: Option<RemoteBackupConfig>,
|
|
}
|
|
|
|
impl AlbatrossConfig {
|
|
/// Create new backup from file
|
|
pub fn new(config_path: &str) -> Result<Self, ConfigError> {
|
|
let cfg = Config::builder()
|
|
.add_source(File::with_name(config_path))
|
|
.build()?;
|
|
|
|
cfg.try_deserialize()
|
|
}
|
|
}
|