also load vpks from hl2

This commit is contained in:
Robin Appelman 2023-12-12 16:48:57 +01:00
commit 8ea62d2cc6

View file

@ -34,19 +34,24 @@ impl Loader {
} }
pub fn with_opt_pack(pack: Option<Packfile>) -> Result<Self, Error> { pub fn with_opt_pack(pack: Option<Packfile>) -> Result<Self, Error> {
let tf_dir = match var("TF_DIR") { let tf2_dir = match var("TF_DIR") {
Ok(dir) => PathBuf::from(dir).join("tf"), Ok(dir) => PathBuf::from(dir),
Err(_) => SteamDir::locate() Err(_) => SteamDir::locate()
.ok_or("Can't find steam directory")? .ok_or("Can't find steam directory")?
.app(&440) .app(&440)
.ok_or("Can't find tf2 directory")? .ok_or("Can't find tf2 directory")?
.path .path
.join("tf"), .clone(),
}; };
let tf_dir = tf2_dir.join("tf");
let vpk_dirs = [tf_dir.clone(), tf2_dir.join("hl2")];
let download = tf_dir.join("download"); let download = tf_dir.join("download");
let vpks = tf_dir let vpks = vpk_dirs
.read_dir()? .iter()
.filter_map(|item| item.ok()) .flat_map(|dir| dir.read_dir())
.flatten()
.flatten()
.filter_map(|item| Some(item.path().to_str()?.to_string())) .filter_map(|item| Some(item.path().to_str()?.to_string()))
.filter(|path| path.ends_with("dir.vpk")) .filter(|path| path.ends_with("dir.vpk"))
.map(|path| vpk::from_path(&path)) .map(|path| vpk::from_path(&path))