Add sqlite and config support
This commit is contained in:
36
src/config/mod.rs
Normal file
36
src/config/mod.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
use std::path::{PathBuf};
|
||||
use ini::Ini;
|
||||
use crate::config::types::{ApplicationConfig, BasicConfig};
|
||||
|
||||
pub mod types;
|
||||
|
||||
impl ApplicationConfig {
|
||||
pub fn from_file(path: &PathBuf) -> Self {
|
||||
let conf = Ini::load_from_file(path).unwrap();
|
||||
let basic_conf_section = conf.section(Some("Basic")).unwrap();
|
||||
let basic_conf = BasicConfig {
|
||||
db_path: basic_conf_section.get("DBPath").unwrap().to_string(),
|
||||
tick_rate: basic_conf_section.get("TickRate").unwrap().parse().unwrap(),
|
||||
};
|
||||
Self {
|
||||
basic_config: basic_conf
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
basic_config: BasicConfig {
|
||||
db_path: "games.db".to_string(),
|
||||
tick_rate: 250
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_to_file(self, path: PathBuf) {
|
||||
let mut conf = Ini::new();
|
||||
conf.with_section(Some("Basic"))
|
||||
.set("DBPath", self.basic_config.db_path)
|
||||
.set("TickRate", self.basic_config.tick_rate.to_string());
|
||||
conf.write_to_file(path).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user