Skip to content

Commit

Permalink
fix: add files limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dulingzhi committed Mar 25, 2024
1 parent f8a205a commit 965750d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions crates/stormlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ impl Archive {
unsafe_try_call!(SFileCompactArchive(self.handle, ptr::null_mut(), false));
Ok(())
}

pub fn get_max_files(&mut self) -> Result<u32> {
unsafe {
let count = SFileGetMaxFileCount(self.handle);
Ok(count)
}
}

pub fn set_max_files(&mut self, count: u32) -> Result<()> {
unsafe_try_call!(SFileSetMaxFileCount(self.handle, count));
Ok(())
}
}

impl std::ops::Drop for Archive {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ fn extract(mpq: &str, file: &str, output: &str) -> Result<bool, Error> {

fn pack(mpq: &str, files: &FileList) -> Result<bool, Error> {
let mut ar = stormlib::Archive::open(mpq, OpenArchiveFlags::MPQ_OPEN_NO_FLAG)?;
let count = ar.get_max_files().unwrap();
ar.set_max_files(count + (files.len() as u32));
for f in files {
ar.add_file(f.name.as_str(), f.path.as_str())?;
}
Expand Down

0 comments on commit 965750d

Please sign in to comment.