Skip to main content

IniFileSystem

Struct IniFileSystem 

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

A hierarchical file system of IniFile.

example usage:

 use std::path::PathBuf;
 use rpkg_rs::misc::ini_file_system::IniFileSystem;

 let retail_path = PathBuf::from("Path to retail folder");
 let thumbs_path = retail_path.join("thumbs.dat");

 let thumbs = IniFileSystem::from(&thumbs_path.as_path())?;

 let app_options = &thumbs.root()?;

 if let (Some(proj_path), Some(runtime_path)) = (app_options.get("PROJECT_PATH"), app_options.get("RUNTIME_PATH")) {
    println!("Project path: {}", proj_path);
    println!("Runtime path: {}", runtime_path);
 }

Implementations§

Source§

impl IniFileSystem

Source

pub fn new(ini_file: IniFile) -> Self

Source

pub fn from_path( root_file: impl AsRef<Path>, xtea_config: XteaConfig, ) -> Result<Self, IniFileError>

Loads an IniFileSystem from a root file on disk.

The file is read from root_file and decrypted using the provided XteaConfig, parsed as an IniFile, and any !include directives are resolved recursively relative to the root file’s parent directory.

Examples found in repository?
examples/mount_ini_system.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4    let ini = glacier_ini::IniFileSystem::from_path("./Retail/thumbs.dat", XteaConfig::Knt)?;
5    println!("{:?}", ini);
6    Ok(())
7}
Source

pub fn write_to_folder<P: AsRef<Path>>( &self, path: P, xtea_config: XteaConfig, ) -> Result<(), IniFileError>

Writes the entire IniFileSystem to a folder on disk.

The root file and all included files are written recursively, preserving their relative paths. Output is encrypted with the provided XteaConfig.

If path points to a file, its parent directory is used as the export root. If you don’t want multiple included ini files in the export path you should consider using the normalize function first first

Source

pub fn normalize(&mut self)

Normalizes the IniFileSystem by merging all included files into the root file.

Sections and console commands from included files are applied breadth-first. When an option already exists in the root, later values overwrite earlier ones. Included files are removed from the hierarchy as part of normalization.

Source

pub fn console_cmds(&self) -> Vec<String>

Retrieves all console commands from the IniFileSystem, including those from included files.

Source

pub fn option( &self, key: impl Into<IniKey> + Clone, ) -> Result<String, IniFileError>

Retrieves the value of an option in a section from the IniFileSystem, including values from included files.

Source

pub fn root(&self) -> &IniFile

Retrieves a reference to the root IniFile of the IniFileSystem.

Source

pub fn root_mut(&mut self) -> &mut IniFile

Retrieves a reference to the root IniFile of the IniFileSystem.

Trait Implementations§

Source§

impl Debug for IniFileSystem

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> 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, 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.