|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
use std::boxed::Box;
|
|
|
|
|
use std::fs::File;
|
|
|
|
|
use std::io::Read;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
@ -12,11 +13,29 @@ pub struct Apps {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Apps {
|
|
|
|
|
pub fn load<T: Into<PathBuf>>(p: T) -> Result<Self> {
|
|
|
|
|
let mut file = File::open(p.into())?;
|
|
|
|
|
let mut buf = String::new();
|
|
|
|
|
file.read_to_string(&mut buf)?;
|
|
|
|
|
Ok(toml::from_str(&buf)?)
|
|
|
|
|
pub fn load(p: PathBuf) -> Result<Self> {
|
|
|
|
|
match File::open(p.into()) {
|
|
|
|
|
Ok(file) => {
|
|
|
|
|
let mut buf = String::new();
|
|
|
|
|
|
|
|
|
|
if let Err(e) = file.read_to_string(&mut buf) {
|
|
|
|
|
error!("unable to read apps file: {}: {:?}", p.display(), e);
|
|
|
|
|
return Err(Box::new(e));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match toml::from_str(&buf) {
|
|
|
|
|
Ok(t) => Ok(t),
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("Invalid toml in apps file: {}: {:?}", p.display(), e);
|
|
|
|
|
Err(Box::new(e))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Err(e) => {
|
|
|
|
|
error!("Unable to open apps file: {}: {:?}", p.display(), e);
|
|
|
|
|
Err(Box::new(e))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn apps(&self) -> Vec<App> {
|
|
|
|
|