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) + } + } + } + } }