use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
pub struct Wpaperd;
impl Wpaperd {
pub fn new(
path: &String,
hash: &String,
wallpapers: &HashMap<String, String>,
) -> Result<(), String> {
let mut config_file = File::create(path).map_err(|_| "wpaperd: cant open config file")?;
config_file
.write(format!("# {}\n# DO NOT EDIT! AUTOGENERATED CONFIG!\n\n", hash).as_bytes())
.map_err(|_| "wpaperd: TOML write error")?;
config_file
.write(format!("[default]\nmode = \"center\"\n\n").as_bytes())
.map_err(|_| "wpaperd: TOML write error")?;
for paper in wallpapers {
config_file
.write(format!("[{}]\npath = \"{}\"\n\n", paper.0, paper.1).as_bytes())
.map_err(|_| "wpaperd: TOML write error")?;
}
Ok(())
}
pub fn check_existing(path: &String, hash: &String) -> bool {
let read_file = std::fs::read_to_string(path).unwrap_or_default();
if read_file.starts_with(&format!("# {}", hash)) {
return true;
}
false
}
}