RFile

Struct RFile 

Source
pub struct RFile { /* private fields */ }
Expand description

This struct represents an individual file, including the metadata associated with it.

It can represent both, a file within a Pack (or anything implementing Container really), or a single file on disk.

It supports Lazy-Loading to reduce RAM usage.

Implementations§

Source§

impl RFile

Source

pub fn new_from_container<C: Container>( container: &C, size: u64, is_compressed: bool, is_encrypted: Option<PFHVersion>, data_pos: u64, file_timestamp: u64, path_in_container: &str, ) -> Result<Self>

This function creates a RFile from a lazy-loaded file inside a Container.

About the parameters:

  • container: The container this RFile is on.
  • size: Size in bytes of the RFile.
  • is_compressed: If the RFile is compressed.
  • is_encrypted: If the RFile is encrypted.
  • data_pos: Byte offset of the data from the beginning of the Container.
  • file_timestamp: Timestamp of this specific file (not of the container, but the file). If it doesn’t have one, pass 0.
  • path_in_container: Path of the RFile in the container.

NOTE: Remember to call guess_file_type after this to properly set the FileType.

Source

pub fn new_from_file(path: &str) -> Result<Self>

This function creates a RFile from a path on disk.

This may fail if the file doesn’t exist or errors out when trying to be read for metadata.

NOTE: Remember to call guess_file_type after this to properly set the FileType.

Source

pub fn new_from_file_path(path: &Path) -> Result<Self>

This function creates a RFile from a path on disk.

This may fail if the file doesn’t exist or errors out when trying to be read for metadata.

NOTE: Remember to call guess_file_type after this to properly set the FileType.

Source

pub fn new_from_vec( data: &[u8], file_type: FileType, timestamp: u64, path: &str, ) -> Self

This function creates a RFile from raw data on memory.

NOTE: Remember to call guess_file_type after this to properly set the FileType.

Source

pub fn new_from_decoded(data: &RFileDecoded, timestamp: u64, path: &str) -> Self

This function creates a RFile from an RFileDecoded on memory.

NOTE: Remember to call guess_file_type after this to properly set the FileType.

Source

pub fn cached(&self) -> Result<&[u8]>

This function returns a reference to the cached data of an RFile, if said RFile has been cached. If not, it returns an error.

Useful for accessing preloaded data.

Source

pub fn cached_mut(&mut self) -> Result<&mut Vec<u8>>

This function returns a mutable reference to the cached data of an RFile, if said RFile has been cached. If not, it returns an error.

Useful for accessing preloaded data.

Source

pub fn decoded(&self) -> Result<&RFileDecoded>

This function returns a reference to the decoded data of an RFile, if said RFile has been decoded. If not, it returns an error.

Useful for accessing preloaded data.

Source

pub fn decoded_mut(&mut self) -> Result<&mut RFileDecoded>

This function returns a mutable reference to the decoded data of an RFile, if said RFile has been decoded. If not, it returns an error.

Useful for accessing preloaded data.

Source

pub fn set_cached(&mut self, data: &[u8])

This function replace any data a RFile has with the provided raw data.

Source

pub fn set_decoded(&mut self, decoded: RFileDecoded) -> Result<()>

This function allows to replace the inner decoded data of a RFile with another. It’ll fail if the decoded data is not valid for the file’s type.

Source

