forked from akanyan/STARTLINER
feat: etc
This commit is contained in:
@ -17,9 +17,23 @@ async fn symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Resul
|
||||
junction::create(src, dst)
|
||||
}
|
||||
|
||||
pub async fn line_up(p: &Profile) -> Result<()> {
|
||||
let dir_out = util::profile_dir(&p);
|
||||
log::info!("Preparing {}", dir_out.to_string_lossy());
|
||||
pub async fn line_up(p: &Profile, pkg_hash: String) -> Result<()> {
|
||||
let hash_path = p.dir().join(".sl-state");
|
||||
let prev_hash = fs::read_to_string(&hash_path).await.unwrap_or_default();
|
||||
if prev_hash != pkg_hash {
|
||||
log::debug!("state {} -> {}", prev_hash, pkg_hash);
|
||||
fs::write(hash_path, pkg_hash).await
|
||||
.map_err(|e| anyhow!("Unable to write the state file: {}", e))?;
|
||||
prepare_packages(p).await?;
|
||||
}
|
||||
|
||||
prepare_config(p).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn prepare_packages(p: &Profile) -> Result<()> {
|
||||
let dir_out = p.dir();
|
||||
|
||||
let mut futures = JoinSet::new();
|
||||
if dir_out.join("BepInEx").exists() {
|
||||
@ -34,25 +48,29 @@ pub async fn line_up(p: &Profile) -> Result<()> {
|
||||
|
||||
for m in &p.mods {
|
||||
log::debug!("Preparing {}", m);
|
||||
let dir_out = util::profile_dir(&p);
|
||||
let (namespace, name) = m.0.split_at(m.0.find("-").expect("Invalid mod definition"));
|
||||
let bpx = util::pkg_dir_of(namespace, &name[1..])
|
||||
let bpx_dir = util::pkg_dir_of(namespace, &name[1..])
|
||||
.join("app")
|
||||
.join("BepInEx");
|
||||
if bpx.exists() {
|
||||
util::copy_recursive(&bpx, &dir_out.join("BepInEx"))?;
|
||||
if bpx_dir.exists() {
|
||||
util::copy_recursive(&bpx_dir, &dir_out.join("BepInEx"))?;
|
||||
}
|
||||
|
||||
let opt = util::pkg_dir_of(namespace, &name[1..]).join("option");
|
||||
if opt.exists() {
|
||||
let x = opt.read_dir().unwrap().next().unwrap()?;
|
||||
let opt_dir = util::pkg_dir_of(namespace, &name[1..]).join("option");
|
||||
if opt_dir.exists() {
|
||||
let x = opt_dir.read_dir().unwrap().next().unwrap()?;
|
||||
if x.metadata()?.is_dir() {
|
||||
symlink(&x.path(), &dir_out.join("option").join(x.file_name())).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Todo temporary
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn prepare_config(p: &Profile) -> Result<()> {
|
||||
let dir_out = p.dir();
|
||||
|
||||
let ini_in_raw = fs::read_to_string(p.exe_dir.join("segatools.ini")).await?;
|
||||
let ini_in = Ini::load_from_str(&ini_in_raw)?;
|
||||
let mut opt_dir_in = PathBuf::from(
|
||||
@ -78,7 +96,7 @@ pub async fn line_up(p: &Profile) -> Result<()> {
|
||||
util::path_to_str(dir_out.join("BepInEx").join("core").join("BepInEx.Preloader.dll"))?
|
||||
);
|
||||
|
||||
if prepare_aime(p).await.unwrap_or(false) {
|
||||
if p.get_bool("aime", false) {
|
||||
ini_out.with_section(Some("aime"))
|
||||
.set("enable", "1")
|
||||
.set("aimePath", util::path_to_str(dir_out.join("aime.txt"))?);
|
||||
@ -93,16 +111,4 @@ pub async fn line_up(p: &Profile) -> Result<()> {
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Todo multiple codes
|
||||
async fn prepare_aime(p: &Profile) -> Result<bool> {
|
||||
if p.get_bool("aime", true) {
|
||||
if let Some(code) = p.cfg.get("aime-code") {
|
||||
let code = code.as_str().expect("Invalid config");
|
||||
fs::write(util::profile_dir(&p).join("aime.txt"), code).await?;
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
Reference in New Issue
Block a user