Ensure that the save file is generated before overriding the old one
This commit is contained in:
parent
68bace9004
commit
4261ab76ca
1 changed files with 5 additions and 2 deletions
|
|
@ -604,12 +604,13 @@ impl Application for Glaurung {
|
|||
Message::FontLoaded(r) => r.expect("could not load font"),
|
||||
Message::Event(ev) => {
|
||||
if let Event::Window(window::Event::CloseRequested) = ev {
|
||||
let tmp_path = format!(".glaurung-{}", std::process::id());
|
||||
let save_file = OpenOptions::new()
|
||||
.create(true)
|
||||
.write(true)
|
||||
.truncate(true)
|
||||
.open(&self.save_file)
|
||||
.expect("Can't open data file");
|
||||
.open(&tmp_path)
|
||||
.expect("Can't open temp save file");
|
||||
serde_json::to_writer(
|
||||
save_file,
|
||||
&SaveFile {
|
||||
|
|
@ -624,6 +625,8 @@ impl Application for Glaurung {
|
|||
)
|
||||
.expect("could not write save file");
|
||||
|
||||
std::fs::rename(tmp_path, &self.save_file).expect("could not save data");
|
||||
|
||||
return window::close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue