1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-05-09 11:57:46 +00:00

Remove possibility of None from GameData::from_existing

This simplifes the handling of "new installs" in applications like
Astra, who may end up calling GameData::apply_patch on an "invalid"
GameData struct. We should allow applications to still hold onto these
so it keeps track of game_directory.
This commit is contained in:
Joshua Goins 2025-05-05 17:07:49 -04:00
parent da094ea261
commit a9a3538d85
2 changed files with 14 additions and 13 deletions

View file

@ -21,10 +21,7 @@ fn main() {
let destination_path = &args[3];
/// Create a GameData struct, this manages the repositories. It allows us to easily extract files.
let Some(mut game_data) = GameData::from_existing(Platform::Win32, game_dir) else {
println!("Invalid game directory ({})!", game_dir);
return;
};
let mut game_data = GameData::from_existing(Platform::Win32, game_dir);
/// Extract said file:
let Some(game_file) = game_data.extract(file_path) else {

View file

@ -58,8 +58,8 @@ pub enum RepairError<'a> {
impl GameData {
/// Read game data from an existing game installation.
///
/// This will return _None_ if the game directory is not valid, but it does not check the validity
/// of each individual file.
/// This will return a GameData even if the game directory is technically
/// invalid, but it won't have any repositories.
///
/// # Example
///
@ -68,7 +68,7 @@ impl GameData {
/// use physis::gamedata::GameData;
/// GameData::from_existing(Platform::Win32, "$FFXIV/game");
/// ```
pub fn from_existing(platform: Platform, directory: &str) -> Option<GameData> {
pub fn from_existing(platform: Platform, directory: &str) -> GameData {
debug!(directory, "Loading game directory");
match is_valid(directory) {
@ -79,11 +79,15 @@ impl GameData {
index_files: HashMap::new(),
};
data.reload_repositories(platform);
Some(data)
data
}
false => {
warn!("Game data is not valid!");
None
warn!("Game data is not valid! Treating it as a new install...");
Self {
game_directory: String::from(directory),
repositories: vec![],
index_files: HashMap::new(),
}
}
}
}
@ -146,7 +150,7 @@ impl GameData {
/// ```should_panic
/// # use physis::common::Platform;
/// use physis::gamedata::GameData;
/// # let mut game = GameData::from_existing(Platform::Win32, "SquareEnix/Final Fantasy XIV - A Realm Reborn/game").unwrap();
/// # let mut game = GameData::from_existing(Platform::Win32, "SquareEnix/Final Fantasy XIV - A Realm Reborn/game");
/// if game.exists("exd/cid.exl") {
/// println!("Cid really does exist!");
/// } else {
@ -170,7 +174,7 @@ impl GameData {
/// # use physis::gamedata::GameData;
/// # use std::io::Write;
/// use physis::common::Platform;
/// # let mut game = GameData::from_existing(Platform::Win32, "SquareEnix/Final Fantasy XIV - A Realm Reborn/game").unwrap();
/// # let mut game = GameData::from_existing(Platform::Win32, "SquareEnix/Final Fantasy XIV - A Realm Reborn/game");
/// let data = game.extract("exd/root.exl").unwrap();
///
/// let mut file = std::fs::File::create("root.exl").unwrap();
@ -433,7 +437,7 @@ mod tests {
d.push("valid_sqpack");
d.push("game");
GameData::from_existing(Platform::Win32, d.to_str().unwrap()).unwrap()
GameData::from_existing(Platform::Win32, d.to_str().unwrap())
}
#[test]