blob: 366f499f48989c99967345e04b6ec179a84dd334 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
use fparkan_assets::game_settings::GameSettings;
use fparkan_vfs::DirectoryVfs;
use std::{fs, io, io::Write, path::Path};
pub(super) fn save_integers(root: &Path, updates: &[(&str, i32)]) -> io::Result<()> {
if updates.is_empty() {
return Ok(());
}
let profile = GameSettings::load(&DirectoryVfs::new(root)).map_err(io::Error::other)?;
let updated = profile.with_cs_integers(updates);
let path = root.join("Iron_3D.ini");
let temporary = root.join(format!("Iron_3D.ini.fparkan-{}.tmp", std::process::id()));
let mut file = fs::OpenOptions::new()
.write(true)
.create_new(true)
.open(&temporary)?;
let written = file.write_all(&updated).and_then(|()| file.sync_all());
drop(file);
if let Err(error) = written.and_then(|()| fs::rename(&temporary, path)) {
let _ = fs::remove_file(&temporary);
return Err(error);
}
Ok(())
}
|