lib: insert padding when listing objects too

Fixes a number of repacking issues with larger SI files
This commit is contained in:
itsmattkc 2023-08-21 18:12:38 -07:00
parent 9452a41a71
commit c0bfa09e35
3 changed files with 38 additions and 0 deletions

View file

@ -449,6 +449,13 @@ Interleaf::Error Interleaf::Write(FileBase *f) const
void Interleaf::WriteObject(FileBase *f, const Object *o) const
{
size_t projected_end = f->pos() + o->CalculateMaximumDiskSize();
size_t this_buf = f->pos()/m_BufferSize;
size_t end_buf = projected_end/m_BufferSize;
if (this_buf != end_buf) {
WritePadding(f, (end_buf * m_BufferSize) - f->pos());
}
RIFF::Chk mxob = RIFF::BeginChunk(f, RIFF::MxOb);
f->WriteU16(o->type_);

View file

@ -277,6 +277,35 @@ size_t Object::GetFileBodySize() const
return s;
}
size_t Object::CalculateMaximumDiskSize() const
{
size_t s = 0;
s += 108;
s += presenter_.size() + 1;
s += name_.size() + 1;
s += extra_.size();
if (type_ != MxOb::Presenter && type_ != MxOb::World && type_ != MxOb::Animation) {
s += filename_.size() + 1;
s += 24;
if (filetype_ == MxOb::WAV) {
s += 4;
}
}
if (this->HasChildren()) {
s += 16;
for (size_t i = 0; i < this->GetChildCount(); i++) {
s += static_cast<Object*>(this->GetChildAt(i))->CalculateMaximumDiskSize();
}
}
return s;
}
Object *Object::FindSubObjectWithID(uint32_t id)
{
if (this->id() == id) {

View file

@ -38,6 +38,8 @@ public:
const std::string &filename() const { return filename_; }
const ChunkedData &data() const { return data_; }
size_t CalculateMaximumDiskSize() const;
Object *FindSubObjectWithID(uint32_t id);
MxOb::Type type_;