feat: Implement new bundle format
This commit is contained in:
parent
aa9277c394
commit
1c27224221
2 changed files with 31 additions and 19 deletions
|
@ -325,6 +325,7 @@ impl From<BundleFileType> for Murmur64 {
|
||||||
struct BundleFileHeader {
|
struct BundleFileHeader {
|
||||||
variant: u32,
|
variant: u32,
|
||||||
size: usize,
|
size: usize,
|
||||||
|
len_data_file_name: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BundleFileHeader {
|
impl BundleFileHeader {
|
||||||
|
@ -335,26 +336,22 @@ impl BundleFileHeader {
|
||||||
{
|
{
|
||||||
let variant = read_u32(r).await?;
|
let variant = read_u32(r).await?;
|
||||||
skip_u8(r, 0).await?;
|
skip_u8(r, 0).await?;
|
||||||
let size_1 = read_u32(r).await? as usize;
|
let size = read_u32(r).await? as usize;
|
||||||
skip_u8(r, 1).await?;
|
skip_u8(r, 1).await?;
|
||||||
let size_2 = read_u32(r).await? as usize;
|
let len_data_file_name = read_u32(r).await? as usize;
|
||||||
|
|
||||||
tracing::debug!(size_1, size_2);
|
Ok(Self {
|
||||||
|
size,
|
||||||
// NOTE: Very weird. There must be something affecting this.
|
variant,
|
||||||
let size = if size_2 == 30 {
|
len_data_file_name,
|
||||||
size_1 + size_2
|
})
|
||||||
} else {
|
|
||||||
size_1
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self { size, variant })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct BundleFileVariant {
|
pub struct BundleFileVariant {
|
||||||
header: BundleFileHeader,
|
header: BundleFileHeader,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
|
data_file_name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BundleFileVariant {
|
impl BundleFileVariant {
|
||||||
|
@ -410,7 +407,18 @@ impl BundleFile {
|
||||||
let mut data = vec![0; header.size];
|
let mut data = vec![0; header.size];
|
||||||
r.read_exact(&mut data).await?;
|
r.read_exact(&mut data).await?;
|
||||||
|
|
||||||
let variant = BundleFileVariant { header, data };
|
let data_file_name = {
|
||||||
|
let mut buf = vec![0; header.len_data_file_name];
|
||||||
|
r.read_exact(&mut buf).await?;
|
||||||
|
|
||||||
|
String::from_utf8(buf)?
|
||||||
|
};
|
||||||
|
|
||||||
|
let variant = BundleFileVariant {
|
||||||
|
header,
|
||||||
|
data,
|
||||||
|
data_file_name,
|
||||||
|
};
|
||||||
|
|
||||||
variants.push(variant);
|
variants.push(variant);
|
||||||
}
|
}
|
||||||
|
@ -446,11 +454,12 @@ impl BundleFile {
|
||||||
write_u8(w, 1).await?;
|
write_u8(w, 1).await?;
|
||||||
// TODO: The previous size value and this one are somehow connected,
|
// TODO: The previous size value and this one are somehow connected,
|
||||||
// but so far it is unknown how
|
// but so far it is unknown how
|
||||||
write_u32(w, 0).await?;
|
write_u32(w, variant.data_file_name.len() as u32).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for variant in self.variants.iter() {
|
for variant in self.variants.iter() {
|
||||||
w.write_all(&variant.data).await?;
|
w.write_all(&variant.data).await?;
|
||||||
|
w.write_all(variant.data_file_name.as_bytes()).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -22,7 +22,8 @@ pub use file::BundleFile;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
enum BundleFormat {
|
enum BundleFormat {
|
||||||
Darktide,
|
F7,
|
||||||
|
F8,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for BundleFormat {
|
impl TryFrom<u32> for BundleFormat {
|
||||||
|
@ -30,7 +31,8 @@ impl TryFrom<u32> for BundleFormat {
|
||||||
|
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
||||||
match value {
|
match value {
|
||||||
0xF0000007 => Ok(Self::Darktide),
|
0xF0000007 => Ok(Self::F7),
|
||||||
|
0xF0000008 => Ok(Self::F8),
|
||||||
_ => Err(eyre::eyre!("Unknown bundle format '{:08X}'", value)),
|
_ => Err(eyre::eyre!("Unknown bundle format '{:08X}'", value)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +41,8 @@ impl TryFrom<u32> for BundleFormat {
|
||||||
impl From<BundleFormat> for u32 {
|
impl From<BundleFormat> for u32 {
|
||||||
fn from(value: BundleFormat) -> Self {
|
fn from(value: BundleFormat) -> Self {
|
||||||
match value {
|
match value {
|
||||||
BundleFormat::Darktide => 0xF0000007,
|
BundleFormat::F7 => 0xF0000007,
|
||||||
|
BundleFormat::F8 => 0xF0000008,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,7 +138,7 @@ impl Bundle {
|
||||||
.wrap_err("failed to read from file")
|
.wrap_err("failed to read from file")
|
||||||
.and_then(BundleFormat::try_from)?;
|
.and_then(BundleFormat::try_from)?;
|
||||||
|
|
||||||
if format != BundleFormat::Darktide {
|
if !matches!(format, BundleFormat::F7 | BundleFormat::F8) {
|
||||||
return Err(eyre::eyre!("Unknown bundle format: {:?}", format));
|
return Err(eyre::eyre!("Unknown bundle format: {:?}", format));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +352,7 @@ where
|
||||||
{
|
{
|
||||||
let format = read_u32(&mut r).await.and_then(BundleFormat::try_from)?;
|
let format = read_u32(&mut r).await.and_then(BundleFormat::try_from)?;
|
||||||
|
|
||||||
if format != BundleFormat::Darktide {
|
if !matches!(format, BundleFormat::F7 | BundleFormat::F8) {
|
||||||
eyre::bail!("Unknown bundle format: {:?}", format);
|
eyre::bail!("Unknown bundle format: {:?}", format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue