From dd2b7d5c63a050acf26a82399aecf9f967429b62 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 7 Feb 2013 13:26:00 +0100 Subject: [PATCH] handle deleted records --- apps/opencs/model/world/idcollection.hpp | 56 +++++++++++++++++------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/apps/opencs/model/world/idcollection.hpp b/apps/opencs/model/world/idcollection.hpp index dd8fbcb382..5a1d21ae4c 100644 --- a/apps/opencs/model/world/idcollection.hpp +++ b/apps/opencs/model/world/idcollection.hpp @@ -321,32 +321,54 @@ namespace CSMWorld { std::string id = reader.getHNOString ("NAME"); - /// \todo deal with deleted flag - - ESXRecordT record; - record.mId = id; - record.load (reader); - int index = searchId (id); - if (index==-1) + if (reader.isNextSub ("DELE")) { - // new record - Record record2; - record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; - (base ? record2.mBase : record2.mModified) = record; + reader.skipRecord(); - appendRecord (record2); + if (index==-1) + { + // deleting a record that does not exist + + // ignore it for now + + /// \todo report the problem to the user + } + else if (base) + { + removeRows (index, 1); + } + else + { + mRecords[index].mState = RecordBase::State_Deleted; + } } else { - // old record - Record& record2 = mRecords[index]; + ESXRecordT record; + record.mId = id; + record.load (reader); + + if (index==-1) + { + // new record + Record record2; + record2.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly; + (base ? record2.mBase : record2.mModified) = record; - if (base) - record2.mBase = record; + appendRecord (record2); + } else - record2.setModified (record); + { + // old record + Record& record2 = mRecords[index]; + + if (base) + record2.mBase = record; + else + record2.setModified (record); + } } }