the other bit of Shadow .one writing

This commit is contained in:
lifning 2021-01-17 03:54:14 -08:00
parent 5ac56fb114
commit d8a0ecf273
1 changed files with 17 additions and 6 deletions

View File

@ -26,7 +26,8 @@ const MAGIC_60: &'static str = "One Ver 0.60";
const SIZE_OF_MAGIC: usize = 16;
const SIZE_OF_COMMENT: usize = 0x90;
const SIZE_OF_PRE_HEADER: u32 = (3 * size_of::<u32>()) as u32;
const SIZE_OF_HEADER: u32 = SIZE_OF_PRE_HEADER + (size_of::<u32>() + SIZE_OF_MAGIC + SIZE_OF_COMMENT) as u32;
const SIZE_OF_HEADER: u32 =
SIZE_OF_PRE_HEADER + (size_of::<u32>() + SIZE_OF_MAGIC + SIZE_OF_COMMENT) as u32;
const SIZE_OF_FILENAME: usize = 0x2c;
const SIZE_OF_ENTRY: u32 = (3 * size_of::<u32>() + SIZE_OF_FILENAME) as u32;
@ -58,7 +59,7 @@ pub struct ShadOne {
/// 0. presumably where data starts, not counting the "pre-header" of these first three u32's
start: u32,
/// the size of the archive, not counting the "pre-header" of these first three u32's
archive_size_minus_twelve: u32,
archive_size_minus_12: u32,
/// presumably the archiver version. known values: 0x1c020037 and 0x1c020020 from GCN version
pub version: u32,
#[br(pad_size_to = self::SIZE_OF_MAGIC, map = string_binread_helper)]
@ -69,7 +70,7 @@ pub struct ShadOne {
#[br(pad_size_to = self::SIZE_OF_COMMENT, map = string_binread_helper)]
#[binwrite(preprocessor(string_binwrite_helper(self::SIZE_OF_COMMENT)))]
pub comment: String,
#[br(count = count, args(count, archive_size_minus_twelve))]
#[br(count = count, args(count, archive_size_minus_12))]
pub entries: Vec<ShadOneEntry>,
}
@ -124,8 +125,18 @@ impl std::fmt::Debug for ShadOneEntry {
impl OneArchiveEntry for ShadOneEntry {}
impl OneArchive for ShadOne {
fn write(&self, mut _writer: &mut dyn WriteSeek) -> std::io::Result<()> {
todo!()
fn write(&self, mut writer: &mut dyn WriteSeek) -> std::io::Result<()> {
BinWrite::write(&self, &mut writer)?;
for entry in &self.entries {
let loc = writer.seek(std::io::SeekFrom::Current(0)).unwrap() as usize;
let padding = vec![0; entry.data.ptr as usize - loc];
writer.write(&padding)?;
writer.write(entry.data.value.as_ref().unwrap())?;
}
let loc = writer.seek(std::io::SeekFrom::Current(0)).unwrap() as usize;
let padding = vec![0; (self.archive_size_minus_12 + SIZE_OF_PRE_HEADER) as usize - loc];
writer.write(&padding)?;
Ok(())
}
fn pack(contents: impl IntoIterator<Item = (PathBuf, Vec<u8>)>) -> Self
@ -172,7 +183,7 @@ impl OneArchive for ShadOne {
// user can overwrite string/version fields afterward
ShadOne {
start: 0,
archive_size_minus_twelve: loc - SIZE_OF_PRE_HEADER,
archive_size_minus_12: loc - SIZE_OF_PRE_HEADER,
version: 0x1c020037,
magic: MAGIC_60.to_string(),
count: entries.len() as u32,