pub struct ApplyContext { /* private fields */ }Expand description
Apply-time state: install root, target platform, flag toggles, and the internal file-handle cache used by SQPK writers.
§Construction
Build with ApplyContext::new, then chain the with_* builder methods
to override defaults:
use zipatch_rs::{ApplyContext, Platform};
let ctx = ApplyContext::new("/opt/ffxiv/game")
.with_platform(Platform::Win32)
.with_ignore_missing(true);
assert_eq!(ctx.game_path().to_str().unwrap(), "/opt/ffxiv/game");
assert_eq!(ctx.platform(), Platform::Win32);
assert!(ctx.ignore_missing());§Platform mutation
The platform defaults to Platform::Win32. If the patch stream contains
a crate::chunk::sqpk::SqpkTargetInfo chunk, applying it overwrites
ApplyContext::platform with the platform declared in the chunk. This is
the normal case: real FFXIV patches begin with a TargetInfo chunk that
pins the platform, so the default is rarely used in practice.
Set the platform explicitly with ApplyContext::with_platform when you
know the target in advance or are processing a synthetic patch.
§Flag mutation
ApplyContext::ignore_missing and ApplyContext::ignore_old_mismatch
can also be overwritten mid-stream by ApplyOption chunks embedded in the
patch file. Set initial values with the with_ignore_* builder methods.
§File-handle cache
Internally, ApplyContext maintains a bounded map of open file handles
keyed by absolute path. The cache is an optimisation: a patch that writes
many chunks into the same .dat file re-uses a single handle rather than
opening and closing the file for every write.
The cache is capped at 256 entries. When that limit is reached and a new
path is needed, all entries are evicted at once. Handles are also
evicted explicitly before deleting a file (see DeleteFile) and before a
RemoveAll bulk operation.
Implementations§
Source§impl ApplyContext
impl ApplyContext
Sourcepub fn new(game_path: impl Into<PathBuf>) -> Self
pub fn new(game_path: impl Into<PathBuf>) -> Self
Create a context targeting the given game install directory.
Defaults: platform is Platform::Win32, both ignore-flags are off.
Use the with_* builder methods to change these defaults before
applying the first chunk.
§Example
use zipatch_rs::ApplyContext;
let ctx = ApplyContext::new("/opt/ffxiv/game");
assert_eq!(ctx.game_path().to_str().unwrap(), "/opt/ffxiv/game");Sourcepub fn game_path(&self) -> &Path
pub fn game_path(&self) -> &Path
Returns the game installation directory.
All file paths produced during apply are relative to this root.
Sourcepub fn platform(&self) -> Platform
pub fn platform(&self) -> Platform
Returns the current target platform.
This value may change during apply if the patch stream contains a
crate::chunk::sqpk::SqpkTargetInfo chunk.
Sourcepub fn ignore_missing(&self) -> bool
pub fn ignore_missing(&self) -> bool
Returns whether missing files are silently ignored during apply.
When true, operations that target a file that does not exist log a
warning instead of returning an error. This flag may be overwritten
mid-stream by an ApplyOption chunk.
Sourcepub fn ignore_old_mismatch(&self) -> bool
pub fn ignore_old_mismatch(&self) -> bool
Returns whether old-data mismatches are silently ignored during apply.
When true, apply operations that detect a checksum or data mismatch
against the existing on-disk content proceed without error. This flag
may be overwritten mid-stream by an ApplyOption chunk.
Sourcepub fn with_platform(self, platform: Platform) -> Self
pub fn with_platform(self, platform: Platform) -> Self
Sets the target platform. Defaults to Platform::Win32.
The platform determines the directory suffix used when resolving SqPack
file paths (win32, ps3, or ps4).
Note: a crate::chunk::sqpk::SqpkTargetInfo chunk encountered during
apply will override this value.
Sourcepub fn with_ignore_missing(self, v: bool) -> Self
pub fn with_ignore_missing(self, v: bool) -> Self
Silently ignore missing files instead of returning an error during apply.
When false (the default), any apply operation that cannot find its
target file returns crate::ZiPatchError::Io with kind
std::io::ErrorKind::NotFound.
When true, those failures are demoted to warn!-level tracing events.
Sourcepub fn with_ignore_old_mismatch(self, v: bool) -> Self
pub fn with_ignore_old_mismatch(self, v: bool) -> Self
Silently ignore old-data mismatches instead of returning an error during apply.
When false (the default), an apply operation that detects that the
on-disk data does not match the expected “before” state returns an error.
When true, the mismatch is logged at warn! level and the operation
continues.