From 862b16b681e8593f2b327442deddc12922209531 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Mon, 30 Jun 2025 21:29:23 -0400 Subject: [PATCH] Fix reading subrow ids again, add helpers to get subrow --- src/exd.rs | 21 +++++++++++++++++++++ src/exd_file_operations.rs | 15 ++++++++------- src/exh.rs | 2 +- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/exd.rs b/src/exd.rs index 60a1412..8f90a6d 100644 --- a/src/exd.rs +++ b/src/exd.rs @@ -237,6 +237,27 @@ impl EXD { None } + /// Finds the entry with the specified ID, otherwise returns `None`. + pub fn get_subrow(&self, row_id: u32, subrow_id: u16) -> Option { + for row in &self.rows { + if row.row_id == row_id { + match &row.kind { + ExcelRowKind::SingleRow(_) => {} + ExcelRowKind::SubRows(subrows) => { + dbg!(subrows); + if let Some(subrow) = + subrows.iter().filter(|(id, _)| *id == subrow_id).next() + { + return Some(subrow.1.clone()); + } + } + } + } + } + + None + } + /// Calculate the filename of an EXD from the `name`, `language`, and `page`. pub fn calculate_filename( name: &str, diff --git a/src/exd_file_operations.rs b/src/exd_file_operations.rs index e3bab7c..c3dda9e 100644 --- a/src/exd_file_operations.rs +++ b/src/exd_file_operations.rs @@ -36,14 +36,14 @@ pub fn read_data_sections(header: &EXDHeader) -> BinResult> { Ok(rows) } -fn read_row(reader: &mut T, exh: &EXH, row_offset: u32) -> Option { +fn read_row(reader: &mut T, exh: &EXH, row_offset: u64) -> Option { let mut subrow = ExcelSingleRow { columns: Vec::with_capacity(exh.column_definitions.len()), }; for column in &exh.column_definitions { reader - .seek(SeekFrom::Start((row_offset + column.offset as u32).into())) + .seek(SeekFrom::Start((row_offset + column.offset as u64).into())) .ok()?; subrow @@ -63,17 +63,18 @@ pub fn parse_rows(exh: &EXH, data_offsets: &Vec) -> BinResult 1 { let mut rows = Vec::new(); for i in 0..row_header.row_count { - let subrow_offset = data_offset + (i * exh.header.data_offset + 2 * (i + 1)) as u32; + let subrow_offset = data_offset + i as u64 * (2 + exh.header.row_size as u64); + reader.seek(SeekFrom::Start(subrow_offset))?; let subrow_header = SubRowHeader::read(reader)?; rows.push(( subrow_header.subrow_id, - read_row(reader, &exh, subrow_offset).unwrap(), + read_row(reader, &exh, subrow_offset + 2).unwrap(), )); } ExcelRowKind::SubRows(rows) @@ -256,7 +257,7 @@ impl EXD { pub(crate) fn read_column( cursor: &mut T, exh: &EXH, - row_offset: u32, + row_offset: u64, column: &ExcelColumnDefinition, ) -> Option { let mut read_packed_bool = |shift: i32| -> bool { @@ -272,7 +273,7 @@ impl EXD { cursor .seek(SeekFrom::Start( - (row_offset + exh.header.data_offset as u32 + string_offset).into(), + (row_offset + exh.header.row_size as u64 + string_offset as u64).into(), )) .ok()?; diff --git a/src/exh.rs b/src/exh.rs index 4c7c2b0..1dd34a6 100644 --- a/src/exh.rs +++ b/src/exh.rs @@ -22,7 +22,7 @@ use crate::common::Language; pub struct EXHHeader { pub(crate) version: u16, - pub data_offset: u16, // TODO: might not be an offset + pub row_size: u16, pub(crate) column_count: u16, pub(crate) page_count: u16, pub(crate) language_count: u16,