Reformat code
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::path::{PathBuf};
|
||||
use ini::Ini;
|
||||
use color_eyre::Result;
|
||||
use crate::config::types::{ApplicationConfig, BasicConfig, PathConfig};
|
||||
use crate::constants::{APP_CONIFG_FILE_PATH, APP_DATA_DIR};
|
||||
use color_eyre::Result;
|
||||
use ini::Ini;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub mod types;
|
||||
|
||||
@@ -16,26 +16,37 @@ impl ApplicationConfig {
|
||||
};
|
||||
let path_conf_section = conf.section(Some("Path")).unwrap();
|
||||
let path_conf = PathConfig {
|
||||
dlsite_paths: path_conf_section.get("DLSite").unwrap()
|
||||
.split(":").map(|s| s.to_string()).collect(),
|
||||
dlsite_paths: path_conf_section
|
||||
.get("DLSite")
|
||||
.unwrap()
|
||||
.split(":")
|
||||
.map(|s| s.to_string())
|
||||
.collect(),
|
||||
};
|
||||
Ok(Self {
|
||||
basic_config: basic_conf,
|
||||
path_config: path_conf
|
||||
path_config: path_conf,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new() -> Self {
|
||||
let conf = Self {
|
||||
basic_config: BasicConfig {
|
||||
db_path: APP_DATA_DIR.clone().join("games.db").to_str().unwrap().to_string(),
|
||||
tick_rate: 250
|
||||
db_path: APP_DATA_DIR
|
||||
.clone()
|
||||
.join("games.db")
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string(),
|
||||
tick_rate: 250,
|
||||
},
|
||||
path_config: PathConfig {
|
||||
dlsite_paths: vec![]
|
||||
}
|
||||
dlsite_paths: vec![],
|
||||
},
|
||||
};
|
||||
conf.clone().write_to_file(&APP_CONIFG_FILE_PATH.to_path_buf()).unwrap();
|
||||
conf.clone()
|
||||
.write_to_file(&APP_CONIFG_FILE_PATH.to_path_buf())
|
||||
.unwrap();
|
||||
conf
|
||||
}
|
||||
|
||||
@@ -44,10 +55,16 @@ impl ApplicationConfig {
|
||||
conf.with_section(Some("Basic"))
|
||||
.set("DBPath", self.basic_config.db_path)
|
||||
.set("TickRate", self.basic_config.tick_rate.to_string());
|
||||
conf.with_section(Some("Path"))
|
||||
.set("DLSite", self.path_config.dlsite_paths.into_iter()
|
||||
.filter(|x| !x.is_empty()).collect::<Vec<String>>().join(":"));
|
||||
conf.with_section(Some("Path")).set(
|
||||
"DLSite",
|
||||
self.path_config
|
||||
.dlsite_paths
|
||||
.into_iter()
|
||||
.filter(|x| !x.is_empty())
|
||||
.collect::<Vec<String>>()
|
||||
.join(":"),
|
||||
);
|
||||
conf.write_to_file(path)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user