2022-07-19 19:29:41 -04:00
|
|
|
use std::fs;
|
|
|
|
use std::path::PathBuf;
|
2022-08-09 21:53:20 -04:00
|
|
|
use crate::patch::{apply_patch, PatchError};
|
2022-07-19 19:29:41 -04:00
|
|
|
|
|
|
|
/// Boot data for FFXIV.
|
|
|
|
pub struct BootData {
|
2022-08-09 21:51:52 -04:00
|
|
|
path : String,
|
|
|
|
|
|
|
|
pub version : String,
|
2022-07-19 19:29:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2022-08-09 21:51:52 -04:00
|
|
|
path: directory.parse().unwrap(),
|
2022-08-09 23:17:19 -04:00
|
|
|
version: fs::read_to_string(format!("{directory}/ffxivboot.ver")).unwrap()
|
2022-07-19 19:29:41 -04:00
|
|
|
}),
|
|
|
|
false => {
|
|
|
|
println!("Boot data is not valid!");
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-09 21:51:52 -04:00
|
|
|
|
2022-08-09 21:53:20 -04:00
|
|
|
pub fn apply_patch(&self, patch_path : &str) -> Result<(), PatchError> {
|
|
|
|
apply_patch(&self.path, patch_path)
|
2022-08-09 21:51:52 -04:00
|
|
|
}
|
2022-07-19 19:29:41 -04:00
|
|
|
}
|