use anyhow::Result; use std::collections::BTreeSet; use std::path::PathBuf; use crate::model::misc::Game; use crate::pkg::{PkgKey, Status}; use crate::pkg_store::PackageStore; use crate::util; use crate::profiles::types::ProfilePaths; pub async fn prepare_packages<'a>(p: &'a impl ProfilePaths, pkgs: &BTreeSet, mut redo_bepinex: bool) -> Result<()> { log::debug!("begin prepare packages"); let pfx_dir = p.data_dir(); let opt_dir = pfx_dir.join("option"); for m in pkgs { let (namespace, _) = m.split()?; if namespace == "local" { log::info!("package with the 'local' namespace enabled -- force refreshing"); redo_bepinex = true; } } if redo_bepinex { if pfx_dir.join("BepInEx").exists() { util::remove_dir_all(pfx_dir.join("BepInEx")).await?; } if pfx_dir.join("lang").exists() { util::remove_dir_all(pfx_dir.join("lang")).await?; } } if !opt_dir.exists() { tokio::fs::create_dir(opt_dir).await?; } for m in pkgs { log::debug!("preparing {}", m); let (namespace, name) = m.split()?; if redo_bepinex { let bpx_dir = util::pkg_dir_of(&namespace, &name) .join("app") .join("BepInEx"); if bpx_dir.exists() { util::copy_directory(&bpx_dir, &pfx_dir.join("BepInEx"), true)?; } let lang_dir = util::pkg_dir_of(&namespace, &name) .join("app") .join("lang"); if lang_dir.exists() { util::copy_directory(&lang_dir, &pfx_dir.join("lang"), true)?; } } let opt_dir = util::pkg_dir_of(&namespace, &name).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(()) } pub fn prepare_dlls( game: Game, enabled_pkgs: &BTreeSet, store: &PackageStore, ) -> Result<(Vec, Vec)> { let mut res_game = Vec::new(); let mut res_amd = Vec::new(); for pkg in enabled_pkgs { if let Ok(pkg) = store.get(&pkg) { if let Some(loc) = &pkg.loc { if let Status::OK(_, dlls) = &loc.status { if let Some(game_dll) = &dlls.game { res_game.push(pkg.path().join(game_dll.clone())); } if let Some(game32_dll) = &dlls.game32 { if game.bitness() == 32 { res_game.push(pkg.path().join(game32_dll.clone())); } } if let Some(game64_dll) = &dlls.game64 { if game.bitness() == 64 { res_game.push(pkg.path().join(game64_dll.clone())); } } if let Some(amd_dll) = &dlls.amd { res_amd.push(pkg.path().join(amd_dll.clone())); } } } } } Ok((res_game, res_amd)) }