use std::path::{Path, PathBuf};
use crate::error::{Error, Result};
use crate::virtual_texture::utils::{ExtractResult, extract_all};
use super::discovery::discover_virtual_textures;
use super::types::DiscoveredVirtualTexture;
pub fn find_gts_for_gtex(gtex_hash: &str, search_paths: &[PathBuf]) -> Result<Option<PathBuf>> {
let discovered = discover_virtual_textures(search_paths)?;
for vt in discovered {
if vt.gtex_hash == gtex_hash {
return Ok(Some(vt.gts_path));
}
}
Ok(None)
}
pub fn find_virtual_texture(
gtex_hash: &str,
search_paths: &[PathBuf],
) -> Result<Option<DiscoveredVirtualTexture>> {
let discovered = discover_virtual_textures(search_paths)?;
for vt in discovered {
if vt.gtex_hash == gtex_hash {
return Ok(Some(vt));
}
}
Ok(None)
}
pub fn extract_by_gtex(
gtex_hash: &str,
search_paths: &[PathBuf],
output_dir: &Path,
) -> Result<ExtractResult> {
let vt = find_virtual_texture(gtex_hash, search_paths)?.ok_or_else(|| {
Error::ConversionError(format!("GTex hash '{gtex_hash}' not found in search paths"))
})?;
if !vt.gts_path.exists() {
return Err(Error::ConversionError(format!(
"GTS file not found at derived path: {}",
vt.gts_path.display()
)));
}
extract_all(&vt.gts_path, output_dir)
}