feat: use sets etc.

This commit is contained in:
2025-02-27 16:42:43 +00:00
parent 3d96d89846
commit d25841853c
11 changed files with 587 additions and 563 deletions

View File

@ -1,4 +1,3 @@
use tokio::task::JoinSet;
use anyhow::{Result, anyhow};
use tokio::fs;
use std::path::{Path, PathBuf};
@ -18,6 +17,14 @@ async fn symlink(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Resul
}
pub async fn line_up(p: &Profile, pkg_hash: String) -> Result<()> {
let dir_out = p.dir();
if dir_out.join("option").exists() {
fs::remove_dir_all(dir_out.join("option")).await?;
}
fs::create_dir_all(dir_out.join("option")).await?;
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 {
@ -35,21 +42,14 @@ pub async fn line_up(p: &Profile, pkg_hash: String) -> Result<()> {
async fn prepare_packages(p: &Profile) -> Result<()> {
let dir_out = p.dir();
let mut futures = JoinSet::new();
if dir_out.join("BepInEx").exists() {
futures.spawn(fs::remove_dir_all(dir_out.join("BepInEx")));
fs::remove_dir_all(dir_out.join("BepInEx")).await?;
}
if dir_out.join("option").exists() {
futures.spawn(fs::remove_dir_all(dir_out.join("option")));
}
while let Some(_) = futures.join_next().await {}
fs::create_dir_all(dir_out.join("option")).await?;
for m in &p.mods {
log::debug!("Preparing {}", m);
let (namespace, name) = m.0.split_at(m.0.find("-").expect("Invalid mod definition"));
let bpx_dir = util::pkg_dir_of(namespace, &name[1..])
let bpx_dir = util::pkg_dir_of(namespace, &name[1..]) // cut the hyphen
.join("app")
.join("BepInEx");
if bpx_dir.exists() {