get oodle decompress function

This commit is contained in:
spuds 2023-09-20 10:07:47 +01:00
parent 6c0ef1ce7b
commit 01515310e4
No known key found for this signature in database
GPG key ID: 0B6CA6068E827C8F

View file

@ -1,6 +1,8 @@
use std::collections::BTreeMap; use std::collections::BTreeMap;
use std::fs::{self, File}; use std::fs::{self, File};
use std::io::{self, BufReader, BufWriter}; use std::io::{self, BufReader, BufWriter};
#[cfg(windows)]
use std::ops::Deref;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use clap::builder::TypedValueParser; use clap::builder::TypedValueParser;
@ -248,12 +250,8 @@ fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(),
let hashes: std::sync::Arc<std::sync::Mutex<BTreeMap<std::borrow::Cow<'_, str>, Vec<u8>>>> = let hashes: std::sync::Arc<std::sync::Mutex<BTreeMap<std::borrow::Cow<'_, str>, Vec<u8>>>> =
Default::default(); Default::default();
use std::ops::Deref; #[cfg(windows)]
let lib = match OODLE.deref() { let oodle_decompress = decompress()?;
Ok(lib) => lib,
Err(e) => return Err(repak::Error::Other(e.clone())),
};
let oodle_decompress = unsafe { lib.get(b"OodleLZ_Decompress") }.unwrap();
full_paths.par_iter().zip(stripped).try_for_each_init( full_paths.par_iter().zip(stripped).try_for_each_init(
|| (hashes.clone(), File::open(&action.input)), || (hashes.clone(), File::open(&action.input)),
@ -261,6 +259,13 @@ fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(),
use sha2::Digest; use sha2::Digest;
let mut hasher = sha2::Sha256::new(); let mut hasher = sha2::Sha256::new();
#[cfg(not(windows))]
pak.read_file(
path,
&mut BufReader::new(file.as_ref().unwrap()),
&mut hasher,
)?;
#[cfg(windows)]
pak.read_file_with_oodle( pak.read_file_with_oodle(
path, path,
&mut BufReader::new(file.as_ref().unwrap()), &mut BufReader::new(file.as_ref().unwrap()),
@ -361,12 +366,9 @@ fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repa
let progress = indicatif::ProgressBar::new(entries.len() as u64) let progress = indicatif::ProgressBar::new(entries.len() as u64)
.with_style(indicatif::ProgressStyle::with_template(STYLE).unwrap()); .with_style(indicatif::ProgressStyle::with_template(STYLE).unwrap());
use std::ops::Deref;
let lib = match OODLE.deref() { #[cfg(windows)]
Ok(lib) => lib, let oodle_decompress = decompress()?;
Err(e) => return Err(repak::Error::Other(e.clone())),
};
let decompress = unsafe { lib.get(b"OodleLZ_Decompress") }.unwrap();
entries.par_iter().try_for_each_init( entries.par_iter().try_for_each_init(
|| (progress.clone(), File::open(input)), || (progress.clone(), File::open(input)),
|(progress, file), entry| -> Result<(), repak::Error> { |(progress, file), entry| -> Result<(), repak::Error> {
@ -374,6 +376,16 @@ fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repa
progress.println(format!("unpacking {}", entry.entry_path)); progress.println(format!("unpacking {}", entry.entry_path));
} }
fs::create_dir_all(&entry.out_dir)?; fs::create_dir_all(&entry.out_dir)?;
#[cfg(not(windows))]
pak.read_file(
&entry.entry_path,
&mut BufReader::new(
file.as_ref()
.map_err(|e| repak::Error::Other(format!("error reading pak: {e}")))?,
),
&mut fs::File::create(&entry.out_path)?,
)?;
#[cfg(windows)]
pak.read_file_with_oodle( pak.read_file_with_oodle(
&entry.entry_path, &entry.entry_path,
&mut BufReader::new( &mut BufReader::new(
@ -381,7 +393,7 @@ fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repa
.map_err(|e| repak::Error::Other(format!("error reading pak: {e}")))?, .map_err(|e| repak::Error::Other(format!("error reading pak: {e}")))?,
), ),
&mut fs::File::create(&entry.out_path)?, &mut fs::File::create(&entry.out_path)?,
&decompress, &oodle_decompress,
)?; )?;
progress.inc(1); progress.inc(1);
Ok(()) Ok(())
@ -477,17 +489,22 @@ fn get(aes_key: Option<aes::Aes256>, args: ActionGet) -> Result<(), repak::Error
})?; })?;
use std::io::Write; use std::io::Write;
use std::ops::Deref; std::io::stdout().write_all(
#[cfg(not(windows))]
&pak.get(&file.to_slash_lossy(), &mut reader)?,
#[cfg(windows)]
&pak.get_with_oodle(&file.to_slash_lossy(), &mut reader, decompress()?.deref())?,
)?;
Ok(())
}
#[cfg(windows)]
fn decompress<'func>() -> Result<libloading::Symbol<'func, repak::DECOMPRESS>, repak::Error> {
let lib = match OODLE.deref() { let lib = match OODLE.deref() {
Ok(lib) => lib, Ok(lib) => lib,
Err(e) => return Err(repak::Error::Other(e.clone())), Err(e) => return Err(repak::Error::Other(e.clone())),
}; };
std::io::stdout().write_all(&pak.get_with_oodle( Ok(unsafe { lib.get(b"OodleLZ_Decompress") }.unwrap())
&file.to_slash_lossy(),
&mut reader,
&unsafe { lib.get(b"OodleLZ_Decompress") }.unwrap(),
)?)?;
Ok(())
} }
#[cfg(windows)] #[cfg(windows)]