diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 0000000..59c989e --- /dev/null +++ b/.cargo/config @@ -0,0 +1,11 @@ +[target.x86_64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] + +[target.aarch64-apple-darwin] +rustflags = [ + "-C", "link-arg=-undefined", + "-C", "link-arg=dynamic_lookup", +] \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1adece0..b1f802a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -2,26 +2,27 @@ name: Rust on: push: - branches: [ "main" ] pull_request: - branches: [ "main" ] env: CARGO_TERM_COLOR: always jobs: check: - runs-on: windows-latest + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + build_type: [Release] + steps: - name: checkout uses: actions/checkout@v3 with: submodules: 'true' - - name: unzip resources - run: | - cd src - Expand-Archive -Path .\metadata-resources.zip -DestinationPath .\ - uses: actions-rs/toolchain@v1 with: @@ -29,9 +30,5 @@ jobs: toolchain: stable override: true - - uses: actions-rs/cargo@v1 - with: - command: build - - uses: actions-rs/cargo@v1 - with: - command: test + - run: cargo build + - run: cargo test diff --git a/src/archive.rs b/src/archive.rs index 5705753..ef23a21 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -312,8 +312,8 @@ impl FromReader for LxrsFooter { // buffer is compressed let mut compressed_buffer = vec![0; zsize as usize]; reader.read_exact(&mut compressed_buffer[..])?; - let mut output_buffer = vec![0; size as usize]; - let result = decompress(compressed_buffer, &mut output_buffer); + let mut output_buffer = vec![]; + let result = decompress(compressed_buffer, &mut output_buffer, size as usize); assert_eq!(result as u32, size); // read from buffer @@ -378,8 +378,8 @@ fn decompress_segment( } let mut compressed_buffer = vec![0; segment.z_size as usize - 8]; archive_reader.read_exact(&mut compressed_buffer[..])?; - let mut output_buffer = vec![0; size as usize]; - let result = decompress(compressed_buffer, &mut output_buffer); + let mut output_buffer = vec![]; + let result = decompress(compressed_buffer, &mut output_buffer, size as usize); assert_eq!(result as u32, size); // write diff --git a/src/kraken.rs b/src/kraken.rs index 42ea751..da4b757 100644 --- a/src/kraken.rs +++ b/src/kraken.rs @@ -33,15 +33,23 @@ pub enum CompressionLevel { } /// Decompresses a compressed buffer into another -pub fn decompress(compressed_buffer: Vec, output_buffer: &mut Vec) -> i32 { +pub fn decompress(compressed_buffer: Vec, output_buffer: &mut Vec, size: usize) -> i32 { + let mut buffer = vec![0; size * 2]; + let result; + unsafe { - Kraken_Decompress( + result = Kraken_Decompress( compressed_buffer.as_ptr(), compressed_buffer.len() as i64, - output_buffer.as_mut_ptr(), - output_buffer.len() as i64, - ) + buffer.as_mut_ptr(), + size as i64, + ); + + buffer.resize(result as usize, 0); + *output_buffer = buffer; } + + result } /// Compresses a buffer into another diff --git a/tests/functional_tests.rs b/tests/functional_tests.rs index 541e070..d08e81c 100644 --- a/tests/functional_tests.rs +++ b/tests/functional_tests.rs @@ -5,16 +5,14 @@ #[cfg(test)] mod tests { use std::fs::create_dir_all; + use std::io::{self, Read}; use std::path::Path; use std::time::Instant; use std::{fs, path::PathBuf}; - use red4lib::archive::write_archive; - use red4lib::sha1_hash_file; - use red4lib::{ - archive::{extract_archive, Archive}, - get_red4_hashes, - }; + use red4lib::archive::*; + use red4lib::io::FromReader; + use red4lib::*; #[test] fn time_csv() { @@ -26,6 +24,18 @@ mod tests { println!("Execution time csv: {:?}", duration); } + #[test] + fn read_srxl() { + let file_path = PathBuf::from("tests").join("srxl.bin"); + let mut file = fs::File::open(file_path).expect("Could not open file"); + let mut buffer: Vec = vec![]; + file.read_to_end(&mut buffer).expect("Could not read file"); + + let mut cursor = io::Cursor::new(&buffer); + + let _srxl = LxrsFooter::from_reader(&mut cursor).unwrap(); + } + #[test] fn read_archive() { let archive_path = PathBuf::from("tests").join("test1.archive"); @@ -71,8 +81,12 @@ mod tests { assert!(result.is_ok()); // check - let expected_files = get_files_in_folder_recursive(&data_path); - let expected = expected_files + let binding = get_files_in_folder_recursive(&data_path); + let mut expected_files = binding + .iter() + .filter(|f| !f.ends_with(".DS_Store")) + .collect::>(); + let mut expected = expected_files .iter() .map(|f| { // Convert the absolute path to a relative path @@ -83,10 +97,15 @@ mod tests { } }) .map(|f| f.to_string_lossy().to_ascii_lowercase()) + .map(|f| f.replace('\\', "/")) .collect::>(); - let found_files = get_files_in_folder_recursive(&dst_path); - let found = found_files + let binding = get_files_in_folder_recursive(&dst_path); + let mut found_files = binding + .iter() + .filter(|f| !f.ends_with(".DS_Store")) + .collect::>(); + let mut found = found_files .iter() .map(|f| { // Convert the absolute path to a relative path @@ -97,14 +116,20 @@ mod tests { } }) .map(|f| f.to_string_lossy().to_ascii_lowercase()) + .map(|f| f.replace('\\', "/")) .collect::>(); + expected.sort(); + found.sort(); + expected_files.sort(); + found_files.sort(); + assert_eq!(expected.len(), found.len()); assert_eq!(expected, found); for (i, e) in expected_files.into_iter().enumerate() { let f = found_files.get(i).unwrap(); - assert_binary_equality(&e, f); + assert_binary_equality(e, f); } // cleanup diff --git a/tests/srxl.bin b/tests/srxl.bin new file mode 100644 index 0000000..c1c1f86 Binary files /dev/null and b/tests/srxl.bin differ