1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-07-20 07:47:45 +00:00

Fix reading subrow ids again, add helpers to get subrow

This commit is contained in:
Joshua Goins 2025-06-30 21:29:23 -04:00
parent 6ebb7acfcd
commit 862b16b681
3 changed files with 30 additions and 8 deletions

View file

@ -237,6 +237,27 @@ impl EXD {
None None
} }
/// Finds the entry with the specified ID, otherwise returns `None`.
pub fn get_subrow(&self, row_id: u32, subrow_id: u16) -> Option<ExcelSingleRow> {
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`. /// Calculate the filename of an EXD from the `name`, `language`, and `page`.
pub fn calculate_filename( pub fn calculate_filename(
name: &str, name: &str,

View file

@ -36,14 +36,14 @@ pub fn read_data_sections(header: &EXDHeader) -> BinResult<Vec<DataSection>> {
Ok(rows) Ok(rows)
} }
fn read_row<T: Read + Seek>(reader: &mut T, exh: &EXH, row_offset: u32) -> Option<ExcelSingleRow> { fn read_row<T: Read + Seek>(reader: &mut T, exh: &EXH, row_offset: u64) -> Option<ExcelSingleRow> {
let mut subrow = ExcelSingleRow { let mut subrow = ExcelSingleRow {
columns: Vec::with_capacity(exh.column_definitions.len()), columns: Vec::with_capacity(exh.column_definitions.len()),
}; };
for column in &exh.column_definitions { for column in &exh.column_definitions {
reader reader
.seek(SeekFrom::Start((row_offset + column.offset as u32).into())) .seek(SeekFrom::Start((row_offset + column.offset as u64).into()))
.ok()?; .ok()?;
subrow subrow
@ -63,17 +63,18 @@ pub fn parse_rows(exh: &EXH, data_offsets: &Vec<ExcelDataOffset>) -> BinResult<V
let row_header = DataSectionHeader::read(reader)?; let row_header = DataSectionHeader::read(reader)?;
let data_offset = reader.stream_position().unwrap() as u32; let data_offset = reader.stream_position().unwrap() as u64;
let new_row = if row_header.row_count > 1 { let new_row = if row_header.row_count > 1 {
let mut rows = Vec::new(); let mut rows = Vec::new();
for i in 0..row_header.row_count { 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)?; let subrow_header = SubRowHeader::read(reader)?;
rows.push(( rows.push((
subrow_header.subrow_id, subrow_header.subrow_id,
read_row(reader, &exh, subrow_offset).unwrap(), read_row(reader, &exh, subrow_offset + 2).unwrap(),
)); ));
} }
ExcelRowKind::SubRows(rows) ExcelRowKind::SubRows(rows)
@ -256,7 +257,7 @@ impl EXD {
pub(crate) fn read_column<T: Read + Seek>( pub(crate) fn read_column<T: Read + Seek>(
cursor: &mut T, cursor: &mut T,
exh: &EXH, exh: &EXH,
row_offset: u32, row_offset: u64,
column: &ExcelColumnDefinition, column: &ExcelColumnDefinition,
) -> Option<ColumnData> { ) -> Option<ColumnData> {
let mut read_packed_bool = |shift: i32| -> bool { let mut read_packed_bool = |shift: i32| -> bool {
@ -272,7 +273,7 @@ impl EXD {
cursor cursor
.seek(SeekFrom::Start( .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()?; .ok()?;

View file

@ -22,7 +22,7 @@ use crate::common::Language;
pub struct EXHHeader { pub struct EXHHeader {
pub(crate) version: u16, 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) column_count: u16,
pub(crate) page_count: u16, pub(crate) page_count: u16,
pub(crate) language_count: u16, pub(crate) language_count: u16,