Always check for extracted files in object resolution

Fixes an issue where extracted files would not be found after
removing the disc image from the orig dir.
This commit is contained in:
Luke Street 2024-10-13 13:36:01 -06:00
parent 18bd608fe8
commit bee4570a4c
3 changed files with 19 additions and 9 deletions

2
Cargo.lock generated
View File

@ -348,7 +348,7 @@ dependencies = [
[[package]] [[package]]
name = "decomp-toolkit" name = "decomp-toolkit"
version = "1.1.2" version = "1.1.3"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"ar", "ar",

View File

@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "Yet another GameCube/Wii decompilation toolkit." description = "Yet another GameCube/Wii decompilation toolkit."
authors = ["Luke Street <luke@street.dev>"] authors = ["Luke Street <luke@street.dev>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
version = "1.1.2" version = "1.1.3"
edition = "2021" edition = "2021"
publish = false publish = false
repository = "https://github.com/encounter/decomp-toolkit" repository = "https://github.com/encounter/decomp-toolkit"

View File

@ -1116,7 +1116,7 @@ fn split(args: SplitArgs) -> Result<()> {
if config.extract_objects && matches!(object_base, ObjectBase::Vfs(..)) { if config.extract_objects && matches!(object_base, ObjectBase::Vfs(..)) {
// Extract files from the VFS into the object base directory // Extract files from the VFS into the object base directory
let target_dir = extract_objects(&config, &object_base)?; let target_dir = extract_objects(&config, &object_base)?;
object_base = ObjectBase::Extracted(target_dir); object_base = ObjectBase::Directory(target_dir);
} }
for module_config in config.modules.iter_mut() { for module_config in config.modules.iter_mut() {
@ -2015,7 +2015,6 @@ fn apply_add_relocations(obj: &mut ObjInfo, relocations: &[AddRelocationConfig])
pub enum ObjectBase { pub enum ObjectBase {
None, None,
Directory(Utf8NativePathBuf), Directory(Utf8NativePathBuf),
Extracted(Utf8NativePathBuf),
Vfs(Utf8NativePathBuf, Box<dyn Vfs + Send + Sync>), Vfs(Utf8NativePathBuf, Box<dyn Vfs + Send + Sync>),
} }
@ -2023,8 +2022,14 @@ impl ObjectBase {
pub fn join(&self, path: &Utf8UnixPath) -> Utf8NativePathBuf { pub fn join(&self, path: &Utf8UnixPath) -> Utf8NativePathBuf {
match self { match self {
ObjectBase::None => path.with_encoding(), ObjectBase::None => path.with_encoding(),
ObjectBase::Directory(base) => base.join(path.with_encoding()), ObjectBase::Directory(base) => {
ObjectBase::Extracted(base) => extracted_path(base, path), // If the extracted file exists, use it directly
let extracted = extracted_path(base, path);
if fs::exists(&extracted).unwrap_or(false) {
return extracted;
}
base.join(path.with_encoding())
}
ObjectBase::Vfs(base, _) => Utf8NativePathBuf::from(format!("{}:{}", base, path)), ObjectBase::Vfs(base, _) => Utf8NativePathBuf::from(format!("{}:{}", base, path)),
} }
} }
@ -2032,8 +2037,14 @@ impl ObjectBase {
pub fn open(&self, path: &Utf8UnixPath) -> Result<Box<dyn VfsFile>> { pub fn open(&self, path: &Utf8UnixPath) -> Result<Box<dyn VfsFile>> {
match self { match self {
ObjectBase::None => open_file(&path.with_encoding(), true), ObjectBase::None => open_file(&path.with_encoding(), true),
ObjectBase::Directory(base) => open_file(&base.join(path.with_encoding()), true), ObjectBase::Directory(base) => {
ObjectBase::Extracted(base) => open_file(&extracted_path(base, path), true), // If the extracted file exists, use it directly
let extracted = extracted_path(base, path);
if fs::exists(&extracted).unwrap_or(false) {
return open_file(&extracted, true);
}
open_file(&base.join(path.with_encoding()), true)
}
ObjectBase::Vfs(vfs_path, vfs) => { ObjectBase::Vfs(vfs_path, vfs) => {
open_file_with_fs(vfs.clone(), &path.with_encoding(), true) open_file_with_fs(vfs.clone(), &path.with_encoding(), true)
.with_context(|| format!("Using disc image {}", vfs_path)) .with_context(|| format!("Using disc image {}", vfs_path))
@ -2045,7 +2056,6 @@ impl ObjectBase {
match self { match self {
ObjectBase::None => Utf8NativePath::new(""), ObjectBase::None => Utf8NativePath::new(""),
ObjectBase::Directory(base) => base, ObjectBase::Directory(base) => base,
ObjectBase::Extracted(base) => base,
ObjectBase::Vfs(base, _) => base, ObjectBase::Vfs(base, _) => base,
} }
} }