mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-30 17:15:33 +00:00
moved load code from Document to Loader class
This commit is contained in:
parent
ab94e70724
commit
e09218f164
4 changed files with 50 additions and 45 deletions
|
@ -8,23 +8,6 @@
|
||||||
#include <components/files/configurationmanager.hpp>
|
#include <components/files/configurationmanager.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void CSMDoc::Document::load (const std::vector<boost::filesystem::path>::const_iterator& begin,
|
|
||||||
const std::vector<boost::filesystem::path>::const_iterator& end, bool lastAsModified)
|
|
||||||
{
|
|
||||||
assert (begin!=end);
|
|
||||||
|
|
||||||
std::vector<boost::filesystem::path>::const_iterator end2 (end);
|
|
||||||
|
|
||||||
if (lastAsModified)
|
|
||||||
--end2;
|
|
||||||
|
|
||||||
for (std::vector<boost::filesystem::path>::const_iterator iter (begin); iter!=end2; ++iter)
|
|
||||||
getData().loadFile (*iter, true, false);
|
|
||||||
|
|
||||||
if (lastAsModified)
|
|
||||||
getData().loadFile (*end2, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSMDoc::Document::addGmsts()
|
void CSMDoc::Document::addGmsts()
|
||||||
{
|
{
|
||||||
static const char *gmstFloats[] =
|
static const char *gmstFloats[] =
|
||||||
|
@ -2272,21 +2255,6 @@ CSMDoc::Document::~Document()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::Document::setupData()
|
|
||||||
{
|
|
||||||
if (!mNew || mContentFiles.size()>1)
|
|
||||||
{
|
|
||||||
std::vector<boost::filesystem::path>::const_iterator end = mContentFiles.end();
|
|
||||||
|
|
||||||
if (mNew)
|
|
||||||
--end;
|
|
||||||
|
|
||||||
load (mContentFiles.begin(), end, !mNew);
|
|
||||||
}
|
|
||||||
|
|
||||||
getData().loadFile (mProjectPath, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
QUndoStack& CSMDoc::Document::getUndoStack()
|
QUndoStack& CSMDoc::Document::getUndoStack()
|
||||||
{
|
{
|
||||||
return mUndoStack;
|
return mUndoStack;
|
||||||
|
@ -2313,6 +2281,11 @@ const boost::filesystem::path& CSMDoc::Document::getSavePath() const
|
||||||
return mSavePath;
|
return mSavePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const boost::filesystem::path& CSMDoc::Document::getProjectPath() const
|
||||||
|
{
|
||||||
|
return mProjectPath;
|
||||||
|
}
|
||||||
|
|
||||||
const std::vector<boost::filesystem::path>& CSMDoc::Document::getContentFiles() const
|
const std::vector<boost::filesystem::path>& CSMDoc::Document::getContentFiles() const
|
||||||
{
|
{
|
||||||
return mContentFiles;
|
return mContentFiles;
|
||||||
|
|
|
@ -54,10 +54,6 @@ namespace CSMDoc
|
||||||
Document (const Document&);
|
Document (const Document&);
|
||||||
Document& operator= (const Document&);
|
Document& operator= (const Document&);
|
||||||
|
|
||||||
void load (const std::vector<boost::filesystem::path>::const_iterator& begin,
|
|
||||||
const std::vector<boost::filesystem::path>::const_iterator& end, bool lastAsModified);
|
|
||||||
///< \param lastAsModified Store the last file in Modified instead of merging it into Base.
|
|
||||||
|
|
||||||
void createBase();
|
void createBase();
|
||||||
|
|
||||||
void addGmsts();
|
void addGmsts();
|
||||||
|
@ -78,14 +74,14 @@ namespace CSMDoc
|
||||||
|
|
||||||
~Document();
|
~Document();
|
||||||
|
|
||||||
void setupData();
|
|
||||||
|
|
||||||
QUndoStack& getUndoStack();
|
QUndoStack& getUndoStack();
|
||||||
|
|
||||||
int getState() const;
|
int getState() const;
|
||||||
|
|
||||||
const boost::filesystem::path& getSavePath() const;
|
const boost::filesystem::path& getSavePath() const;
|
||||||
|
|
||||||
|
const boost::filesystem::path& getProjectPath() const;
|
||||||
|
|
||||||
const std::vector<boost::filesystem::path>& getContentFiles() const;
|
const std::vector<boost::filesystem::path>& getContentFiles() const;
|
||||||
///< \attention The last element in this collection is the file that is being edited,
|
///< \attention The last element in this collection is the file that is being edited,
|
||||||
/// but with its original path instead of the save path.
|
/// but with its original path instead of the save path.
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
#include "document.hpp"
|
#include "document.hpp"
|
||||||
|
|
||||||
|
CSMDoc::Loader::Stage::Stage() : mFile (0) {}
|
||||||
|
|
||||||
|
|
||||||
CSMDoc::Loader::Loader()
|
CSMDoc::Loader::Loader()
|
||||||
{
|
{
|
||||||
QTimer *timer = new QTimer (this);
|
QTimer *timer = new QTimer (this);
|
||||||
|
@ -28,31 +31,57 @@ void CSMDoc::Loader::load()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::pair<Document *, bool> >::iterator iter = mDocuments.begin();
|
std::vector<std::pair<Document *, Stage> >::iterator iter = mDocuments.begin();
|
||||||
|
|
||||||
Document *document = iter->first;
|
Document *document = iter->first;
|
||||||
|
|
||||||
mDocuments.erase (iter);
|
int size = static_cast<int> (document->getContentFiles().size());
|
||||||
|
|
||||||
|
if (document->isNew())
|
||||||
|
--size;
|
||||||
|
|
||||||
|
bool done = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
document->setupData();
|
if (iter->second.mFile<size)
|
||||||
emit documentLoaded (document);
|
{
|
||||||
|
document->getData().loadFile (document->getContentFiles()[iter->second.mFile],
|
||||||
|
iter->second.mFile<size-1, false);
|
||||||
|
}
|
||||||
|
else if (iter->second.mFile==size)
|
||||||
|
{
|
||||||
|
document->getData().loadFile (document->getProjectPath(), false, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
++(iter->second.mFile);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
mDocuments.erase (iter);
|
||||||
emit documentNotLoaded (document, e.what());
|
emit documentNotLoaded (document, e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (done)
|
||||||
|
{
|
||||||
|
mDocuments.erase (iter);
|
||||||
|
emit documentLoaded (document);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::Loader::loadDocument (CSMDoc::Document *document)
|
void CSMDoc::Loader::loadDocument (CSMDoc::Document *document)
|
||||||
{
|
{
|
||||||
mDocuments.push_back (std::make_pair (document, false));
|
mDocuments.push_back (std::make_pair (document, Stage()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMDoc::Loader::abortLoading (Document *document)
|
void CSMDoc::Loader::abortLoading (Document *document)
|
||||||
{
|
{
|
||||||
for (std::vector<std::pair<Document *, bool> >::iterator iter = mDocuments.begin();
|
for (std::vector<std::pair<Document *, Stage> >::iterator iter = mDocuments.begin();
|
||||||
iter!=mDocuments.end(); ++iter)
|
iter!=mDocuments.end(); ++iter)
|
||||||
{
|
{
|
||||||
if (iter->first==document)
|
if (iter->first==document)
|
||||||
|
|
|
@ -15,9 +15,16 @@ namespace CSMDoc
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
struct Stage
|
||||||
|
{
|
||||||
|
int mFile;
|
||||||
|
|
||||||
|
Stage();
|
||||||
|
};
|
||||||
|
|
||||||
QMutex mMutex;
|
QMutex mMutex;
|
||||||
QWaitCondition mThingsToDo;
|
QWaitCondition mThingsToDo;
|
||||||
std::vector<std::pair<Document *, bool> > mDocuments;
|
std::vector<std::pair<Document *, Stage> > mDocuments;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue