add load_accounts

This commit is contained in:
Carson McManus 2021-03-26 14:05:54 -04:00
parent 4e583530cd
commit d7b952b40f

View file

@ -37,7 +37,9 @@ impl Manifest {
Ok(file) => {
let reader = BufReader::new(file);
match serde_json::from_reader(reader) {
Ok(manifest) => {
Ok(m) => {
let mut manifest: Manifest = m;
manifest.folder = String::from(path.parent().unwrap().to_str().unwrap());
return Ok(manifest);
}
Err(e) => {
@ -50,4 +52,27 @@ impl Manifest {
}
}
}
pub fn load_accounts(&mut self) {
for entry in &self.entries {
let path = Path::new(&self.folder).join(&entry.filename);
match File::open(path) {
Ok(f) => {
let reader = BufReader::new(f);
match serde_json::from_reader(reader) {
Ok(a) => {
let account: SteamGuardAccount = a;
self.accounts.push(account);
}
Err(e) => {
panic!("invalid json")
}
}
}
Err(e) => {
panic!(e)
}
}
}
}
}