feat: new config format
This commit is contained in:
93
rust/src/modules/segatools.rs
Normal file
93
rust/src/modules/segatools.rs
Normal file
@ -0,0 +1,93 @@
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use ini::Ini;
|
||||
use crate::{model::{config::Segatools, segatools_base::segatools_base}, profiles::ProfilePaths, util::{self, PathStr}};
|
||||
|
||||
impl Default for Segatools {
|
||||
fn default() -> Self {
|
||||
Segatools {
|
||||
target: PathBuf::default(),
|
||||
amfs: PathBuf::default(),
|
||||
option: PathBuf::default(),
|
||||
appdata: PathBuf::from("appdata"),
|
||||
enable_aime: false,
|
||||
intel: false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Segatools {
|
||||
pub async fn line_up(&self, p: &impl ProfilePaths) -> Result<Ini> {
|
||||
log::debug!("begin line-up: segatools");
|
||||
|
||||
let pfx_dir = p.data_dir();
|
||||
let exe_dir = self.target.parent().ok_or_else(|| anyhow!("Invalid target path"))?;
|
||||
|
||||
log::debug!("segatools: {:?} {:?}", pfx_dir, exe_dir);
|
||||
|
||||
let ini_path = p.config_dir().join("segatools-base.ini");
|
||||
|
||||
if !ini_path.exists() {
|
||||
tokio::fs::write(&ini_path, segatools_base()).await
|
||||
.map_err(|e| anyhow!("Error creating {:?}: {}", ini_path, e))?;
|
||||
}
|
||||
if !pfx_dir.exists() {
|
||||
tokio::fs::create_dir(&pfx_dir).await
|
||||
.map_err(|e| anyhow!("Error creating {:?}: {}", pfx_dir, e))?;
|
||||
}
|
||||
|
||||
let ini_in = tokio::fs::read_to_string(&ini_path).await?;
|
||||
let ini_in = Ini::load_from_str(&ini_in)?;
|
||||
|
||||
let opt_dir_out = &pfx_dir.join("option");
|
||||
let opt_dir_in = if self.option.as_os_str().len() > 0 && self.option.is_relative() {
|
||||
exe_dir.join(&self.option)
|
||||
} else {
|
||||
self.option.clone()
|
||||
};
|
||||
|
||||
let mut ini_out = ini_in.clone();
|
||||
ini_out.with_section(Some("vfs"))
|
||||
.set(
|
||||
"option",
|
||||
opt_dir_out.stringify()?
|
||||
)
|
||||
.set("amfs", self.amfs.stringify()?)
|
||||
.set("appdata", self.appdata.stringify()?);
|
||||
|
||||
ini_out.with_section(Some("unity"))
|
||||
.set("enable", "1")
|
||||
.set(
|
||||
"targetAssembly",
|
||||
pfx_dir.join("BepInEx").join("core").join("BepInEx.Preloader.dll").stringify()?
|
||||
);
|
||||
|
||||
if self.enable_aime {
|
||||
ini_out.with_section(Some("aime"))
|
||||
.set("enable", "1")
|
||||
.set("aimePath", p.config_dir().join("aime.txt").stringify()?);
|
||||
} else {
|
||||
ini_out.with_section(Some("aime"))
|
||||
.set("enable", "0");
|
||||
}
|
||||
|
||||
log::debug!("option dir: {:?} -> {:?}", opt_dir_in, opt_dir_out);
|
||||
|
||||
if !opt_dir_out.exists() {
|
||||
tokio::fs::create_dir(opt_dir_out).await?;
|
||||
}
|
||||
|
||||
if opt_dir_in.as_os_str().len() > 0 {
|
||||
for opt in opt_dir_in.read_dir()? {
|
||||
let opt = opt?;
|
||||
util::symlink(&opt.path(), opt_dir_out.join(opt.file_name())).await?;
|
||||
}
|
||||
}
|
||||
|
||||
log::debug!("end line-up: segatools");
|
||||
|
||||
Ok(ini_out)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user