2012-12-08 10:59:13 +00:00
|
|
|
#include "tools.hpp"
|
|
|
|
|
|
|
|
#include <QThreadPool>
|
|
|
|
|
2012-12-08 13:44:03 +00:00
|
|
|
#include "../doc/state.hpp"
|
2013-09-14 13:16:31 +00:00
|
|
|
#include "../doc/operation.hpp"
|
2014-07-21 10:15:21 +00:00
|
|
|
#include "../doc/document.hpp"
|
2012-12-08 10:59:13 +00:00
|
|
|
|
2012-12-08 22:27:59 +00:00
|
|
|
#include "../world/data.hpp"
|
2012-12-11 14:35:47 +00:00
|
|
|
#include "../world/universalid.hpp"
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2012-12-11 14:35:47 +00:00
|
|
|
#include "reportmodel.hpp"
|
2012-12-08 22:27:59 +00:00
|
|
|
#include "mandatoryid.hpp"
|
2013-03-25 10:07:04 +00:00
|
|
|
#include "skillcheck.hpp"
|
2013-04-04 08:10:26 +00:00
|
|
|
#include "classcheck.hpp"
|
2013-04-04 08:39:43 +00:00
|
|
|
#include "factioncheck.hpp"
|
2013-04-06 15:35:36 +00:00
|
|
|
#include "racecheck.hpp"
|
2013-04-06 19:48:52 +00:00
|
|
|
#include "soundcheck.hpp"
|
2013-04-07 17:39:13 +00:00
|
|
|
#include "regioncheck.hpp"
|
2013-04-07 21:25:35 +00:00
|
|
|
#include "birthsigncheck.hpp"
|
2013-04-09 10:44:49 +00:00
|
|
|
#include "spellcheck.hpp"
|
2013-12-20 19:02:42 +00:00
|
|
|
#include "referenceablecheck.hpp"
|
2014-02-14 12:38:30 +00:00
|
|
|
#include "scriptcheck.hpp"
|
2014-08-26 15:55:31 +00:00
|
|
|
#include "bodypartcheck.hpp"
|
2015-02-13 03:11:36 +00:00
|
|
|
#include "referencecheck.hpp"
|
2015-03-05 10:24:01 +00:00
|
|
|
#include "startscriptcheck.hpp"
|
2015-03-27 15:33:54 +00:00
|
|
|
#include "searchoperation.hpp"
|
2015-05-27 12:12:11 +00:00
|
|
|
#include "pathgridcheck.hpp"
|
2015-06-13 16:08:31 +00:00
|
|
|
#include "soundgencheck.hpp"
|
2015-08-03 16:08:01 +00:00
|
|
|
#include "magiceffectcheck.hpp"
|
2015-08-13 10:03:20 +00:00
|
|
|
#include "mergeoperation.hpp"
|
2016-01-18 02:55:03 +00:00
|
|
|
#include "gmstcheck.hpp"
|
2016-02-17 20:38:30 +00:00
|
|
|
#include "topicinfocheck.hpp"
|
2016-02-22 22:01:15 +00:00
|
|
|
#include "journalcheck.hpp"
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
CSMDoc::OperationHolder *CSMTools::Tools::get (int type)
|
2012-12-08 16:00:58 +00:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2015-03-14 11:00:24 +00:00
|
|
|
case CSMDoc::State_Verifying: return &mVerifier;
|
2015-03-17 11:30:47 +00:00
|
|
|
case CSMDoc::State_Searching: return &mSearch;
|
2015-08-13 10:03:20 +00:00
|
|
|
case CSMDoc::State_Merging: return &mMerge;
|
2012-12-08 16:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
const CSMDoc::OperationHolder *CSMTools::Tools::get (int type) const
|
2012-12-08 16:00:58 +00:00
|
|
|
{
|
2013-12-30 17:41:16 +00:00
|
|
|
return const_cast<Tools *> (this)->get (type);
|
2012-12-08 16:00:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
CSMDoc::OperationHolder *CSMTools::Tools::getVerifier()
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2015-03-14 11:00:24 +00:00
|
|
|
if (!mVerifierOperation)
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation = new CSMDoc::Operation (CSMDoc::State_Verifying, false);
|
2012-12-08 10:59:13 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
connect (&mVerifier, SIGNAL (progress (int, int, int)), this, SIGNAL (progress (int, int, int)));
|
|
|
|
connect (&mVerifier, SIGNAL (done (int, bool)), this, SIGNAL (done (int, bool)));
|
2015-06-20 15:56:42 +00:00
|
|
|
connect (&mVerifier, SIGNAL (reportMessage (const CSMDoc::Message&, int)),
|
|
|
|
this, SLOT (verifierMessage (const CSMDoc::Message&, int)));
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2018-05-03 16:56:01 +00:00
|
|
|
std::vector<std::string> mandatoryIds {"Day", "DaysPassed", "GameHour", "Month", "PCRace"};
|
2012-12-08 22:27:59 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new MandatoryIdStage (mData.getGlobals(),
|
2013-12-30 17:41:16 +00:00
|
|
|
CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Globals), mandatoryIds));
|
2013-03-25 10:07:04 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new SkillCheckStage (mData.getSkills()));
|
2013-04-04 08:10:26 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new ClassCheckStage (mData.getClasses()));
|
2013-04-04 08:39:43 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new FactionCheckStage (mData.getFactions()));
|
2013-04-06 15:35:36 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new RaceCheckStage (mData.getRaces()));
|
2013-04-06 19:48:52 +00:00
|
|
|
|
2018-08-24 21:47:38 +00:00
|
|
|
mVerifierOperation->appendStage (new SoundCheckStage (mData.getSounds(), mData.getResources (CSMWorld::UniversalId::Type_SoundsRes)));
|
2013-04-07 17:39:13 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new RegionCheckStage (mData.getRegions()));
|
2013-04-07 21:25:35 +00:00
|
|
|
|
2018-08-24 14:37:07 +00:00
|
|
|
mVerifierOperation->appendStage (new BirthsignCheckStage (mData.getBirthsigns(), mData.getResources (CSMWorld::UniversalId::Type_Textures)));
|
2013-04-09 10:44:49 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new SpellCheckStage (mData.getSpells()));
|
2013-12-30 12:23:16 +00:00
|
|
|
|
2018-08-24 22:22:41 +00:00
|
|
|
mVerifierOperation->appendStage (new ReferenceableCheckStage (mData.getReferenceables().getDataSet(), mData.getRaces(), mData.getClasses(), mData.getFactions(), mData.getScripts(),
|
2018-08-24 22:44:46 +00:00
|
|
|
mData.getResources (CSMWorld::UniversalId::Type_Meshes), mData.getResources (CSMWorld::UniversalId::Type_Icons)));
|
2014-02-14 12:38:30 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new ReferenceCheckStage(mData.getReferences(), mData.getReferenceables(), mData.getCells(), mData.getFactions()));
|
2015-02-13 03:11:36 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new ScriptCheckStage (mDocument));
|
2014-08-26 15:55:31 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage (new StartScriptCheckStage (mData.getStartScripts(), mData.getScripts()));
|
2015-03-05 10:24:01 +00:00
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifierOperation->appendStage(
|
2014-08-26 15:55:31 +00:00
|
|
|
new BodyPartCheckStage(
|
|
|
|
mData.getBodyParts(),
|
|
|
|
mData.getResources(
|
|
|
|
CSMWorld::UniversalId( CSMWorld::UniversalId::Type_Meshes )),
|
|
|
|
mData.getRaces() ));
|
2015-03-14 11:00:24 +00:00
|
|
|
|
2015-05-27 12:12:11 +00:00
|
|
|
mVerifierOperation->appendStage (new PathgridCheckStage (mData.getPathgrids()));
|
|
|
|
|
2015-06-13 16:08:31 +00:00
|
|
|
mVerifierOperation->appendStage (new SoundGenCheckStage (mData.getSoundGens(),
|
|
|
|
mData.getSounds(),
|
|
|
|
mData.getReferenceables()));
|
|
|
|
|
2015-08-03 16:08:01 +00:00
|
|
|
mVerifierOperation->appendStage (new MagicEffectCheckStage (mData.getMagicEffects(),
|
|
|
|
mData.getSounds(),
|
|
|
|
mData.getReferenceables(),
|
|
|
|
mData.getResources (CSMWorld::UniversalId::Type_Icons),
|
|
|
|
mData.getResources (CSMWorld::UniversalId::Type_Textures)));
|
2016-02-17 20:38:30 +00:00
|
|
|
|
2016-01-18 17:34:33 +00:00
|
|
|
mVerifierOperation->appendStage (new GmstCheckStage (mData.getGmsts()));
|
2015-08-03 16:08:01 +00:00
|
|
|
|
2016-02-17 20:38:30 +00:00
|
|
|
mVerifierOperation->appendStage (new TopicInfoCheckStage (mData.getTopicInfos(),
|
|
|
|
mData.getCells(),
|
|
|
|
mData.getClasses(),
|
|
|
|
mData.getFactions(),
|
|
|
|
mData.getGmsts(),
|
|
|
|
mData.getGlobals(),
|
|
|
|
mData.getJournals(),
|
|
|
|
mData.getRaces(),
|
|
|
|
mData.getRegions(),
|
|
|
|
mData.getTopics(),
|
|
|
|
mData.getReferenceables().getDataSet(),
|
|
|
|
mData.getResources (CSMWorld::UniversalId::Type_SoundsRes)));
|
|
|
|
|
2016-02-22 22:01:15 +00:00
|
|
|
mVerifierOperation->appendStage (new JournalCheckStage(mData.getJournals(), mData.getJournalInfos()));
|
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
mVerifier.setOperation (mVerifierOperation);
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2015-03-14 11:00:24 +00:00
|
|
|
return &mVerifier;
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 16:27:17 +00:00
|
|
|
CSMTools::Tools::Tools (CSMDoc::Document& document, ToUTF8::FromType encoding)
|
2015-05-01 00:24:27 +00:00
|
|
|
: mDocument (document), mData (document.getData()), mVerifierOperation (0),
|
2015-08-16 16:27:17 +00:00
|
|
|
mSearchOperation (0), mMergeOperation (0), mNextReportNumber (0), mEncoding (encoding)
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2014-05-10 10:04:36 +00:00
|
|
|
// index 0: load error log
|
|
|
|
mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel));
|
|
|
|
mActiveReports.insert (std::make_pair (CSMDoc::State_Loading, 0));
|
2015-03-27 15:33:54 +00:00
|
|
|
|
|
|
|
connect (&mSearch, SIGNAL (progress (int, int, int)), this, SIGNAL (progress (int, int, int)));
|
|
|
|
connect (&mSearch, SIGNAL (done (int, bool)), this, SIGNAL (done (int, bool)));
|
2015-06-20 15:56:42 +00:00
|
|
|
connect (&mSearch, SIGNAL (reportMessage (const CSMDoc::Message&, int)),
|
|
|
|
this, SLOT (verifierMessage (const CSMDoc::Message&, int)));
|
2015-08-13 12:49:32 +00:00
|
|
|
|
|
|
|
connect (&mMerge, SIGNAL (progress (int, int, int)), this, SIGNAL (progress (int, int, int)));
|
|
|
|
connect (&mMerge, SIGNAL (done (int, bool)), this, SIGNAL (done (int, bool)));
|
|
|
|
// don't need to connect report message, since there are no messages for merge
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSMTools::Tools::~Tools()
|
|
|
|
{
|
2015-03-14 11:00:24 +00:00
|
|
|
if (mVerifierOperation)
|
|
|
|
{
|
|
|
|
mVerifier.abortAndWait();
|
|
|
|
delete mVerifierOperation;
|
|
|
|
}
|
2014-05-06 09:44:20 +00:00
|
|
|
|
2015-03-17 11:30:47 +00:00
|
|
|
if (mSearchOperation)
|
|
|
|
{
|
|
|
|
mSearch.abortAndWait();
|
|
|
|
delete mSearchOperation;
|
|
|
|
}
|
2015-05-27 05:55:00 +00:00
|
|
|
|
2015-08-13 10:03:20 +00:00
|
|
|
if (mMergeOperation)
|
|
|
|
{
|
|
|
|
mMerge.abortAndWait();
|
|
|
|
delete mMergeOperation;
|
|
|
|
}
|
|
|
|
|
2014-05-06 09:44:20 +00:00
|
|
|
for (std::map<int, ReportModel *>::iterator iter (mReports.begin()); iter!=mReports.end(); ++iter)
|
|
|
|
delete iter->second;
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 10:03:40 +00:00
|
|
|
CSMWorld::UniversalId CSMTools::Tools::runVerifier (const CSMWorld::UniversalId& reportId)
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2015-06-25 10:03:40 +00:00
|
|
|
int reportNumber = reportId.getType()==CSMWorld::UniversalId::Type_VerificationResults ?
|
|
|
|
reportId.getIndex() : mNextReportNumber++;
|
|
|
|
|
|
|
|
if (mReports.find (reportNumber)==mReports.end())
|
|
|
|
mReports.insert (std::make_pair (reportNumber, new ReportModel));
|
2015-08-13 10:03:20 +00:00
|
|
|
|
2015-06-25 10:03:40 +00:00
|
|
|
mActiveReports[CSMDoc::State_Verifying] = reportNumber;
|
2012-12-11 14:35:47 +00:00
|
|
|
|
2012-12-08 10:59:13 +00:00
|
|
|
getVerifier()->start();
|
2012-12-11 14:35:47 +00:00
|
|
|
|
2015-06-25 10:03:40 +00:00
|
|
|
return CSMWorld::UniversalId (CSMWorld::UniversalId::Type_VerificationResults, reportNumber);
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 11:30:47 +00:00
|
|
|
CSMWorld::UniversalId CSMTools::Tools::newSearch()
|
|
|
|
{
|
2015-06-20 17:04:19 +00:00
|
|
|
mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel (true, false)));
|
2015-03-17 11:30:47 +00:00
|
|
|
|
2015-05-27 05:55:00 +00:00
|
|
|
return CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Search, mNextReportNumber-1);
|
2015-03-17 11:30:47 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:33:54 +00:00
|
|
|
void CSMTools::Tools::runSearch (const CSMWorld::UniversalId& searchId, const Search& search)
|
|
|
|
{
|
|
|
|
mActiveReports[CSMDoc::State_Searching] = searchId.getIndex();
|
|
|
|
|
|
|
|
if (!mSearchOperation)
|
|
|
|
{
|
|
|
|
mSearchOperation = new SearchOperation (mDocument);
|
2015-05-27 05:55:00 +00:00
|
|
|
mSearch.setOperation (mSearchOperation);
|
2015-03-27 15:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mSearchOperation->configure (search);
|
2015-05-27 05:55:00 +00:00
|
|
|
|
2015-03-27 15:33:54 +00:00
|
|
|
mSearch.start();
|
|
|
|
}
|
|
|
|
|
2017-04-28 15:30:26 +00:00
|
|
|
void CSMTools::Tools::runMerge (std::unique_ptr<CSMDoc::Document> target)
|
2015-08-13 10:03:20 +00:00
|
|
|
{
|
|
|
|
// not setting an active report, because merge does not produce messages
|
|
|
|
|
|
|
|
if (!mMergeOperation)
|
|
|
|
{
|
2015-08-16 16:27:17 +00:00
|
|
|
mMergeOperation = new MergeOperation (mDocument, mEncoding);
|
2015-08-13 10:03:20 +00:00
|
|
|
mMerge.setOperation (mMergeOperation);
|
2015-08-16 13:24:48 +00:00
|
|
|
connect (mMergeOperation, SIGNAL (mergeDone (CSMDoc::Document*)),
|
|
|
|
this, SIGNAL (mergeDone (CSMDoc::Document*)));
|
2015-08-13 10:03:20 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 10:37:45 +00:00
|
|
|
target->flagAsDirty();
|
|
|
|
|
2017-04-28 15:30:26 +00:00
|
|
|
mMergeOperation->setTarget (std::move(target));
|
2015-08-13 10:03:20 +00:00
|
|
|
|
|
|
|
mMerge.start();
|
|
|
|
}
|
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
void CSMTools::Tools::abortOperation (int type)
|
2012-12-08 10:59:13 +00:00
|
|
|
{
|
2015-03-14 11:00:24 +00:00
|
|
|
if (CSMDoc::OperationHolder *operation = get (type))
|
2012-12-08 16:00:58 +00:00
|
|
|
operation->abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
int CSMTools::Tools::getRunningOperations() const
|
|
|
|
{
|
|
|
|
static const int sOperations[] =
|
|
|
|
{
|
2013-12-30 17:41:16 +00:00
|
|
|
CSMDoc::State_Verifying,
|
2015-03-17 11:30:47 +00:00
|
|
|
CSMDoc::State_Searching,
|
2015-08-13 10:03:20 +00:00
|
|
|
CSMDoc::State_Merging,
|
2012-12-08 16:00:58 +00:00
|
|
|
-1
|
|
|
|
};
|
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
for (int i=0; sOperations[i]!=-1; ++i)
|
2015-03-14 11:00:24 +00:00
|
|
|
if (const CSMDoc::OperationHolder *operation = get (sOperations[i]))
|
2012-12-08 16:00:58 +00:00
|
|
|
if (operation->isRunning())
|
|
|
|
result |= sOperations[i];
|
2012-12-08 10:59:13 +00:00
|
|
|
|
2012-12-08 16:00:58 +00:00
|
|
|
return result;
|
2012-12-08 10:59:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
CSMTools::ReportModel *CSMTools::Tools::getReport (const CSMWorld::UniversalId& id)
|
2012-12-11 14:35:47 +00:00
|
|
|
{
|
2014-05-10 10:04:36 +00:00
|
|
|
if (id.getType()!=CSMWorld::UniversalId::Type_VerificationResults &&
|
2015-03-17 11:30:47 +00:00
|
|
|
id.getType()!=CSMWorld::UniversalId::Type_LoadErrorLog &&
|
|
|
|
id.getType()!=CSMWorld::UniversalId::Type_Search)
|
2013-12-30 17:41:16 +00:00
|
|
|
throw std::logic_error ("invalid request for report model: " + id.toString());
|
2015-05-27 05:55:00 +00:00
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
return mReports.at (id.getIndex());
|
2012-12-11 14:35:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 15:56:42 +00:00
|
|
|
void CSMTools::Tools::verifierMessage (const CSMDoc::Message& message, int type)
|
2012-12-08 17:38:36 +00:00
|
|
|
{
|
2013-12-30 17:41:16 +00:00
|
|
|
std::map<int, int>::iterator iter = mActiveReports.find (type);
|
2012-12-08 17:38:36 +00:00
|
|
|
|
2013-12-30 17:41:16 +00:00
|
|
|
if (iter!=mActiveReports.end())
|
2015-06-20 15:56:42 +00:00
|
|
|
mReports[iter->second]->add (message);
|
2013-12-20 19:02:42 +00:00
|
|
|
}
|