From cc4e80db8ae63c434b95452ea55ed425428dbe73 Mon Sep 17 00:00:00 2001
From: Quaternions <krakow20@gmail.com>
Date: Wed, 10 Jan 2024 17:04:25 -0800
Subject: [PATCH] search pak list

---
 src/main.rs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 45a67a9..8adc17f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -45,7 +45,7 @@ fn main() -> AResult<()> {
 	match cli.command {
 		Commands::Download(map_list)=>download(map_list.maps),
 		Commands::DownloadTextures(pathlist)=>download_textures(pathlist.paths),
-		Commands::ExtractTextures(pathlist)=>extract_textures(pathlist.paths,cli.path.unwrap()),
+		Commands::ExtractTextures(pathlist)=>extract_textures(vec![cli.path.unwrap()],pathlist.paths),
 		Commands::VPKContents=>vpk_contents(cli.path.unwrap()),
 		Commands::BSPContents=>bsp_contents(cli.path.unwrap()),
 		Commands::ConvertTextures=>convert_textures(),
@@ -1116,8 +1116,8 @@ fn recursive_vmt_loader<F:Fn(String)->AResult<Option<Vec<u8>>>>(find_stuff:&F,ma
 	}
 }
 
-fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->AResult<()>{
-	let vpk_index=vpk::VPK::read(&vpk_path)?;
+fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_paths:Vec<std::path::PathBuf>)->AResult<()>{
+	let vpk_list:Vec<vpk::VPK>=vpk_paths.into_iter().map(|vpk_path|vpk::VPK::read(&vpk_path).expect("vpk file does not exist")).collect();
 	for path in paths{
 		let mut deduplicate=std::collections::HashSet::new();
 		let bsp=vbsp::Bsp::read(std::fs::read(path)?.as_ref())?;
@@ -1162,7 +1162,7 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->
 		}
 
 		let pack=&bsp.pack;
-		let tree=&vpk_index.tree;
+		let vpk_list=&vpk_list;
 		std::thread::scope(move|s|{
 			let mut thread_handles=Vec::new();
 			for texture_name in deduplicate{
@@ -1200,8 +1200,8 @@ fn extract_textures(paths:Vec<std::path::PathBuf>,vpk_path:std::path::PathBuf)->
 						_=>(),
 					}
 					//search pak list
-					for tree in [tree]{
-						if let Some(vpk_entry)=tree.get(search_file_name.as_str()){
+					for vpk_index in vpk_list{
+						if let Some(vpk_entry)=vpk_index.tree.get(search_file_name.as_str()){
 							return Ok(Some(vpk_entry.get()?.to_vec()));
 						}
 					}