use anyhow::Result; use std::collections::BTreeSet; use crate::pkg::PkgKey; use crate::util; use crate::profiles::ProfilePaths; pub async fn prepare_packages<'a>(p: &'a impl ProfilePaths, pkgs: &BTreeSet) -> Result<()> { log::debug!("begin prepare packages"); let pfx_dir = p.data_dir(); let opt_dir = pfx_dir.join("option"); if pfx_dir.join("BepInEx").exists() { tokio::fs::remove_dir_all(pfx_dir.join("BepInEx")).await?; } if !opt_dir.exists() { tokio::fs::create_dir(opt_dir).await?; } for m in pkgs { 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..]) // cut the hyphen .join("app") .join("BepInEx"); if bpx_dir.exists() { util::copy_recursive(&bpx_dir, &pfx_dir.join("BepInEx"))?; } 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() { util::symlink(&x.path(), &pfx_dir.join("option").join(x.file_name())).await?; } } } log::debug!("end prepare packages"); Ok(()) }