1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-28 06:57:46 +00:00

Finally, implement SqpkFileOperation::RemoveAll

This commit is contained in:
Joshua Goins 2022-10-17 19:05:58 -04:00
parent 263f18a544
commit 78856af0a5

View file

@ -340,10 +340,14 @@ fn write_empty_file_block_at(
Ok(()) Ok(())
} }
fn get_expansion_folder(sub_id: u16) -> String { fn get_expansion_folder_sub(sub_id: u16) -> String {
let expansion_id = sub_id >> 8; let expansion_id = sub_id >> 8;
match expansion_id { get_expansion_folder(expansion_id)
}
fn get_expansion_folder(id: u16) -> String {
match id {
0 => "ffxiv".to_string(), 0 => "ffxiv".to_string(),
n => format!("ex{}", n), n => format!("ex{}", n),
} }
@ -385,7 +389,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
get_platform_string(&target_info.platform), get_platform_string(&target_info.platform),
file_id file_id
); );
let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder(sub_id), &filename] let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder_sub(sub_id), &filename]
.iter() .iter()
.collect(); .collect();
@ -406,7 +410,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
filename += &*format!("{}", file_id); filename += &*format!("{}", file_id);
} }
let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder(sub_id), &filename] let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder_sub(sub_id), &filename]
.iter() .iter()
.collect(); .collect();
@ -512,7 +516,6 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
match fop.operation { match fop.operation {
SqpkFileOperation::AddFile => { SqpkFileOperation::AddFile => {
// TODO: we should not be handling this here, probably
fs::create_dir_all(&parent_directory)?; fs::create_dir_all(&parent_directory)?;
// reverse reading crc32 // reverse reading crc32
@ -542,7 +545,13 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
fs::remove_file(file_path.as_str())?; fs::remove_file(file_path.as_str())?;
} }
SqpkFileOperation::RemoveAll => { SqpkFileOperation::RemoveAll => {
println!("PATCH: NOP RemoveAll"); let path: PathBuf = [data_dir, "sqpack", &get_expansion_folder(fop.expansion_id)]
.iter()
.collect();
if fs::read_dir(&path).is_ok() {
fs::remove_dir_all(&path)?;
}
} }
SqpkFileOperation::MakeDirTree => { SqpkFileOperation::MakeDirTree => {
fs::create_dir_all(parent_directory)?; fs::create_dir_all(parent_directory)?;