simplify manifest and account loading
This commit is contained in:
parent
258e758395
commit
d6cdbd5541
1 changed files with 12 additions and 38 deletions
|
@ -1,6 +1,5 @@
|
||||||
use log::*;
|
use log::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::error::Error;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -33,49 +32,24 @@ pub struct ManifestEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Manifest {
|
impl Manifest {
|
||||||
pub fn load(path: &Path) -> Result<Manifest, Box<dyn Error>> {
|
pub fn load(path: &Path) -> anyhow::Result<Manifest> {
|
||||||
debug!("loading manifest: {:?}", &path);
|
debug!("loading manifest: {:?}", &path);
|
||||||
match File::open(path) {
|
let file = File::open(path)?;
|
||||||
Ok(file) => {
|
|
||||||
let reader = BufReader::new(file);
|
let reader = BufReader::new(file);
|
||||||
match serde_json::from_reader(reader) {
|
let mut manifest: Manifest = serde_json::from_reader(reader)?;
|
||||||
Ok(m) => {
|
|
||||||
let mut manifest: Manifest = m;
|
|
||||||
manifest.folder = String::from(path.parent().unwrap().to_str().unwrap());
|
manifest.folder = String::from(path.parent().unwrap().to_str().unwrap());
|
||||||
return Ok(manifest);
|
return Ok(manifest);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
|
||||||
return Err(Box::new(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Box::new(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn load_accounts(&mut self) {
|
pub fn load_accounts(&mut self) -> anyhow::Result<()> {
|
||||||
for entry in &self.entries {
|
for entry in &self.entries {
|
||||||
let path = Path::new(&self.folder).join(&entry.filename);
|
let path = Path::new(&self.folder).join(&entry.filename);
|
||||||
debug!("loading account: {:?}", path);
|
debug!("loading account: {:?}", path);
|
||||||
match File::open(path) {
|
let file = File::open(path)?;
|
||||||
Ok(f) => {
|
let reader = BufReader::new(file);
|
||||||
let reader = BufReader::new(f);
|
let account: SteamGuardAccount = serde_json::from_reader(reader)?;
|
||||||
match serde_json::from_reader(reader) {
|
|
||||||
Ok(a) => {
|
|
||||||
let account: SteamGuardAccount = a;
|
|
||||||
self.accounts.push(account);
|
self.accounts.push(account);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Ok(())
|
||||||
error!("invalid json: {}", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
error!("unable to open account: {}", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue