use std::path::{Path, PathBuf};
use anyhow::{Result, bail};
use home::home_dir;
use steamlocate::SteamDir;
const PDX_LINUX: &str = ".local/share/Paradox Interactive";
const PDX_MAC: &str = "Library/Application Support/Paradox Interactive"; const PDX_WINDOWS: &str = "Documents/Paradox Interactive";
pub fn find_game_directory_steam(steam_app_id: u32) -> Result<PathBuf> {
let steamdir = SteamDir::locate()?;
if let Some((app, library)) = steamdir.find_app(steam_app_id)? {
Ok(library.resolve_app_dir(&app))
} else {
bail!("Game not found in Steam library")
}
}
pub fn find_workshop_directory_steam(steam_app_id: u32) -> Result<PathBuf> {
let steamdir = SteamDir::locate()?;
Ok({
let mut path = steamdir.path().to_path_buf();
path.push("steamapps/workshop/content");
path.push(steam_app_id.to_string());
path
})
}
pub fn find_paradox_directory(dir_under: &Path) -> Option<PathBuf> {
if let Some(home) = home_dir() {
for try_dir in &[PDX_LINUX, PDX_MAC, PDX_WINDOWS] {
let full_try_dir = home.join(try_dir).join(dir_under);
if full_try_dir.is_dir() {
return Some(fix_slashes_for_target_platform(full_try_dir));
}
}
}
None
}
fn fix_slashes_for_target_platform<P: std::borrow::Borrow<Path>>(path: P) -> PathBuf {
path.borrow().components().collect()
}