Skip to content

Commit

Permalink
Fixed callback not firing on failed partition mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
dafitius committed Aug 7, 2024
1 parent 30d94c9 commit ef1bede
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions examples/mount_game_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ fn main() {
last_index = current;
print!("Mounting partition {} ", current);
}
if !state.installing && !state.mounted {
println!("[Failed to mount this partition. Is it installed?]");
}
let install_progress = (state.install_progress * 10.0).ceil() / 10.0;

let chars_to_add = (install_progress * 10.0 - progress * 10.0) as usize * 2;
Expand Down
17 changes: 14 additions & 3 deletions src/resource/resource_partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ResourcePartition {
}

/// search through the package_dir to figure out which patch indices are there.
/// We have to use this inside of using the patchlevel inside the PartitionInfo.
/// We have to use this instead of using the patchlevel inside the PartitionInfo.
fn read_patch_indices(
&self,
package_dir: &Path,
Expand Down Expand Up @@ -114,13 +114,23 @@ impl ResourcePartition {
Ok(patch_indices)
}

/// Mounts resource packages in the partition.
///
/// This function attempts to mount all necessary resource packages into the current partition.
/// If successful, the resources will be available for use within the partition.
/// This function will fail silently when this package can't be found inside runtime directory
pub fn mount_resource_packages_in_partition(
&mut self,
runtime_path: &Path,
) -> Result<(), ResourcePartitionError> {
self.mount_resource_packages_in_partition_with_hook(runtime_path, |_| {})
}

/// Mounts resource packages in the partition with a callback.
///
/// This function attempts to mount all necessary resource packages into the current partition.
/// If successful, the resources will be available for use within the partition.
/// This function will fail silently when this package can't be found inside runtime directory.
pub fn mount_resource_packages_in_partition_with_hook<F>(
&mut self,
runtime_path: &Path,
Expand All @@ -135,11 +145,12 @@ impl ResourcePartition {
install_progress: 0.0,
};

//maybe don't error on a missing partition? the game doesn't...
//let patch_indices = self.read_patch_indices(runtime_path)?;
//The process can silently fail here. You are able to detect this using a callback.
//This behaviour was chosen because the game is able to refer to non-installed partitions in its packagedefs file.
let patch_idx_result = self.read_patch_indices(runtime_path);
if patch_idx_result.is_err() {
state.installing = false;
progress_callback(&state);
return Ok(());
}

Expand Down

0 comments on commit ef1bede

Please sign in to comment.