|
|
@ -21,10 +21,14 @@ pub struct StateManager { |
|
|
|
}
|
|
|
|
|
|
|
|
fn read_state<P: AsRef<Path>>(path: P) -> Result<State, Box<dyn Error>> {
|
|
|
|
let file = File::open(path)?;
|
|
|
|
let reader = BufReader::new(file);
|
|
|
|
let result: State = from_reader(reader)?;
|
|
|
|
Ok(result)
|
|
|
|
if path.as_ref().exists() {
|
|
|
|
let file = File::open(path)?;
|
|
|
|
let reader = BufReader::new(file);
|
|
|
|
let result: State = from_reader(reader)?;
|
|
|
|
Ok(result)
|
|
|
|
} else {
|
|
|
|
Ok(State { downloaded: vec![] })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn save_state<P: AsRef<Path>>(path: P, state: &State) -> serde_json::Result<()> {
|
|
|
|