diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-03 13:09:16 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-03 13:09:16 +0300 |
| commit | dda84190134cf656d6f43c938a63098c0aa3486f (patch) | |
| tree | 249a235f3c946d19e69460ea6248d5da3d987705 /apps/fparkan-game/src/launch_menu/profile.rs | |
| parent | 5575b7f79381c4dac0b4af9effa5dc1050a88607 (diff) | |
| download | fparkan-dda84190134cf656d6f43c938a63098c0aa3486f.tar.xz fparkan-dda84190134cf656d6f43c938a63098c0aa3486f.zip | |
feat(ui): apply graphics settings from the menu
Diffstat (limited to 'apps/fparkan-game/src/launch_menu/profile.rs')
| -rw-r--r-- | apps/fparkan-game/src/launch_menu/profile.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/apps/fparkan-game/src/launch_menu/profile.rs b/apps/fparkan-game/src/launch_menu/profile.rs new file mode 100644 index 00000000..366f499f --- /dev/null +++ b/apps/fparkan-game/src/launch_menu/profile.rs @@ -0,0 +1,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(()) +} |
