|
|
|
@ -9,6 +9,45 @@
|
|
|
|
|
#include <components/esm/esmreader.hpp>
|
|
|
|
|
#include <components/esm/esmwriter.hpp>
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
void readRefs(const ESM::Cell& cell, std::map<ESM::RefNum, std::string>& refs, std::vector<ESM::ESMReader>& readers)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < cell.mContextList.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
size_t index = cell.mContextList[i].index;
|
|
|
|
|
if (readers.size() <= index)
|
|
|
|
|
readers.resize(index + 1);
|
|
|
|
|
cell.restore(readers[index], i);
|
|
|
|
|
ESM::CellRef ref;
|
|
|
|
|
ref.mRefNum.mContentFile = ESM::RefNum::RefNum_NoContentFile;
|
|
|
|
|
bool deleted = false;
|
|
|
|
|
while(cell.getNextRef(readers[index], ref, deleted))
|
|
|
|
|
{
|
|
|
|
|
if(deleted)
|
|
|
|
|
refs.erase(ref.mRefNum);
|
|
|
|
|
else if (std::find(cell.mMovedRefs.begin(), cell.mMovedRefs.end(), ref.mRefNum) == cell.mMovedRefs.end())
|
|
|
|
|
{
|
|
|
|
|
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
|
|
|
|
|
refs[ref.mRefNum] = ref.mRefID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(const auto& it : cell.mLeasedRefs)
|
|
|
|
|
{
|
|
|
|
|
bool deleted = it.second;
|
|
|
|
|
if(deleted)
|
|
|
|
|
refs.erase(it.first.mRefNum);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ESM::CellRef ref = it.first;
|
|
|
|
|
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
|
|
|
|
|
refs[ref.mRefNum] = ref.mRefID;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -146,7 +185,33 @@ void ESMStore::setUp(bool validateRecords)
|
|
|
|
|
mDialogs.setUp();
|
|
|
|
|
|
|
|
|
|
if (validateRecords)
|
|
|
|
|
{
|
|
|
|
|
validate();
|
|
|
|
|
countRecords();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ESMStore::countRecords()
|
|
|
|
|
{
|
|
|
|
|
if(!mRefCount.empty())
|
|
|
|
|
return;
|
|
|
|
|
std::map<ESM::RefNum, std::string> refs;
|
|
|
|
|
std::vector<ESM::ESMReader> readers;
|
|
|
|
|
for(auto it = mCells.intBegin(); it != mCells.intEnd(); it++)
|
|
|
|
|
readRefs(*it, refs, readers);
|
|
|
|
|
for(auto it = mCells.extBegin(); it != mCells.extEnd(); it++)
|
|
|
|
|
readRefs(*it, refs, readers);
|
|
|
|
|
for(const auto& pair : refs)
|
|
|
|
|
mRefCount[pair.second]++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ESMStore::getRefCount(const std::string& id) const
|
|
|
|
|
{
|
|
|
|
|
const std::string lowerId = Misc::StringUtils::lowerCase(id);
|
|
|
|
|
auto it = mRefCount.find(lowerId);
|
|
|
|
|
if(it == mRefCount.end())
|
|
|
|
|
return 0;
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ESMStore::validate()
|
|
|
|
|