Quicksave, working on update logic and stuff

This commit is contained in:
2026-08-27 16:53:56 +02:00
parent 7bd95a826e
commit a6e0134d2e
5 changed files with 317 additions and 122 deletions
+6 -10
View File
@@ -18,9 +18,8 @@
Functions fot system interaction
*/
use serde::{Serialize, Deserialize};
use std::{fs, io};
use serde::{Deserialize, Serialize};
use std::fs;
use toml;
const CONFIG_PATH: &str = "/etc/hive_up.toml";
@@ -49,7 +48,6 @@ pub struct UpdateConfig {
pub auto_update: bool,
}
#[derive(Debug)]
pub enum ConfigError {
IoError(std::io::Error),
@@ -82,10 +80,10 @@ impl std::fmt::Display for ConfigError {
ConfigError::IoError(e) => write!(f, "IO Error: {}", e),
ConfigError::TomlParseError(e) => {
write!(f, "TOML parse error: {}", e)
},
}
ConfigError::TomlSerError(e) => {
write!(f, "TOML serialize error: {}", e)
},
}
}
}
}
@@ -95,11 +93,10 @@ impl std::error::Error for ConfigError {}
pub fn read_config() -> Result<HiveConfig, ConfigError> {
let file_content = fs::read_to_string(CONFIG_PATH)?;
let config:HiveConfig = toml::from_str(&file_content)?;
let config: HiveConfig = toml::from_str(&file_content)?;
Ok(config)
}
pub fn change_updates_check_interval(new_interval: u64) -> Result<HiveConfig, ConfigError> {
let mut config: HiveConfig = read_config()?;
config.update.updates_check_interval = new_interval;
@@ -107,5 +104,4 @@ pub fn change_updates_check_interval(new_interval: u64) -> Result<HiveConfig, Co
fs::write(CONFIG_PATH, conf_str)?;
Ok(config)
}
}