forked from teamnwah/openmw-tes3coop
consider script blacklist in OpenCS verifier
This commit is contained in:
parent
d87630b41a
commit
a9f9dec923
12 changed files with 122 additions and 17 deletions
|
@ -9,7 +9,7 @@ opencs_units (model/doc
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units_noqt (model/doc
|
opencs_units_noqt (model/doc
|
||||||
stage savingstate savingstages
|
stage savingstate savingstages blacklist
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_hdrs_noqt (model/doc
|
opencs_hdrs_noqt (model/doc
|
||||||
|
|
|
@ -86,7 +86,11 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
||||||
("encoding", boost::program_options::value<std::string>()->default_value("win1252"))
|
("encoding", boost::program_options::value<std::string>()->default_value("win1252"))
|
||||||
("resources", boost::program_options::value<std::string>()->default_value("resources"))
|
("resources", boost::program_options::value<std::string>()->default_value("resources"))
|
||||||
("fallback-archive", boost::program_options::value<std::vector<std::string> >()->
|
("fallback-archive", boost::program_options::value<std::vector<std::string> >()->
|
||||||
default_value(std::vector<std::string>(), "fallback-archive")->multitoken());
|
default_value(std::vector<std::string>(), "fallback-archive")->multitoken())
|
||||||
|
("script-blacklist", boost::program_options::value<std::vector<std::string> >()->default_value(std::vector<std::string>(), "")
|
||||||
|
->multitoken(), "exclude specified script from the verifier (if the use of the blacklist is enabled)")
|
||||||
|
("script-blacklist-use", boost::program_options::value<bool>()->implicit_value(true)
|
||||||
|
->default_value(true), "enable script blacklisting");
|
||||||
|
|
||||||
boost::program_options::notify(variables);
|
boost::program_options::notify(variables);
|
||||||
|
|
||||||
|
@ -97,6 +101,10 @@ std::pair<Files::PathContainer, std::vector<std::string> > CS::Editor::readConfi
|
||||||
|
|
||||||
mDocumentManager.setResourceDir (mResources = variables["resources"].as<std::string>());
|
mDocumentManager.setResourceDir (mResources = variables["resources"].as<std::string>());
|
||||||
|
|
||||||
|
if (variables["script-blacklist-use"].as<bool>())
|
||||||
|
mDocumentManager.setBlacklistedScripts (
|
||||||
|
variables["script-blacklist"].as<std::vector<std::string> >());
|
||||||
|
|
||||||
mFsStrict = variables["fs-strict"].as<bool>();
|
mFsStrict = variables["fs-strict"].as<bool>();
|
||||||
|
|
||||||
Files::PathContainer dataDirs, dataLocal;
|
Files::PathContainer dataDirs, dataLocal;
|
||||||
|
|
31
apps/opencs/model/doc/blacklist.cpp
Normal file
31
apps/opencs/model/doc/blacklist.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
|
||||||
|
#include "blacklist.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <components/misc/stringops.hpp>
|
||||||
|
|
||||||
|
bool CSMDoc::Blacklist::isBlacklisted (const CSMWorld::UniversalId& id) const
|
||||||
|
{
|
||||||
|
std::map<CSMWorld::UniversalId::Type, std::vector<std::string> >::const_iterator iter =
|
||||||
|
mIds.find (id.getType());
|
||||||
|
|
||||||
|
if (iter==mIds.end())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return std::binary_search (iter->second.begin(), iter->second.end(),
|
||||||
|
Misc::StringUtils::lowerCase (id.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSMDoc::Blacklist::add (CSMWorld::UniversalId::Type type,
|
||||||
|
const std::vector<std::string>& ids)
|
||||||
|
{
|
||||||
|
std::vector<std::string>& list = mIds[type];
|
||||||
|
|
||||||
|
int size = list.size();
|
||||||
|
|
||||||
|
list.resize (size+ids.size());
|
||||||
|
|
||||||
|
std::transform (ids.begin(), ids.end(), list.begin()+size, Misc::StringUtils::lowerCase);
|
||||||
|
std::sort (list.begin(), list.end());
|
||||||
|
}
|
25
apps/opencs/model/doc/blacklist.hpp
Normal file
25
apps/opencs/model/doc/blacklist.hpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef CSM_DOC_BLACKLIST_H
|
||||||
|
#define CSM_DOC_BLACKLIST_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "../world/universalid.hpp"
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
/// \brief ID blacklist sorted by UniversalId type
|
||||||
|
class Blacklist
|
||||||
|
{
|
||||||
|
std::map<CSMWorld::UniversalId::Type, std::vector<std::string> > mIds;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool isBlacklisted (const CSMWorld::UniversalId& id) const;
|
||||||
|
|
||||||
|
void add (CSMWorld::UniversalId::Type type, const std::vector<std::string>& ids);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -2205,9 +2205,10 @@ void CSMDoc::Document::createBase()
|
||||||
CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
|
CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
|
||||||
const std::vector< boost::filesystem::path >& files, bool new_,
|
const std::vector< boost::filesystem::path >& files, bool new_,
|
||||||
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
|
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
|
||||||
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager)
|
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager,
|
||||||
|
const std::vector<std::string>& blacklistedScripts)
|
||||||
: mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, resourcesManager),
|
: mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, resourcesManager),
|
||||||
mTools (mData), mResDir(resDir),
|
mTools (*this), mResDir(resDir),
|
||||||
mProjectPath ((configuration.getUserDataPath() / "projects") /
|
mProjectPath ((configuration.getUserDataPath() / "projects") /
|
||||||
(savePath.filename().string() + ".project")),
|
(savePath.filename().string() + ".project")),
|
||||||
mSaving (*this, mProjectPath, encoding)
|
mSaving (*this, mProjectPath, encoding)
|
||||||
|
@ -2239,6 +2240,8 @@ CSMDoc::Document::Document (const Files::ConfigurationManager& configuration,
|
||||||
createBase();
|
createBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mBlacklist.add (CSMWorld::UniversalId::Type_Script, blacklistedScripts);
|
||||||
|
|
||||||
addOptionalGmsts();
|
addOptionalGmsts();
|
||||||
addOptionalGlobals();
|
addOptionalGlobals();
|
||||||
|
|
||||||
|
@ -2358,6 +2361,13 @@ CSMTools::ReportModel *CSMDoc::Document::getReport (const CSMWorld::UniversalId&
|
||||||
return mTools.getReport (id);
|
return mTools.getReport (id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSMDoc::Document::isBlacklisted (const CSMWorld::UniversalId& id)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mBlacklist.isBlacklisted (id);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CSMDoc::Document::progress (int current, int max, int type)
|
void CSMDoc::Document::progress (int current, int max, int type)
|
||||||
{
|
{
|
||||||
emit progress (current, max, type, 1, this);
|
emit progress (current, max, type, 1, this);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
#include "state.hpp"
|
#include "state.hpp"
|
||||||
#include "saving.hpp"
|
#include "saving.hpp"
|
||||||
|
#include "blacklist.hpp"
|
||||||
|
|
||||||
class QAbstractItemModel;
|
class QAbstractItemModel;
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ namespace CSMDoc
|
||||||
boost::filesystem::path mProjectPath;
|
boost::filesystem::path mProjectPath;
|
||||||
Saving mSaving;
|
Saving mSaving;
|
||||||
boost::filesystem::path mResDir;
|
boost::filesystem::path mResDir;
|
||||||
|
Blacklist mBlacklist;
|
||||||
|
|
||||||
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
|
// It is important that the undo stack is declared last, because on desctruction it fires a signal, that is connected to a slot, that is
|
||||||
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
|
// using other member variables. Unfortunately this connection is cut only in the QObject destructor, which is way too late.
|
||||||
|
@ -78,7 +80,8 @@ namespace CSMDoc
|
||||||
Document (const Files::ConfigurationManager& configuration,
|
Document (const Files::ConfigurationManager& configuration,
|
||||||
const std::vector< boost::filesystem::path >& files, bool new_,
|
const std::vector< boost::filesystem::path >& files, bool new_,
|
||||||
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
|
const boost::filesystem::path& savePath, const boost::filesystem::path& resDir,
|
||||||
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager);
|
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager,
|
||||||
|
const std::vector<std::string>& blacklistedScripts);
|
||||||
|
|
||||||
~Document();
|
~Document();
|
||||||
|
|
||||||
|
@ -110,6 +113,8 @@ namespace CSMDoc
|
||||||
CSMTools::ReportModel *getReport (const CSMWorld::UniversalId& id);
|
CSMTools::ReportModel *getReport (const CSMWorld::UniversalId& id);
|
||||||
///< The ownership of the returned report is not transferred.
|
///< The ownership of the returned report is not transferred.
|
||||||
|
|
||||||
|
bool isBlacklisted (const CSMWorld::UniversalId& id) const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void stateChanged (int state, CSMDoc::Document *document);
|
void stateChanged (int state, CSMDoc::Document *document);
|
||||||
|
|
|
@ -52,7 +52,7 @@ CSMDoc::DocumentManager::~DocumentManager()
|
||||||
void CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
|
void CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
|
||||||
bool new_)
|
bool new_)
|
||||||
{
|
{
|
||||||
Document *document = new Document (mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager);
|
Document *document = new Document (mConfiguration, files, new_, savePath, mResDir, mEncoding, mResourcesManager, mBlacklistedScripts);
|
||||||
|
|
||||||
mDocuments.push_back (document);
|
mDocuments.push_back (document);
|
||||||
|
|
||||||
|
@ -85,6 +85,11 @@ void CSMDoc::DocumentManager::setEncoding (ToUTF8::FromType encoding)
|
||||||
mEncoding = encoding;
|
mEncoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSMDoc::DocumentManager::setBlacklistedScripts (const std::vector<std::string>& scriptIds)
|
||||||
|
{
|
||||||
|
mBlacklistedScripts = scriptIds;
|
||||||
|
}
|
||||||
|
|
||||||
void CSMDoc::DocumentManager::listResources()
|
void CSMDoc::DocumentManager::listResources()
|
||||||
{
|
{
|
||||||
mResourcesManager.listResources();
|
mResourcesManager.listResources();
|
||||||
|
|
|
@ -34,6 +34,7 @@ namespace CSMDoc
|
||||||
Loader mLoader;
|
Loader mLoader;
|
||||||
ToUTF8::FromType mEncoding;
|
ToUTF8::FromType mEncoding;
|
||||||
CSMWorld::ResourcesManager mResourcesManager;
|
CSMWorld::ResourcesManager mResourcesManager;
|
||||||
|
std::vector<std::string> mBlacklistedScripts;
|
||||||
|
|
||||||
DocumentManager (const DocumentManager&);
|
DocumentManager (const DocumentManager&);
|
||||||
DocumentManager& operator= (const DocumentManager&);
|
DocumentManager& operator= (const DocumentManager&);
|
||||||
|
@ -53,6 +54,8 @@ namespace CSMDoc
|
||||||
|
|
||||||
void setEncoding (ToUTF8::FromType encoding);
|
void setEncoding (ToUTF8::FromType encoding);
|
||||||
|
|
||||||
|
void setBlacklistedScripts (const std::vector<std::string>& scriptIds);
|
||||||
|
|
||||||
/// Ask OGRE for a list of available resources.
|
/// Ask OGRE for a list of available resources.
|
||||||
void listResources();
|
void listResources();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include <components/compiler/exception.hpp>
|
#include <components/compiler/exception.hpp>
|
||||||
#include <components/compiler/extensions0.hpp>
|
#include <components/compiler/extensions0.hpp>
|
||||||
|
|
||||||
|
#include "../doc/document.hpp"
|
||||||
|
|
||||||
#include "../world/data.hpp"
|
#include "../world/data.hpp"
|
||||||
|
|
||||||
void CSMTools::ScriptCheckStage::report (const std::string& message, const Compiler::TokenLoc& loc,
|
void CSMTools::ScriptCheckStage::report (const std::string& message, const Compiler::TokenLoc& loc,
|
||||||
|
@ -37,8 +39,8 @@ void CSMTools::ScriptCheckStage::report (const std::string& message, Type type)
|
||||||
(type==ErrorMessage ? "error: " : "warning: ") + message));
|
(type==ErrorMessage ? "error: " : "warning: ") + message));
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::ScriptCheckStage::ScriptCheckStage (const CSMWorld::Data& data)
|
CSMTools::ScriptCheckStage::ScriptCheckStage (const CSMDoc::Document& document)
|
||||||
: mData (data), mContext (data), mMessages (0)
|
: mDocument (document), mContext (document.getData()), mMessages (0)
|
||||||
{
|
{
|
||||||
/// \todo add an option to configure warning mode
|
/// \todo add an option to configure warning mode
|
||||||
setWarningsMode (0);
|
setWarningsMode (0);
|
||||||
|
@ -53,18 +55,25 @@ int CSMTools::ScriptCheckStage::setup()
|
||||||
mMessages = 0;
|
mMessages = 0;
|
||||||
mId.clear();
|
mId.clear();
|
||||||
|
|
||||||
return mData.getScripts().getSize();
|
return mDocument.getData().getScripts().getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSMTools::ScriptCheckStage::perform (int stage, Messages& messages)
|
void CSMTools::ScriptCheckStage::perform (int stage, Messages& messages)
|
||||||
{
|
{
|
||||||
|
mId = mDocument.getData().getScripts().getId (stage);
|
||||||
|
|
||||||
|
if (mDocument.isBlacklisted (
|
||||||
|
CSMWorld::UniversalId (CSMWorld::UniversalId::Type_Script, mId)))
|
||||||
|
return;
|
||||||
|
|
||||||
mMessages = &messages;
|
mMessages = &messages;
|
||||||
mId = mData.getScripts().getId (stage);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mFile = mData.getScripts().getRecord (stage).get().mId;
|
const CSMWorld::Data& data = mDocument.getData();
|
||||||
std::istringstream input (mData.getScripts().getRecord (stage).get().mScriptText);
|
|
||||||
|
mFile = data.getScripts().getRecord (stage).get().mId;
|
||||||
|
std::istringstream input (data.getScripts().getRecord (stage).get().mScriptText);
|
||||||
|
|
||||||
Compiler::Scanner scanner (*this, input, mContext.getExtensions());
|
Compiler::Scanner scanner (*this, input, mContext.getExtensions());
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,17 @@
|
||||||
|
|
||||||
#include "../world/scriptcontext.hpp"
|
#include "../world/scriptcontext.hpp"
|
||||||
|
|
||||||
|
namespace CSMDoc
|
||||||
|
{
|
||||||
|
class Document;
|
||||||
|
}
|
||||||
|
|
||||||
namespace CSMTools
|
namespace CSMTools
|
||||||
{
|
{
|
||||||
/// \brief VerifyStage: make sure that scripts compile
|
/// \brief VerifyStage: make sure that scripts compile
|
||||||
class ScriptCheckStage : public CSMDoc::Stage, private Compiler::ErrorHandler
|
class ScriptCheckStage : public CSMDoc::Stage, private Compiler::ErrorHandler
|
||||||
{
|
{
|
||||||
const CSMWorld::Data& mData;
|
const CSMDoc::Document& mDocument;
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
CSMWorld::ScriptContext mContext;
|
CSMWorld::ScriptContext mContext;
|
||||||
std::string mId;
|
std::string mId;
|
||||||
|
@ -28,7 +33,7 @@ namespace CSMTools
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ScriptCheckStage (const CSMWorld::Data& data);
|
ScriptCheckStage (const CSMDoc::Document& document);
|
||||||
|
|
||||||
virtual int setup();
|
virtual int setup();
|
||||||
///< \return number of steps
|
///< \return number of steps
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "../doc/state.hpp"
|
#include "../doc/state.hpp"
|
||||||
#include "../doc/operation.hpp"
|
#include "../doc/operation.hpp"
|
||||||
|
#include "../doc/document.hpp"
|
||||||
|
|
||||||
#include "../world/data.hpp"
|
#include "../world/data.hpp"
|
||||||
#include "../world/universalid.hpp"
|
#include "../world/universalid.hpp"
|
||||||
|
@ -80,13 +81,14 @@ CSMDoc::Operation *CSMTools::Tools::getVerifier()
|
||||||
|
|
||||||
mVerifier->appendStage (new ReferenceableCheckStage (mData.getReferenceables().getDataSet(), mData.getRaces(), mData.getClasses(), mData.getFactions()));
|
mVerifier->appendStage (new ReferenceableCheckStage (mData.getReferenceables().getDataSet(), mData.getRaces(), mData.getClasses(), mData.getFactions()));
|
||||||
|
|
||||||
mVerifier->appendStage (new ScriptCheckStage (mData));
|
mVerifier->appendStage (new ScriptCheckStage (mDocument));
|
||||||
}
|
}
|
||||||
|
|
||||||
return mVerifier;
|
return mVerifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMTools::Tools::Tools (CSMWorld::Data& data) : mData (data), mVerifier (0), mNextReportNumber (0)
|
CSMTools::Tools::Tools (CSMDoc::Document& document)
|
||||||
|
: mDocument (document), mData (document.getData()), mVerifier (0), mNextReportNumber (0)
|
||||||
{
|
{
|
||||||
// index 0: load error log
|
// index 0: load error log
|
||||||
mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel));
|
mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel));
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace CSMWorld
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
class Operation;
|
class Operation;
|
||||||
|
class Document;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CSMTools
|
namespace CSMTools
|
||||||
|
@ -24,6 +25,7 @@ namespace CSMTools
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
CSMDoc::Document& mDocument;
|
||||||
CSMWorld::Data& mData;
|
CSMWorld::Data& mData;
|
||||||
CSMDoc::Operation *mVerifier;
|
CSMDoc::Operation *mVerifier;
|
||||||
std::map<int, ReportModel *> mReports;
|
std::map<int, ReportModel *> mReports;
|
||||||
|
@ -44,7 +46,7 @@ namespace CSMTools
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Tools (CSMWorld::Data& data);
|
Tools (CSMDoc::Document& document);
|
||||||
|
|
||||||
virtual ~Tools();
|
virtual ~Tools();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue