Compare commits

...

3 Commits

3 changed files with 19 additions and 15 deletions

View File

@ -1,22 +1,23 @@
[package]
name = "ttmp"
version = "5.0.0"
version = "5.1.0"
edition = "2021"
autoexamples = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
flate2 = "1"
blake3 = { version = "1", features = ["traits-preview"] }
flate2 = { version = "1", default-features = false, features = ["zlib-ng"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sha3 = "0.10"
sqpack = { git = "https://git.anna.lgbt/ascclemens/sqpack-rs", features = ["read", "write"] }
tempfile = "3"
thiserror = "1"
zip = { version = "0.6", default-features = false, features = ["deflate"] }
[dev-dependencies]
blake3 = { version = "1", features = ["traits-preview"] }
criterion = "0.4"
data-encoding = "2"
sha3 = "0.10"
@ -25,3 +26,7 @@ tempfile = "3"
[[bench]]
name = "extract"
harness = false
[profile.release]
debug = 1
lto = true

View File

@ -3,12 +3,13 @@ use std::fs::File;
use std::io::{Seek, SeekFrom};
use std::path::Path;
use sha3::{Digest, Sha3_256};
use blake3::Hasher as Blake3;
use blake3::traits::digest::Digest;
use ttmp::ttmp_extractor::TtmpExtractor;
pub fn main() {
let mut sha = Sha3_256::default();
let mut blake = Blake3::new();
let arg = std::env::args().skip(1).next().unwrap();
let file = File::open(&arg).unwrap();
let extractor = TtmpExtractor::new(file).unwrap();
@ -29,7 +30,6 @@ pub fn main() {
for file in files {
// handle deduped ttmps
if Some(file.file.mod_offset) == last_offset {
println!("already seen offset {}", file.file.mod_offset);
continue;
}
@ -38,7 +38,6 @@ pub fn main() {
temp.set_len(0).unwrap();
temp.seek(SeekFrom::Start(0)).unwrap();
println!("{:#?}", file);
// write each file into a temp file, then hash
// mod files can get quite large, so storing them entirely in memory is probably a bad idea
// let mut cursor = Cursor::new(Vec::with_capacity(file.file.mod_size));
@ -52,9 +51,9 @@ pub fn main() {
// let data = cursor.into_inner();
// sha.update(&data);
temp.seek(SeekFrom::Start(0)).unwrap();
std::io::copy(&mut temp, &mut sha).unwrap();
std::io::copy(&mut temp, &mut blake).unwrap();
temp.seek(SeekFrom::Start(0)).unwrap();
let hash = sha.finalize_reset();
let hash = blake.finalize_reset();
let hash = data_encoding::BASE64URL_NOPAD.encode(&*hash);
let new = !hashes.contains_key(&hash);
let saved = SavedFile {
@ -66,12 +65,11 @@ pub fn main() {
if new {
let path = Path::new("files").join(&hash);
println!("writing {}", path.to_string_lossy());
std::io::copy(&mut temp, &mut File::create(&path).unwrap()).unwrap();
}
}
println!("{:#?}", hashes);
println!("done");
}
#[derive(Debug)]

View File

@ -2,9 +2,10 @@ use std::collections::{HashMap, HashSet};
use std::fs::File;
use std::io::{BufWriter, Read, Seek, SeekFrom, Write};
use blake3::Hasher as Blake3;
use blake3::traits::digest::Digest;
use flate2::Compression;
use flate2::write::DeflateEncoder;
use sha3::{Digest, Sha3_384};
use sqpack::{DatBlockHeader, DatStdFileBlockInfos, FileKind, LodBlock, ModelBlock, SqPackFileInfo, SqPackFileInfoHeader};
use sqpack::binrw::{self, BinWriterExt};
@ -134,7 +135,7 @@ impl MpdEncoder {
const HEADER_SIZE: usize = std::mem::size_of::<RawTextureHeader>();
let mut buf = [0; Self::BLOCK_SIZE];
let mut hasher = Sha3_384::default();
let mut hasher = Blake3::default();
// read the texture file's header
let header: RawTextureHeader = read_struct(&mut data, &mut buf)?;
@ -297,7 +298,7 @@ impl MpdEncoder {
}
let mut buf = [0; Self::BLOCK_SIZE];
let mut hasher = Sha3_384::default();
let mut hasher = Blake3::default();
// read the model file's header
let header: RawModelHeader = read_struct(&mut data, &mut buf)?;
@ -510,7 +511,7 @@ impl MpdEncoder {
let after_header = self.writer.stream_position().map_err(Error::Io)?;
// write the data
let mut hasher = Sha3_384::default();
let mut hasher = Blake3::default();
let infos = self.write_blocks(data, &mut hasher)?;
let hash = hasher.finalize();