mirror of
https://github.com/redstrate/Physis.git
synced 2025-06-08 07:37:46 +00:00
Implement MakeDirTree, consolidate some parts of FileOperation
This commit is contained in:
parent
a4641cdfce
commit
ebc7ae77e7
1 changed files with 8 additions and 10 deletions
18
src/patch.rs
18
src/patch.rs
|
@ -536,13 +536,13 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
new_file.write_all(&*header.header_data)?;
|
new_file.write_all(&*header.header_data)?;
|
||||||
}
|
}
|
||||||
SqpkOperation::FileOperation(fop) => {
|
SqpkOperation::FileOperation(fop) => {
|
||||||
|
let file_path = format!("{}/{}", data_dir, fop.path);
|
||||||
|
let (parent_directory, _) = file_path.rsplit_once('/').unwrap();
|
||||||
|
|
||||||
match fop.operation {
|
match fop.operation {
|
||||||
SqpkFileOperation::AddFile => {
|
SqpkFileOperation::AddFile => {
|
||||||
let new_path = data_dir.to_owned() + "/" + &fop.path;
|
// TODO: we should not be handling this here, probably
|
||||||
|
fs::create_dir_all(&parent_directory)?;
|
||||||
let (left, _) = new_path.rsplit_once('/').unwrap();
|
|
||||||
|
|
||||||
fs::create_dir_all(left)?;
|
|
||||||
|
|
||||||
// reverse reading crc32
|
// reverse reading crc32
|
||||||
file.seek(SeekFrom::Current(-4))?;
|
file.seek(SeekFrom::Current(-4))?;
|
||||||
|
@ -558,7 +558,7 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
|
|
||||||
// now apply the file!
|
// now apply the file!
|
||||||
let mut new_file =
|
let mut new_file =
|
||||||
OpenOptions::new().write(true).create(true).open(new_path)?;
|
OpenOptions::new().write(true).create(true).open(file_path)?;
|
||||||
|
|
||||||
if fop.offset == 0 {
|
if fop.offset == 0 {
|
||||||
new_file.set_len(0)?;
|
new_file.set_len(0)?;
|
||||||
|
@ -568,15 +568,13 @@ pub fn apply_patch(data_dir: &str, patch_path: &str) -> Result<(), PatchError> {
|
||||||
new_file.write_all(&data)?;
|
new_file.write_all(&data)?;
|
||||||
}
|
}
|
||||||
SqpkFileOperation::DeleteFile => {
|
SqpkFileOperation::DeleteFile => {
|
||||||
let new_path = data_dir.to_owned() + "/" + &fop.path;
|
fs::remove_file(file_path.as_str())?;
|
||||||
|
|
||||||
fs::remove_file(new_path.as_str())?;
|
|
||||||
}
|
}
|
||||||
SqpkFileOperation::RemoveAll => {
|
SqpkFileOperation::RemoveAll => {
|
||||||
println!("PATCH: NOP RemoveAll");
|
println!("PATCH: NOP RemoveAll");
|
||||||
}
|
}
|
||||||
SqpkFileOperation::MakeDirTree => {
|
SqpkFileOperation::MakeDirTree => {
|
||||||
println!("PATCH: NOP MakeDirTree");
|
fs::create_dir_all(parent_directory)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue