1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 21:49:55 +00:00

While loading overwrite records with the same id. Should resolve bug #1750.

This commit is contained in:
cc9cii 2014-09-27 17:46:48 +10:00
parent f5e493de7e
commit 810ba61909

View file

@ -7,6 +7,7 @@
#include <cctype>
#include <stdexcept>
#include <functional>
#include <iostream>
#include <QVariant>
@ -431,18 +432,27 @@ namespace CSMWorld
const Record<ESXRecordT>& record2 = dynamic_cast<const Record<ESXRecordT>&> (record);
mRecords.insert (mRecords.begin()+index, record2);
std::pair<std::map<std::string, int>::iterator, bool> insertResult =
mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (record2.get())),
index));
if(!insertResult.second) // duplicate index found, replace the current record
{
std::cerr << "Duplicate record found, using new: " + IdAccessorT().getId(record2.get()) << std::endl;
replace(insertResult.first->second, record2);
return;
}
// else update the index except for the record to be inserted
if (index<static_cast<int> (mRecords.size())-1)
{
for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end();
++iter)
if (iter->second>=index)
std::string id = IdAccessorT().getId(record2.get());
for (std::map<std::string, int>::iterator iter (mIndex.begin()); iter!=mIndex.end(); ++iter)
if (iter->second > index || (iter->second == index && iter->first != id))
++(iter->second);
}
mIndex.insert (std::make_pair (Misc::StringUtils::lowerCase (IdAccessorT().getId (
record2.get())), index));
mRecords.insert (mRecords.begin()+index, record2);
}
template<typename ESXRecordT, typename IdAccessorT>