Compare commits
3 Commits
0bf9129986
...
33caf0802c
Author | SHA1 | Date |
---|---|---|
Anna | 33caf0802c | |
Anna | 17a1afac16 | |
Anna | f2a2373d58 |
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ttmp"
|
name = "ttmp"
|
||||||
version = "6.0.0"
|
version = "6.0.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
autoexamples = true
|
autoexamples = true
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ zip = { version = "0.6", default-features = false, features = ["deflate-zlib"],
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
blake3 = { version = "1", features = ["traits-preview"] }
|
blake3 = { version = "1", features = ["traits-preview"] }
|
||||||
criterion = "0.4"
|
criterion = "0.5"
|
||||||
data-encoding = "2"
|
data-encoding = "2"
|
||||||
sha3 = "0.10"
|
sha3 = "0.10"
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
|
@ -71,16 +71,18 @@ impl<R: Read + Seek> TtmpExtractor<R> {
|
||||||
let expected = file.mod_size;
|
let expected = file.mod_size;
|
||||||
|
|
||||||
let info: SqPackFileInfoHeader = read_struct(&mut data_file, &mut buf)?;
|
let info: SqPackFileInfoHeader = read_struct(&mut data_file, &mut buf)?;
|
||||||
|
let limit = expected - std::mem::size_of::<SqPackFileInfoHeader>();
|
||||||
|
let limited = (&mut data_file).take(limit as u64);
|
||||||
match info.kind {
|
match info.kind {
|
||||||
FileKind::Empty => todo!(),
|
FileKind::Empty => todo!(),
|
||||||
FileKind::Standard => {
|
FileKind::Standard => {
|
||||||
Self::extract_standard_file(&info, &mut data_file, &mut writer, &mut buf)?;
|
Self::extract_standard_file(&info, limited, &mut writer, &mut buf)?;
|
||||||
}
|
}
|
||||||
FileKind::Model => {
|
FileKind::Model => {
|
||||||
Self::extract_model_file(&info, &mut data_file, &mut writer, &mut buf)?;
|
Self::extract_model_file(&info, limited, &mut writer, &mut buf)?;
|
||||||
}
|
}
|
||||||
FileKind::Texture => {
|
FileKind::Texture => {
|
||||||
Self::extract_texture_file(&info, &mut data_file, &mut writer, &mut buf)?;
|
Self::extract_texture_file(&info, limited, &mut writer, &mut buf)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,19 +145,22 @@ impl<R: Read> TtmpExtractor<R> {
|
||||||
let expected = file.mod_size;
|
let expected = file.mod_size;
|
||||||
|
|
||||||
let info: SqPackFileInfoHeader = read_struct(&mut reader, &mut buf)?;
|
let info: SqPackFileInfoHeader = read_struct(&mut reader, &mut buf)?;
|
||||||
|
let limit = expected - std::mem::size_of::<SqPackFileInfoHeader>();
|
||||||
|
let limited = (&mut reader).take(limit as u64);
|
||||||
match info.kind {
|
match info.kind {
|
||||||
FileKind::Empty => todo!(),
|
FileKind::Empty => todo!(),
|
||||||
FileKind::Standard => {
|
FileKind::Standard => {
|
||||||
Self::extract_standard_file(&info, &mut reader, &mut writer, &mut buf)?;
|
Self::extract_standard_file(&info, limited, &mut writer, &mut buf)?;
|
||||||
}
|
}
|
||||||
FileKind::Model => {
|
FileKind::Model => {
|
||||||
Self::extract_model_file(&info, &mut reader, &mut writer, &mut buf)?;
|
Self::extract_model_file(&info, limited, &mut writer, &mut buf)?;
|
||||||
}
|
}
|
||||||
FileKind::Texture => {
|
FileKind::Texture => {
|
||||||
Self::extract_texture_file(&info, &mut reader, &mut writer, &mut buf)?;
|
Self::extract_texture_file(&info, limited, &mut writer, &mut buf)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debug_assert!(reader.read <= expected);
|
||||||
if reader.read < expected {
|
if reader.read < expected {
|
||||||
let to_skip = expected - reader.read;
|
let to_skip = expected - reader.read;
|
||||||
Self::skip(&mut reader, &mut buf, to_skip)?;
|
Self::skip(&mut reader, &mut buf, to_skip)?;
|
||||||
|
@ -433,7 +438,12 @@ impl<R: Read> TtmpExtractor<R> {
|
||||||
let mut left = amt;
|
let mut left = amt;
|
||||||
while left > 0 {
|
while left > 0 {
|
||||||
let to_read = std::cmp::min(left, buf.len());
|
let to_read = std::cmp::min(left, buf.len());
|
||||||
left -= reader.read(&mut buf[..to_read]).map_err(Error::Io)?;
|
let amt_read = reader.read(&mut buf[..to_read]).map_err(Error::Io)?;
|
||||||
|
if amt_read == 0 {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
left -= amt_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue