Skip to content

Update upstream CascLib + minor optimizations #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion casclib-bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bindgen = "0.56.0"
bindgen = "0.60"
18 changes: 9 additions & 9 deletions casclib-bindgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ fn main() {
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.whitelist_type("^CASC.+")
.whitelist_function("^Casc.+")
.whitelist_function("SetCascError")
.whitelist_function("GetCascError")
.whitelist_var("^CASC.+")
.whitelist_var("^ERROR_.+")
.whitelist_var("FILE_BEGIN")
.whitelist_var("FILE_CURRENT")
.whitelist_var("FILE_END");
.allowlist_type("^CASC.+")
.allowlist_function("^Casc.+")
.allowlist_function("SetCascError")
.allowlist_function("GetCascError")
.allowlist_var("^CASC.+")
.allowlist_var("^ERROR_.+")
.allowlist_var("FILE_BEGIN")
.allowlist_var("FILE_CURRENT")
.allowlist_var("FILE_END");

let bindings = bindings
// Finish the builder and generate the bindings.
Expand Down
2 changes: 1 addition & 1 deletion casclib-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build = "build.rs"
edition = "2018"

[dependencies]
libc = "0.2.81"
libc = "0.2"

[build-dependencies]
cmake = "0.1"
Expand Down
11 changes: 9 additions & 2 deletions casclib-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate cmake;

use std::env;
use std::{ env, fs };

fn main() {
// Gets CacsLib source path from env CASCLIB_DIR
Expand All @@ -22,7 +22,14 @@ fn main() {
.define("CASC_BUILD_STATIC_LIB", "ON")
.build();

let lib = dst.join("lib");
let mut lib = dst.join("lib");
// on some distributions on 64 bit lib dir is called lib64
if fs::metadata(&lib).is_err() {
lib = dst.join("lib64");
if fs::metadata(&lib).is_err() {
println!("libcasc is missing");
}
}

println!("cargo:rustc-link-search=native={}", lib.display());
println!("cargo:rustc-link-lib=static=casc");
Expand Down
10 changes: 3 additions & 7 deletions casclib-sys/src/bindings_linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub const ERROR_BUFFER_OVERFLOW: u32 = 1008;
pub const ERROR_CANCELLED: u32 = 1009;
pub const ERROR_INDEX_PARSING_DONE: u32 = 1010;
pub const CASCLIB_VERSION: u32 = 512;
pub const CASCLIB_VERSION_STRING: &'static [u8; 4usize] = b"2.0\0";
pub const CASCLIB_VERSION_STRING: &[u8; 4usize] = b"2.0\0";
pub const CASC_OPEN_BY_NAME: u32 = 0;
pub const CASC_OPEN_BY_CKEY: u32 = 1;
pub const CASC_OPEN_BY_EKEY: u32 = 2;
Expand Down Expand Up @@ -536,21 +536,17 @@ fn bindgen_test_layout__CASC_FIND_DATA() {
impl _CASC_FIND_DATA {
#[inline]
pub fn bFileAvailable(&self) -> DWORD {
unsafe { ::std::mem::transmute(self._bitfield_1.get(0usize, 1u8) as u32) }
self._bitfield_1.get(0usize, 1u8) as u32
}
#[inline]
pub fn set_bFileAvailable(&mut self, val: DWORD) {
unsafe {
let val: u32 = ::std::mem::transmute(val);
self._bitfield_1.set(0usize, 1u8, val as u64)
}
self._bitfield_1.set(0usize, 1u8, val as u64)
}
#[inline]
pub fn new_bitfield_1(bFileAvailable: DWORD) -> __BindgenBitfieldUnit<[u8; 1usize], u8> {
let mut __bindgen_bitfield_unit: __BindgenBitfieldUnit<[u8; 1usize], u8> =
Default::default();
__bindgen_bitfield_unit.set(0usize, 1u8, {
let bFileAvailable: u32 = unsafe { ::std::mem::transmute(bFileAvailable) };
bFileAvailable as u64
});
__bindgen_bitfield_unit
Expand Down
2 changes: 1 addition & 1 deletion casclib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ casclib-sys = { path = "../casclib-sys" }
log = "0.4"

[target.'cfg(windows)'.dependencies]
widestring = "0.4"
widestring = "1.0"
18 changes: 9 additions & 9 deletions casclib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl error::Error for CascError {
pub fn open<P: AsRef<Path>>(path: P) -> Result<Storage, CascError> {
#[cfg(not(target_os = "windows"))]
let cpath = {
let pathstr = path.as_ref().to_str().ok_or_else(|| CascError::NonUtf8)?;
let pathstr = path.as_ref().to_str().ok_or(CascError::NonUtf8)?;
CString::new(pathstr).map_err(|_| CascError::InvalidPath)?
};
#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -119,14 +119,14 @@ impl Storage {
self.file_count
}

pub fn files<'a, T>(&'a self) -> Find<'a>
pub fn files<T>(&self) -> Find
where
T: AsRef<[u8]>,
{
self.files_with_mask("*")
}

pub fn files_with_mask<'a, T>(&'a self, mask: T) -> Find<'a>
pub fn files_with_mask<T>(&self, mask: T) -> Find
where
T: AsRef<[u8]>,
{
Expand All @@ -138,7 +138,7 @@ impl Storage {
}
}

pub fn entry<'a, T>(&'a self, name: T) -> FileEntry<'a>
pub fn entry<T>(&self, name: T) -> FileEntry
where
T: Into<String>,
{
Expand Down Expand Up @@ -193,7 +193,7 @@ impl<'a> FindIterator<'a> {
&mut self.data as *mut casclib::CASC_FIND_DATA,
ptr::null(),
);
if handle == ptr::null_mut() {
if handle.is_null() {
let code = casclib::GetCascError();
if code == casclib::ERROR_NO_MORE_FILES {
return None;
Expand All @@ -219,7 +219,7 @@ impl<'a> FindIterator<'a> {
impl<'a> Iterator for FindIterator<'a> {
type Item = Result<FileEntry<'a>, CascError>;

fn next<'b>(&'b mut self) -> Option<Self::Item> {
fn next(&mut self) -> Option<Self::Item> {
match self.handle {
None => self.find_first(),
Some(handle) => unsafe {
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<'a> File<'a> {
let pos = casclib::CascSetFilePointer(
self.handle,
0,
0 as *mut casclib::LONG,
std::ptr::null_mut::<casclib::LONG>(),
casclib::FILE_BEGIN as casclib::DWORD,
);
if pos == casclib::CASC_INVALID_POS {
Expand All @@ -351,8 +351,8 @@ impl<'a> File<'a> {
let end_pos = bytes_read as usize;
if bytes_read != 0 {
w.write_all(&buffer[0..end_pos])
.map_err(|e| CascError::Io(e))?;
bytes_write_total = bytes_write_total + end_pos;
.map_err(CascError::Io)?;
bytes_write_total += end_pos;
}
}
match casclib::GetCascError() {
Expand Down
2 changes: 1 addition & 1 deletion deps/CascLib
Submodule CascLib updated 61 files
+1 −0 .gitignore
+97 −70 CMakeLists.txt
+24 −0 CascLib_vs08.vcproj
+28 −4 CascLib_vs08_dll.vcproj
+36 −0 CascLib_vs08_test.vcproj
+7 −1 CascLib_vs19.vcxproj
+18 −0 CascLib_vs19.vcxproj.filters
+7 −1 CascLib_vs19_dll.vcxproj
+18 −0 CascLib_vs19_dll.vcxproj.filters
+41 −1 CascLib_vs19_test.vcxproj
+18 −0 CascLib_vs19_test.vcxproj.filters
+11 −0 Config.cmake.in
+10 −0 README.md
+6 −0 debian/README
+5 −0 debian/changelog
+24 −0 debian/control
+44 −0 debian/copyright
+2 −0 debian/libcasc-dev.dirs
+3 −0 debian/libcasc-dev.install
+2 −0 debian/libcasc-dev.substvars
+3 −0 debian/libcasc-docs.docs
+1 −0 debian/libcasc1.dirs
+1 −0 debian/libcasc1.install
+3 −0 debian/libcasc1.substvars
+28 −0 debian/rules
+336 −0 doc/casclib-test-005.txt
+0 −6 doc/history.txt
+0 −1 sources
+8 −3 sources-c.c
+2 −0 sources-cpp.cpp
+9 −7 src/CascCommon.h
+6 −0 src/CascDumpData.cpp
+228 −124 src/CascFiles.cpp
+5 −1 src/CascIndexFiles.cpp
+28 −18 src/CascLib.h
+177 −105 src/CascOpenStorage.cpp
+44 −27 src/CascPort.h
+1 −1 src/CascReadFile.cpp
+1 −1 src/CascRootFile_WoW.cpp
+6 −2 src/DllMain.def
+7 −11 src/DllMain.rc
+9 −19 src/common/Common.cpp
+13 −4 src/common/Common.h
+28 −10 src/common/Csv.cpp
+22 −0 src/common/Csv.h
+7 −11 src/common/Directory.cpp
+211 −216 src/common/FileStream.cpp
+10 −9 src/common/FileStream.h
+1 −1 src/common/FileTree.cpp
+677 −0 src/common/Mime.cpp
+130 −0 src/common/Mime.h
+2 −2 src/common/Path.h
+441 −0 src/common/Sockets.cpp
+115 −0 src/common/Sockets.h
+15 −0 src/resource.h
+2,163 −0 src/zlib/deflate.c
+349 −0 src/zlib/deflate.h
+1,203 −0 src/zlib/trees.c
+128 −0 src/zlib/trees.h
+192 −138 test/CascTest.cpp
+7 −7 test/TLogHelper.cpp