mirror of
https://github.com/redstrate/Physis.git
synced 2025-05-10 12:27:45 +00:00
Allow constructing invalid/empty BootData
For the same reasons as outlined wrt GameData in the previous commit.
This commit is contained in:
parent
a9a3538d85
commit
ceeb56fabe
1 changed files with 18 additions and 12 deletions
|
@ -18,25 +18,29 @@ pub struct BootData {
|
||||||
impl BootData {
|
impl BootData {
|
||||||
/// Reads from an existing boot data location.
|
/// 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
|
/// This will return a BootData even if the game directory is technically
|
||||||
/// of each individual file.
|
/// invalid, but it won't have a valid version.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use physis::bootdata::BootData;
|
/// # use physis::bootdata::BootData;
|
||||||
/// let boot = BootData::from_existing("SquareEnix/Final Fantasy XIV - A Realm Reborn/boot");
|
/// 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> {
|
pub fn from_existing(directory: &str) -> BootData {
|
||||||
match Self::is_valid(directory) {
|
match Self::is_valid(directory) {
|
||||||
true => Some(BootData {
|
true => BootData {
|
||||||
path: directory.parse().ok()?,
|
path: directory.parse().ok().unwrap(),
|
||||||
version: fs::read_to_string(format!("{directory}/ffxivboot.ver")).ok()?,
|
version: fs::read_to_string(format!("{directory}/ffxivboot.ver"))
|
||||||
}),
|
.ok()
|
||||||
|
.unwrap(),
|
||||||
|
},
|
||||||
false => {
|
false => {
|
||||||
warn!("Boot data is not valid!");
|
warn!("Boot data is not valid! Returning one anyway, but without a version.");
|
||||||
None
|
BootData {
|
||||||
|
path: directory.parse().ok().unwrap(),
|
||||||
|
version: String::default(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,7 +71,8 @@ mod tests {
|
||||||
d.push("resources/tests");
|
d.push("resources/tests");
|
||||||
d.push("valid_boot");
|
d.push("valid_boot");
|
||||||
|
|
||||||
assert!(BootData::from_existing(d.as_path().to_str().unwrap()).is_some());
|
let boot_data = BootData::from_existing(d.as_path().to_str().unwrap());
|
||||||
|
assert_eq!(boot_data.version, "2012.01.01.0000.0000");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -76,6 +81,7 @@ mod tests {
|
||||||
d.push("resources/tests");
|
d.push("resources/tests");
|
||||||
d.push("invalid_boot"); // intentionally missing so it doesn't have a .ver
|
d.push("invalid_boot"); // intentionally missing so it doesn't have a .ver
|
||||||
|
|
||||||
assert!(BootData::from_existing(d.as_path().to_str().unwrap()).is_none());
|
let boot_data = BootData::from_existing(d.as_path().to_str().unwrap());
|
||||||
|
assert_eq!(boot_data.version, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue