2013-09-29 09:11:57 +02:00
|
|
|
#include "esmloader.hpp"
|
|
|
|
#include "esmstore.hpp"
|
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include <components/esm3/esmreader.hpp>
|
2022-06-01 22:53:18 +02:00
|
|
|
#include <components/esm3/readerscache.hpp>
|
2013-09-29 09:11:57 +02:00
|
|
|
|
|
|
|
namespace MWWorld
|
|
|
|
{
|
|
|
|
|
2022-06-01 22:53:18 +02:00
|
|
|
EsmLoader::EsmLoader(MWWorld::ESMStore& store, ESM::ReadersCache& readers, ToUTF8::Utf8Encoder* encoder)
|
|
|
|
: mReaders(readers)
|
2021-11-23 15:15:22 +01:00
|
|
|
, mStore(store)
|
|
|
|
, mEncoder(encoder)
|
2022-04-16 16:28:39 +02:00
|
|
|
, mDialogue(nullptr) // A content file containing INFO records without a DIAL record appends them to the previous file's dialogue
|
2013-09-29 09:11:57 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-23 15:15:22 +01:00
|
|
|
void EsmLoader::load(const boost::filesystem::path& filepath, int& index, Loading::Listener* listener)
|
2013-09-29 09:11:57 +02:00
|
|
|
{
|
2022-06-01 22:53:18 +02:00
|
|
|
const ESM::ReadersCache::BusyItem reader = mReaders.get(static_cast<std::size_t>(index));
|
|
|
|
|
|
|
|
reader->setEncoder(mEncoder);
|
|
|
|
reader->setIndex(index);
|
|
|
|
reader->open(filepath.string());
|
|
|
|
reader->resolveParentFileIndices(mReaders);
|
|
|
|
|
|
|
|
assert(reader->getGameFiles().size() == reader->getParentFileIndices().size());
|
|
|
|
for (std::size_t i = 0, n = reader->getParentFileIndices().size(); i < n; ++i)
|
|
|
|
if (i == static_cast<std::size_t>(reader->getIndex()))
|
|
|
|
throw std::runtime_error("File " + reader->getName() + " asks for parent file "
|
|
|
|
+ reader->getGameFiles()[i].name
|
|
|
|
+ ", but it is not available or has been loaded in the wrong order. "
|
|
|
|
"Please run the launcher to fix this issue.");
|
|
|
|
|
|
|
|
mStore.load(*reader, listener, mDialogue);
|
|
|
|
|
2022-06-06 00:57:44 +02:00
|
|
|
if (!mMasterFileFormat.has_value() && (Misc::StringUtils::ciEndsWith(reader->getName(), ".esm")
|
|
|
|
|| Misc::StringUtils::ciEndsWith(reader->getName(), ".omwgame")))
|
2022-06-01 22:53:18 +02:00
|
|
|
mMasterFileFormat = reader->getFormat();
|
2013-09-29 09:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace MWWorld */
|