1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-05-10 12:27:45 +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]; let destination_path = &args[3];
/// Create a GameData struct, this manages the repositories. It allows us to easily extract files. /// 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 { let mut game_data = GameData::from_existing(Platform::Win32, game_dir);
println!("Invalid game directory ({})!", game_dir);
return;
};
/// Extract said file: /// Extract said file:
let Some(game_file) = game_data.extract(file_path) else { let Some(game_file) = game_data.extract(file_path) else {

View file

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