From d7b952b40fee3855f41c62f8f5e37980f9825ea7 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Fri, 26 Mar 2021 14:05:54 -0400 Subject: [PATCH] add load_accounts --- src/accountmanager.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/accountmanager.rs b/src/accountmanager.rs index 026d231..fd8ae2b 100644 --- a/src/accountmanager.rs +++ b/src/accountmanager.rs @@ -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) + } + } + } + } }