mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 12:09:41 +00:00
Issue #168: Configuration cleanup, part 2
Corrected --data and --data-local parameters handling. Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
This commit is contained in:
parent
54cb6deab9
commit
d43455fd57
8 changed files with 32 additions and 31 deletions
|
@ -127,7 +127,7 @@ DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent)
|
||||||
void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
||||||
{
|
{
|
||||||
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
// Put the paths in a boost::filesystem vector to use with Files::Collections
|
||||||
std::vector<boost::filesystem::path> dataDirs;
|
Files::PathContainer dataDirs;
|
||||||
|
|
||||||
foreach (const QString ¤tPath, paths) {
|
foreach (const QString ¤tPath, paths) {
|
||||||
dataDirs.push_back(boost::filesystem::path(currentPath.toStdString()));
|
dataDirs.push_back(boost::filesystem::path(currentPath.toStdString()));
|
||||||
|
@ -142,8 +142,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
||||||
|
|
||||||
for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter)
|
for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter)
|
||||||
{
|
{
|
||||||
std::string filename = boost::filesystem::path (iter->second.filename()).string();
|
QString currentMaster = QString::fromStdString(
|
||||||
QString currentMaster = QString::fromStdString(filename);
|
boost::filesystem::path (iter->second.filename()).string());
|
||||||
|
|
||||||
const QList<QTableWidgetItem*> itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly);
|
const QList<QTableWidgetItem*> itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly);
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
||||||
ESMReader fileReader;
|
ESMReader fileReader;
|
||||||
QStringList availableMasters; // Will contain all found masters
|
QStringList availableMasters; // Will contain all found masters
|
||||||
|
|
||||||
fileReader.setEncoding("win1252");
|
fileReader.setEncoding("win1252"); // FIXME: This should be configurable!
|
||||||
fileReader.open(iter->second.string());
|
fileReader.open(iter->second.string());
|
||||||
|
|
||||||
// First we fill the availableMasters and the mMastersWidget
|
// First we fill the availableMasters and the mMastersWidget
|
||||||
|
@ -190,8 +190,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
|
||||||
// Now we put the current plugin in the mDataFilesModel under its masters
|
// Now we put the current plugin in the mDataFilesModel under its masters
|
||||||
QStandardItem *parent = new QStandardItem(availableMasters.join(","));
|
QStandardItem *parent = new QStandardItem(availableMasters.join(","));
|
||||||
|
|
||||||
std::string filename = boost::filesystem::path (iter->second.filename()).string();
|
QStandardItem *child = new QStandardItem(QString::fromStdString(
|
||||||
QStandardItem *child = new QStandardItem(QString::fromStdString(std::string(filename)));
|
boost::filesystem::path (iter->second.filename()).string()));
|
||||||
|
|
||||||
const QList<QStandardItem*> masterList = mDataFilesModel->findItems(availableMasters.join(","));
|
const QList<QStandardItem*> masterList = mDataFilesModel->findItems(availableMasters.join(","));
|
||||||
|
|
||||||
|
|
|
@ -252,9 +252,8 @@ void OMW::Engine::loadBSA()
|
||||||
Bsa::addBSA (iter->second.string());
|
Bsa::addBSA (iter->second.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string m = mDataDir.string();
|
std::cout << "Data dir " << mDataDir.string() << std::endl;
|
||||||
std::cout << "Data dir" << m << "\n";
|
Bsa::addDir(mDataDir.string(), mFSStrict);
|
||||||
Bsa::addDir(m, mFSStrict);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add resources directory
|
// add resources directory
|
||||||
|
@ -273,12 +272,11 @@ void OMW::Engine::enableFSStrict(bool fsStrict)
|
||||||
|
|
||||||
// Set data dir
|
// Set data dir
|
||||||
|
|
||||||
void OMW::Engine::setDataDirs (const std::vector<boost::filesystem::path>& dataDirs)
|
void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs)
|
||||||
{
|
{
|
||||||
/// \todo remove mDataDir, once resources system can handle multiple directories
|
/// \todo remove mDataDir, once resources system can handle multiple directories
|
||||||
assert (!dataDirs.empty());
|
assert (!dataDirs.empty());
|
||||||
mDataDir = dataDirs[0];
|
mDataDir = dataDirs.back();
|
||||||
|
|
||||||
mFileCollections = Files::Collections (dataDirs, !mFSStrict);
|
mFileCollections = Files::Collections (dataDirs, !mFSStrict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace OMW
|
||||||
void enableFSStrict(bool fsStrict);
|
void enableFSStrict(bool fsStrict);
|
||||||
|
|
||||||
/// Set data dirs
|
/// Set data dirs
|
||||||
void setDataDirs(const Files::Collections::PathContainer& dataDirs);
|
void setDataDirs(const Files::PathContainer& dataDirs);
|
||||||
|
|
||||||
/// Set resource dir
|
/// Set resource dir
|
||||||
void setResourceDir(const boost::filesystem::path& parResDir);
|
void setResourceDir(const boost::filesystem::path& parResDir);
|
||||||
|
|
|
@ -57,7 +57,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio
|
||||||
desc.add_options()
|
desc.add_options()
|
||||||
("help", "print help message")
|
("help", "print help message")
|
||||||
("version", "print version information and quit")
|
("version", "print version information and quit")
|
||||||
("data", bpo::value<Files::Collections::PathContainer>()->default_value(Files::Collections::PathContainer(), "data")
|
("data", bpo::value<Files::PathContainer>()->default_value(Files::PathContainer(), "data")
|
||||||
->multitoken(), "set data directories (later directories have higher priority)")
|
->multitoken(), "set data directories (later directories have higher priority)")
|
||||||
|
|
||||||
("data-local", bpo::value<std::string>()->default_value(""),
|
("data-local", bpo::value<std::string>()->default_value(""),
|
||||||
|
@ -153,17 +153,17 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio
|
||||||
// directory settings
|
// directory settings
|
||||||
engine.enableFSStrict(variables["fs-strict"].as<bool>());
|
engine.enableFSStrict(variables["fs-strict"].as<bool>());
|
||||||
|
|
||||||
Files::Collections::PathContainer dataDirs = variables["data"].as<Files::Collections::PathContainer>();
|
Files::PathContainer dataDirs(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())
|
||||||
{
|
{
|
||||||
dataDirs.push_back(local);
|
dataDirs.push_back(Files::PathContainer::value_type(local));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataDirs.empty())
|
if (dataDirs.empty())
|
||||||
{
|
{
|
||||||
dataDirs.push_back(cfgMgr.getLocalDataPath().string());
|
dataDirs.push_back(cfgMgr.getLocalDataPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.setDataDirs(dataDirs);
|
engine.setDataDirs(dataDirs);
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Files
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections::Collections(const std::vector<boost::filesystem::path>& directories, bool foldCase)
|
Collections::Collections(const Files::PathContainer& directories, bool foldCase)
|
||||||
: mDirectories(directories)
|
: mDirectories(directories)
|
||||||
, mFoldCase(foldCase)
|
, mFoldCase(foldCase)
|
||||||
, mCollections()
|
, mCollections()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef COMPONENTS_FILES_COLLECTION_HPP
|
#ifndef COMPONENTS_FILES_COLLECTION_HPP
|
||||||
#define COMPONENTS_FILES_COLLECTION_HPP
|
#define COMPONENTS_FILES_COLLECTION_HPP
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
|
@ -13,12 +12,10 @@ namespace Files
|
||||||
class Collections
|
class Collections
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::vector<boost::filesystem::path> PathContainer;
|
|
||||||
|
|
||||||
Collections();
|
Collections();
|
||||||
|
|
||||||
///< Directories are listed with increasing priority.
|
///< Directories are listed with increasing priority.
|
||||||
Collections(const PathContainer& directories, bool foldCase);
|
Collections(const Files::PathContainer& directories, bool foldCase);
|
||||||
|
|
||||||
///< Return a file collection for the given extension. Extension must contain the
|
///< Return a file collection for the given extension. Extension must contain the
|
||||||
/// leading dot and must be all lower-case.
|
/// leading dot and must be all lower-case.
|
||||||
|
@ -26,7 +23,7 @@ namespace Files
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef std::map<std::string, MultiDirCollection> MultiDirCollectionContainer;
|
typedef std::map<std::string, MultiDirCollection> MultiDirCollectionContainer;
|
||||||
PathContainer mDirectories;
|
Files::PathContainer mDirectories;
|
||||||
|
|
||||||
bool mFoldCase;
|
bool mFoldCase;
|
||||||
mutable MultiDirCollectionContainer mCollections;
|
mutable MultiDirCollectionContainer mCollections;
|
||||||
|
|
|
@ -39,21 +39,25 @@ namespace Files
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MultiDirCollection::MultiDirCollection (const std::vector<boost::filesystem::path>& directories,
|
MultiDirCollection::MultiDirCollection(const Files::PathContainer& directories,
|
||||||
const std::string& extension, bool foldCase)
|
const std::string& extension, bool foldCase)
|
||||||
: mFiles (NameLess (!foldCase))
|
: mFiles (NameLess (!foldCase))
|
||||||
{
|
{
|
||||||
NameEqual equal (!foldCase);
|
NameEqual equal (!foldCase);
|
||||||
|
|
||||||
for (std::vector<boost::filesystem::path>::const_iterator iter = directories.begin();
|
for (PathContainer::const_iterator iter = directories.begin();
|
||||||
iter!=directories.end(); ++iter)
|
iter!=directories.end(); ++iter)
|
||||||
{
|
{
|
||||||
boost::filesystem::path dataDirectory = *iter;
|
if (!boost::filesystem::is_directory(*iter))
|
||||||
|
|
||||||
for (boost::filesystem::directory_iterator iter (dataDirectory);
|
|
||||||
iter!=boost::filesystem::directory_iterator(); ++iter)
|
|
||||||
{
|
{
|
||||||
boost::filesystem::path path = *iter;
|
std::cout << "Skipping invalid directory: " << (*iter).string() << std::endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (boost::filesystem::directory_iterator dirIter(*iter);
|
||||||
|
dirIter != boost::filesystem::directory_iterator(); ++dirIter)
|
||||||
|
{
|
||||||
|
boost::filesystem::path path = *dirIter;
|
||||||
|
|
||||||
if (!equal (extension, boost::filesystem::path (path.extension()).string()))
|
if (!equal (extension, boost::filesystem::path (path.extension()).string()))
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
|
|
||||||
namespace Files
|
namespace Files
|
||||||
{
|
{
|
||||||
|
typedef std::vector<boost::filesystem::path> PathContainer;
|
||||||
|
|
||||||
struct NameLess
|
struct NameLess
|
||||||
{
|
{
|
||||||
bool mStrict;
|
bool mStrict;
|
||||||
|
@ -58,7 +60,7 @@ namespace Files
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MultiDirCollection (const std::vector<boost::filesystem::path>& directories,
|
MultiDirCollection (const Files::PathContainer& directories,
|
||||||
const std::string& extension, bool foldCase);
|
const std::string& extension, bool foldCase);
|
||||||
///< Directories are listed with increasing priority.
|
///< Directories are listed with increasing priority.
|
||||||
/// \param extension The extension that should be listed in this collection. Must
|
/// \param extension The extension that should be listed in this collection. Must
|
||||||
|
|
Loading…
Reference in a new issue