Skip to content

Commit

Permalink
Always check for extracted files in object resolution
Browse files Browse the repository at this point in the history
Fixes an issue where extracted files would not be found after
removing the disc image from the orig dir.
  • Loading branch information
encounter committed Oct 13, 2024
1 parent 18bd608 commit bee4570
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "decomp-toolkit"
description = "Yet another GameCube/Wii decompilation toolkit."
authors = ["Luke Street <[email protected]>"]
license = "MIT OR Apache-2.0"
version = "1.1.2"
version = "1.1.3"
edition = "2021"
publish = false
repository = "https://github.com/encounter/decomp-toolkit"
Expand Down
24 changes: 17 additions & 7 deletions src/cmd/dol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ fn split(args: SplitArgs) -> Result<()> {
if config.extract_objects && matches!(object_base, ObjectBase::Vfs(..)) {
// Extract files from the VFS into the object base directory
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() {
Expand Down Expand Up @@ -2015,25 +2015,36 @@ fn apply_add_relocations(obj: &mut ObjInfo, relocations: &[AddRelocationConfig])
pub enum ObjectBase {
None,
Directory(Utf8NativePathBuf),
Extracted(Utf8NativePathBuf),
Vfs(Utf8NativePathBuf, Box<dyn Vfs + Send + Sync>),
}

impl ObjectBase {
pub fn join(&self, path: &Utf8UnixPath) -> Utf8NativePathBuf {
match self {
ObjectBase::None => path.with_encoding(),
ObjectBase::Directory(base) => base.join(path.with_encoding()),
ObjectBase::Extracted(base) => extracted_path(base, path),
ObjectBase::Directory(base) => {
// 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)),
}
}

pub fn open(&self, path: &Utf8UnixPath) -> Result<Box<dyn VfsFile>> {
match self {
ObjectBase::None => open_file(&path.with_encoding(), true),
ObjectBase::Directory(base) => open_file(&base.join(path.with_encoding()), true),
ObjectBase::Extracted(base) => open_file(&extracted_path(base, path), true),
ObjectBase::Directory(base) => {
// 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) => {
open_file_with_fs(vfs.clone(), &path.with_encoding(), true)
.with_context(|| format!("Using disc image {}", vfs_path))
Expand All @@ -2045,7 +2056,6 @@ impl ObjectBase {
match self {
ObjectBase::None => Utf8NativePath::new(""),
ObjectBase::Directory(base) => base,
ObjectBase::Extracted(base) => base,
ObjectBase::Vfs(base, _) => base,
}
}
Expand Down

0 comments on commit bee4570

Please sign in to comment.