From 37e272b3b5e18d1a93a1d69804a96845f8762ba1 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 13 Jan 2012 20:41:38 +0100 Subject: [PATCH 01/17] Issue #178 - workaround for compilation problems with ogre 1.8.0. --- components/bsa/bsa_archive.cpp | 6 ++++++ extern/caelum/src/CaelumPlugin.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 2178be318..87b46b34c 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -221,6 +221,12 @@ class BSAArchive : public Archive { BSAFile arc; + FileInfoListPtr findFileInfo(const String&, bool, bool) const + { + static FileInfoListPtr filp(new FileInfoList()); + return filp; + } + public: BSAArchive(const String& name) : Archive(name, "BSA") diff --git a/extern/caelum/src/CaelumPlugin.cpp b/extern/caelum/src/CaelumPlugin.cpp index 288ad9220..340a26559 100644 --- a/extern/caelum/src/CaelumPlugin.cpp +++ b/extern/caelum/src/CaelumPlugin.cpp @@ -21,17 +21,17 @@ along with Caelum. If not, see . #include "CaelumPrecompiled.h" #include "CaelumPlugin.h" -template<> Caelum::CaelumPlugin* Ogre::Singleton::ms_Singleton = 0; +template<> Caelum::CaelumPlugin* Ogre::Singleton::msSingleton = 0; namespace Caelum { CaelumPlugin* CaelumPlugin::getSingletonPtr () { - return ms_Singleton; + return msSingleton; } CaelumPlugin& CaelumPlugin::getSingleton () { - assert (ms_Singleton); - return *ms_Singleton; + assert (msSingleton); + return *msSingleton; } extern "C" void CAELUM_EXPORT dllStartPlugin () { From 96ed96d4dd432b3ee78c081575f888d0692c78c5 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 16 Jan 2012 23:09:25 +0100 Subject: [PATCH 02/17] Quick test at getting Morrowinds install path from the registry on windows --- components/files/path.hpp | 2 +- components/files/windowspath.cpp | 37 +++++++++++++++++++++++++++++++- components/files/windowspath.hpp | 7 ++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/components/files/path.hpp b/components/files/path.hpp index 0788cefb1..5a4cf337b 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -30,7 +30,7 @@ #include namespace Files { typedef LinuxPath TargetPathType; } -#elif defined(__WIN32) || defined(__WINDOWS__) +#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WINDOWS) #include namespace Files { typedef WindowsPath TargetPathType; } diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f42f149c1..5c87eba92 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -5,7 +5,10 @@ #include #include -#include +#include +#include + +#pragma comment(lib, "Shlwapi.lib") namespace Files { @@ -67,6 +70,38 @@ boost::filesystem::path WindowsPath::getRuntimeDataPath() const return boost::filesystem::path("./data/"); } +boost::filesystem::path WindowsPath::getInstallPath() const +{ + boost::filesystem::path installPath(""); + + HKEY hKey; + + BOOL f64 = FALSE; + LPCTSTR regkey; + if (IsWow64Process(GetCurrentProcess(), &f64) && f64) + { + regkey = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\Morrowind"; + } + else + { + regkey = "SOFTWARE\\Bethesda Softworks\\Morrowind"; + } + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(regkey), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) + { + //Key existed, let's try to read the install dir + char* data = new char[4096]; + int len = 4096; + + if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)data, (LPDWORD)&len) == ERROR_SUCCESS) + { + installPath = data; + } + } + + return installPath; +} + } /* namespace Files */ #endif /* defined(_WIN32) || defined(__WINDOWS__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 47dfc08d8..4550fc05f 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -81,6 +81,13 @@ struct WindowsPath * \return boost::filesystem::path */ boost::filesystem::path getRuntimeDataPath() const; + + /** + * \brief Gets the path of the installed Morrowind version if there is one. + * + * \return boost::filesystem::path + */ + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ From 8663177ad175d549ef9d08c26e9e740d10d2b73e Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 16 Jan 2012 23:21:13 +0100 Subject: [PATCH 03/17] Oops, forgot the delete... --- components/files/windowspath.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 5c87eba92..d83877232 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -97,6 +97,8 @@ boost::filesystem::path WindowsPath::getInstallPath() const { installPath = data; } + + delete[] data; } return installPath; From b4174b64195ddf6d03ded66dd574d80879c30708 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Tue, 17 Jan 2012 09:02:45 +0100 Subject: [PATCH 04/17] Vector instead of new/delete --- components/files/windowspath.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index d83877232..4fa70980e 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -90,15 +90,13 @@ boost::filesystem::path WindowsPath::getInstallPath() const if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT(regkey), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) { //Key existed, let's try to read the install dir - char* data = new char[4096]; - int len = 4096; + std::vector buf(512); + int len = 512; - if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)data, (LPDWORD)&len) == ERROR_SUCCESS) + if (RegQueryValueEx(hKey, TEXT("Installed Path"), NULL, NULL, (LPBYTE)&buf[0], (LPDWORD)&len) == ERROR_SUCCESS) { - installPath = data; + installPath = &buf[0]; } - - delete[] data; } return installPath; From 16c214a17af6c4506d89bad139a4d66e7423f180 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 17 Jan 2012 19:18:17 +0100 Subject: [PATCH 05/17] find InstalledPath in wine registry; mInstalledPath in Files::Path --- components/files/linuxpath.cpp | 70 ++++++++++++++++++++++++++++++++++ components/files/linuxpath.hpp | 8 ++++ components/files/path.hpp | 22 +++++++++++ 3 files changed, 100 insertions(+) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index c485002fd..b11f27305 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -154,6 +154,76 @@ boost::filesystem::path LinuxPath::getRuntimeDataPath() const return boost::filesystem::path("./data/"); } +boost::filesystem::path LinuxPath::getInstallPath() const +{ + char *homePath = getenv("HOME"); + if(!homePath) + { + return boost::filesystem::path(""); + } + + boost::filesystem::path wineDefaultRegistry(homePath); + wineDefaultRegistry /= ".wine/system.reg"; + + boost::filesystem::path wineDriveC(homePath); + wineDriveC /= ".wine/drive_c"; + + boost::filesystem::file_status fileStatus = boost::filesystem::status(wineDefaultRegistry); + boost::filesystem::file_status dirStatus = boost::filesystem::status(wineDriveC); + if(!boost::filesystem::is_regular_file(fileStatus) || !boost::filesystem::is_directory(dirStatus)) + { + return boost::filesystem::path(""); + } + + + boost::filesystem::ifstream file(wineDefaultRegistry); + bool isRegEntry = false; + std::string line; + int startPos, pos; + + while (std::getline(file, line)) + { + if(line.length() > 0 && line[0] == '[') // we found an entry + { + std::string regkey = line.substr(1, line.find(']')-1); + if( regkey.compare("SOFTWARE\\\\Wow6432Node\\\\Bethesda Softworks\\\\Morrowind") == 0 + || regkey.compare("SOFTWARE\\\\Bethesda Softworks\\\\Morrowind") == 0 ) + { + isRegEntry = true; + } + } + else if(isRegEntry) + { + if(line.length() == 0 || line[0] != '"') // empty line means new registry key + { + break; + } + std::string key = line.substr(1, line.find('"', 1)-1); + if(key.compare("Installed Path") == 0) { + startPos = line.find('=')+2; + std::string installPath = line.substr(startPos, line.find('"', startPos+1)-startPos); + installPath.replace(0, 2, wineDriveC.string()); + + pos = -1; + do + { + pos = static_cast(installPath.find("\\\\", pos+1)); + if(static_cast(pos) == std::string::npos) + { + break; + } + + installPath.replace(pos, 2, "/"); + } while(true); + + return boost::filesystem::path(installPath); + } + } + } + + return boost::filesystem::path(""); +} + } /* namespace Files */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index d6e717fc4..62cf93664 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -26,6 +26,7 @@ #if defined(__linux__) #include +#include /** * \namespace Files @@ -81,6 +82,13 @@ struct LinuxPath * \return boost::filesystem::path */ boost::filesystem::path getRuntimeDataPath() const; + + /** + * \brief Gets the path of the installed Morrowind version if there is one. + * + * \return boost::filesystem::path + */ + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ diff --git a/components/files/path.hpp b/components/files/path.hpp index 5a4cf337b..5139d9f78 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -76,6 +76,7 @@ struct Path , mLocalDataPath(mPath.getLocalDataPath()) , mGlobalDataPath(mPath.getGlobalDataPath()) , mRuntimeDataPath(mPath.getRuntimeDataPath()) + , mInstalledPath(mPath.getInstallPath()) { if (!application_name.empty()) { @@ -209,6 +210,26 @@ struct Path mRuntimeDataPath = path; } + /** + * \brief Return path pointing to the directory where application was started. + * + * \return boost::filesystem::path + */ + const boost::filesystem::path& getInstalledPath() const + { + return mInstalledPath; + } + + /** + * \brief Sets new runtime data directory. + * + * \param [in] path - New path + */ + void setInstalledPath(const boost::filesystem::path& path) + { + mInstalledPath = path; + } + private: PathType mPath; @@ -223,6 +244,7 @@ struct Path boost::filesystem::path mRuntimeDataPath; /**< Runtime path to the configuration files. By default it is a 'data' directory in same directory where application was run */ + boost::filesystem::path mInstalledPath; /**< Runtime path to the configuration files. */ }; From 62eaaab69d607c11ae7eb645fe5df56243505383 Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Tue, 17 Jan 2012 23:19:17 +0100 Subject: [PATCH 06/17] move include from .hpp to .cpp; line.empty() instead of line.size() > 0; change type of startPos and pos and move to other scope --- components/files/linuxpath.cpp | 12 +++++++----- components/files/linuxpath.hpp | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index b11f27305..5ca0856f1 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -28,6 +28,7 @@ #include #include #include +#include /** * \namespace Files @@ -179,11 +180,10 @@ boost::filesystem::path LinuxPath::getInstallPath() const boost::filesystem::ifstream file(wineDefaultRegistry); bool isRegEntry = false; std::string line; - int startPos, pos; while (std::getline(file, line)) { - if(line.length() > 0 && line[0] == '[') // we found an entry + if(!line.empty() && line[0] == '[') // we found an entry { std::string regkey = line.substr(1, line.find(']')-1); if( regkey.compare("SOFTWARE\\\\Wow6432Node\\\\Bethesda Softworks\\\\Morrowind") == 0 @@ -194,12 +194,14 @@ boost::filesystem::path LinuxPath::getInstallPath() const } else if(isRegEntry) { - if(line.length() == 0 || line[0] != '"') // empty line means new registry key + if(line.empty() || line[0] != '"') // empty line means new registry key { break; } std::string key = line.substr(1, line.find('"', 1)-1); if(key.compare("Installed Path") == 0) { + std::string::size_type pos, startPos; + startPos = line.find('=')+2; std::string installPath = line.substr(startPos, line.find('"', startPos+1)-startPos); installPath.replace(0, 2, wineDriveC.string()); @@ -207,8 +209,8 @@ boost::filesystem::path LinuxPath::getInstallPath() const pos = -1; do { - pos = static_cast(installPath.find("\\\\", pos+1)); - if(static_cast(pos) == std::string::npos) + pos = installPath.find("\\\\", pos+1); + if(pos == std::string::npos) { break; } diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 62cf93664..62cc14fff 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -26,7 +26,6 @@ #if defined(__linux__) #include -#include /** * \namespace Files From 463acb2f75b339d075d08ed9285eaba3ab97044d Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Wed, 28 Sep 2011 03:40:27 +0400 Subject: [PATCH 07/17] Use linuxpath for FreeBSD as well --- components/files/linuxpath.cpp | 4 ++-- components/files/linuxpath.hpp | 4 ++-- components/files/path.hpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index c485002fd..27581a1e2 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -22,7 +22,7 @@ #include "linuxpath.hpp" -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include #include @@ -157,4 +157,4 @@ boost::filesystem::path LinuxPath::getRuntimeDataPath() const } /* namespace Files */ -#endif /* defined(__linux__) */ +#endif /* defined(__linux__) || defined(__FreeBSD__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index d6e717fc4..53f7a73b4 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -23,7 +23,7 @@ #ifndef COMPONENTS_FILES_LINUXPATH_H #define COMPONENTS_FILES_LINUXPATH_H -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include @@ -85,6 +85,6 @@ struct LinuxPath } /* namespace Files */ -#endif /* defined(__linux__) */ +#endif /* defined(__linux__) || defined(__FreeBSD__) */ #endif /* COMPONENTS_FILES_LINUXPATH_H */ diff --git a/components/files/path.hpp b/components/files/path.hpp index 0788cefb1..78de9c585 100644 --- a/components/files/path.hpp +++ b/components/files/path.hpp @@ -26,7 +26,7 @@ #include #include -#if defined(__linux__) +#if defined(__linux__) || defined(__FreeBSD__) #include namespace Files { typedef LinuxPath TargetPathType; } From 6b3242f5141b68b0a2c814fcb47adda814c52dfd Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 21 Jan 2012 01:09:06 +0100 Subject: [PATCH 08/17] Updated .gitignore file Updated .gitignore file - added ignore rules for: *.a, *.o, cmake_install.cmake, moc_*.cxx files. Signed-off-by: Lukasz Gromanowski --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index ada874bb2..e57bcfc62 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,7 @@ Docs/mainpage.hpp CMakeFiles */CMakeFiles CMakeCache.txt +moc_*.cxx +cmake_install.cmake +*.[ao] + From 7c24ae9ac7f48aa4b1ba3a17db2e9b6cd57b7d41 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 21 Jan 2012 01:14:35 +0100 Subject: [PATCH 09/17] Issue #168 - Configuration cleanup - WIP This is "work in progress" commit, it shall not be merged alone, without succeeding commits (it's not fully functional). Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 12 +- apps/launcher/datafilespage.hpp | 6 +- apps/launcher/graphicspage.cpp | 13 +- apps/launcher/graphicspage.hpp | 7 +- apps/launcher/maindialog.cpp | 10 +- apps/launcher/maindialog.hpp | 4 +- apps/openmw/engine.cpp | 6 +- apps/openmw/engine.hpp | 10 +- apps/openmw/main.cpp | 10 +- components/CMakeLists.txt | 6 +- components/cfg/configurationmanager.cpp | 157 ---------------- components/cfg/configurationmanager.hpp | 62 ------- components/files/configurationmanager.cpp | 177 +++++++++++++++++++ components/files/configurationmanager.hpp | 65 +++++++ components/files/{path.hpp => fixedpath.hpp} | 78 +++----- components/files/linuxpath.cpp | 82 ++------- components/files/linuxpath.hpp | 30 +--- components/files/macospath.cpp | 62 +------ components/files/macospath.hpp | 28 +-- components/files/windowspath.cpp | 37 ++-- components/files/windowspath.hpp | 30 +--- 21 files changed, 354 insertions(+), 538 deletions(-) delete mode 100644 components/cfg/configurationmanager.cpp delete mode 100644 components/cfg/configurationmanager.hpp create mode 100644 components/files/configurationmanager.cpp create mode 100644 components/files/configurationmanager.hpp rename components/files/{path.hpp => fixedpath.hpp} (68%) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index c8311846f..8b59f1b81 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "datafilespage.hpp" #include "lineedit.hpp" @@ -26,7 +26,9 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2) return index1.row() <= index2.row(); } -DataFilesPage::DataFilesPage(QWidget *parent) : QWidget(parent) +DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent) + : QWidget(parent) + , mCfgMgr(cfg) { mDataFilesModel = new QStandardItemModel(); // Contains all plugins with masters mPluginsModel = new PluginsModel(); // Contains selectable plugins @@ -236,13 +238,11 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) void DataFilesPage::setupConfig() { - Cfg::ConfigurationManager cfg; - - QString config = (cfg.getRuntimeConfigPath() / "launcher.cfg").string().c_str(); + QString config = (mCfgMgr.getLocalPath() / "launcher.cfg").string().c_str(); QFile file(config); if (!file.exists()) { - config = QString::fromStdString((cfg.getLocalConfigPath() / "launcher.cfg").string()); + config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string()); } file.setFileName(config); // Just for displaying information diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index 2d0a385a7..db1068abd 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -19,12 +19,14 @@ class PluginsModel; class PluginsView; class ComboBox; +namespace Files { struct ConfigurationManager; } + class DataFilesPage : public QWidget { Q_OBJECT public: - DataFilesPage(QWidget *parent = 0); + DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); ComboBox *mProfilesComboBox; QSettings *mLauncherConfig; @@ -81,6 +83,8 @@ private: QAction *mCheckAction; QAction *mUncheckAction; + Files::ConfigurationManager& mCfgMgr; + void addPlugins(const QModelIndex &index); void removePlugins(const QModelIndex &index); void uncheckPlugins(); diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index 92fbf3350..d41a33356 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -1,8 +1,11 @@ #include #include "graphicspage.hpp" +#include -GraphicsPage::GraphicsPage(QWidget *parent) : QWidget(parent) +GraphicsPage::GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent) + : QWidget(parent) + , mCfgMgr(cfg) { QGroupBox *rendererGroup = new QGroupBox(tr("Renderer"), this); @@ -147,21 +150,21 @@ void GraphicsPage::createPages() void GraphicsPage::setupConfig() { - QString ogreCfg = mCfg.getOgreConfigPath().string().c_str(); + QString ogreCfg = mCfgMgr.getOgreConfigPath().string().c_str(); QFile file(ogreCfg); mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); } void GraphicsPage::setupOgre() { - QString pluginCfg = mCfg.getPluginsConfigPath().string().c_str(); + QString pluginCfg = mCfgMgr.getPluginsConfigPath().string().c_str(); QFile file(pluginCfg); // Create a log manager so we can surpress debug text to stdout/stderr Ogre::LogManager* logMgr = OGRE_NEW Ogre::LogManager; - logMgr->createLog((mCfg.getLogPath().string() + "/launcherOgre.log"), true, false, false); + logMgr->createLog((mCfgMgr.getLogPath().string() + "/launcherOgre.log"), true, false, false); - QString ogreCfg = QString::fromStdString(mCfg.getOgreConfigPath().string()); + QString ogreCfg = QString::fromStdString(mCfgMgr.getOgreConfigPath().string()); file.setFileName(ogreCfg); //we need to check that the path to the configuration file exists before we diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index 5d50cfc61..ffd7a41b8 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -7,19 +7,20 @@ #include #include #include -#include class QComboBox; class QCheckBox; class QStackedWidget; class QSettings; +namespace Files { struct ConfigurationManager; } + class GraphicsPage : public QWidget { Q_OBJECT public: - GraphicsPage(QWidget *parent = 0); + GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); QSettings *mOgreConfig; @@ -29,7 +30,7 @@ public slots: void rendererChanged(const QString &renderer); private: - Cfg::ConfigurationManager mCfg; + Files::ConfigurationManager& mCfgMgr; Ogre::Root *mOgre; Ogre::RenderSystem *mSelectedRenderSystem; Ogre::RenderSystem *mOpenGLRenderSystem; diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 4ec8b309c..3bef0b6f9 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -152,20 +152,20 @@ QStringList MainDialog::readConfig(const QString &fileName) void MainDialog::createPages() { mPlayPage = new PlayPage(this); - mGraphicsPage = new GraphicsPage(this); - mDataFilesPage = new DataFilesPage(this); + mGraphicsPage = new GraphicsPage(mCfgMgr, this); + mDataFilesPage = new DataFilesPage(mCfgMgr, this); // Retrieve all data entries from the configs QStringList dataDirs; // Global location - QFile file(QString::fromStdString((mCfg.getGlobalConfigPath()/"openmw.cfg").string())); + QFile file(QString::fromStdString((mCfgMgr.getGlobalPath()/"openmw.cfg").string())); if (file.exists()) { dataDirs = readConfig(file.fileName()); } // User location - file.setFileName(QString::fromStdString((mCfg.getLocalConfigPath()/"openmw.cfg").string())); + file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (file.exists()) { dataDirs = readConfig(file.fileName()); } @@ -328,7 +328,7 @@ void MainDialog::writeConfig() dataFiles.append(mDataFilesPage->checkedPlugins()); // Open the config as a QFile - QFile file(QString::fromStdString((mCfg.getLocalConfigPath()/"openmw.cfg").string())); + QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { // File cannot be opened or created diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index 047050902..718fde4f7 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -3,7 +3,7 @@ #include -#include +#include class QListWidget; class QListWidgetItem; @@ -47,7 +47,7 @@ private: QStringList mDataDirs; bool mStrict; - Cfg::ConfigurationManager mCfg; + Files::ConfigurationManager mCfgMgr; }; #endif diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 7fa98f8e2..bbc68b8e2 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -17,7 +17,9 @@ #include #include #include -#include +#include +#include + #include #include "mwinput/inputmanager.hpp" @@ -154,7 +156,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt) return true; } -OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager) +OMW::Engine::Engine(Files::ConfigurationManager& configurationManager) : mOgre (0) , mPhysicEngine (0) , mShowFPS (false) diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 443f790a4..97079f5a5 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -11,7 +11,6 @@ #include #include -#include #include "mwworld/environment.hpp" #include "mwworld/ptr.hpp" @@ -54,6 +53,11 @@ namespace OEngine } } +namespace Files +{ + struct ConfigurationManager; +} + namespace OMW { /// \brief Main engine class, that brings together all the components of OpenMW @@ -104,7 +108,7 @@ namespace OMW virtual bool frameRenderingQueued (const Ogre::FrameEvent& evt); public: - Engine(Cfg::ConfigurationManager& configurationManager); + Engine(Files::ConfigurationManager& configurationManager); virtual ~Engine(); /// Enable strict filesystem mode (do not fold case) @@ -159,7 +163,7 @@ namespace OMW void setEncoding(const std::string& encoding); private: - Cfg::ConfigurationManager& mCfgMgr; + Files::ConfigurationManager& mCfgMgr; }; } diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 933d1c48a..0f66925d3 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -6,9 +6,9 @@ #include #include -#include +#include #include -#include +#include #include "engine.hpp" @@ -46,7 +46,7 @@ using namespace std; * \retval true - Everything goes OK * \retval false - Error */ -bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::ConfigurationManager& cfgMgr) +bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::ConfigurationManager& cfgMgr) { // Create a local alias for brevity namespace bpo = boost::program_options; @@ -166,7 +166,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::Configuratio if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath()); + dataDirs.push_back(cfgMgr.getDataPath("local:data?")); } engine.setDataDirs(dataDirs); @@ -220,7 +220,7 @@ int main(int argc, char**argv) try { - Cfg::ConfigurationManager cfgMgr; + Files::ConfigurationManager cfgMgr; OMW::Engine engine(cfgMgr); if (parseOptions(argc, argv, engine, cfgMgr)) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 75b8aff8c..3f7d6d49a 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -6,10 +6,6 @@ add_component_dir (bsa bsa_archive bsa_file ) -add_component_dir (cfg - configurationmanager - ) - add_component_dir (nif controlled effect nif_types record controller extra node record_ptr data nif_file property ) @@ -47,7 +43,7 @@ add_component_dir (misc ) add_component_dir (files - linuxpath windowspath macospath path multidircollection collections fileops + linuxpath windowspath macospath fixedpath multidircollection collections fileops configurationmanager ) add_component_dir (compiler diff --git a/components/cfg/configurationmanager.cpp b/components/cfg/configurationmanager.cpp deleted file mode 100644 index 0998debee..000000000 --- a/components/cfg/configurationmanager.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include "configurationmanager.hpp" - -#include -#include -#include - -namespace Cfg -{ - -static const char* const openmwCfgFile = "openmw.cfg"; -static const char* const ogreCfgFile = "ogre.cfg"; -static const char* const pluginsCfgFile = "plugins.cfg"; - - -ConfigurationManager::ConfigurationManager() - : mPath("openmw") -{ - /** - * According to task #168 plugins.cfg file shall be located in global - * configuration path or in runtime configuration path. - */ - mPluginsCfgPath = mPath.getGlobalConfigPath() / pluginsCfgFile; - if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) - { - mPluginsCfgPath = mPath.getRuntimeConfigPath() / pluginsCfgFile; - if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) - { - std::cerr << "Failed to find " << pluginsCfgFile << " file!" << std::endl; - mPluginsCfgPath.clear(); - } - } - - /** - * According to task #168 ogre.cfg file shall be located only - * in user configuration path. - */ - mOgreCfgPath = mPath.getLocalConfigPath() / ogreCfgFile; - - mLogPath = mPath.getLocalConfigPath(); -} - -ConfigurationManager::~ConfigurationManager() -{ -} - -void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, - boost::program_options::options_description& description) -{ - loadConfig(mPath.getLocalConfigPath(), variables, description); - boost::program_options::notify(variables); - loadConfig(mPath.getRuntimeConfigPath(), variables, description); - boost::program_options::notify(variables); - loadConfig(mPath.getGlobalConfigPath(), variables, description); - boost::program_options::notify(variables); -} - -void ConfigurationManager::loadConfig(const boost::filesystem::path& path, - boost::program_options::variables_map& variables, - boost::program_options::options_description& description) -{ - boost::filesystem::path cfgFile(path); - cfgFile /= std::string(openmwCfgFile); - if (boost::filesystem::is_regular_file(cfgFile)) - { - std::cout << "Loading config file: " << cfgFile.string() << "... "; - - std::ifstream configFileStream(cfgFile.string().c_str()); - if (configFileStream.is_open()) - { - boost::program_options::store(boost::program_options::parse_config_file( - configFileStream, description), variables); - - std::cout << "done." << std::endl; - } - else - { - std::cout << "failed." << std::endl; - } - } -} - -const boost::filesystem::path& ConfigurationManager::getGlobalConfigPath() const -{ - return mPath.getGlobalConfigPath(); -} - -void ConfigurationManager::setGlobalConfigPath(const boost::filesystem::path& newPath) -{ - mPath.setGlobalConfigPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getLocalConfigPath() const -{ - return mPath.getLocalConfigPath(); -} - -void ConfigurationManager::setLocalConfigPath(const boost::filesystem::path& newPath) -{ - mPath.setLocalConfigPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getRuntimeConfigPath() const -{ - return mPath.getRuntimeConfigPath(); -} - -void ConfigurationManager::setRuntimeConfigPath(const boost::filesystem::path& newPath) -{ - mPath.setRuntimeConfigPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const -{ - return mPath.getGlobalDataPath(); -} - -void ConfigurationManager::setGlobalDataPath(const boost::filesystem::path& newPath) -{ - mPath.setGlobalDataPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const -{ - return mPath.getLocalDataPath(); -} - -void ConfigurationManager::setLocalDataPath(const boost::filesystem::path& newPath) -{ - mPath.setLocalDataPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getRuntimeDataPath() const -{ - return mPath.getRuntimeDataPath(); -} - -void ConfigurationManager::setRuntimeDataPath(const boost::filesystem::path& newPath) -{ - mPath.setRuntimeDataPath(newPath); -} - -const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const -{ - return mOgreCfgPath; -} - -const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const -{ - return mPluginsCfgPath; -} - -const boost::filesystem::path& ConfigurationManager::getLogPath() const -{ - return mLogPath; -} - -} /* namespace Cfg */ diff --git a/components/cfg/configurationmanager.hpp b/components/cfg/configurationmanager.hpp deleted file mode 100644 index 7f13d0914..000000000 --- a/components/cfg/configurationmanager.hpp +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP -#define COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP - -#include -#include - -#include - -/** - * \namespace Cfg - */ -namespace Cfg -{ - -/** - * \struct ConfigurationManager - */ -struct ConfigurationManager -{ - ConfigurationManager(); - virtual ~ConfigurationManager(); - - void readConfiguration(boost::program_options::variables_map& variables, - boost::program_options::options_description& description); - - const boost::filesystem::path& getGlobalConfigPath() const; - void setGlobalConfigPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getLocalConfigPath() const; - void setLocalConfigPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getRuntimeConfigPath() const; - void setRuntimeConfigPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getGlobalDataPath() const; - void setGlobalDataPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getLocalDataPath() const; - void setLocalDataPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getRuntimeDataPath() const; - void setRuntimeDataPath(const boost::filesystem::path& newPath); - - const boost::filesystem::path& getOgreConfigPath() const; - const boost::filesystem::path& getPluginsConfigPath() const; - const boost::filesystem::path& getLogPath() const; - - private: - void loadConfig(const boost::filesystem::path& path, - boost::program_options::variables_map& variables, - boost::program_options::options_description& description); - - Files::Path<> mPath; - - boost::filesystem::path mOgreCfgPath; - boost::filesystem::path mPluginsCfgPath; - boost::filesystem::path mLogPath; -}; - -} /* namespace Cfg */ - -#endif /* COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP */ diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp new file mode 100644 index 000000000..224fd2649 --- /dev/null +++ b/components/files/configurationmanager.cpp @@ -0,0 +1,177 @@ +#include "configurationmanager.hpp" + +#include +#include +#include +#include + +namespace Files +{ + +static const char* const openmwCfgFile = "openmw.cfg"; +static const char* const ogreCfgFile = "ogre.cfg"; +static const char* const pluginsCfgFile = "plugins.cfg"; + +static const char* const mwDataToken = "?mw:data?"; +static const char* const localDataToken = "?local:data?"; +static const char* const userDataToken = "?user:data?"; +static const char* const globalDataToken = "?global:data?"; + +ConfigurationManager::ConfigurationManager() + : mFixedPath("openmw") +{ + setupTokensMapping(); + + /** + * According to task #168 plugins.cfg file shall be located in global + * configuration path or in runtime configuration path. + */ + mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; + if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) + { + mPluginsCfgPath = mFixedPath.getLocalPath() / pluginsCfgFile; + if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) + { + std::cerr << "Failed to find " << pluginsCfgFile << " file!" << std::endl; + mPluginsCfgPath.clear(); + } + } + + /** + * According to task #168 ogre.cfg file shall be located only + * in user configuration path. + */ + mOgreCfgPath = mFixedPath.getUserPath() / ogreCfgFile; + + /** + * FIXME: Logs shoudn't be stored in the same dir where configuration is placed. + */ + mLogPath = mFixedPath.getUserPath(); +} + +ConfigurationManager::~ConfigurationManager() +{ +} + +void ConfigurationManager::setupTokensMapping() +{ + mTokensMapping.insert(std::make_pair(mwDataToken, &ConfigurationManager::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &ConfigurationManager::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &ConfigurationManager::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &ConfigurationManager::getGlobalDataPath)); +} + +void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, + boost::program_options::options_description& description) +{ + loadConfig(mFixedPath.getUserPath(), variables, description); + boost::program_options::notify(variables); + loadConfig(mFixedPath.getLocalPath(), variables, description); + boost::program_options::notify(variables); + loadConfig(mFixedPath.getGlobalPath(), variables, description); + boost::program_options::notify(variables); +} + +void ConfigurationManager::loadConfig(const boost::filesystem::path& path, + boost::program_options::variables_map& variables, + boost::program_options::options_description& description) +{ + boost::filesystem::path cfgFile(path); + cfgFile /= std::string(openmwCfgFile); + if (boost::filesystem::is_regular_file(cfgFile)) + { + std::cout << "Loading config file: " << cfgFile.string() << "... "; + + std::ifstream configFileStream(cfgFile.string().c_str()); + if (configFileStream.is_open()) + { + boost::program_options::store(boost::program_options::parse_config_file( + configFileStream, description), variables); + + std::cout << "done." << std::endl; + } + else + { + std::cout << "failed." << std::endl; + } + } +} + +const boost::filesystem::path& ConfigurationManager::getGlobalPath() const +{ + return mFixedPath.getGlobalPath(); +} + +const boost::filesystem::path& ConfigurationManager::getUserPath() const +{ + return mFixedPath.getUserPath(); +} + +const boost::filesystem::path& ConfigurationManager::getLocalPath() const +{ + return mFixedPath.getLocalPath(); +} + +const boost::filesystem::path& ConfigurationManager::getDataPath(const std::string& type) const +{ + TokensMappingContainer::const_iterator it = mTokensMapping.find(type); + if (it != mTokensMapping.end()) + { + return ((this)->*(it->second))(); + } + + return mFixedPath.getLocalDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getInstallPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getInstallPath(); +} + +const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getGlobalDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getUserDataPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + + //return mFixedPath.getUserDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const +{ +// TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; + //return mFixedPath.getLocalDataPath(); +} + + +const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const +{ + return mOgreCfgPath; +} + +const boost::filesystem::path& ConfigurationManager::getPluginsConfigPath() const +{ + return mPluginsCfgPath; +} + +const boost::filesystem::path& ConfigurationManager::getLogPath() const +{ + return mLogPath; +} + +} /* namespace Cfg */ diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp new file mode 100644 index 000000000..3004b6281 --- /dev/null +++ b/components/files/configurationmanager.hpp @@ -0,0 +1,65 @@ +#ifndef COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP +#define COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP + +#include + +#include +#include + +#include + +/** + * \namespace Files + */ +namespace Files +{ + +/** + * \struct ConfigurationManager + */ +struct ConfigurationManager +{ + ConfigurationManager(); + virtual ~ConfigurationManager(); + + void readConfiguration(boost::program_options::variables_map& variables, + boost::program_options::options_description& description); + + /**< Fixed paths */ + const boost::filesystem::path& getGlobalPath() const; + const boost::filesystem::path& getUserPath() const; + const boost::filesystem::path& getLocalPath() const ; + + const boost::filesystem::path& getDataPath(const std::string& type) const; + + const boost::filesystem::path& getOgreConfigPath() const; + const boost::filesystem::path& getPluginsConfigPath() const; + const boost::filesystem::path& getLogPath() const; + + private: + typedef const boost::filesystem::path& (ConfigurationManager::*path_type_f)() const; + typedef std::tr1::unordered_map TokensMappingContainer; + + void loadConfig(const boost::filesystem::path& path, + boost::program_options::variables_map& variables, + boost::program_options::options_description& description); + + void setupTokensMapping(); + + const boost::filesystem::path& getInstallPath() const; + const boost::filesystem::path& getGlobalDataPath() const; + const boost::filesystem::path& getUserDataPath() const; + const boost::filesystem::path& getLocalDataPath() const; + + Files::FixedPath<> mFixedPath; + + boost::filesystem::path mOgreCfgPath; + boost::filesystem::path mPluginsCfgPath; + boost::filesystem::path mLogPath; + + TokensMappingContainer mTokensMapping; +}; + +} /* namespace Cfg */ + +#endif /* COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP */ diff --git a/components/files/path.hpp b/components/files/fixedpath.hpp similarity index 68% rename from components/files/path.hpp rename to components/files/fixedpath.hpp index 78de9c585..4e2b20e3c 100644 --- a/components/files/path.hpp +++ b/components/files/fixedpath.hpp @@ -18,10 +18,10 @@ * along with this program. If not, see . */ -/** \file components/files/path.hpp */ +/** \file components/files/fixedpath.hpp */ -#ifndef COMPONENTS_FILES_PATH_HPP -#define COMPONENTS_FILES_PATH_HPP +#ifndef COMPONENTS_FILES_FIXEDPATH_HPP +#define COMPONENTS_FILES_FIXEDPATH_HPP #include #include @@ -59,7 +59,7 @@ template < class P = TargetPathType > -struct Path +struct FixedPath { typedef P PathType; @@ -68,21 +68,21 @@ struct Path * * \param [in] application_name - Name of the application */ - Path(const std::string& application_name) + FixedPath(const std::string& application_name) : mPath() - , mLocalConfigPath(mPath.getLocalConfigPath()) - , mGlobalConfigPath(mPath.getGlobalConfigPath()) - , mRuntimeConfigPath(mPath.getRuntimeConfigPath()) - , mLocalDataPath(mPath.getLocalDataPath()) - , mGlobalDataPath(mPath.getGlobalDataPath()) - , mRuntimeDataPath(mPath.getRuntimeDataPath()) + , mUserPath(mPath.getUserPath()) + , mGlobalPath(mPath.getGlobalPath()) + , mLocalPath(mPath.getLocalPath()) + , mLocalDataPath() + , mGlobalDataPath() + , mRuntimeDataPath() { if (!application_name.empty()) { boost::filesystem::path suffix(application_name + std::string("/")); - mLocalConfigPath /= suffix; - mGlobalConfigPath /= suffix; + mUserPath /= suffix; + mGlobalPath /= suffix; mLocalDataPath /= suffix; mGlobalDataPath /= suffix; @@ -94,19 +94,9 @@ struct Path * * \return boost::filesystem::path */ - const boost::filesystem::path& getLocalConfigPath() const + const boost::filesystem::path& getUserPath() const { - return mLocalConfigPath; - } - - /** - * \brief Sets new local configuration path. - * - * \param [in] path - New path - */ - void setLocalConfigPath(const boost::filesystem::path& path) - { - mLocalConfigPath = path; + return mUserPath; } /** @@ -114,19 +104,9 @@ struct Path * * \return boost::filesystem::path */ - const boost::filesystem::path& getGlobalConfigPath() const + const boost::filesystem::path& getGlobalPath() const { - return mGlobalConfigPath; - } - - /** - * \brief Sets new global configuration path. - * - * \param [in] path - New path - */ - void setGlobalConfigPath(const boost::filesystem::path& path) - { - mGlobalConfigPath = path; + return mGlobalPath; } /** @@ -134,19 +114,9 @@ struct Path * * \return boost::filesystem::path */ - const boost::filesystem::path& getRuntimeConfigPath() const - { - return mRuntimeConfigPath; - } - - /** - * \brief Sets new runtime configuration path. - * - * \param [in] path - New path - */ - void setRuntimeConfigPath(const boost::filesystem::path& path) + const boost::filesystem::path& getLocalPath() const { - mRuntimeConfigPath = path; + return mLocalPath; } /** @@ -212,11 +182,9 @@ struct Path private: PathType mPath; - boost::filesystem::path mLocalConfigPath; /**< User local path to the configuration files */ - boost::filesystem::path mGlobalConfigPath; /**< Global path to the configuration files */ - boost::filesystem::path mRuntimeConfigPath; /**< Runtime path to the configuration files. - By default it is the same directory where - application was run */ + boost::filesystem::path mUserPath; /**< User path */ + boost::filesystem::path mGlobalPath; /**< Global path */ + boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ boost::filesystem::path mLocalDataPath; /**< User local application data path (user plugins / mods / etc.) */ boost::filesystem::path mGlobalDataPath; /**< Global application data path */ @@ -229,4 +197,4 @@ struct Path } /* namespace Files */ -#endif /* COMPONENTS_FILES_PATH_HPP */ +#endif /* COMPONENTS_FILES_FIXEDPATH_HPP */ diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 27581a1e2..11ddc3104 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -35,9 +35,9 @@ namespace Files { -boost::filesystem::path LinuxPath::getLocalConfigPath() const +boost::filesystem::path LinuxPath::getUserPath() const { - boost::filesystem::path localConfigPath("."); + boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); const char* theDir = getenv("OPENMW_CONFIG"); @@ -63,17 +63,17 @@ boost::filesystem::path LinuxPath::getLocalConfigPath() const } if (theDir != NULL) { - localConfigPath = boost::filesystem::path(theDir); + userPath = boost::filesystem::path(theDir); } - localConfigPath /= suffix; + userPath /= suffix; - return localConfigPath; + return userPath; } -boost::filesystem::path LinuxPath::getGlobalConfigPath() const +boost::filesystem::path LinuxPath::getGlobalPath() const { - boost::filesystem::path globalConfigPath("/etc/xdg/"); + boost::filesystem::path globalPath("/etc/xdg/"); char* theDir = getenv("XDG_CONFIG_DIRS"); if (theDir != NULL) @@ -82,79 +82,19 @@ boost::filesystem::path LinuxPath::getGlobalConfigPath() const char* ptr = strtok(theDir, ":"); if (ptr != NULL) { - globalConfigPath = boost::filesystem::path(ptr); - globalConfigPath /= boost::filesystem::path("/"); + globalPath = boost::filesystem::path(ptr); + globalPath /= boost::filesystem::path("/"); } } - return globalConfigPath; + return globalPath; } -boost::filesystem::path LinuxPath::getRuntimeConfigPath() const +boost::filesystem::path LinuxPath::getLocalPath() const { return boost::filesystem::path("./"); } -boost::filesystem::path LinuxPath::getLocalDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("XDG_DATA_HOME"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/.local/share/"); - } - } - } - - if (theDir != NULL) { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - -boost::filesystem::path LinuxPath::getGlobalDataPath() const -{ - boost::filesystem::path globalDataPath("/usr/local/share/"); - - char* theDir = getenv("XDG_DATA_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalDataPath = boost::filesystem::path(ptr); - globalDataPath /= boost::filesystem::path("/"); - } - } - - return globalDataPath; -} - -boost::filesystem::path LinuxPath::getRuntimeDataPath() const -{ - return boost::filesystem::path("./data/"); -} - - } /* namespace Files */ #endif /* defined(__linux__) || defined(__FreeBSD__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 53f7a73b4..af92326be 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -39,18 +39,18 @@ namespace Files struct LinuxPath { /** - * \brief Return path to the local configuration directory. + * \brief Return path to the user directory. * * \return boost::filesystem::path */ - boost::filesystem::path getLocalConfigPath() const; + boost::filesystem::path getUserPath() const; /** * \brief Return path to the global (system) configuration directory. * * \return boost::filesystem::path */ - boost::filesystem::path getGlobalConfigPath() const; + boost::filesystem::path getGlobalPath() const; /** * \brief Return path to the runtime configuration directory which is the @@ -58,29 +58,7 @@ struct LinuxPath * * \return boost::filesystem::path */ - boost::filesystem::path getRuntimeConfigPath() const; - - /** - * \brief Return path to the local data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - - /** - * \brief Return path to the global (system) data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getGlobalDataPath() const; - - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getRuntimeDataPath() const; + boost::filesystem::path getLocalPath() const; }; } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 46e775030..1ffb44399 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -34,9 +34,9 @@ namespace Files { -boost::filesystem::path MacOsPath::getLocalConfigPath() const +boost::filesystem::path MacOsPath::getUserPath() const { - boost::filesystem::path localConfigPath("."); + boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); const char* theDir = getenv("HOME"); @@ -50,69 +50,25 @@ boost::filesystem::path MacOsPath::getLocalConfigPath() const } if (theDir != NULL) { - localConfigPath = boost::filesystem::path(theDir) / "Library/Preferences/"; + userPath = boost::filesystem::path(theDir) / "Library/Preferences/"; } - localConfigPath /= suffix; + userPath /= suffix; - return localConfigPath; + return userPath; } -boost::filesystem::path MacOsPath::getGlobalConfigPath() const +boost::filesystem::path MacOsPath::getGlobalPath() const { - boost::filesystem::path globalConfigPath("/Library/Preferences/"); - return globalConfigPath; + boost::filesystem::path globalPath("/Library/Preferences/"); + return globalPath; } -boost::filesystem::path MacOsPath::getRuntimeConfigPath() const +boost::filesystem::path MacOsPath::getLocalPath() const { return boost::filesystem::path("./"); } -boost::filesystem::path MacOsPath::getLocalDataPath() const -{ - boost::filesystem::path localDataPath("."); - boost::filesystem::path suffix("/"); - - const char* theDir = getenv("OPENMW_DATA"); - if (theDir == NULL) - { - theDir = getenv("HOME"); - if (theDir == NULL) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd != NULL) - { - theDir = pwd->pw_dir; - } - } - if (theDir != NULL) - { - suffix = boost::filesystem::path("/Library/Application Support/"); - } - } - - if (theDir != NULL) - { - localDataPath = boost::filesystem::path(theDir); - } - - localDataPath /= suffix; - return localDataPath; -} - -boost::filesystem::path MacOsPath::getGlobalDataPath() const -{ - boost::filesystem::path globalDataPath("/Library/Application Support/"); - return globalDataPath; -} - -boost::filesystem::path MacOsPath::getRuntimeDataPath() const -{ - return boost::filesystem::path("./data/"); -} - - } /* namespace Files */ #endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */ diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 26f2c907f..2087a21c7 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -43,14 +43,14 @@ struct MacOsPath * * \return boost::filesystem::path */ - boost::filesystem::path getLocalConfigPath() const; + boost::filesystem::path getUserPath() const; /** * \brief Return path to the global (system) configuration directory. * * \return boost::filesystem::path */ - boost::filesystem::path getGlobalConfigPath() const; + boost::filesystem::path getGlobalPath() const; /** * \brief Return path to the runtime configuration directory which is the @@ -58,29 +58,7 @@ struct MacOsPath * * \return boost::filesystem::path */ - boost::filesystem::path getRuntimeConfigPath() const; - - /** - * \brief Return path to the local data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - - /** - * \brief Return path to the global (system) data directory. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getGlobalDataPath() const; - - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getRuntimeDataPath() const; + boost::filesystem::path getLocalPath() const; }; } /* namespace Files */ diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index f42f149c1..7a4bab1df 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -10,9 +10,9 @@ namespace Files { -boost::filesystem::path WindowsPath::getLocalConfigPath() const +boost::filesystem::path WindowsPath::getUserPath() const { - boost::filesystem::path localConfigPath("."); + boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); TCHAR path[MAX_PATH]; @@ -21,17 +21,17 @@ boost::filesystem::path WindowsPath::getLocalConfigPath() const if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path))) { PathAppend(path, TEXT("My Games")); - localConfigPath = boost::filesystem::path(path); + userPath = boost::filesystem::path(path); } - localConfigPath /= suffix; + userPath /= suffix; - return localConfigPath; + return userPath; } -boost::filesystem::path WindowsPath::getGlobalConfigPath() const +boost::filesystem::path WindowsPath::getGlobalPath() const { - boost::filesystem::path globalConfigPath("."); + boost::filesystem::path globalPath("."); boost::filesystem::path suffix("/"); TCHAR path[MAX_PATH]; @@ -39,34 +39,19 @@ boost::filesystem::path WindowsPath::getGlobalConfigPath() const if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, NULL, 0, path))) { - globalConfigPath = boost::filesystem::path(path); + globalPath = boost::filesystem::path(path); } - globalConfigPath /= suffix; + globalPath /= suffix; - return globalConfigPath; + return globalPath; } -boost::filesystem::path WindowsPath::getRuntimeConfigPath() const +boost::filesystem::path WindowsPath::getLocalPath() const { return boost::filesystem::path("./"); } -boost::filesystem::path WindowsPath::getLocalDataPath() const -{ - return getLocalConfigPath(); -} - -boost::filesystem::path WindowsPath::getGlobalDataPath() const -{ - return getGlobalConfigPath(); -} - -boost::filesystem::path WindowsPath::getRuntimeDataPath() const -{ - return boost::filesystem::path("./data/"); -} - } /* namespace Files */ #endif /* defined(_WIN32) || defined(__WINDOWS__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 47dfc08d8..78b3981bb 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -43,44 +43,22 @@ struct WindowsPath * * \return boost::filesystem::path */ - boost::filesystem::path getLocalConfigPath() const; + boost::filesystem::path getUserPath() const; /** * \brief Returns "X:\Program Files\" * * \return boost::filesystem::path */ - boost::filesystem::path getGlobalConfigPath() const; + boost::filesystem::path getGlobalPath() const; /** - * \brief Return runtime configuration path which is a location where + * \brief Return local path which is a location where * an application was started * * \return boost::filesystem::path */ - boost::filesystem::path getRuntimeConfigPath() const; - - /** - * \brief Return same path like getLocalConfigPath - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - - /** - * \brief Return same path like getGlobalConfigPath - * - * \return boost::filesystem::path - */ - boost::filesystem::path getGlobalDataPath() const; - - /** - * \brief Return runtime data path which is a location where - * an application was started with 'data' suffix. - * - * \return boost::filesystem::path - */ - boost::filesystem::path getRuntimeDataPath() const; + boost::filesystem::path getLocalPath() const; }; } /* namespace Files */ From 406897aa646b387fd29a65c6911ae1e958d24cc5 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 21 Jan 2012 17:58:49 +0100 Subject: [PATCH 10/17] Issue #168 - Configuration cleanup - WIP Sources update. Signed-off-by: Lukasz Gromanowski --- apps/openmw/main.cpp | 2 +- components/files/configurationmanager.cpp | 54 +++--------------- components/files/configurationmanager.hpp | 17 +++--- components/files/fixedpath.hpp | 68 ++++++----------------- components/files/linuxpath.cpp | 65 ++++++++++++++++++++++ components/files/linuxpath.hpp | 23 ++++++++ components/files/macospath.cpp | 48 ++++++++++++++++ components/files/macospath.hpp | 2 + components/files/windowspath.cpp | 29 ++++++++++ components/files/windowspath.hpp | 24 ++++++++ 10 files changed, 228 insertions(+), 104 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 0f66925d3..02fa1d765 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -166,7 +166,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getDataPath("local:data?")); + dataDirs.push_back(cfgMgr.getDataPath(Files::localDataToken)); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 224fd2649..aaa26977c 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -12,10 +12,10 @@ static const char* const openmwCfgFile = "openmw.cfg"; static const char* const ogreCfgFile = "ogre.cfg"; static const char* const pluginsCfgFile = "plugins.cfg"; -static const char* const mwDataToken = "?mw:data?"; -static const char* const localDataToken = "?local:data?"; -static const char* const userDataToken = "?user:data?"; -static const char* const globalDataToken = "?global:data?"; +const char* const mwDataToken = "?mw:data?"; +const char* const localDataToken = "?local:data?"; +const char* const userDataToken = "?user:data?"; +const char* const globalDataToken = "?global:data?"; ConfigurationManager::ConfigurationManager() : mFixedPath("openmw") @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &ConfigurationManager::getInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &ConfigurationManager::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &ConfigurationManager::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &ConfigurationManager::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -117,48 +117,12 @@ const boost::filesystem::path& ConfigurationManager::getDataPath(const std::stri TokensMappingContainer::const_iterator it = mTokensMapping.find(type); if (it != mTokensMapping.end()) { - return ((this)->*(it->second))(); + return ((mFixedPath).*(it->second))(); } return mFixedPath.getLocalDataPath(); } -const boost::filesystem::path& ConfigurationManager::getInstallPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - - //return mFixedPath.getInstallPath(); -} - -const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - - //return mFixedPath.getGlobalDataPath(); -} - -const boost::filesystem::path& ConfigurationManager::getUserDataPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - - //return mFixedPath.getUserDataPath(); -} - -const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const -{ -// TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; - //return mFixedPath.getLocalDataPath(); -} - - const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const { return mOgreCfgPath; diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 3004b6281..d1c999979 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -14,6 +14,12 @@ namespace Files { +extern const char* const mwDataToken; +extern const char* const localDataToken; +extern const char* const userDataToken; +extern const char* const globalDataToken; + + /** * \struct ConfigurationManager */ @@ -37,7 +43,9 @@ struct ConfigurationManager const boost::filesystem::path& getLogPath() const; private: - typedef const boost::filesystem::path& (ConfigurationManager::*path_type_f)() const; + typedef Files::FixedPath<> FixedPathType; + + typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, @@ -46,12 +54,7 @@ struct ConfigurationManager void setupTokensMapping(); - const boost::filesystem::path& getInstallPath() const; - const boost::filesystem::path& getGlobalDataPath() const; - const boost::filesystem::path& getUserDataPath() const; - const boost::filesystem::path& getLocalDataPath() const; - - Files::FixedPath<> mFixedPath; + FixedPathType mFixedPath; boost::filesystem::path mOgreCfgPath; boost::filesystem::path mPluginsCfgPath; diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 4e2b20e3c..3a27bd21d 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -73,9 +73,10 @@ struct FixedPath , mUserPath(mPath.getUserPath()) , mGlobalPath(mPath.getGlobalPath()) , mLocalPath(mPath.getLocalPath()) - , mLocalDataPath() - , mGlobalDataPath() - , mRuntimeDataPath() + , mUserDataPath(mPath.getUserDataPath()) + , mGlobalDataPath(mPath.getGlobalDataPath()) + , mLocalDataPath(mPath.getLocalDataPath()) + , mInstallPath(mPath.getInstallPath()) { if (!application_name.empty()) { @@ -119,64 +120,28 @@ struct FixedPath return mLocalPath; } - /** - * \brief Return path pointing to the user local data directory. - * - * \return boost::filesystem::path - */ - const boost::filesystem::path& getLocalDataPath() const + const boost::filesystem::path& getInstallPath() const { - return mLocalDataPath; - } + // TODO: It will be corrected later. + static boost::filesystem::path p("./"); + return p; - /** - * \brief Sets new local data path. - * - * \param [in] path - New path - */ - void setLocalDataPath(const boost::filesystem::path& path) - { - mLocalDataPath = path; + //return mFixedPath.getInstallPath(); } - /** - * \brief Return path pointing to the global (system) data directory. - * - * \return boost::filesystem::path - */ const boost::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; } - /** - * \brief Sets new global (system) data directory. - * - * \param [in] path - New path - */ - void setGlobalDataPath(const boost::filesystem::path& path) + const boost::filesystem::path& getUserDataPath() const { - mGlobalDataPath = path; + return mUserDataPath; } - /** - * \brief Return path pointing to the directory where application was started. - * - * \return boost::filesystem::path - */ - const boost::filesystem::path& getRuntimeDataPath() const - { - return mRuntimeDataPath; - } - - /** - * \brief Sets new runtime data directory. - * - * \param [in] path - New path - */ - void setRuntimeDataPath(const boost::filesystem::path& path) + const boost::filesystem::path& getLocalDataPath() const { - mRuntimeDataPath = path; + return mLocalDataPath; } private: @@ -186,11 +151,12 @@ struct FixedPath boost::filesystem::path mGlobalPath; /**< Global path */ boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ - boost::filesystem::path mLocalDataPath; /**< User local application data path (user plugins / mods / etc.) */ - boost::filesystem::path mGlobalDataPath; /**< Global application data path */ - boost::filesystem::path mRuntimeDataPath; /**< Runtime path to the configuration files. + boost::filesystem::path mUserDataPath; /**< User data path */ + boost::filesystem::path mGlobalDataPath; /**< Global application data path */ + boost::filesystem::path mLocalDataPath; /**< Local path to the configuration files. By default it is a 'data' directory in same directory where application was run */ + boost::filesystem::path mInstallPath; }; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 11ddc3104..8466f0222 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -95,6 +95,71 @@ boost::filesystem::path LinuxPath::getLocalPath() const return boost::filesystem::path("./"); } +boost::filesystem::path LinuxPath::getUserDataPath() const +{ + boost::filesystem::path localDataPath("."); + boost::filesystem::path suffix("/"); + + const char* theDir = getenv("OPENMW_DATA"); + if (theDir == NULL) + { + theDir = getenv("XDG_DATA_HOME"); + if (theDir == NULL) + { + theDir = getenv("HOME"); + if (theDir == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + theDir = pwd->pw_dir; + } + } + if (theDir != NULL) + { + suffix = boost::filesystem::path("/.local/share/"); + } + } + } + + if (theDir != NULL) { + localDataPath = boost::filesystem::path(theDir); + } + + localDataPath /= suffix; + return localDataPath; +} + +boost::filesystem::path LinuxPath::getGlobalDataPath() const +{ + boost::filesystem::path globalDataPath("/usr/local/share/"); + + char* theDir = getenv("XDG_DATA_DIRS"); + if (theDir != NULL) + { + // We take only first path from list + char* ptr = strtok(theDir, ":"); + if (ptr != NULL) + { + globalDataPath = boost::filesystem::path(ptr); + globalDataPath /= boost::filesystem::path("/"); + } + } + + return globalDataPath; +} + +boost::filesystem::path LinuxPath::getLocalDataPath() const +{ + return boost::filesystem::path("./data/"); +} + + +boost::filesystem::path LinuxPath::getInstallPath() const +{ + return boost::filesystem::path("./"); +} + } /* namespace Files */ #endif /* defined(__linux__) || defined(__FreeBSD__) */ diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index af92326be..51be6242c 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -59,6 +59,29 @@ struct LinuxPath * \return boost::filesystem::path */ boost::filesystem::path getLocalPath() const; + + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getUserDataPath() const; + + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getLocalDataPath() const; + + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 1ffb44399..87ac42202 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -69,6 +69,54 @@ boost::filesystem::path MacOsPath::getLocalPath() const return boost::filesystem::path("./"); } +boost::filesystem::path MacOsPath::getUserDataPath() const +{ + boost::filesystem::path localDataPath("."); + boost::filesystem::path suffix("/"); + + const char* theDir = getenv("OPENMW_DATA"); + if (theDir == NULL) + { + theDir = getenv("HOME"); + if (theDir == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + theDir = pwd->pw_dir; + } + } + if (theDir != NULL) + { + suffix = boost::filesystem::path("/Library/Application Support/"); + } + } + + if (theDir != NULL) + { + localDataPath = boost::filesystem::path(theDir); + } + + localDataPath /= suffix; + return localDataPath; +} + +boost::filesystem::path MacOsPath::getGlobalDataPath() const +{ + boost::filesystem::path globalDataPath("/Library/Application Support/"); + return globalDataPath; +} + +boost::filesystem::path MacOsPath::getLocalDataPath() const +{ + return boost::filesystem::path("./data/"); +} + +boost::filesystem::path MacOsPath::getInstallPath() const; +{ + return boost::filesystem::path("./"); +} + } /* namespace Files */ #endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */ diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 2087a21c7..2194dbb94 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -59,6 +59,8 @@ struct MacOsPath * \return boost::filesystem::path */ boost::filesystem::path getLocalPath() const; + + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 7a4bab1df..a54f800d4 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -52,6 +52,35 @@ boost::filesystem::path WindowsPath::getLocalPath() const return boost::filesystem::path("./"); } +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ +boost::filesystem::path WindowsPath::getUserDataPath() const +{ + return getUserConfigPath(); +} + +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ +boost::filesystem::path WindowsPath::getGlobalDataPath() const +{ + return getGlobalConfigPath(); +} + +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ +boost::filesystem::path WindowsPath::getLocalDataPath() const +{ + return boost::filesystem::path("./data/"); +} + +boost::filesystem::path WindowsPath::getInstallPath() const; +{ + return boost::filesystem::path("./"); +} + } /* namespace Files */ #endif /* defined(_WIN32) || defined(__WINDOWS__) */ diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 78b3981bb..95af3ea90 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -59,6 +59,30 @@ struct WindowsPath * \return boost::filesystem::path */ boost::filesystem::path getLocalPath() const; + + /** + * \brief Return same path like getUserConfigPath + * + * \return boost::filesystem::path + */ + boost::filesystem::path getUserDataPath() const; + + /** + * \brief Return same path like getGlobalConfigPath + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + + /** + * \brief Return runtime data path which is a location where + * an application was started with 'data' suffix. + * + * \return boost::filesystem::path + */ + boost::filesystem::path getLocalDataPath() const; + + boost::filesystem::path getInstallPath() const; }; } /* namespace Files */ From 1d96b99532f069bd50dd6cc7d1ef3a552e4c3e7f Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 25 Jan 2012 23:55:43 +0100 Subject: [PATCH 11/17] Issue #168 - Configuration cleanup Added tokens processing, modified getInstallPath for linux so we could use ~/.wine/dosdevices symlinks. Signed-off-by: Lukasz Gromanowski --- apps/openmw/main.cpp | 3 +- components/files/configurationmanager.cpp | 77 ++++++++++++--- components/files/configurationmanager.hpp | 17 ++-- components/files/fixedpath.hpp | 24 ++++- components/files/linuxpath.cpp | 112 +++++++++++----------- components/files/macospath.cpp | 76 ++++++++++++++- 6 files changed, 226 insertions(+), 83 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 02fa1d765..9f70fac15 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -157,6 +157,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat engine.enableFSStrict(variables["fs-strict"].as()); Files::PathContainer dataDirs(variables["data"].as()); + cfgMgr.processPaths(dataDirs); std::string local(variables["data-local"].as()); if (!local.empty()) @@ -166,7 +167,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getDataPath(Files::localDataToken)); + dataDirs.push_back(cfgMgr.getLocalDataPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index aaa26977c..e1bf48a6f 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace Files { @@ -24,7 +24,7 @@ ConfigurationManager::ConfigurationManager() /** * According to task #168 plugins.cfg file shall be located in global - * configuration path or in runtime configuration path. + * configuration path or in local configuration path. */ mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -66,10 +66,54 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m { loadConfig(mFixedPath.getUserPath(), variables, description); boost::program_options::notify(variables); + loadConfig(mFixedPath.getLocalPath(), variables, description); boost::program_options::notify(variables); loadConfig(mFixedPath.getGlobalPath(), variables, description); boost::program_options::notify(variables); + +} + +struct EmptyPath : public std::unary_function +{ + bool operator()(const boost::filesystem::path& path) const + { + return path.empty(); + } +}; + +void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) +{ + for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) + { + const std::string& path = it->string(); + if (!path.empty() && path[0] == '?') + { + std::string::size_type pos = path.find('?', 1); + if (pos != std::string::npos) + { + ++pos; + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos)); + + if (tokenIt != mTokensMapping.end()) + { + boost::filesystem::path tempPath(path.substr(pos, path.length() - pos)); + + if (boost::filesystem::is_directory(tempPath)) + { + ((mFixedPath).*(tokenIt->second))(tempPath); + (*it) = tempPath; + } + else + { + (*it).clear(); + } + } + } + } + } + + dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), EmptyPath()), dataDirs.end()); } void ConfigurationManager::loadConfig(const boost::filesystem::path& path, @@ -112,17 +156,26 @@ const boost::filesystem::path& ConfigurationManager::getLocalPath() const return mFixedPath.getLocalPath(); } -const boost::filesystem::path& ConfigurationManager::getDataPath(const std::string& type) const +const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const { - TokensMappingContainer::const_iterator it = mTokensMapping.find(type); - if (it != mTokensMapping.end()) - { - return ((mFixedPath).*(it->second))(); - } + return mFixedPath.getGlobalDataPath(); +} + +const boost::filesystem::path& ConfigurationManager::getUserDataPath() const +{ + return mFixedPath.getUserDataPath(); +} +const boost::filesystem::path& ConfigurationManager::getLocalDataPath() const +{ return mFixedPath.getLocalDataPath(); } +const boost::filesystem::path& ConfigurationManager::getInstallPath() const +{ + return mFixedPath.getInstallPath(); +} + const boost::filesystem::path& ConfigurationManager::getOgreConfigPath() const { return mOgreCfgPath; diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index d1c999979..dce56ea5d 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -7,6 +7,7 @@ #include #include +#include /** * \namespace Files @@ -14,12 +15,6 @@ namespace Files { -extern const char* const mwDataToken; -extern const char* const localDataToken; -extern const char* const userDataToken; -extern const char* const globalDataToken; - - /** * \struct ConfigurationManager */ @@ -30,13 +25,17 @@ struct ConfigurationManager void readConfiguration(boost::program_options::variables_map& variables, boost::program_options::options_description& description); + void processPaths(Files::PathContainer& dataDirs); /**< Fixed paths */ const boost::filesystem::path& getGlobalPath() const; const boost::filesystem::path& getUserPath() const; - const boost::filesystem::path& getLocalPath() const ; + const boost::filesystem::path& getLocalPath() const; - const boost::filesystem::path& getDataPath(const std::string& type) const; + const boost::filesystem::path& getGlobalDataPath() const; + const boost::filesystem::path& getUserDataPath() const; + const boost::filesystem::path& getLocalDataPath() const; + const boost::filesystem::path& getInstallPath() const; const boost::filesystem::path& getOgreConfigPath() const; const boost::filesystem::path& getPluginsConfigPath() const; @@ -45,7 +44,7 @@ struct ConfigurationManager private: typedef Files::FixedPath<> FixedPathType; - typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; + typedef void (FixedPathType::*path_type_f)(const boost::filesystem::path&); typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 3a27bd21d..3db409b2c 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -122,11 +122,12 @@ struct FixedPath const boost::filesystem::path& getInstallPath() const { - // TODO: It will be corrected later. - static boost::filesystem::path p("./"); - return p; + return mInstallPath; + } - //return mFixedPath.getInstallPath(); + void setInstallPath(const boost::filesystem::path& path) + { + mInstallPath = path; } const boost::filesystem::path& getGlobalDataPath() const @@ -134,16 +135,31 @@ struct FixedPath return mGlobalDataPath; } + void setGlobalDataPath(const boost::filesystem::path& path) + { + mGlobalDataPath = path; + } + const boost::filesystem::path& getUserDataPath() const { return mUserDataPath; } + void setUserDataPath(const boost::filesystem::path& path) + { + mUserDataPath = path; + } + const boost::filesystem::path& getLocalDataPath() const { return mLocalDataPath; } + void setLocalDataPath(const boost::filesystem::path& path) + { + mLocalDataPath = path; + } + private: PathType mPath; diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index a1d1168d9..41891661e 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -157,73 +157,75 @@ boost::filesystem::path LinuxPath::getLocalDataPath() const boost::filesystem::path LinuxPath::getInstallPath() const { + boost::filesystem::path installPath; + char *homePath = getenv("HOME"); - if(!homePath) - { - return boost::filesystem::path(""); - } - - boost::filesystem::path wineDefaultRegistry(homePath); - wineDefaultRegistry /= ".wine/system.reg"; - - boost::filesystem::path wineDriveC(homePath); - wineDriveC /= ".wine/drive_c"; - - boost::filesystem::file_status fileStatus = boost::filesystem::status(wineDefaultRegistry); - boost::filesystem::file_status dirStatus = boost::filesystem::status(wineDriveC); - if(!boost::filesystem::is_regular_file(fileStatus) || !boost::filesystem::is_directory(dirStatus)) + if (homePath == NULL) { - return boost::filesystem::path(""); - } - - - boost::filesystem::ifstream file(wineDefaultRegistry); - bool isRegEntry = false; - std::string line; - - while (std::getline(file, line)) - { - if(!line.empty() && line[0] == '[') // we found an entry + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) { - std::string regkey = line.substr(1, line.find(']')-1); - if( regkey.compare("SOFTWARE\\\\Wow6432Node\\\\Bethesda Softworks\\\\Morrowind") == 0 - || regkey.compare("SOFTWARE\\\\Bethesda Softworks\\\\Morrowind") == 0 ) - { - isRegEntry = true; - } + homePath = pwd->pw_dir; } - else if(isRegEntry) + } + + if (homePath != NULL) + { + boost::filesystem::path wineDefaultRegistry(homePath); + wineDefaultRegistry /= ".wine/system.reg"; + + if (boost::filesystem::is_regular_file(wineDefaultRegistry)) { - if(line.empty() || line[0] != '"') // empty line means new registry key + boost::filesystem::ifstream file(wineDefaultRegistry); + bool isRegEntry = false; + std::string line; + std::string mwpath; + + while (std::getline(file, line) && !line.empty()) { - break; - } - std::string key = line.substr(1, line.find('"', 1)-1); - if(key.compare("Installed Path") == 0) { - std::string::size_type pos, startPos; - - startPos = line.find('=')+2; - std::string installPath = line.substr(startPos, line.find('"', startPos+1)-startPos); - installPath.replace(0, 2, wineDriveC.string()); - - pos = -1; - do + if (line[0] == '[') // we found an entry + { + isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + } + else if (isRegEntry) { - pos = installPath.find("\\\\", pos+1); - if(pos == std::string::npos) + if (line[0] == '"') // empty line means new registry key { - break; + std::string key = line.substr(1, line.find('"', 1) - 1); + if (strcasecmp(key.c_str(), "Installed Path") == 0) + { + std::string::size_type valuePos = line.find('=') + 2; + mwpath = line.substr(valuePos, line.rfind('"') - valuePos); + + std::string::size_type pos = mwpath.find("\\"); + while (pos != std::string::npos) + { + mwpath.replace(pos, 2, "/"); + pos = mwpath.find("\\", pos + 1); + } + break; + } } - - installPath.replace(pos, 2, "/"); - } while(true); - - return boost::filesystem::path(installPath); + } + } + + if (!mwpath.empty()) + { + // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + mwpath[0] = tolower(mwpath[0]); + installPath /= homePath; + installPath /= ".wine/dosdevices/"; + installPath /= mwpath; + + if (!boost::filesystem::is_directory(installPath)) + { + installPath.clear(); + } } } } - - return boost::filesystem::path(""); + + return installPath; } } /* namespace Files */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 87ac42202..789c87709 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -112,11 +112,83 @@ boost::filesystem::path MacOsPath::getLocalDataPath() const return boost::filesystem::path("./data/"); } -boost::filesystem::path MacOsPath::getInstallPath() const; +/** + * FIXME: This should be verified on MacOS system! + */ +boost::filesystem::path MacOsPath::getInstallPath() const { - return boost::filesystem::path("./"); + boost::filesystem::path installPath; + + char *homePath = getenv("HOME"); + if (homePath == NULL) + { + struct passwd* pwd = getpwuid(getuid()); + if (pwd != NULL) + { + homePath = pwd->pw_dir; + } + } + + if (homePath != NULL) + { + boost::filesystem::path wineDefaultRegistry(homePath); + wineDefaultRegistry /= ".wine/system.reg"; + + if (boost::filesystem::is_regular_file(wineDefaultRegistry)) + { + boost::filesystem::ifstream file(wineDefaultRegistry); + bool isRegEntry = false; + std::string line; + std::string mwpath; + + while (std::getline(file, line) && !line.empty()) + { + if (line[0] == '[') // we found an entry + { + isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + } + else if (isRegEntry) + { + if (line[0] == '"') // empty line means new registry key + { + std::string key = line.substr(1, line.find('"', 1) - 1); + if (strcasecmp(key.c_str(), "Installed Path") == 0) + { + std::string::size_type valuePos = line.find('=') + 2; + mwpath = line.substr(valuePos, line.rfind('"') - valuePos); + + std::string::size_type pos = mwpath.find("\\"); + while (pos != std::string::npos) + { + mwpath.replace(pos, 2, "/"); + pos = mwpath.find("\\", pos + 1); + } + break; + } + } + } + } + + if (!mwpath.empty()) + { + // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + mwpath[0] = tolower(mwpath[0]); + installPath /= homePath; + installPath /= ".wine/dosdevices/"; + installPath /= mwpath; + + if (!boost::filesystem::is_directory(installPath)) + { + installPath.clear(); + } + } + } + } + + return installPath; } + } /* namespace Files */ #endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */ From f4b6caac5961e869b531a63d1113e2a00d89080c Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Thu, 26 Jan 2012 00:14:03 +0100 Subject: [PATCH 12/17] Revert "Issue #178 - workaround for compilation problems with ogre 1.8.0." This reverts commit 37e272b3b5e18d1a93a1d69804a96845f8762ba1. It shouldn't be commited and pushed to config branch. --- components/bsa/bsa_archive.cpp | 6 ------ extern/caelum/src/CaelumPlugin.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/components/bsa/bsa_archive.cpp b/components/bsa/bsa_archive.cpp index 87b46b34c..2178be318 100644 --- a/components/bsa/bsa_archive.cpp +++ b/components/bsa/bsa_archive.cpp @@ -221,12 +221,6 @@ class BSAArchive : public Archive { BSAFile arc; - FileInfoListPtr findFileInfo(const String&, bool, bool) const - { - static FileInfoListPtr filp(new FileInfoList()); - return filp; - } - public: BSAArchive(const String& name) : Archive(name, "BSA") diff --git a/extern/caelum/src/CaelumPlugin.cpp b/extern/caelum/src/CaelumPlugin.cpp index 340a26559..288ad9220 100644 --- a/extern/caelum/src/CaelumPlugin.cpp +++ b/extern/caelum/src/CaelumPlugin.cpp @@ -21,17 +21,17 @@ along with Caelum. If not, see . #include "CaelumPrecompiled.h" #include "CaelumPlugin.h" -template<> Caelum::CaelumPlugin* Ogre::Singleton::msSingleton = 0; +template<> Caelum::CaelumPlugin* Ogre::Singleton::ms_Singleton = 0; namespace Caelum { CaelumPlugin* CaelumPlugin::getSingletonPtr () { - return msSingleton; + return ms_Singleton; } CaelumPlugin& CaelumPlugin::getSingleton () { - assert (msSingleton); - return *msSingleton; + assert (ms_Singleton); + return *ms_Singleton; } extern "C" void CAELUM_EXPORT dllStartPlugin () { From c5dee2c4fb792ea31f24c0aad13dbe23df66941a Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 28 Jan 2012 09:49:09 +0100 Subject: [PATCH 13/17] Issue #168 - Configuration cleanup Corrected tokens processing. If directory exist then tokens shall be replaced by correct path, otherwise they are silently removed from path container. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 37 ++++++++++------------- components/files/configurationmanager.hpp | 2 +- components/files/fixedpath.hpp | 20 ------------ 3 files changed, 17 insertions(+), 42 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index e1bf48a6f..91e279051 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::setInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::setLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::setUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::setGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -87,27 +87,22 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) { const std::string& path = it->string(); - if (!path.empty() && path[0] == '?') + + // Check if path contains a token + if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?') { - std::string::size_type pos = path.find('?', 1); - if (pos != std::string::npos) + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path); + if (tokenIt != mTokensMapping.end()) { - ++pos; - TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos)); + boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); - if (tokenIt != mTokensMapping.end()) + if (boost::filesystem::is_directory(tempPath)) + { + (*it) = tempPath; + } + else { - boost::filesystem::path tempPath(path.substr(pos, path.length() - pos)); - - if (boost::filesystem::is_directory(tempPath)) - { - ((mFixedPath).*(tokenIt->second))(tempPath); - (*it) = tempPath; - } - else - { - (*it).clear(); - } + (*it).clear(); } } } diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index dce56ea5d..7d77df9c0 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -44,7 +44,7 @@ struct ConfigurationManager private: typedef Files::FixedPath<> FixedPathType; - typedef void (FixedPathType::*path_type_f)(const boost::filesystem::path&); + typedef const boost::filesystem::path& (FixedPathType::*path_type_f)() const; typedef std::tr1::unordered_map TokensMappingContainer; void loadConfig(const boost::filesystem::path& path, diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 3db409b2c..1bf582ab9 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -125,41 +125,21 @@ struct FixedPath return mInstallPath; } - void setInstallPath(const boost::filesystem::path& path) - { - mInstallPath = path; - } - const boost::filesystem::path& getGlobalDataPath() const { return mGlobalDataPath; } - void setGlobalDataPath(const boost::filesystem::path& path) - { - mGlobalDataPath = path; - } - const boost::filesystem::path& getUserDataPath() const { return mUserDataPath; } - void setUserDataPath(const boost::filesystem::path& path) - { - mUserDataPath = path; - } - const boost::filesystem::path& getLocalDataPath() const { return mLocalDataPath; } - void setLocalDataPath(const boost::filesystem::path& path) - { - mLocalDataPath = path; - } - private: PathType mPath; From 86f88bedae4a7bca9ae3e8645825388eefb579fc Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 28 Jan 2012 11:59:08 +0100 Subject: [PATCH 14/17] Issue #168 - Configuration cleanup Removed 'data' part from token names, added token cleaning when invalid or unknown token is passed as commandline parameter. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 91e279051..28d49a50c 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -12,10 +12,10 @@ static const char* const openmwCfgFile = "openmw.cfg"; static const char* const ogreCfgFile = "ogre.cfg"; static const char* const pluginsCfgFile = "plugins.cfg"; -const char* const mwDataToken = "?mw:data?"; -const char* const localDataToken = "?local:data?"; -const char* const userDataToken = "?user:data?"; -const char* const globalDataToken = "?global:data?"; +const char* const mwToken = "?mw?"; +const char* const localToken = "?local?"; +const char* const userToken = "?user?"; +const char* const globalToken = "?global?"; ConfigurationManager::ConfigurationManager() : mFixedPath("openmw") @@ -55,10 +55,10 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { - mTokensMapping.insert(std::make_pair(mwDataToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localDataToken, &FixedPath<>::getLocalDataPath)); - mTokensMapping.insert(std::make_pair(userDataToken, &FixedPath<>::getUserDataPath)); - mTokensMapping.insert(std::make_pair(globalDataToken, &FixedPath<>::getGlobalDataPath)); + mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalDataPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserDataPath)); + mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, @@ -105,6 +105,11 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) (*it).clear(); } } + else + { + // Clean invalid / unknown token, it will be removed outside the loop + (*it).clear(); + } } } From b004e2479c335a40d61ea944f69403cf0176bff8 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 29 Jan 2012 20:27:03 +0100 Subject: [PATCH 15/17] Issue #133 Handle resources across multiple data directories - WIP Work In Progress - added support for multiple paths in SoundManager. Signed-off-by: Lukasz Gromanowski --- apps/openmw/engine.cpp | 12 +- apps/openmw/engine.hpp | 2 +- apps/openmw/mwsound/soundmanager.cpp | 171 +++++++++++++----------- apps/openmw/mwsound/soundmanager.hpp | 11 +- components/file_finder/file_finder.hpp | 89 +++++++++++- components/file_finder/search.cpp | 28 ++-- components/files/multidircollection.hpp | 2 +- 7 files changed, 201 insertions(+), 114 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index bbc68b8e2..31c947054 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -200,12 +200,12 @@ void OMW::Engine::loadBSA() for (Files::MultiDirCollection::TIter iter (bsa.begin()); iter!=bsa.end(); ++iter) { - std::cout << "Adding " << iter->second.string() << std::endl; - Bsa::addBSA (iter->second.string()); + std::cout << "Adding " << iter->second.string() << std::endl; + Bsa::addBSA (iter->second.string()); } - std::cout << "Data dir " << mDataDir.string() << std::endl; - Bsa::addDir(mDataDir.string(), mFSStrict); + //std::cout << "Data dir " << mDataDir.string() << std::endl; + //Bsa::addDir(mDataDir.string(), mFSStrict); } // add resources directory @@ -228,7 +228,7 @@ void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs) { /// \todo remove mDataDir, once resources system can handle multiple directories assert (!dataDirs.empty()); - mDataDir = dataDirs.back(); + mDataDirs = dataDirs; mFileCollections = Files::Collections (dataDirs, !mFSStrict); } @@ -339,7 +339,7 @@ void OMW::Engine::go() mEnvironment.mSoundManager = new MWSound::SoundManager(mOgre->getRoot(), mOgre->getCamera(), mEnvironment.mWorld->getStore(), - (mDataDir), + mDataDirs, mUseSound, mFSStrict, mEnvironment); // Create script system diff --git a/apps/openmw/engine.hpp b/apps/openmw/engine.hpp index 97079f5a5..40bf73c6d 100644 --- a/apps/openmw/engine.hpp +++ b/apps/openmw/engine.hpp @@ -64,7 +64,7 @@ namespace OMW class Engine : private Ogre::FrameListener { std::string mEncoding; - boost::filesystem::path mDataDir; + Files::PathContainer mDataDirs; boost::filesystem::path mResDir; OEngine::Render::OgreRenderer *mOgre; OEngine::Physic::PhysicEngine* mPhysicEngine; diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 7390e4c5c..76ef23bc2 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -4,8 +4,6 @@ #include #include -using namespace std; - #include #include @@ -15,6 +13,7 @@ using namespace std; #include #include + #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" #include "../mwworld/player.hpp" @@ -90,24 +89,28 @@ namespace MWSound // relative to the sound dir, and translates them into full paths // of existing files in the filesystem, if they exist. bool FSstrict; - FileFinder::FileFinder files; - FileFinder::FileFinderStrict strict; - FileFinder::FileFinder musicpath; - FileFinder::FileFinderStrict musicpathStrict; - - SoundImpl(Ogre::Root *root, Ogre::Camera *camera, - const ESMS::ESMStore &str, - const std::string &soundDir, const std::string &musicDir, bool fsstrict) + FileFinder::LessTreeFileFinder files; + FileFinder::StrictTreeFileFinder strict; + FileFinder::LessTreeFileFinder musicpath; + FileFinder::StrictTreeFileFinder musicpathStrict; + + SoundImpl(Ogre::Root *root, Ogre::Camera *camera, const ESMS::ESMStore &str, + const Files::PathContainer& soundDir, + const Files::PathContainer& musicDir, + bool fsstrict) : mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY))) , updater(mgr) , cameraTracker(mgr) , store(str) - , files(soundDir), strict(soundDir) - ,musicpath(musicDir), musicpathStrict(musicDir) + , FSstrict(fsstrict) + , files(soundDir) + , strict(soundDir) + , musicpath(musicDir) + , musicpathStrict(musicDir) { - FSstrict = fsstrict; - cout << "Sound output: " << SOUND_OUT << endl; - cout << "Sound decoder: " << SOUND_IN << endl; + + std::cout << "Sound output: " << SOUND_OUT << std::endl; + std::cout << "Sound decoder: " << SOUND_IN << std::endl; // Attach the camera to the camera tracker cameraTracker.followCamera(camera); @@ -136,36 +139,49 @@ namespace MWSound bool hasFile(const std::string &str, bool music = false) { - if(FSstrict == false) + bool found = false; + if(!FSstrict) { if(music) { - if(musicpath.has(str)) return true; - + found = musicpath.has(str); // Not found? Try with .mp3 - return musicpath.has(toMp3(str)); + if (!found) + { + found = musicpath.has(toMp3(str)); + } } else { - if(files.has(str)) return true; - return files.has(toMp3(str)); + found = files.has(str); + if (!found) + { + found = files.has(toMp3(str)); + } } } else { if(music) { - if(musicpathStrict.has(str)) return true; - + found = musicpathStrict.has(str); // Not found? Try with .mp3 - return musicpathStrict.has(toMp3(str)); + if (!found) + { + found = musicpathStrict.has(toMp3(str)); + } } else { - if(strict.has(str)) return true; - return strict.has(toMp3(str)); + found = strict.has(str); + if (!found) + { + found = strict.has(toMp3(str)); + } } } + + return found; } // Convert a Morrowind sound path (eg. Fx\funny.wav) to full path @@ -258,13 +274,13 @@ namespace MWSound } catch(...) { - cout << "Error loading " << file << ", skipping.\n"; + std::cout << "Error loading " << file << ", skipping.\n"; } } // Clears all the sub-elements of a given iterator, and then // removes it from 'sounds'. - void clearAll(PtrMap::iterator it) + void clearAll(PtrMap::iterator& it) { IDMap::iterator sit = it->second.begin(); @@ -362,9 +378,9 @@ namespace MWSound } } } - }; + }; /* SoundImpl */ - void SoundManager::streamMusicFull (const std::string& filename) + void SoundManager::streamMusicFull(const std::string& filename) { if(!mData) return; @@ -381,20 +397,24 @@ namespace MWSound } SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera, - const ESMS::ESMStore &store, - boost::filesystem::path dataDir, - bool useSound, bool fsstrict, MWWorld::Environment& environment) - : mData(NULL), fsStrict (fsstrict), mEnvironment (environment) + const ESMS::ESMStore &store, const Files::PathContainer& dataDirs, + bool useSound, bool fsstrict, MWWorld::Environment& environment) + : mData(NULL) + , fsStrict(fsstrict) + , mEnvironment(environment) { - MP3Lookup(dataDir / "Music/Explore/"); - if(useSound) - mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict); + for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) + { + MP3Lookup((*it) / "Music/Explore/"); + } + if(useSound) + { + mData = new SoundImpl(root, camera, store, dataDirs /* Sound */, dataDirs /* Music */, fsstrict); + } test.name = ""; total = 0; - - } SoundManager::~SoundManager() @@ -407,14 +427,12 @@ namespace MWSound { if(mData->hasFile(filename, true)) { - std::string fullpath = mData->convertPath(filename, true); - streamMusicFull(fullpath); + streamMusicFull(mData->convertPath(filename, true)); } } - - void SoundManager::MP3Lookup(boost::filesystem::path dir) -{ + void SoundManager::MP3Lookup(const boost::filesystem::path& dir) + { boost::filesystem::directory_iterator dir_iter(dir), dir_end; std::string mp3extension = ".mp3"; @@ -425,35 +443,30 @@ namespace MWSound files.push_back(*dir_iter); } } -} + } void SoundManager::startRandomTitle() -{ - std::vector::iterator fileIter; - - if(files.size() > 0) + { + if(!files.empty()) { - fileIter = files.begin(); - srand ( time(NULL) ); + Files::PathContainer::iterator fileIter = files.begin(); + srand( time(NULL) ); int r = rand() % files.size() + 1; //old random code - for(int i = 1; i < r; i++) - { - fileIter++; - } + std::advance(fileIter, r - 1); std::string music = fileIter->string(); + std::cout << "Playing " << music << "\n"; + try { - std::cout << "Playing " << music << "\n"; streamMusicFull(music); } - catch(std::exception &e) + catch (std::exception &e) { std::cout << " Music Error: " << e.what() << "\n"; } } -} - + } bool SoundManager::isMusicPlaying() { @@ -465,14 +478,12 @@ namespace MWSound return test; } - SoundManager::SoundImpl SoundManager::getMData() + SoundManager::SoundImpl SoundManager::getMData() { // bool test = mData->music->isPlaying(); return *mData; } - - void SoundManager::say (MWWorld::Ptr ptr, const std::string& filename) { // The range values are not tested @@ -480,7 +491,7 @@ namespace MWSound if(mData->hasFile(filename)) mData->add(mData->convertPath(filename), ptr, "_say_sound", 1, 1, 100, 20000, false); else - cout << "Sound file " << filename << " not found, skipping.\n"; + std::cout << "Sound file " << filename << " not found, skipping.\n"; } bool SoundManager::sayDone (MWWorld::Ptr ptr) const @@ -490,20 +501,20 @@ namespace MWSound } - void SoundManager::playSound (const std::string& soundId, float volume, float pitch) + void SoundManager::playSound(const std::string& soundId, float volume, float pitch) { if(!mData) return; // Play and forget float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); - if(file != "") - { + if (file != "") + { SoundPtr snd = mData->mgr->load(file); snd->setVolume(volume); snd->setRange(min,max); snd->setPitch(pitch); snd->play(); - } + } } void SoundManager::playSound3D (MWWorld::Ptr ptr, const std::string& soundId, @@ -514,7 +525,7 @@ namespace MWSound // Look up the sound in the ESM data float min, max; const std::string &file = mData->lookup(soundId, volume, min, max); - if(file != "") + if (file != "") mData->add(file, ptr, soundId, volume, pitch, min, max, loop); } @@ -541,18 +552,19 @@ namespace MWSound void SoundManager::updateObject(MWWorld::Ptr ptr) { - if(!mData) return; - mData->updatePositions(ptr); + if (mData != NULL) + { + mData->updatePositions(ptr); + } } void SoundManager::update (float duration) { - std::string effect; - MWWorld::Ptr::CellStore *current = mEnvironment.mWorld->getPlayer().getPlayer().getCell(); //If the region has changed - if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10){ + if(!(current->cell->data.flags & current->cell->Interior) && timer.elapsed() >= 10) + { timer.restart(); if (test.name != current->cell->region) { @@ -564,11 +576,12 @@ namespace MWSound { std::vector::iterator soundIter = test.soundList.begin(); //mEnvironment.mSoundManager - if(total == 0){ - while (!(soundIter == test.soundList.end())) + if(total == 0) + { + while (soundIter != test.soundList.end()) { - ESM::NAME32 go = soundIter->sound; int chance = (int) soundIter->chance; + //ESM::NAME32 go = soundIter->sound; //std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; soundIter++; total += chance; @@ -578,7 +591,7 @@ namespace MWSound int r = rand() % total; //old random code int pos = 0; soundIter = test.soundList.begin(); - while (!(soundIter == test.soundList.end())) + while (soundIter != test.soundList.end()) { const ESM::NAME32 go = soundIter->sound; int chance = (int) soundIter->chance; @@ -586,13 +599,11 @@ namespace MWSound soundIter++; if( r - pos < chance) { - effect = go.name; //play sound std::cout << "Sound: " << go.name <<" Chance:" << chance << "\n"; - mEnvironment.mSoundManager->playSound(effect, 20.0, 1.0); + mEnvironment.mSoundManager->playSound(go.name, 20.0, 1.0); break; - } pos += chance; } diff --git a/apps/openmw/mwsound/soundmanager.hpp b/apps/openmw/mwsound/soundmanager.hpp index 7dff16c76..5c3f473f2 100644 --- a/apps/openmw/mwsound/soundmanager.hpp +++ b/apps/openmw/mwsound/soundmanager.hpp @@ -2,14 +2,15 @@ #define GAME_SOUND_SOUNDMANAGER_H #include -#include #include +#include + #include "../mwworld/ptr.hpp" #include +#include -#include namespace Ogre { @@ -37,7 +38,7 @@ namespace MWSound struct SoundImpl; SoundImpl *mData; - std::vector files; + Files::PathContainer files; bool fsStrict; MWWorld::Environment& mEnvironment; @@ -52,7 +53,7 @@ namespace MWSound public: SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store, - boost::filesystem::path dataDir, bool useSound, bool fsstrict, + const Files::PathContainer& dataDir, bool useSound, bool fsstrict, MWWorld::Environment& environment); ~SoundManager(); @@ -61,7 +62,7 @@ namespace MWSound /// \param filename name of a sound file in "Music/" in the data directory. void startRandomTitle(); - void MP3Lookup(boost::filesystem::path dir); + void MP3Lookup(const boost::filesystem::path& dir); bool isMusicPlaying(); diff --git a/components/file_finder/file_finder.hpp b/components/file_finder/file_finder.hpp index 0e1e07226..8a15af73a 100644 --- a/components/file_finder/file_finder.hpp +++ b/components/file_finder/file_finder.hpp @@ -1,9 +1,11 @@ #ifndef FILE_FINDER_MAIN_H #define FILE_FINDER_MAIN_H +#include + #include "search.hpp" #include "filename_less.hpp" -#include +#include namespace FileFinder { @@ -11,7 +13,8 @@ namespace FileFinder template class FileFinderT { - std::map table; + typedef std::map TableContainer; + TableContainer table; struct Inserter : ReturnPath { @@ -35,12 +38,12 @@ public: // Remember the original path length, so we can cut it away from // the relative paths used as keys - std::string pstring = path.string(); + const std::string& pstring = path.string(); inserter.cut = pstring.size(); // If the path does not end in a slash, then boost will add one // later, which means one more character we have to remove. - char last = pstring[pstring.size()-1]; + char last = *pstring.rbegin(); if(last != '\\' && last != '/') inserter.cut++; @@ -56,12 +59,84 @@ public: // Find the full path from a relative path. const std::string &lookup(const std::string& file) const { - return table.find(file)->second; + static std::string empty; + typename TableContainer::const_iterator it = table.find(file); + return (it != table.end()) ? it->second : empty; } }; +template +< + class LESS +> +struct TreeFileFinder +{ + typedef TreeFileFinder finder_t; + + TreeFileFinder(const Files::PathContainer& paths, bool recurse = true) + { + struct : ReturnPath + { + finder_t *owner; + int cut; + + void add(const boost::filesystem::path &pth) + { + std::string file = pth.string(); + std::string key = file.substr(cut); + owner->mTable[key] = file; + } + } inserter; + + inserter.owner = this; + + for (Files::PathContainer::const_iterator it = paths.begin(); it != paths.end(); ++it) + { + + // Remember the original path length, so we can cut it away from + // the relative paths used as keys + const std::string& pstring = it->string(); + inserter.cut = pstring.size(); + + // If the path does not end in a slash, then boost will add one + // later, which means one more character we have to remove. + char last = *pstring.rbegin(); + if (last != '\\' && last != '/') + { + inserter.cut++; + } + + // Fill the map + find(*it, inserter, recurse); + } + } + + bool has(const std::string& file) const + { + return mTable.find(file) != mTable.end(); + } + + const std::string& lookup(const std::string& file) const + { + static std::string empty; + typename TableContainer::const_iterator it = mTable.find(file); + return (it != mTable.end()) ? it->second : empty; + } + + private: + typedef std::map TableContainer; + TableContainer mTable; + +// Inserter inserter; +}; + + // The default is to use path_less for equality checks typedef FileFinderT FileFinder; typedef FileFinderT FileFinderStrict; -} -#endif + +typedef TreeFileFinder LessTreeFileFinder; +typedef TreeFileFinder StrictTreeFileFinder; + +} /* namespace FileFinder */ +#endif /* FILE_FINDER_MAIN_H */ diff --git a/components/file_finder/search.cpp b/components/file_finder/search.cpp index b05b30e83..eb4392abc 100644 --- a/components/file_finder/search.cpp +++ b/components/file_finder/search.cpp @@ -2,27 +2,27 @@ #include -using namespace std; -using namespace boost::filesystem; - -void FileFinder::find(const path & dir_path, ReturnPath &ret, bool recurse) +void FileFinder::find(const boost::filesystem::path & dir_path, ReturnPath &ret, bool recurse) { - if ( !exists( dir_path ) ) + if ( !boost::filesystem::exists( dir_path ) ) { - cout << "Path " << dir_path << " not found\n"; + std::cout << "Path " << dir_path << " not found" << std::endl; return; } - directory_iterator end_itr; // default construction yields past-the-end - for ( directory_iterator itr(dir_path); - itr != end_itr; - ++itr ) + boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::directory_iterator itr(dir_path); itr != end_itr; ++itr) { - if ( is_directory( *itr ) ) + if (boost::filesystem::is_directory( *itr )) + { + if (recurse) + { + find(*itr, ret); + } + } + else { - if(recurse) find(*itr, ret); + ret.add(*itr); } - else - ret.add(*itr); } } diff --git a/components/files/multidircollection.hpp b/components/files/multidircollection.hpp index 391f8b6a4..e8abeb45d 100644 --- a/components/files/multidircollection.hpp +++ b/components/files/multidircollection.hpp @@ -68,7 +68,7 @@ namespace Files /// \param foldCase Ignore filename case boost::filesystem::path getPath (const std::string& file) const; - ///< Return full path (including filename) of \æ file. + ///< Return full path (including filename) of \a file. /// /// If the file does not exist, an exception is thrown. \a file must include /// the extension. From eea8773be1c752d92e53ea3e07dd07828b4b5210 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Fri, 10 Feb 2012 21:45:46 +0100 Subject: [PATCH 16/17] Changed the order of preference for the configuration files --- apps/launcher/maindialog.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 3bef0b6f9..dd9f0d653 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -164,15 +164,15 @@ void MainDialog::createPages() dataDirs = readConfig(file.fileName()); } - // User location - file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); + // Local location + file.setFileName("./openmw.cfg"); + if (file.exists()) { dataDirs = readConfig(file.fileName()); } - // Local location - file.setFileName("./openmw.cfg"); - + // User location + file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (file.exists()) { dataDirs = readConfig(file.fileName()); } From bcc4d7a7c98cf03231de39c6d5f185f8c90887a5 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 12 Feb 2012 13:31:19 +0100 Subject: [PATCH 17/17] Issue #133 Handle resources across multiple data directories Signed-off-by: Lukasz Gromanowski --- apps/openmw/engine.cpp | 13 +++++++------ components/file_finder/search.cpp | 32 +++++++++++++++++++------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 31c947054..2a0c23e51 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -197,15 +197,16 @@ OMW::Engine::~Engine() void OMW::Engine::loadBSA() { const Files::MultiDirCollection& bsa = mFileCollections.getCollection (".bsa"); - - for (Files::MultiDirCollection::TIter iter (bsa.begin()); iter!=bsa.end(); ++iter) + std::string dataDirectory; + for (Files::MultiDirCollection::TIter iter(bsa.begin()); iter!=bsa.end(); ++iter) { std::cout << "Adding " << iter->second.string() << std::endl; - Bsa::addBSA (iter->second.string()); - } + Bsa::addBSA(iter->second.string()); - //std::cout << "Data dir " << mDataDir.string() << std::endl; - //Bsa::addDir(mDataDir.string(), mFSStrict); + dataDirectory = iter->second.parent_path().string(); + std::cout << "Data dir " << dataDirectory << std::endl; + Bsa::addDir(dataDirectory, mFSStrict); + } } // add resources directory diff --git a/components/file_finder/search.cpp b/components/file_finder/search.cpp index eb4392abc..06deaf83a 100644 --- a/components/file_finder/search.cpp +++ b/components/file_finder/search.cpp @@ -4,25 +4,33 @@ void FileFinder::find(const boost::filesystem::path & dir_path, ReturnPath &ret, bool recurse) { - if ( !boost::filesystem::exists( dir_path ) ) + if (boost::filesystem::exists(dir_path)) { - std::cout << "Path " << dir_path << " not found" << std::endl; - return; - } - - boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end - for (boost::filesystem::directory_iterator itr(dir_path); itr != end_itr; ++itr) - { - if (boost::filesystem::is_directory( *itr )) + if (!recurse) { - if (recurse) + boost::filesystem::directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::directory_iterator itr(dir_path); itr != end_itr; ++itr) { - find(*itr, ret); + if (!boost::filesystem::is_directory( *itr )) + { + ret.add(*itr); + } } } else { - ret.add(*itr); + boost::filesystem::recursive_directory_iterator end_itr; // default construction yields past-the-end + for (boost::filesystem::recursive_directory_iterator itr(dir_path); itr != end_itr; ++itr) + { + if (!boost::filesystem::is_directory(*itr)) + { + ret.add(*itr); + } + } } } + else + { + std::cout << "Path " << dir_path << " not found" << std::endl; + } }