1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-07-19 23:37:46 +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
}
/// 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`.
pub fn calculate_filename(
name: &str,

View file

@ -36,14 +36,14 @@ pub fn read_data_sections(header: &EXDHeader) -> BinResult<Vec<DataSection>> {
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 {
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<ExcelDataOffset>) -> BinResult<V
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 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<T: Read + Seek>(
cursor: &mut T,
exh: &EXH,
row_offset: u32,
row_offset: u64,
column: &ExcelColumnDefinition,
) -> Option<ColumnData> {
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()?;

View file

@ -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,