pub fn decode( &mut self, extra_data: &Option<DecodeableExtraData<'_>>, keep_in_cache: bool, return_data: bool, ) -> Result<Option<RFileDecoded>>

This function decodes an RFile from binary data, optionally caching and returning the decoded RFile.

About the arguments:

  • extra_data: any data needed to decode specific file types. Check each file type for info about what do each file type need.
  • keep_in_cache: if true, the data will be cached on memory.
  • return_data: if true, the decoded data will be returned.

NOTE: Passing keep_in_cache and return_data at false causes this function to decode the RFile and immediately drop the resulting data.

Source

pub fn encode( &mut self, extra_data: &Option<EncodeableExtraData<'_>>, move_decoded_to_cache: bool, move_undecoded_to_cache: bool, return_data: bool, ) -> Result<Option<Vec<u8>>>

This function encodes an RFile to binary, optionally caching and returning the data.

About the arguments:

  • extra_data: any data needed to encode specific file types. Check each file type for info about what do each file type need.
  • move_decoded_to_cache: if true, the decoded data will be dropped in favor of undecoded cached data.
  • move_undecoded_to_cache: if true, the data will be cached on memory.
  • return_data: if true, the data will be returned.
Source

pub fn load(&mut self) -> Result<()>

This function loads the data of an RFile to memory if it’s not yet loaded.

If it has already been loaded either to cache, or for decoding, this does nothing.

Source

pub fn timestamp(&self) -> Option<u64>

This function returns a copy of the Last modified date of this RFile, if any.

Source

pub fn file_type(&self) -> FileType

This function returns a copy of the FileType of this RFile.

Source

pub fn file_name(&self) -> Option<&str>

This function returns the file name if this RFile, if it has one.

Source

pub fn container_name(&self) -> &Option<String>

This function returns the file name of the container this RFile originates from, if any.

Source

pub fn path_in_container(&self) -> ContainerPath

This function returns the ContainerPath corresponding to this file.

Source

pub fn path_in_container_raw(&self) -> &str

This function returns the ContainerPath corresponding to this file as an &str.

Source

pub fn path_in_container_split(&self) -> Vec<&str>

This function returns the ContainerPath corresponding to this file as a Vec of &str.

Source

pub fn db_table_name_from_path(&self) -> Option<&str>

This function the table_name of this file (the folder that contains this file) if this file is a DB table.

It returns None of the file provided is not a DB Table.

Source

pub fn set_path_in_container_raw(&mut self, path: &str)

This function sets the ContainerPath of the provided RFile to the provided path..

Source

pub fn is_compressible(&self, game_info: &GameInfo) -> bool

This function returns if the RFile can be compressed or not.

Source

pub fn guess_file_type(&mut self) -> Result<()>

This function guesses the FileType of the provided RFile and stores it on it for later queries.

The way it works is: first it tries to guess it by extension (fast), then by full path (not as fast), then by data (slow and it may fail on lazy-loaded files).

This may fail for some files, so if you doubt set the type manually.

Source

pub fn tsv_import_from_path( path: &Path, schema: &Option<Schema>, ) -> Result<Self>

This function allows to import a TSV file on the provided Path into a binary database file.

It requires the path on disk of the TSV file and the Schema to use. Schema is only needed for DB tables.

Source

pub fn tsv_export_to_path( &mut self, path: &Path, schema: &Schema, keys_first: bool, ) -> Result<()>

This function allows to export a RFile into a TSV file on disk.

Only supported for DB and Loc files.

Source

pub fn merge(sources: &[&Self], path: &str) -> Result<Self>

This function tries to merge multiple files into one.

All files must be of the same type and said type must support merging.

Source

pub fn update(&mut self, definition: &Option<Definition>) -> Result<()>

This function tries to update a file to a new version of the same file’s format.

Files used by this function are expected to be pre-decoded.

Source

pub fn data_hash( &mut self, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<u64>

This function returns the data hash of the file.

Source

pub fn sanitize_and_create_file( &mut self, destination_path: &Path, extra_data: &Option<EncodeableExtraData<'_>>, ) -> Result<PathBuf>

Sanitizes a destination path and creates a file with the sanitized path. Logs a message if the filename was changed due to invalid Windows characters.

Trait Implementations§

Source§

impl Clone for RFile

Source§

fn clone(&self) -> RFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for RFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for RFile

Source§

fn eq(&self, other: &RFile) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for RFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for RFile

Auto Trait Implementations§

§

impl Freeze for RFile

§

impl RefUnwindSafe for RFile

§

impl Send for RFile

§

impl Sync for RFile

§

impl Unpin for RFile

§

impl UnwindSafe for RFile

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,