Add dlsite cli add folder
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::path::{PathBuf};
|
||||
use ini::Ini;
|
||||
use color_eyre::Result;
|
||||
use crate::config::types::{ApplicationConfig, BasicConfig};
|
||||
use crate::config::types::{ApplicationConfig, BasicConfig, PathConfig};
|
||||
use crate::constants::{APP_CONIFG_FILE_PATH, APP_DATA_DIR};
|
||||
|
||||
pub mod types;
|
||||
@@ -14,8 +14,14 @@ impl ApplicationConfig {
|
||||
db_path: basic_conf_section.get("DBPath").unwrap().to_string(),
|
||||
tick_rate: basic_conf_section.get("TickRate").unwrap().parse()?,
|
||||
};
|
||||
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(),
|
||||
};
|
||||
Ok(Self {
|
||||
basic_config: basic_conf
|
||||
basic_config: basic_conf,
|
||||
path_config: path_conf
|
||||
})
|
||||
}
|
||||
|
||||
@@ -24,17 +30,23 @@ impl ApplicationConfig {
|
||||
basic_config: BasicConfig {
|
||||
db_path: APP_DATA_DIR.clone().join("games.db").to_str().unwrap().to_string(),
|
||||
tick_rate: 250
|
||||
},
|
||||
path_config: PathConfig {
|
||||
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
|
||||
}
|
||||
|
||||
pub fn write_to_file(self, path: PathBuf) -> Result<()> {
|
||||
pub fn write_to_file(self, path: &PathBuf) -> Result<()> {
|
||||
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.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