Files
STARTLINER/rust/src/modules/mu3ini.rs
2025-04-19 19:48:08 +00:00

47 lines
1.4 KiB
Rust

use std::path::Path;
use anyhow::{anyhow, Result};
use ini::Ini;
use crate::model::profile::{Mu3Audio, Mu3Ini};
impl Mu3Ini {
pub fn line_up(&self, data_dir: impl AsRef<Path>, cfg_dir: impl AsRef<Path>) -> Result<()> {
let file = cfg_dir.as_ref().join("mu3.ini");
if !file.exists() {
std::fs::write(&file, "")?;
}
let mut ini = Ini::load_from_file(&file)?;
if let Some(audio) = self.audio {
let value = match audio {
Mu3Audio::Shared => "0",
Mu3Audio::Excl6Ch => "1",
Mu3Audio::Excl2Ch => "2",
};
ini.with_section(Some("Sound"))
.set("WasapiExclusive", value)
.set("SampleRate", self.sample_rate.to_string());
}
if let Some(blacklist) = self.blacklist {
ini.with_section(Some("Extra"))
.set("BlacklistMin", blacklist.0.to_string())
.set("BlacklistMax", blacklist.1.to_string());
}
let cache_path = data_dir.as_ref().join("mu3-mods-cache");
let cache_path = cache_path.to_str()
.ok_or_else(|| anyhow!("Invalid cache path"))?;
ini.with_section(Some("Extra"))
.set("GP", self.gp.to_string())
.set("CacheDir", cache_path)
.set("UnlockBonusTracks", crate::util::bool_to_01(self.enable_bonus_tracks));
ini.write_to_file(file)?;
Ok(())
}
}