1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-24 21:37:46 +00:00
physis/src/bootdata.rs

59 lines
1.7 KiB
Rust
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
// SPDX-License-Identifier: GPL-3.0-or-later
2022-07-19 19:29:41 -04:00
use std::fs;
use std::path::PathBuf;
2023-11-10 17:25:53 -05:00
use tracing::warn;
2022-07-19 19:29:41 -04:00
use crate::patch::{apply_patch, PatchError};
/// Represents the boot data for FFXIV, which is located under the "boot" directory.
2022-07-19 19:29:41 -04:00
pub struct BootData {
2022-08-16 11:52:07 -04:00
path: String,
/// The current version of the boot data, e.g. "2012.01.01.0000.0000".
2022-08-16 11:52:07 -04:00
pub version: String,
2022-07-19 19:29:41 -04:00
}
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 Self::is_valid(directory) {
2022-07-19 19:29:41 -04:00
true => Some(BootData {
path: directory.parse().unwrap(),
2022-08-16 11:52:07 -04:00
version: fs::read_to_string(format!("{directory}/ffxivboot.ver")).unwrap(),
2022-07-19 19:29:41 -04:00
}),
false => {
2023-11-10 17:25:53 -05:00
warn!("Boot data is not valid!");
2022-07-19 19:29:41 -04:00
None
}
}
}
/// Applies the patch to boot data and returns any errors it encounters. This function will not update the version in the BootData struct.
2022-08-16 11:52:07 -04:00
pub fn apply_patch(&self, patch_path: &str) -> Result<(), PatchError> {
apply_patch(&self.path, patch_path)
}
fn is_valid(path: &str) -> bool {
let d = PathBuf::from(path);
if fs::metadata(d.as_path()).is_err() {
return false;
}
true
}
2022-08-16 11:52:07 -04:00
}