openmw-config 1.1.0

A library for interacting with the Openmw Configuration system.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::io::Write;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};

pub fn temp_dir(prefix: &str) -> PathBuf {
    static COUNTER: AtomicU64 = AtomicU64::new(0);
    let id = COUNTER.fetch_add(1, Ordering::Relaxed);
    let dir = std::env::temp_dir().join(format!("openmw_cfg_{prefix}_{id}"));
    std::fs::create_dir_all(&dir).unwrap();
    dir
}

pub fn write_cfg(dir: &Path, contents: &str) -> PathBuf {
    let cfg = dir.join("openmw.cfg");
    let mut file = std::fs::File::create(&cfg).unwrap();
    file.write_all(contents.as_bytes()).unwrap();
    cfg
}