1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-26 06:07:45 +00:00
physis/src/bootdata.rs
2022-08-16 11:52:07 -04:00

51 lines
1.3 KiB
Rust
Executable file

use crate::patch::{apply_patch, PatchError};
use std::fs;
use std::path::PathBuf;
/// Boot data for FFXIV.
pub struct BootData {
path: String,
pub version: String,
}
fn is_valid(path: &str) -> bool {
let d = PathBuf::from(path);
if fs::metadata(d.as_path()).is_err() {
return false;
}
true
}
impl BootData {
/// Reads from an existing boot data location.
///
/// This will return _None_ if the boot directory is not valid, but it does not check the validity
/// of each individual file.
///
/// # Example
///
/// ```
/// # use physis::bootdata::BootData;
/// let boot = BootData::from_existing("SquareEnix/Final Fantasy XIV - A Realm Reborn/boot");
/// # assert!(boot.is_none())
/// ```
pub fn from_existing(directory: &str) -> Option<BootData> {
match is_valid(directory) {
true => Some(BootData {
path: directory.parse().unwrap(),
version: fs::read_to_string(format!("{directory}/ffxivboot.ver")).unwrap(),
}),
false => {
println!("Boot data is not valid!");
None
}
}
}
pub fn apply_patch(&self, patch_path: &str) -> Result<(), PatchError> {
apply_patch(&self.path, patch_path)
}
}