implement saving manifest and accounts
This commit is contained in:
parent
d6cdbd5541
commit
afc09a35ac
2 changed files with 45 additions and 3 deletions
|
@ -1,7 +1,7 @@
|
|||
use log::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::io::{BufReader, Write};
|
||||
use std::path::Path;
|
||||
use steamguard::SteamGuardAccount;
|
||||
|
||||
|
@ -52,4 +52,42 @@ impl Manifest {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn add_account(&mut self, account: &SteamGuardAccount) {
|
||||
debug!("adding account to manifest: {}", account.account_name);
|
||||
let steamid = account.session.clone().unwrap().steam_id;
|
||||
self.accounts.push(account.clone());
|
||||
self.entries.push(ManifestEntry {
|
||||
filename: format!("{}.maFile", account.account_name),
|
||||
steam_id: steamid,
|
||||
encryption_iv: None,
|
||||
encryption_salt: None,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn save(&self) -> anyhow::Result<()> {
|
||||
ensure!(
|
||||
self.entries.len() == self.accounts.len(),
|
||||
"Manifest entries don't match accounts."
|
||||
);
|
||||
for (entry, account) in self.entries.iter().zip(&self.accounts) {
|
||||
debug!("saving {}", entry.filename);
|
||||
let serialized = serde_json::to_string(&account)?;
|
||||
ensure!(
|
||||
serialized.len() > 2,
|
||||
"Something extra weird happened and the account was serialized into nothing."
|
||||
);
|
||||
let path = Path::new(&self.folder).join(&entry.filename);
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(serialized.as_bytes())?;
|
||||
file.sync_data()?;
|
||||
}
|
||||
debug!("saving manifest");
|
||||
let manifest_serialized = serde_json::to_string(&self)?;
|
||||
let path = Path::new(&self.folder).join("manifest.json");
|
||||
let mut file = File::create(path)?;
|
||||
file.write_all(manifest_serialized.as_bytes())?;
|
||||
file.sync_data()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ use termion::{
|
|||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
#[macro_use]
|
||||
extern crate anyhow;
|
||||
mod accountlinker;
|
||||
mod accountmanager;
|
||||
|
||||
|
@ -128,11 +130,11 @@ fn main() {
|
|||
let mut selected_accounts: Vec<SteamGuardAccount> = vec![];
|
||||
if matches.is_present("all") {
|
||||
// manifest.accounts.iter().map(|a| selected_accounts.push(a.b));
|
||||
for account in manifest.accounts {
|
||||
for account in &manifest.accounts {
|
||||
selected_accounts.push(account.clone());
|
||||
}
|
||||
} else {
|
||||
for account in manifest.accounts {
|
||||
for account in &manifest.accounts {
|
||||
if !matches.is_present("username") {
|
||||
selected_accounts.push(account.clone());
|
||||
break;
|
||||
|
@ -197,6 +199,8 @@ fn main() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
manifest.save();
|
||||
} else {
|
||||
let server_time = steamapi::get_server_time();
|
||||
for account in selected_accounts {
|
||||
|
|
Loading…
Reference in a new issue