return mutable self

This commit is contained in:
spuds 2023-09-20 20:28:41 +01:00
parent 6805b5c142
commit a15e3fe372
No known key found for this signature in database
GPG key ID: 0B6CA6068E827C8F
2 changed files with 10 additions and 8 deletions

View file

@ -16,12 +16,14 @@ impl PakBuilder {
} }
} }
#[cfg(feature = "encryption")] #[cfg(feature = "encryption")]
pub fn key(&mut self, key: aes::Aes256) { pub fn key(&mut self, key: aes::Aes256) -> &mut Self {
self.key = super::Key::Some(key) self.key = super::Key::Some(key);
self
} }
#[cfg(feature = "oodle")] #[cfg(feature = "oodle")]
pub fn oodle(&mut self, oodle: fn() -> super::Decompress) { pub fn oodle(&mut self, oodle: fn() -> super::Decompress) -> &mut Self {
unsafe { super::OODLE = Some(once_cell::sync::Lazy::new(oodle)) } unsafe { super::OODLE = Some(once_cell::sync::Lazy::new(oodle)) }
self
} }
pub fn reader<R: Read + Seek>(self, reader: &mut R) -> Result<PakReader, super::Error> { pub fn reader<R: Read + Seek>(self, reader: &mut R) -> Result<PakReader, super::Error> {
PakReader::new_any_inner(reader, self.key) PakReader::new_any_inner(reader, self.key)

View file

@ -177,7 +177,7 @@ fn main() -> Result<(), repak::Error> {
fn info(aes_key: Option<aes::Aes256>, action: ActionInfo) -> Result<(), repak::Error> { fn info(aes_key: Option<aes::Aes256>, action: ActionInfo) -> Result<(), repak::Error> {
let mut builder = repak::PakBuilder::new(); let mut builder = repak::PakBuilder::new();
if let Some(aes_key) = aes_key { if let Some(aes_key) = aes_key {
builder.key(aes_key) builder.key(aes_key);
} }
let pak = builder.reader(&mut BufReader::new(File::open(action.input)?))?; let pak = builder.reader(&mut BufReader::new(File::open(action.input)?))?;
println!("mount point: {}", pak.mount_point()); println!("mount point: {}", pak.mount_point());
@ -192,7 +192,7 @@ fn info(aes_key: Option<aes::Aes256>, action: ActionInfo) -> Result<(), repak::E
fn list(aes_key: Option<aes::Aes256>, action: ActionList) -> Result<(), repak::Error> { fn list(aes_key: Option<aes::Aes256>, action: ActionList) -> Result<(), repak::Error> {
let mut builder = repak::PakBuilder::new(); let mut builder = repak::PakBuilder::new();
if let Some(aes_key) = aes_key { if let Some(aes_key) = aes_key {
builder.key(aes_key) builder.key(aes_key);
} }
let pak = builder.reader(&mut BufReader::new(File::open(action.input)?))?; let pak = builder.reader(&mut BufReader::new(File::open(action.input)?))?;
@ -225,7 +225,7 @@ fn list(aes_key: Option<aes::Aes256>, action: ActionList) -> Result<(), repak::E
fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(), repak::Error> { fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(), repak::Error> {
let mut builder = repak::PakBuilder::new(); let mut builder = repak::PakBuilder::new();
if let Some(aes_key) = aes_key { if let Some(aes_key) = aes_key {
builder.key(aes_key) builder.key(aes_key);
} }
let pak = builder.reader(&mut BufReader::new(File::open(&action.input)?))?; let pak = builder.reader(&mut BufReader::new(File::open(&action.input)?))?;
@ -286,7 +286,7 @@ fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repa
#[cfg(windows)] #[cfg(windows)]
builder.oodle(get_oodle::decompress); builder.oodle(get_oodle::decompress);
if let Some(aes_key) = aes_key.clone() { if let Some(aes_key) = aes_key.clone() {
builder.key(aes_key) builder.key(aes_key);
} }
let pak = builder.reader(&mut BufReader::new(File::open(input)?))?; let pak = builder.reader(&mut BufReader::new(File::open(input)?))?;
let output = action let output = action
@ -459,7 +459,7 @@ fn get(aes_key: Option<aes::Aes256>, args: ActionGet) -> Result<(), repak::Error
#[cfg(windows)] #[cfg(windows)]
builder.oodle(get_oodle::decompress); builder.oodle(get_oodle::decompress);
if let Some(aes_key) = aes_key { if let Some(aes_key) = aes_key {
builder.key(aes_key) builder.key(aes_key);
} }
let pak = builder.reader(&mut reader)?; let pak = builder.reader(&mut reader)?;
let mount_point = PathBuf::from(pak.mount_point()); let mount_point = PathBuf::from(pak.mount_point());