2021-03-26 00:47:44 +01:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::BufReader;
|
|
|
|
use std::path::Path;
|
2021-03-25 22:45:41 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
2021-03-26 00:47:44 +01:00
|
|
|
use std::error::Error;
|
2021-07-31 18:24:49 +02:00
|
|
|
use steamguard::SteamGuardAccount;
|
2021-03-27 15:35:52 +01:00
|
|
|
use log::*;
|
2021-03-25 22:45:41 +01:00
|
|
|
|
2021-03-26 18:14:59 +01:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
2021-03-25 22:45:41 +01:00
|
|
|
pub struct Manifest {
|
|
|
|
pub encrypted: bool,
|
|
|
|
pub entries: Vec<ManifestEntry>,
|
|
|
|
pub first_run: bool,
|
|
|
|
pub periodic_checking: bool,
|
|
|
|
pub periodic_checking_interval: i32,
|
|
|
|
pub periodic_checking_checkall: bool,
|
|
|
|
pub auto_confirm_market_transactions: bool,
|
|
|
|
pub auto_confirm_trades: bool,
|
|
|
|
|
2021-03-26 18:14:59 +01:00
|
|
|
#[serde(skip)]
|
|
|
|
pub accounts: Vec<SteamGuardAccount>,
|
|
|
|
#[serde(skip)]
|
|
|
|
folder: String, // I wanted to use a Path here, but it was too hard to make it work...
|
2021-03-25 22:45:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
pub struct ManifestEntry {
|
2021-03-26 00:47:44 +01:00
|
|
|
pub encryption_iv: Option<String>,
|
|
|
|
pub encryption_salt: Option<String>,
|
2021-03-25 22:45:41 +01:00
|
|
|
pub filename: String,
|
2021-03-26 00:47:44 +01:00
|
|
|
#[serde(rename = "steamid")]
|
2021-03-25 22:45:41 +01:00
|
|
|
pub steam_id: u64,
|
|
|
|
}
|
|
|
|
|
2021-03-26 00:47:44 +01:00
|
|
|
impl Manifest {
|
|
|
|
pub fn load(path: &Path) -> Result<Manifest, Box<dyn Error>> {
|
2021-03-27 15:35:52 +01:00
|
|
|
debug!("loading manifest: {:?}", &path);
|
2021-03-26 00:47:44 +01:00
|
|
|
match File::open(path) {
|
|
|
|
Ok(file) => {
|
|
|
|
let reader = BufReader::new(file);
|
|
|
|
match serde_json::from_reader(reader) {
|
2021-03-26 19:05:54 +01:00
|
|
|
Ok(m) => {
|
|
|
|
let mut manifest: Manifest = m;
|
|
|
|
manifest.folder = String::from(path.parent().unwrap().to_str().unwrap());
|
2021-03-26 00:47:44 +01:00
|
|
|
return Ok(manifest);
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
return Err(Box::new(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
return Err(Box::new(e));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 19:05:54 +01:00
|
|
|
|
|
|
|
pub fn load_accounts(&mut self) {
|
|
|
|
for entry in &self.entries {
|
|
|
|
let path = Path::new(&self.folder).join(&entry.filename);
|
2021-03-27 15:35:52 +01:00
|
|
|
debug!("loading account: {:?}", path);
|
2021-03-26 19:05:54 +01:00
|
|
|
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) => {
|
2021-03-27 15:35:52 +01:00
|
|
|
error!("invalid json: {}", e)
|
2021-03-26 19:05:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
2021-03-27 15:35:52 +01:00
|
|
|
error!("unable to open account: {}", e)
|
2021-03-26 19:05:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 00:47:44 +01:00
|
|
|
}
|