forked from mirror/openmw-tes3mp
copy meta data from game file when merging
This commit is contained in:
parent
1b663f01af
commit
47dd9505a9
9 changed files with 52 additions and 13 deletions
|
@ -2250,7 +2250,7 @@ CSMDoc::Document::Document (const VFS::Manager* vfs, const Files::ConfigurationM
|
|||
ToUTF8::FromType encoding, const CSMWorld::ResourcesManager& resourcesManager,
|
||||
const std::vector<std::string>& blacklistedScripts)
|
||||
: mVFS(vfs), mSavePath (savePath), mContentFiles (files), mNew (new_), mData (encoding, resourcesManager),
|
||||
mTools (*this),
|
||||
mTools (*this, encoding),
|
||||
mProjectPath ((configuration.getUserDataPath() / "projects") /
|
||||
(savePath.filename().string() + ".project")),
|
||||
mSavingOperation (*this, mProjectPath, encoding),
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#include "mergestages.hpp"
|
||||
|
||||
CSMTools::MergeOperation::MergeOperation (CSMDoc::Document& document)
|
||||
CSMTools::MergeOperation::MergeOperation (CSMDoc::Document& document, ToUTF8::FromType encoding)
|
||||
: CSMDoc::Operation (CSMDoc::State_Merging, true), mState (document)
|
||||
{
|
||||
appendStage (new FinishMergedDocumentStage (mState));
|
||||
appendStage (new FinishMergedDocumentStage (mState, encoding));
|
||||
}
|
||||
|
||||
void CSMTools::MergeOperation::setTarget (std::auto_ptr<CSMDoc::Document> document)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
#include "../doc/operation.hpp"
|
||||
|
||||
#include "mergestate.hpp"
|
||||
|
@ -22,7 +24,7 @@ namespace CSMTools
|
|||
|
||||
public:
|
||||
|
||||
MergeOperation (CSMDoc::Document& document);
|
||||
MergeOperation (CSMDoc::Document& document, ToUTF8::FromType encoding);
|
||||
|
||||
/// \attention Do not call this function while a merge is running.
|
||||
void setTarget (std::auto_ptr<CSMDoc::Document> document);
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
|
||||
#include "mergestate.hpp"
|
||||
|
||||
CSMTools::FinishMergedDocumentStage::FinishMergedDocumentStage (MergeState& state)
|
||||
: mState (state)
|
||||
#include "../doc/document.hpp"
|
||||
#include "../world/data.hpp"
|
||||
|
||||
CSMTools::FinishMergedDocumentStage::FinishMergedDocumentStage (MergeState& state, ToUTF8::FromType encoding)
|
||||
: mState (state), mEncoder (encoding)
|
||||
{}
|
||||
|
||||
int CSMTools::FinishMergedDocumentStage::setup()
|
||||
|
@ -14,5 +17,25 @@ int CSMTools::FinishMergedDocumentStage::setup()
|
|||
|
||||
void CSMTools::FinishMergedDocumentStage::perform (int stage, CSMDoc::Messages& messages)
|
||||
{
|
||||
// We know that the content file list contains at least two entries and that the first one
|
||||
// does exist on disc (otherwise it would have been impossible to initiate a merge on that
|
||||
// document).
|
||||
boost::filesystem::path path = mState.mSource.getContentFiles()[0];
|
||||
|
||||
ESM::ESMReader reader;
|
||||
reader.setEncoder (&mEncoder);
|
||||
reader.open (path.string());
|
||||
|
||||
CSMWorld::MetaData source;
|
||||
source.mId = "sys::meta";
|
||||
source.load (reader);
|
||||
|
||||
CSMWorld::MetaData target = mState.mTarget->getData().getMetaData();
|
||||
|
||||
target.mAuthor = source.mAuthor;
|
||||
target.mDescription = source.mDescription;
|
||||
|
||||
mState.mTarget->getData().setMetaData (target);
|
||||
|
||||
mState.mCompleted = true;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef CSM_TOOLS_MERGESTAGES_H
|
||||
#define CSM_TOOLS_MERGESTAGES_H
|
||||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
#include "../doc/stage.hpp"
|
||||
|
||||
namespace CSMTools
|
||||
|
@ -10,10 +12,11 @@ namespace CSMTools
|
|||
class FinishMergedDocumentStage : public CSMDoc::Stage
|
||||
{
|
||||
MergeState& mState;
|
||||
ToUTF8::Utf8Encoder mEncoder;
|
||||
|
||||
public:
|
||||
|
||||
FinishMergedDocumentStage (MergeState& state);
|
||||
FinishMergedDocumentStage (MergeState& state, ToUTF8::FromType encoding);
|
||||
|
||||
virtual int setup();
|
||||
///< \return number of steps
|
||||
|
|
|
@ -116,9 +116,9 @@ CSMDoc::OperationHolder *CSMTools::Tools::getVerifier()
|
|||
return &mVerifier;
|
||||
}
|
||||
|
||||
CSMTools::Tools::Tools (CSMDoc::Document& document)
|
||||
CSMTools::Tools::Tools (CSMDoc::Document& document, ToUTF8::FromType encoding)
|
||||
: mDocument (document), mData (document.getData()), mVerifierOperation (0),
|
||||
mSearchOperation (0), mMergeOperation (0), mNextReportNumber (0)
|
||||
mSearchOperation (0), mMergeOperation (0), mNextReportNumber (0), mEncoding (encoding)
|
||||
{
|
||||
// index 0: load error log
|
||||
mReports.insert (std::make_pair (mNextReportNumber++, new ReportModel));
|
||||
|
@ -201,7 +201,7 @@ void CSMTools::Tools::runMerge (std::auto_ptr<CSMDoc::Document> target)
|
|||
|
||||
if (!mMergeOperation)
|
||||
{
|
||||
mMergeOperation = new MergeOperation (mDocument);
|
||||
mMergeOperation = new MergeOperation (mDocument, mEncoding);
|
||||
mMerge.setOperation (mMergeOperation);
|
||||
connect (mMergeOperation, SIGNAL (mergeDone (CSMDoc::Document*)),
|
||||
this, SIGNAL (mergeDone (CSMDoc::Document*)));
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
#include <components/to_utf8/to_utf8.hpp>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
@ -44,6 +46,7 @@ namespace CSMTools
|
|||
std::map<int, ReportModel *> mReports;
|
||||
int mNextReportNumber;
|
||||
std::map<int, int> mActiveReports; // type, report number
|
||||
ToUTF8::FromType mEncoding;
|
||||
|
||||
// not implemented
|
||||
Tools (const Tools&);
|
||||
|
@ -59,7 +62,7 @@ namespace CSMTools
|
|||
|
||||
public:
|
||||
|
||||
Tools (CSMDoc::Document& document);
|
||||
Tools (CSMDoc::Document& document, ToUTF8::FromType encoding);
|
||||
|
||||
virtual ~Tools();
|
||||
|
||||
|
|
|
@ -483,7 +483,7 @@ CSMWorld::Data::Data (ToUTF8::FromType encoding, const ResourcesManager& resourc
|
|||
mMetaData.addColumn (new FormatColumn<MetaData>);
|
||||
mMetaData.addColumn (new AuthorColumn<MetaData>);
|
||||
mMetaData.addColumn (new FileDescriptionColumn<MetaData>);
|
||||
|
||||
|
||||
addModel (new IdTable (&mGlobals), UniversalId::Type_Global);
|
||||
addModel (new IdTable (&mGmsts), UniversalId::Type_Gmst);
|
||||
addModel (new IdTable (&mSkills), UniversalId::Type_Skill);
|
||||
|
@ -828,6 +828,12 @@ const CSMWorld::MetaData& CSMWorld::Data::getMetaData() const
|
|||
return mMetaData.getRecord (0).get();
|
||||
}
|
||||
|
||||
void CSMWorld::Data::setMetaData (const MetaData& metaData)
|
||||
{
|
||||
Record<MetaData> record (RecordBase::State_ModifiedOnly, 0, &metaData);
|
||||
mMetaData.setRecord (0, record);
|
||||
}
|
||||
|
||||
QAbstractItemModel *CSMWorld::Data::getTableModel (const CSMWorld::UniversalId& id)
|
||||
{
|
||||
std::map<UniversalId::Type, QAbstractItemModel *>::iterator iter = mModelIndex.find (id.getType());
|
||||
|
@ -880,7 +886,7 @@ int CSMWorld::Data::startLoading (const boost::filesystem::path& path, bool base
|
|||
|
||||
mMetaData.setRecord (0, Record<MetaData> (RecordBase::State_ModifiedOnly, 0, &metaData));
|
||||
}
|
||||
|
||||
|
||||
return mReader->getRecordCount();
|
||||
}
|
||||
|
||||
|
|
|
@ -255,6 +255,8 @@ namespace CSMWorld
|
|||
|
||||
const MetaData& getMetaData() const;
|
||||
|
||||
void setMetaData (const MetaData& metaData);
|
||||
|
||||
QAbstractItemModel *getTableModel (const UniversalId& id);
|
||||
///< If no table model is available for \a id, an exception is thrown.
|
||||
///
|
||||
|
|
Loading…
Reference in a new issue