1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 07:39:40 +00:00

Added check to load custom filters set when present.

This commit is contained in:
Marek Kochanowicz 2013-10-19 18:43:47 +02:00
parent 4e26a61db3
commit 184456892b
2 changed files with 28 additions and 19 deletions

View file

@ -8,10 +8,11 @@
#include "model/doc/document.hpp" #include "model/doc/document.hpp"
#include "model/world/data.hpp" #include "model/world/data.hpp"
#include <iostream>
CS::Editor::Editor() CS::Editor::Editor()
: mDocumentManager (mCfgMgr), mViewManager (mDocumentManager) : mDocumentManager (mCfgMgr), mViewManager (mDocumentManager)
{ {
mIpcServerName = "org.openmw.OpenCS"; mIpcServerName = "org.openmw.OpenCS";
@ -32,23 +33,23 @@ CS::Editor::Editor()
connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles())); connect (&mFileDialog, SIGNAL(openFiles()), this, SLOT(openFiles()));
connect (&mFileDialog, SIGNAL(createNewFile (const boost::filesystem::path&)), connect (&mFileDialog, SIGNAL(createNewFile (const boost::filesystem::path&)),
this, SLOT(createNewFile (const boost::filesystem::path&))); this, SLOT(createNewFile (const boost::filesystem::path&)));
connect (&mNewGame, SIGNAL (createRequest (const boost::filesystem::path&)), connect (&mNewGame, SIGNAL (createRequest (const boost::filesystem::path&)),
this, SLOT (createNewGame (const boost::filesystem::path&))); this, SLOT (createNewGame (const boost::filesystem::path&)));
} }
void CS::Editor::setupDataFiles() void CS::Editor::setupDataFiles()
{ {
boost::program_options::variables_map variables; boost::program_options::variables_map variables;
boost::program_options::options_description desc("Syntax: opencs <options>\nAllowed options"); boost::program_options::options_description desc("Syntax: opencs <options>\nAllowed options");
desc.add_options() desc.add_options()
("data", boost::program_options::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")->multitoken()) ("data", boost::program_options::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")->multitoken())
("data-local", boost::program_options::value<std::string>()->default_value("")) ("data-local", boost::program_options::value<std::string>()->default_value(""))
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false)) ("fs-strict", boost::program_options::value<bool>()->implicit_value(true)->default_value(false))
("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"), "set resources directory"); ("resources", boost::program_options::value<std::string>()->default_value("resources"));
boost::program_options::notify(variables); boost::program_options::notify(variables);
@ -58,7 +59,7 @@ void CS::Editor::setupDataFiles()
if (!variables["data"].empty()) { if (!variables["data"].empty()) {
dataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>()); dataDirs = Files::PathContainer(variables["data"].as<Files::PathContainer>());
} }
std::string local = variables["data-local"].as<std::string>(); std::string local = variables["data-local"].as<std::string>();
if (!local.empty()) { if (!local.empty()) {
dataLocal.push_back(Files::PathContainer::value_type(local)); dataLocal.push_back(Files::PathContainer::value_type(local));
@ -83,12 +84,12 @@ void CS::Editor::setupDataFiles()
} }
// Set the charset for reading the esm/esp files // Set the charset for reading the esm/esp files
// QString encoding = QString::fromStdString(variables["encoding"].as<std::string>()); // QString encoding = QString::fromStdString(variables["encoding"].as<std::string>());
//mFileDialog.setEncoding(encoding); //mFileDialog.setEncoding(encoding);
dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end()); dataDirs.insert (dataDirs.end(), dataLocal.begin(), dataLocal.end());
// Setting Resources directory. // Adding Resources directory. First check if there is a file defaultfilters in the user path.
mDocumentManager.setResourceDir(variables["resources"].as<std::string>()); mDocumentManager.setResourceDir(variables["resources"].as<std::string>());
for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter) for (Files::PathContainer::const_iterator iter = dataDirs.begin(); iter != dataDirs.end(); ++iter)
@ -222,4 +223,4 @@ int CS::Editor::run()
QApplication::setQuitOnLastWindowClosed (true); QApplication::setQuitOnLastWindowClosed (true);
return QApplication::exec(); return QApplication::exec();
} }

View file

@ -9,7 +9,7 @@
#endif #endif
void CSMDoc::Document::load (const std::vector<boost::filesystem::path>::const_iterator& begin, void CSMDoc::Document::load (const std::vector<boost::filesystem::path>::const_iterator& begin,
const std::vector<boost::filesystem::path>::const_iterator& end, bool lastAsModified) const std::vector<boost::filesystem::path>::const_iterator& end, bool lastAsModified)
{ {
assert (begin!=end); assert (begin!=end);
@ -2147,10 +2147,10 @@ void CSMDoc::Document::createBase()
} }
CSMDoc::Document::Document (const Files::ConfigurationManager& configuration, const std::vector< boost::filesystem::path >& files, const boost::filesystem::path& savePath, const boost::filesystem::path& resDir, bool new_) CSMDoc::Document::Document (const Files::ConfigurationManager& configuration, const std::vector< boost::filesystem::path >& files, const boost::filesystem::path& savePath, const boost::filesystem::path& resDir, bool new_)
: mSavePath (savePath), mContentFiles (files), mTools (mData), mResDir(resDir), : mSavePath (savePath), mContentFiles (files), mTools (mData), mResDir(resDir),
mProjectPath ((configuration.getUserPath() / "projects") / mProjectPath ((configuration.getUserPath() / "projects") /
(savePath.filename().string() + ".project")), (savePath.filename().string() + ".project")),
mSaving (*this, mProjectPath) mSaving (*this, mProjectPath)
{ {
if (files.empty()) if (files.empty())
throw std::runtime_error ("Empty content file sequence"); throw std::runtime_error ("Empty content file sequence");
@ -2181,9 +2181,17 @@ CSMDoc::Document::Document (const Files::ConfigurationManager& configuration, co
} }
else else
{ {
boost::filesystem::path filters = mResDir; boost::filesystem::path locCustomFiltersPath (configuration.getUserPath());
filters /= "defaultfilters.omwaddon.project"; locCustomFiltersPath /= "defaultfilters.omwaddon.project";
boost::filesystem::copy_file(mResDir, mProjectPath); if (boost::filesystem::exists(locCustomFiltersPath))
{
boost::filesystem::copy(locCustomFiltersPath, mProjectPath);
} else {
boost::filesystem::path filters(mResDir);
filters /= "defaultfilters.omwaddon.project";
boost::filesystem::copy_file(filters, mProjectPath);
}
getData().loadFile (mProjectPath, false, true);
} }
} }
@ -2198,7 +2206,7 @@ CSMDoc::Document::Document (const Files::ConfigurationManager& configuration, co
connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int))); connect (&mSaving, SIGNAL (progress (int, int, int)), this, SLOT (progress (int, int, int)));
connect (&mSaving, SIGNAL (done (int)), this, SLOT (operationDone (int))); connect (&mSaving, SIGNAL (done (int)), this, SLOT (operationDone (int)));
connect (&mSaving, SIGNAL (reportMessage (const QString&, int)), connect (&mSaving, SIGNAL (reportMessage (const QString&, int)),
this, SLOT (reportMessage (const QString&, int))); this, SLOT (reportMessage (const QString&, int)));
} }
CSMDoc::Document::~Document() CSMDoc::Document::~Document()