Feat: Ergänzt storage-Struktur in Konfigurationsmodul und implementiert Default-Wert sowie Konfigurationsspeicherung
This commit is contained in:
@@ -20,6 +20,8 @@ pub struct AppConfig {
|
||||
pub local: Local,
|
||||
/// Remote-Einbindungseinstellungen
|
||||
pub remote: Remote,
|
||||
/// Lokaler Zwischenspeicher
|
||||
pub storage: Option<Storage>,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
@@ -28,6 +30,7 @@ impl Default for AppConfig {
|
||||
general: General::default(),
|
||||
local: Local::default(),
|
||||
remote: Remote::default(),
|
||||
storage: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,6 +98,20 @@ impl Default for Remote {
|
||||
}
|
||||
}
|
||||
|
||||
/// Zwischenspeicher für das Programm.
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
pub struct Storage {
|
||||
pub device_ip: String,
|
||||
}
|
||||
|
||||
impl Default for Storage {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
device_ip: "".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Ermittelt den Standard-Einhängepunkt basierend auf dem Betriebssystem.
|
||||
fn get_default_mount_path() -> String {
|
||||
#[cfg(not(any(target_os = "windows")))]
|
||||
@@ -136,12 +153,12 @@ fn load_config() -> AppConfig {
|
||||
confy::load(&*program::program_name(), CONFIG_NAME).unwrap_or_default()
|
||||
}
|
||||
|
||||
// /// Speichert die übergebene Konfiguration in der Konfigurationsdatei.
|
||||
// fn save_config(config: AppConfig) {
|
||||
// #[cfg(target_os = "linux")]
|
||||
// if is_run_as_root() {
|
||||
// confy::store_path(format!("/etc/{}/{}.toml", program::program_name(), CONFIG_NAME), config).unwrap();
|
||||
// return;
|
||||
// }
|
||||
// confy::store(&*program::program_name(), CONFIG_NAME, config).unwrap();
|
||||
// }
|
||||
/// Speichert die übergebene Konfiguration in der Konfigurationsdatei.
|
||||
fn save_config(config: AppConfig) {
|
||||
#[cfg(target_os = "linux")]
|
||||
if is_run_as_root() {
|
||||
confy::store_path(format!("/etc/{}/{}.toml", program::program_name(), CONFIG_NAME), config).unwrap();
|
||||
return;
|
||||
}
|
||||
confy::store(&*program::program_name(), CONFIG_NAME, config).unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user