1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-06-07 15:17:45 +00:00

Stop crashing on first boot, with no expansions installed

This commit is contained in:
Joshua Goins 2023-05-13 17:30:15 -04:00
parent 22b645ec3b
commit b3debd7839
2 changed files with 48 additions and 11 deletions

View file

@ -8,7 +8,7 @@ use crate::patch::{apply_patch, PatchError};
use crate::repository::{string_to_category, Category, Repository};
use crate::sqpack::calculate_hash;
use std::fs;
use std::fs::DirEntry;
use std::fs::{DirEntry, ReadDir};
use std::path::PathBuf;
use tracing::{debug, error, info, span, warn, Level};
@ -88,26 +88,35 @@ impl GameData {
self.repositories.clear();
let mut d = PathBuf::from(self.game_directory.as_str());
// add initial ffxiv directory
if let Some(base_repository) = Repository::from_existing_base(d.to_str().unwrap()) {
self.repositories.push(base_repository);
}
// add expansions
d.push("sqpack");
let repository_paths: Vec<DirEntry> = fs::read_dir(d.as_path())
.unwrap()
.filter_map(Result::ok)
.filter(|s| s.file_type().unwrap().is_dir())
.collect();
if let Ok(repository_paths) = fs::read_dir(d.as_path()) {
let repository_paths : ReadDir = repository_paths;
for repository_path in repository_paths {
debug!(repository_path=repository_path.path().to_str(), "Found repository");
let repository_paths : Vec<DirEntry> = repository_paths
.filter_map(Result::ok)
.filter(|s| s.file_type().unwrap().is_dir())
.collect();
self.repositories
.push(Repository::from_existing(repository_path.path().to_str().unwrap()).unwrap());
for repository_path in repository_paths {
if let Some(expansion_repository) =Repository::from_existing(repository_path.path().to_str().unwrap()) {
self.repositories.push(expansion_repository);
}
}
}
self.repositories.sort();
}
fn get_index_file(&self, path: &str) -> Option<IndexFile> {
let (repository, category) = self.parse_repository_category(path).unwrap();
let (repository, category) = self.parse_repository_category(path)?;
let index_path: PathBuf = [
self.game_directory.clone(),

View file

@ -137,6 +137,11 @@ impl Repository {
}
};
// use from_existing_base instead
if repo_type == Base {
return None
}
let version = if repo_type == Base {
let mut d = PathBuf::from(dir);
d.pop();
@ -158,6 +163,29 @@ impl Repository {
})
}
pub fn from_existing_base(dir: &str) -> Option<Repository> {
let path = Path::new(dir);
if path.metadata().is_err() {
return None;
}
let name = String::from(path.file_stem().unwrap().to_str().unwrap());
let mut d = PathBuf::from(dir);
d.push("ffxivgame.ver");
let version = read_version(d.as_path());
if version != None {
Some(Repository {
name,
repo_type: Base,
version,
})
} else {
None
}
}
fn expansion(&self) -> i32 {
match self.repo_type {
Base => 0,