Cleanup and modernize
+ Bump to rust 2024 + Cleaned up old code + Added more fail safes in case certain files are missing
This commit is contained in:
+26
-11
@@ -1,6 +1,6 @@
|
||||
pub(crate) mod remote;
|
||||
|
||||
use crate::config::remote::{FTPConfig, SFTPConfig, FileConfig};
|
||||
use crate::config::remote::{FTPConfig, FileConfig, SFTPConfig};
|
||||
use config::{Config, ConfigError, File};
|
||||
use serde::Deserialize;
|
||||
use std::path::PathBuf;
|
||||
@@ -9,24 +9,38 @@ use std::path::PathBuf;
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub enum WorldType {
|
||||
/// The End (DIM1)
|
||||
END,
|
||||
End,
|
||||
/// Nether (DIM-1)
|
||||
NETHER,
|
||||
Nether,
|
||||
/// Overworld
|
||||
OVERWORLD,
|
||||
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,
|
||||
"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 {
|
||||
@@ -50,7 +64,7 @@ pub struct RemoteBackupConfig {
|
||||
pub backups_to_keep: usize,
|
||||
pub sftp: Option<SFTPConfig>,
|
||||
pub ftp: Option<FTPConfig>,
|
||||
pub file: Option<FileConfig>
|
||||
pub file: Option<FileConfig>,
|
||||
}
|
||||
|
||||
/// Configs
|
||||
@@ -64,9 +78,10 @@ pub struct AlbatrossConfig {
|
||||
impl AlbatrossConfig {
|
||||
/// Create new backup from file
|
||||
pub fn new(config_path: &str) -> Result<Self, ConfigError> {
|
||||
let mut cfg = Config::new();
|
||||
cfg.merge(File::with_name(config_path))?;
|
||||
let cfg = Config::builder()
|
||||
.add_source(File::with_name(config_path))
|
||||
.build()?;
|
||||
|
||||
cfg.try_into()
|
||||
cfg.try_deserialize()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user