From 37e272b3b5e18d1a93a1d69804a96845f8762ba1 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Fri, 13 Jan 2012 20:41:38 +0100 Subject: [PATCH 01/79] 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/79] 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/79] 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/79] 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/79] 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/79] 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/79] 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/79] 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/79] 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 + const boost::filesystem::path& getLocalPath() const { - return mRuntimeConfigPath; - } - - /** - * \brief Sets new runtime configuration path. - * - * \param [in] path - New path - */ - void setRuntimeConfigPath(const boost::filesystem::path& path) - { - 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/79] 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 | 70 ++++++----------------- 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, 229 insertions(+), 105 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; + + //return mFixedPath.getInstallPath(); } - /** - * \brief Sets new local data path. - * - * \param [in] path - New path - */ - void setLocalDataPath(const boost::filesystem::path& path) - { - mLocalDataPath = path; - } - - /** - * \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 + const boost::filesystem::path& getLocalDataPath() const { - return mRuntimeDataPath; - } - - /** - * \brief Sets new runtime data directory. - * - * \param [in] path - New path - */ - void setRuntimeDataPath(const boost::filesystem::path& path) - { - 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/79] 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 { - 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::path installPath; - 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)) + char *homePath = getenv("HOME"); + 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 { - pos = installPath.find("\\\\", pos+1); - if(pos == std::string::npos) + isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + } + else if (isRegEntry) + { + 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/79] 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/79] 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)) { - 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) = tempPath; + } + else + { + (*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/79] 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/79] 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 | 169 +++++++++++++----------- 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, 200 insertions(+), 113 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; + FileFinder::LessTreeFileFinder files; + FileFinder::StrictTreeFileFinder strict; + FileFinder::LessTreeFileFinder musicpath; + FileFinder::StrictTreeFileFinder musicpathStrict; - SoundImpl(Ogre::Root *root, Ogre::Camera *camera, - const ESMS::ESMStore &str, - const std::string &soundDir, const std::string &musicDir, bool fsstrict) + 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); + if (recurse) + { + find(*itr, ret); + } + } + else + { + 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/79] 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/79] 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; + } } From 77201d05bc64a052b1a52cd1d92d802c73f0018c Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 13 Feb 2012 16:42:01 +0100 Subject: [PATCH 18/79] post-merge fix --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 892e7a188..9e04d1ad0 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -470,7 +470,7 @@ void OMW::Engine::screenshot() // Count screenshots. int shotCount = 0; - const std::string screenshotPath = mCfgMgr.getLocalConfigPath().string(); + const std::string screenshotPath = mCfgMgr.getLocalPath().string(); // Find the first unused filename with a do-while std::ostringstream stream; From 9af08ff18de5403289f053d5da572309d2e5ef03 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 13 Feb 2012 18:34:21 +0100 Subject: [PATCH 19/79] store screenshots in user directory instead of local directory --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 9e04d1ad0..2e4beb65f 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -470,7 +470,7 @@ void OMW::Engine::screenshot() // Count screenshots. int shotCount = 0; - const std::string screenshotPath = mCfgMgr.getLocalPath().string(); + const std::string screenshotPath = mCfgMgr.getUserPath().string(); // Find the first unused filename with a do-while std::ostringstream stream; From e1defd359548b071c92fe6ad9b518d7a186d0eac Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 14 Feb 2012 09:25:12 +0100 Subject: [PATCH 20/79] adjusted the globally installed openmw.cfg file --- files/openmw.cfg | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/files/openmw.cfg b/files/openmw.cfg index f5322ae8c..f76524b33 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,3 +1,5 @@ -data=${MORROWIND_DATA_FILES} +data=?mw?Data Files +data=?global?data +data=?local?data +data-local=?user?data resources=${MORROWIND_RESOURCE_FILES} - From 8277df04b124cbb8d61e13978f24fe796bd2eeec Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 14 Feb 2012 09:26:06 +0100 Subject: [PATCH 21/79] bumping version number --- CMakeLists.txt | 8 ++++---- readme.txt | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d556ae147..75d26645a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,8 @@ include (OpenMWMacros) # Version set (OPENMW_VERSION_MAJOR 0) -set (OPENMW_VERSION_MINOR 11) -set (OPENMW_VERSION_RELEASE 1) +set (OPENMW_VERSION_MINOR 12) +set (OPENMW_VERSION_RELEASE 0) set (OPENMW_VERSION "${OPENMW_VERSION_MAJOR}.${OPENMW_VERSION_MINOR}.${OPENMW_VERSION_RELEASE}") @@ -451,7 +451,7 @@ if (APPLE) # some library already has be "fixed up", i.e. its id name contains @executable_path, # but library is not embedded in bundle. For example, it's Ogre.framework from Ogre SDK. # Current implementation of GetPrerequsities/BundleUtilities doesn't handle that case. - # + # # Current limitations: # 1. Handles only frameworks, not simple libs INSTALL(CODE " @@ -492,4 +492,4 @@ include(CPack) set(CMAKE_EXE_LINKER_FLAGS "-arch i386") set(CMAKE_CXX_FLAGS "-arch i386") -endif (APPLE) \ No newline at end of file +endif (APPLE) diff --git a/readme.txt b/readme.txt index cfddd9a1f..a02374b9b 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ OpenMW: A reimplementation of The Elder Scrolls III: Morrowind OpenMW is an attempt at recreating the engine for the popular role-playing game Morrowind by Bethesda Softworks. You need to own and install the original game for OpenMW to work. -Version: 0.11.1 +Version: 0.12.0 License: GPL (see GPL3.txt for more information) Website: http://www.openmw.org From 7b457c05bc13b93e96e04b37796d712d6fe2f4c7 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 14 Feb 2012 09:39:58 +0100 Subject: [PATCH 22/79] updated readme --- readme.txt | 109 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 10 deletions(-) diff --git a/readme.txt b/readme.txt index a02374b9b..47dd6d3fd 100644 --- a/readme.txt +++ b/readme.txt @@ -14,7 +14,7 @@ THIS IS A WORK IN PROGRESS INSTALLATION Windows: -Just unpack to a location of your choice. Currently there is no installer. +Run the installer. Linux: Ubuntu (and most others) @@ -35,25 +35,87 @@ TODO add description here THE DATA PATH -After the installation OpenMW needs to be told where to find the Morrowind data directory. Create a text file named openmw.cfg (location depends on platform) and enter the following line: +The data path tells OpenMW where to find your Morrowind files. From 0.12.0 on OpenMW should be able to +pick up the location of these files on its own, if both Morrowind and OpenMW are installed properly +(installing Morrowind under WINE is considered a proper install). + +If that does not work for you, please check if you have any leftover openmw.cfg files from versions earlier than 0.12.0. These can interfere with the configuration process, so try to remove then. + +If you are running OpenMW without installing it, you still need to manually adjust the data path. Create a text file named openmw.cfg in the location of the binary and enter the following line: data=path to your data directory (where you replace "path to your data directory" with the actual location of your data directory) -On Windows a suitable location for the cfg file is alongside the binary. Currently the binary release comes with such a file pre-generated, but you still need to adjust the data setting. - -On Linux and Mac the default location will be ~/.config/openmw/openmw.cfg. - COMMAND LINE OPTIONS -TODO add description of command line options + +Syntax: openmw +Allowed options: + --help print help message + --version print version information and quit + --data arg (=data) set data directories (later directories have + higher priority) + --data-local arg set local data directory (highest priority) + --resources arg (=resources) set resources directory + --start arg (=Beshara) set initial cell + --master arg master file(s) + --plugin arg plugin file(s) + --fps [=arg(=1)] (=0) fps counter detail (0 = off, 1 = fps counter + , 2 = full detail) + --anim-verbose [=arg(=1)] (=0) output animation indices files + --debug [=arg(=1)] (=0) debug mode + --nosound [=arg(=1)] (=0) disable all sounds + --script-verbose [=arg(=1)] (=0) verbose script output + --new-game [=arg(=1)] (=0) activate char gen/new game mechanics + --script-all [=arg(=1)] (=0) compile all scripts (excluding dialogue scri + pts) at startup + --fs-strict [=arg(=1)] (=0) strict file system handling (no case folding + ) + --encoding arg (=win1252) Character encoding used in OpenMW game messa + ges: + + win1250 - Central and Eastern European such + as Polish, Czech, Slovak, Hungarian, Slovene + , Bosnian, Croatian, Serbian (Latin script), + Romanian and Albanian languages + + win1251 - Cyrillic alphabet such as Russian, + Bulgarian, Serbian Cyrillic and other langua + ges + + win1252 - Western European (Latin) alphabet, + used by default + --report-focus [=arg(=1)] (=0) write name of focussed object to cout CREDITS -Developers: -TODO add list of developers +Current Developers: +Alexander “Ace” Olofsson +athile +Cris “Mirceam” Mihalache +gugus / gus +Jacob “Yacoby” Essex +Jason “jhooks” Hooks +Lukasz “lgro” Gromanowski +Marc “Zini” Zinnschlag +Nikolay “corristo” Kasyanov +Pieter “pvdk” van der Kloet +Sebastian “swick” Wick + +Retired Developers: +Ardekantur +Armin Preiml +Diggory Hardy +Jan Borsodi +Jan-Peter “peppe” Nilsson +Josua Grawitter +Karl-Felix “k1ll” Glatzer +Nicolay Korslund +sergoz +Star-Demon +Yuri Krupenin OpenMW: Thanks to DokterDume for kindly providing us with the Moon and Star logo used as the application icon and project logo. @@ -64,6 +126,33 @@ Thanks to Kevin Ryan for kindly providing us with the icon used for the Data Fil CHANGELOG +0.12.0 + +Bug #154: FPS Drop +Bug #169: Local scripts continue running if associated object is deleted +Bug #174: OpenMW fails to start if the config directory doesn't exist +Bug #187: Missing lighting +Bug #188: Lights without a mesh are not rendered +Bug #191: Taking screenshot causes crash when running installed +Feature #28: Sort out the cell load problem +Feature #31: Allow the player to move away from pre-defined cells +Feature #35: Use alternate storage location for modified object position +Feature #45: NPC animations +Feature #46: Creature Animation +Feature #89: Basic Journal Window +Feature #110: Automatically pick up the path of existing MW-installations +Feature #133: Handle resources across multiple data directories +Feature #134: Generate a suitable default-value for --data-local +Feature #183: More FPS display settings +Task #19: Refactor engine class +Task #109/Feature #162: Automate Packaging +Task #112: Catch exceptions thrown in input handling functions +Task #128/#168: Cleanup Configuration File Handling +Task #131: NPC Activation doesn't work properly +Task #144: MWRender cleanup +Task #155: cmake cleanup + + 0.11.1 Bug #2: Resources loading doesn't work outside of bsa files @@ -90,4 +179,4 @@ Task #14: Replace tabs with 4 spaces Task #18: Move components from global namespace into their own namespace Task #123: refactor header files in components/esm -TODO add old changelog (take pre 0.11.0 changelog from wiki) +TODO add old changelog (take pre 0.11.1 changelog from wiki) From 57a4b198806ba305822e3404cad9bd387918b654 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Wed, 15 Feb 2012 11:27:51 +0400 Subject: [PATCH 23/79] Feature #162 - Need to create app bundle using CMake, not by hand. Almost complete --- CMakeLists.txt | 14 +++++--------- apps/launcher/CMakeLists.txt | 32 +++++++++++++++++--------------- apps/launcher/main.cpp | 9 +++++++++ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef31dae07..fb58b0124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -384,9 +384,6 @@ endif() if (APPLE) set(INSTALL_SUBDIR OpenMW) - #install(FILES ${MISC_FILES} DESTINATION ../MacOS) - #install(DIRECTORY "${APP_BUNDLE_DIR}/Contents/Plugins" DESTINATION ..) - #install(DIRECTORY "${APP_BUNDLE_DIR}/Contents/Resources/resources" DESTINATION ../Resources) install(DIRECTORY "${APP_BUNDLE_DIR}" USE_SOURCE_PERMISSIONS DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" RENAME "openmw.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) @@ -394,9 +391,6 @@ if (APPLE) install(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) set(CPACK_GENERATOR "DragNDrop") - # set(CPACK_BUNDLE_PLIST "${CMAKE_SOURCE_DIR}/files/mac/Info.plist") - # set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/files/mac/openmw.icns") - # set(CPACK_BUNDLE_NAME "OpenMW") set(CPACK_PACKAGE_VERSION ${OPENMW_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR ${OPENMW_VERSION_MAJOR}) set(CPACK_PACKAGE_VERSION_MINOR ${OPENMW_VERSION_MINO}) @@ -406,11 +400,13 @@ if (APPLE) set(PLUGINS "") # Scan Plugins dir for *.dylibs - file(GLOB ALL_PLUGINS "${APP_BUNDLE_DIR}/Contents/Plugins/*.dylib") + set(PLUGIN_SEARCH_ROOT "${APP_BUNDLE_DIR}/Contents/Plugins") + file(GLOB_RECURSE ALL_PLUGINS "${PLUGIN_SEARCH_ROOT}/*.dylib") + set(PLUGIN_INSTALL_BASE "\${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR}/${APP_BUNDLE_NAME}/Contents/Plugins") foreach(PLUGIN ${ALL_PLUGINS}) - get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) - set(PLUGINS ${PLUGINS} "\${CMAKE_INSTALL_PREFIX}/${INSTALL_SUBDIR}/${APP_BUNDLE_NAME}/Contents/Plugins/${PLUGIN_FILENAME}") + string(REPLACE "${PLUGIN_SEARCH_ROOT}/" "" PLUGIN_RELATIVE "${PLUGIN}") + set(PLUGINS ${PLUGINS} "${PLUGIN_INSTALL_BASE}/${PLUGIN_RELATIVE}") endforeach() #For now, search unresolved dependencies only in default system paths, so if you put unresolveable (i.e. with @executable_path in id name) lib or framework somewhere else, it would fail diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index e46a06205..2879539a7 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -41,8 +41,10 @@ source_group(launcher FILES ${LAUNCHER} ${LAUNCHER_HEADER} ${LAUNCHER_HEADER_MOC find_package(Qt4 REQUIRED) set(QT_USE_QTGUI 1) -#find_package(PNG REQUIRED) -#include_directories(${PNG_INCLUDE_DIR}) +if (NOT APPLE) # this dependency can be completely removed, but now it only tested on OS X + find_package(PNG REQUIRED) + include_directories(${PNG_INCLUDE_DIR}) +endif() QT4_ADD_RESOURCES(RCC_SRCS resources.qrc) QT4_WRAP_CPP(MOC_SRCS ${LAUNCHER_HEADER_MOC}) @@ -51,14 +53,14 @@ include(${QT_USE_FILE}) # list here plugins that can't be detected statically, but loaded in runtime # it needed for packaging automatisation -#set(USED_QT_PLUGINS imageformats/libqgif -# imageformats/libqico -# imageformats/libqjpeg -# imageformats/libqmng -# imageformats/libqsvg -# imageformats/libqtga -# imageformats/libqtiff) -# It seems that launcher works without this plugins, but it loads them into memory if they exists +set(USED_QT_PLUGINS imageformats/libqgif + imageformats/libqico + imageformats/libqjpeg + imageformats/libqmng + imageformats/libqsvg + imageformats/libqtga + imageformats/libqtiff) +# It seems that launcher works without this plugins, but it loads them if they exists # Main executable add_executable(omwlauncher @@ -71,7 +73,7 @@ target_link_libraries(omwlauncher ${Boost_LIBRARIES} ${OGRE_LIBRARIES} ${QT_LIBRARIES} -# ${PNG_LIBRARY} + ${PNG_LIBRARY} components ) @@ -86,10 +88,10 @@ if (APPLE) "${APP_BUNDLE_DIR}/../launcher.cfg") # copy used QT plugins into ${APP_BUNDLE_DIR}/Contents/Plugins - #foreach(PLUGIN ${USED_QT_PLUGINS}) - # get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) - # configure_file("${QT_PLUGINS_DIR}/${PLUGIN}.dylib" "${APP_BUNDLE_DIR}/Contents/Plugins/${PLUGIN_FILENAME}.dylib" COPYONLY) - #endforeach() + foreach(PLUGIN ${USED_QT_PLUGINS}) + get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) + configure_file("${QT_PLUGINS_DIR}/${PLUGIN}.dylib" "${APP_BUNDLE_DIR}/Contents/Plugins/${PLUGIN}.dylib" COPYONLY) + endforeach() else() configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 4e438a4db..93d23371e 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include "maindialog.hpp" @@ -17,6 +18,14 @@ int main(int argc, char *argv[]) dir.cdUp(); dir.cdUp(); } + + QDir pluginsPath(QCoreApplication::applicationDirPath()); + pluginsPath.cdUp(); + pluginsPath.cd("Plugins"); + + QStringList libraryPaths; + libraryPaths << pluginsPath.path() << QCoreApplication::applicationDirPath(); + app.setLibraryPaths(libraryPaths); #endif QDir::setCurrent(dir.absolutePath()); From 2020d916ec482ae592b195fec18db4f6c0745589 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Wed, 15 Feb 2012 11:30:35 +0400 Subject: [PATCH 24/79] added missing comment --- apps/launcher/main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index 93d23371e..f108882a3 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -19,6 +19,7 @@ int main(int argc, char *argv[]) dir.cdUp(); } + // force Qt to load only LOCAL plugins, don't touch system Qt installation QDir pluginsPath(QCoreApplication::applicationDirPath()); pluginsPath.cdUp(); pluginsPath.cd("Plugins"); From 80008ed09f516aed4f68efbf253ab6f716c13820 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 15 Feb 2012 22:34:51 +0100 Subject: [PATCH 25/79] Issue #168 - Configuration cleanup Fixed bug with configuration tokens parsing - when something appear after token it should be appended to replaced path. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 34 +++++++++++++++-------- components/files/fixedpath.hpp | 1 + 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 28d49a50c..46cd0e053 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -89,27 +89,37 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) const std::string& path = it->string(); // Check if path contains a token - if (!path.empty() && *path.begin() == '?' && *path.rbegin() == '?') + if (!path.empty() && *path.begin() == '?') { - TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path); - if (tokenIt != mTokensMapping.end()) + std::string::size_type pos = path.find('?', 1); + if (pos != std::string::npos && pos != 0) { - boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); - - if (boost::filesystem::is_directory(tempPath)) + TokensMappingContainer::iterator tokenIt = mTokensMapping.find(path.substr(0, pos + 1)); + if (tokenIt != mTokensMapping.end()) { - (*it) = tempPath; + boost::filesystem::path tempPath(((mFixedPath).*(tokenIt->second))()); + if (pos < path.length() - 1) + { + // There is something after the token, so we should + // append it to the path + tempPath /= path.substr(pos + 1, path.length() - pos); + } + + if (boost::filesystem::is_directory(tempPath)) + { + (*it) = tempPath; + } + else + { + (*it).clear(); + } } else { + // Clean invalid / unknown token, it will be removed outside the loop (*it).clear(); } } - else - { - // Clean invalid / unknown token, it will be removed outside the loop - (*it).clear(); - } } } diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 1bf582ab9..0e052fd24 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -86,6 +86,7 @@ struct FixedPath mGlobalPath /= suffix; mLocalDataPath /= suffix; + mUserDataPath /= suffix; mGlobalDataPath /= suffix; } } From 8244ed58605fc91ac920f1436f3e6c77b340c91e Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Feb 2012 09:26:27 +0100 Subject: [PATCH 26/79] workaround for space in paths problem --- files/openmw.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/files/openmw.cfg b/files/openmw.cfg index f76524b33..950332cc1 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,5 +1,5 @@ -data=?mw?Data Files -data=?global?data -data=?local?data -data-local=?user?data +data="?mw?Data Files" +data="?global?data" +data="?local?data" +data-"local=?user?data" resources=${MORROWIND_RESOURCE_FILES} From 850501e9221daf1a55d31b72c4389da158b338e6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Feb 2012 13:14:16 +0100 Subject: [PATCH 27/79] workaround for the configuration problems --- components/files/configurationmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 46cd0e053..c6e553418 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -56,9 +56,9 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { 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)); + mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); + mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalPath)); } void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables, From 8186445de9e2bcb6966c5ef86583493c4225a3b6 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Feb 2012 21:06:25 +0100 Subject: [PATCH 28/79] fix for a very silly bug --- files/openmw.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/openmw.cfg b/files/openmw.cfg index 950332cc1..585b735f3 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,5 +1,5 @@ data="?mw?Data Files" data="?global?data" data="?local?data" -data-"local=?user?data" +data-local="?user?data" resources=${MORROWIND_RESOURCE_FILES} From 0c0b5940908c2ea385a9564fd02431d27792bd85 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 19 Feb 2012 23:39:37 +0100 Subject: [PATCH 29/79] Issue #168 - Configuration cleanup Removed unnecessary path methods - according to forum disscusion: http://openmw.org/forum/viewtopic.php?f=6&t=448 Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 2 + apps/openmw/main.cpp | 2 +- components/files/configurationmanager.cpp | 56 ++++--------- components/files/fixedpath.hpp | 20 +---- components/files/linuxpath.cpp | 97 +++-------------------- components/files/linuxpath.hpp | 14 ---- components/files/macospath.cpp | 44 +--------- components/files/macospath.hpp | 7 ++ components/files/windowspath.cpp | 26 ++---- components/files/windowspath.hpp | 18 +---- 10 files changed, 50 insertions(+), 236 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 8b59f1b81..6eb459037 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -135,6 +135,8 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); } + mCfgMgr.processPaths(dataDirs); + // Create a file collection for the dataDirs Files::Collections mFileCollections(dataDirs, strict); diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index 9f70fac15..6bdfdd91f 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -167,7 +167,7 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat if (dataDirs.empty()) { - dataDirs.push_back(cfgMgr.getLocalDataPath()); + dataDirs.push_back(cfgMgr.getLocalPath()); } engine.setDataDirs(dataDirs); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 46cd0e053..c5561d652 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -5,6 +5,11 @@ #include #include +#include + +/** + * \namespace Files + */ namespace Files { @@ -22,10 +27,6 @@ ConfigurationManager::ConfigurationManager() { setupTokensMapping(); - /** - * According to task #168 plugins.cfg file shall be located in global - * configuration path or in local configuration path. - */ mPluginsCfgPath = mFixedPath.getGlobalPath() / pluginsCfgFile; if (!boost::filesystem::is_regular_file(mPluginsCfgPath)) { @@ -37,15 +38,7 @@ ConfigurationManager::ConfigurationManager() } } - /** - * 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(); } @@ -56,8 +49,8 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { 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(localToken, &FixedPath<>::getLocalPath)); + mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalDataPath)); } @@ -74,14 +67,6 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m } -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) @@ -105,14 +90,7 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) tempPath /= path.substr(pos + 1, path.length() - pos); } - if (boost::filesystem::is_directory(tempPath)) - { - (*it) = tempPath; - } - else - { - (*it).clear(); - } + *it = tempPath; } else { @@ -121,9 +99,15 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) } } } + + if (!boost::filesystem::is_directory(*it)) + { + (*it).clear(); + } } - dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), EmptyPath()), dataDirs.end()); + dataDirs.erase(std::remove_if(dataDirs.begin(), dataDirs.end(), + boost::bind(&boost::filesystem::path::empty, _1)), dataDirs.end()); } void ConfigurationManager::loadConfig(const boost::filesystem::path& path, @@ -171,16 +155,6 @@ const boost::filesystem::path& ConfigurationManager::getGlobalDataPath() const 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(); diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 0e052fd24..4e054b17f 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -73,9 +73,7 @@ struct FixedPath , mUserPath(mPath.getUserPath()) , mGlobalPath(mPath.getGlobalPath()) , mLocalPath(mPath.getLocalPath()) - , mUserDataPath(mPath.getUserDataPath()) , mGlobalDataPath(mPath.getGlobalDataPath()) - , mLocalDataPath(mPath.getLocalDataPath()) , mInstallPath(mPath.getInstallPath()) { if (!application_name.empty()) @@ -84,9 +82,6 @@ struct FixedPath mUserPath /= suffix; mGlobalPath /= suffix; - - mLocalDataPath /= suffix; - mUserDataPath /= suffix; mGlobalDataPath /= suffix; } } @@ -131,16 +126,6 @@ struct FixedPath return mGlobalDataPath; } - const boost::filesystem::path& getUserDataPath() const - { - return mUserDataPath; - } - - const boost::filesystem::path& getLocalDataPath() const - { - return mLocalDataPath; - } - private: PathType mPath; @@ -148,11 +133,8 @@ struct FixedPath boost::filesystem::path mGlobalPath; /**< Global path */ boost::filesystem::path mLocalPath; /**< It is the same directory where application was run */ - 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 41891661e..0b315ccfb 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -41,29 +41,19 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path userPath("."); boost::filesystem::path suffix("/"); - const char* theDir = getenv("OPENMW_CONFIG"); + const char* theDir = getenv("HOME"); if (theDir == NULL) { - theDir = getenv("XDG_CONFIG_HOME"); - if (theDir == NULL) + struct passwd* pwd = getpwuid(getuid()); + if (pwd != 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("/.config/"); - } + theDir = pwd->pw_dir; } } - if (theDir != NULL) { + if (theDir != NULL) + { + suffix = boost::filesystem::path("/.config/"); userPath = boost::filesystem::path(theDir); } @@ -74,20 +64,7 @@ boost::filesystem::path LinuxPath::getUserPath() const boost::filesystem::path LinuxPath::getGlobalPath() const { - boost::filesystem::path globalPath("/etc/xdg/"); - - char* theDir = getenv("XDG_CONFIG_DIRS"); - if (theDir != NULL) - { - // We take only first path from list - char* ptr = strtok(theDir, ":"); - if (ptr != NULL) - { - globalPath = boost::filesystem::path(ptr); - globalPath /= boost::filesystem::path("/"); - } - } - + boost::filesystem::path globalPath("/etc/"); return globalPath; } @@ -96,65 +73,12 @@ 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("/"); - } - } - + boost::filesystem::path globalDataPath("/usr/share/games/"); return globalDataPath; } -boost::filesystem::path LinuxPath::getLocalDataPath() const -{ - return boost::filesystem::path("./data/"); -} - boost::filesystem::path LinuxPath::getInstallPath() const { boost::filesystem::path installPath; @@ -211,7 +135,8 @@ boost::filesystem::path LinuxPath::getInstallPath() const if (!mwpath.empty()) { - // Change drive letter to lowercase, so we could use ~/.wine/dosdevice symlinks + // Change drive letter to lowercase, so we could use + // ~/.wine/dosdevices symlinks mwpath[0] = tolower(mwpath[0]); installPath /= homePath; installPath /= ".wine/dosdevices/"; diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 71f45ae32..873f8801d 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -60,13 +60,6 @@ struct LinuxPath */ boost::filesystem::path getLocalPath() const; - /** - * \brief - * - * \return boost::filesystem::path - */ - boost::filesystem::path getUserDataPath() const; - /** * \brief * @@ -74,13 +67,6 @@ struct LinuxPath */ boost::filesystem::path getGlobalDataPath() const; - /** - * \brief - * - * \return boost::filesystem::path - */ - boost::filesystem::path getLocalDataPath() const; - /** * \brief Gets the path of the installed Morrowind version if there is one. * diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 789c87709..6225fc01f 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -28,6 +28,10 @@ #include #include +/** + * FIXME: Someone with MacOS system should check this and correct if necessary + */ + /** * \namespace Files */ @@ -69,52 +73,12 @@ 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/"); -} - -/** - * FIXME: This should be verified on MacOS system! - */ boost::filesystem::path MacOsPath::getInstallPath() const { boost::filesystem::path installPath; diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 2194dbb94..7656538c1 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -60,6 +60,13 @@ struct MacOsPath */ boost::filesystem::path getLocalPath() const; + /** + * \brief + * + * \return boost::filesystem::path + */ + boost::filesystem::path getGlobalDataPath() const; + boost::filesystem::path getInstallPath() const; }; diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index 9bb66a3cb..e81041272 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -10,6 +10,13 @@ #pragma comment(lib, "Shlwapi.lib") +/** + * FIXME: Someone with Windows system should check this and correct if necessary + */ + +/** + * \namespace Files + */ namespace Files { @@ -55,30 +62,11 @@ 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 { boost::filesystem::path installPath(""); diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 0240de257..919d087f1 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -39,7 +39,8 @@ namespace Files struct WindowsPath { /** - * \brief Returns "X:\Documents And Settings\\My Documents\My Games\" + * \brief Returns user path i.e.: + * "X:\Documents And Settings\\My Documents\My Games\" * * \return boost::filesystem::path */ @@ -60,13 +61,6 @@ struct WindowsPath */ 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 * @@ -74,14 +68,6 @@ struct WindowsPath */ 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; - /** * \brief Gets the path of the installed Morrowind version if there is one. * From 971ae94fbf0dc5d4ebab96a2e25b5f731c2f5ca8 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 21 Feb 2012 11:50:04 +0100 Subject: [PATCH 30/79] Revert "workaround for the configuration problems" This reverts commit 850501e9221daf1a55d31b72c4389da158b338e6. --- components/files/configurationmanager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index c6e553418..46cd0e053 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -56,9 +56,9 @@ ConfigurationManager::~ConfigurationManager() void ConfigurationManager::setupTokensMapping() { mTokensMapping.insert(std::make_pair(mwToken, &FixedPath<>::getInstallPath)); - mTokensMapping.insert(std::make_pair(localToken, &FixedPath<>::getLocalPath)); - mTokensMapping.insert(std::make_pair(userToken, &FixedPath<>::getUserPath)); - mTokensMapping.insert(std::make_pair(globalToken, &FixedPath<>::getGlobalPath)); + 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, From 280babc7194bf01dfe5f9c79b4b3d45fecab51df Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Wed, 22 Feb 2012 08:34:47 +0100 Subject: [PATCH 31/79] Fixed stylesheet and configuration problems with the launcher and code cleanup --- CMakeLists.txt | 2 +- apps/launcher/datafilespage.cpp | 195 ++++++++++++++------- apps/launcher/datafilespage.hpp | 18 +- apps/launcher/graphicspage.cpp | 2 +- apps/launcher/graphicspage.hpp | 9 +- apps/launcher/main.cpp | 7 - apps/launcher/maindialog.cpp | 197 +++------------------- apps/launcher/maindialog.hpp | 7 - components/files/configurationmanager.cpp | 2 +- 9 files changed, 169 insertions(+), 270 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a83ca1c0..41da79a05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,7 +329,7 @@ if(WIN32) FILE(GLOB files "${OpenMW_BINARY_DIR}/Release/*.*") INSTALL(FILES ${files} DESTINATION ".") INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "." RENAME "openmw.cfg") - INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.cfg" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".") + INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.qss" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".") INSTALL(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION ".") SET(CPACK_GENERATOR "NSIS") diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 6eb459037..fb8631f73 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -26,7 +26,7 @@ bool rowSmallerThan(const QModelIndex &index1, const QModelIndex &index2) return index1.row() <= index2.row(); } -DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent) +DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) , mCfgMgr(cfg) { @@ -123,25 +123,89 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent) setupConfig(); + setupDataFiles(); createActions(); } -void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) +void DataFilesPage::setupConfig() { - // Put the paths in a boost::filesystem vector to use with Files::Collections - Files::PathContainer dataDirs; + QString config = QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.cfg").string()); + QFile file(config); - foreach (const QString ¤tPath, paths) { - dataDirs.push_back(boost::filesystem::path(currentPath.toStdString())); + if (!file.exists()) { + config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string()); } + // Open our config file + mLauncherConfig = new QSettings(config, QSettings::IniFormat); + mLauncherConfig->sync(); + + + // Make sure we have no groups open + while (!mLauncherConfig->group().isEmpty()) { + mLauncherConfig->endGroup(); + } + + mLauncherConfig->beginGroup("Profiles"); + QStringList profiles = mLauncherConfig->childGroups(); + + if (profiles.isEmpty()) { + // Add a default profile + profiles.append("Default"); + } + + mProfilesComboBox->addItems(profiles); + + QString currentProfile = mLauncherConfig->value("CurrentProfile").toString(); + + if (currentProfile.isEmpty()) { + // No current profile selected + currentProfile = "Default"; + } + mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile)); + + mLauncherConfig->endGroup(); + + // Now we connect the combobox to do something if the profile changes + // This prevents strange behaviour while reading and appending the profiles + connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&))); +} + + +void DataFilesPage::setupDataFiles() +{ + // We use the Configuration Manager to retrieve the configuration values + boost::program_options::variables_map variables; + boost::program_options::options_description desc; + + desc.add_options() + ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()) + ("data-local", boost::program_options::value()->default_value("")) + ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) + ("encoding", boost::program_options::value()->default_value("win1252")); + + mCfgMgr.readConfiguration(variables, desc); + + // Put the paths in a boost::filesystem vector to use with Files::Collections + Files::PathContainer dataDirs(variables["data"].as()); mCfgMgr.processPaths(dataDirs); + std::string local(variables["data-local"].as()); + if (!local.empty()) + { + dataDirs.push_back(Files::PathContainer::value_type(local)); + } + + if (dataDirs.empty()) + { + dataDirs.push_back(mCfgMgr.getLocalPath()); + } + // Create a file collection for the dataDirs - Files::Collections mFileCollections(dataDirs, strict); + Files::Collections fileCollections(dataDirs, !variables["fs-strict"].as()); // First we add all the master files - const Files::MultiDirCollection &esm = mFileCollections.getCollection(".esm"); + const Files::MultiDirCollection &esm = fileCollections.getCollection(".esm"); unsigned int i = 0; // Row number for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter) @@ -161,14 +225,14 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) } // Now on to the plugins - const Files::MultiDirCollection &esp = mFileCollections.getCollection(".esp"); + const Files::MultiDirCollection &esp = fileCollections.getCollection(".esp"); for (Files::MultiDirCollection::TIter iter(esp.begin()); iter!=esp.end(); ++iter) { ESMReader fileReader; QStringList availableMasters; // Will contain all found masters - fileReader.setEncoding("win1252"); // FIXME: This should be configurable! + fileReader.setEncoding(variables["encoding"].as()); fileReader.open(iter->second.string()); // First we fill the availableMasters and the mMastersWidget @@ -238,52 +302,6 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict) readConfig(); } -void DataFilesPage::setupConfig() -{ - QString config = (mCfgMgr.getLocalPath() / "launcher.cfg").string().c_str(); - QFile file(config); - - if (!file.exists()) { - config = QString::fromStdString((mCfgMgr.getUserPath() / "launcher.cfg").string()); - } - - file.setFileName(config); // Just for displaying information - - // Open our config file - mLauncherConfig = new QSettings(config, QSettings::IniFormat); - mLauncherConfig->sync(); - - - // Make sure we have no groups open - while (!mLauncherConfig->group().isEmpty()) { - mLauncherConfig->endGroup(); - } - - mLauncherConfig->beginGroup("Profiles"); - QStringList profiles = mLauncherConfig->childGroups(); - - if (profiles.isEmpty()) { - // Add a default profile - profiles.append("Default"); - } - - mProfilesComboBox->addItems(profiles); - - QString currentProfile = mLauncherConfig->value("CurrentProfile").toString(); - - if (currentProfile.isEmpty()) { - // No current profile selected - currentProfile = "Default"; - } - mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile)); - - mLauncherConfig->endGroup(); - - // Now we connect the combobox to do something if the profile changes - // This prevents strange behaviour while reading and appending the profiles - connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&))); -} - void DataFilesPage::createActions() { // Refresh the plugins @@ -983,6 +1001,53 @@ void DataFilesPage::writeConfig(QString profile) return; } + // Prepare the OpenMW config + + // Open the config as a QFile + QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); + + if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { + // File cannot be opened or created + QMessageBox msgBox; + msgBox.setWindowTitle("Error writing OpenMW configuration file"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not open or create %0

\ + Please make sure you have the right permissions and try again.
").arg(file.fileName())); + msgBox.exec(); + + QApplication::exit(1); + } + + QTextStream in(&file); + QByteArray buffer; + + // Remove all previous master/plugin entries from config + while (!in.atEnd()) { + QString line = in.readLine(); + if (!line.contains("master") && !line.contains("plugin")) { + buffer += line += "\n"; + } + } + + file.close(); + + // Now we write back the other config entries + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { + QMessageBox msgBox; + msgBox.setWindowTitle("Error writing OpenMW configuration file"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setText(tr("
Could not write to %0

\ + Please make sure you have the right permissions and try again.
").arg(file.fileName())); + msgBox.exec(); + + QApplication::exit(1); + } + + file.write(buffer); + QTextStream gameConfig(&file); + // Make sure we have no groups open while (!mLauncherConfig->group().isEmpty()) { mLauncherConfig->endGroup(); @@ -995,13 +1060,16 @@ void DataFilesPage::writeConfig(QString profile) mLauncherConfig->beginGroup(profile); mLauncherConfig->remove(""); // Clear the subgroup - // First write the masters to the config - const QStringList masterList = selectedMasters(); + // First write the masters to the configs + const QStringList masters = selectedMasters(); // We don't use foreach because we need i - for (int i = 0; i < masterList.size(); ++i) { - const QString master = masterList.at(i); - mLauncherConfig->setValue(QString("Master%0").arg(i), master); + for (int i = 0; i < masters.size(); ++i) { + const QString currentMaster = masters.at(i); + + mLauncherConfig->setValue(QString("Master%0").arg(i), currentMaster); + gameConfig << "master=" << currentMaster << endl; + } // Now write all checked plugins @@ -1009,9 +1077,12 @@ void DataFilesPage::writeConfig(QString profile) for (int i = 0; i < plugins.size(); ++i) { - mLauncherConfig->setValue(QString("Plugin%1").arg(i), plugins.at(i)); + const QString currentPlugin = plugins.at(i); + mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin); + gameConfig << "plugin=" << currentPlugin << endl; } + file.close(); mLauncherConfig->endGroup(); mLauncherConfig->endGroup(); diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index db1068abd..a454fa871 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -29,16 +29,9 @@ public: DataFilesPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); ComboBox *mProfilesComboBox; - QSettings *mLauncherConfig; - const QStringList checkedPlugins(); - const QStringList selectedMasters(); - void setupConfig(); - void readConfig(); void writeConfig(QString profile = QString()); - void setupDataFiles(const QStringList &paths, bool strict); - public slots: void masterSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected); void setCheckState(QModelIndex index); @@ -83,13 +76,20 @@ private: QAction *mCheckAction; QAction *mUncheckAction; - Files::ConfigurationManager& mCfgMgr; + Files::ConfigurationManager &mCfgMgr; + + QSettings *mLauncherConfig; + + const QStringList checkedPlugins(); + const QStringList selectedMasters(); void addPlugins(const QModelIndex &index); void removePlugins(const QModelIndex &index); void uncheckPlugins(); void createActions(); - + void setupDataFiles(); + void setupConfig(); + void readConfig(); void scrollToSelection(); }; diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index d41a33356..c9dca1879 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -3,7 +3,7 @@ #include "graphicspage.hpp" #include -GraphicsPage::GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent) +GraphicsPage::GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent) : QWidget(parent) , mCfgMgr(cfg) { diff --git a/apps/launcher/graphicspage.hpp b/apps/launcher/graphicspage.hpp index ffd7a41b8..bdfd4f038 100644 --- a/apps/launcher/graphicspage.hpp +++ b/apps/launcher/graphicspage.hpp @@ -20,9 +20,7 @@ class GraphicsPage : public QWidget Q_OBJECT public: - GraphicsPage(Files::ConfigurationManager& cfg, QWidget *parent = 0); - - QSettings *mOgreConfig; + GraphicsPage(Files::ConfigurationManager &cfg, QWidget *parent = 0); void writeConfig(); @@ -30,7 +28,6 @@ public slots: void rendererChanged(const QString &renderer); private: - Files::ConfigurationManager& mCfgMgr; Ogre::Root *mOgre; Ogre::RenderSystem *mSelectedRenderSystem; Ogre::RenderSystem *mOpenGLRenderSystem; @@ -60,6 +57,10 @@ private: QCheckBox *mD3DVSyncCheckBox; QCheckBox *mD3DFullScreenCheckBox; + QSettings *mOgreConfig; + + Files::ConfigurationManager &mCfgMgr; + QString getConfigValue(const QString &key, Ogre::RenderSystem *renderer); QStringList getAvailableOptions(const QString &key, Ogre::RenderSystem *renderer); diff --git a/apps/launcher/main.cpp b/apps/launcher/main.cpp index f108882a3..bd29e2bca 100644 --- a/apps/launcher/main.cpp +++ b/apps/launcher/main.cpp @@ -31,13 +31,6 @@ int main(int argc, char *argv[]) QDir::setCurrent(dir.absolutePath()); - // Load the stylesheet - QFile file("./launcher.qss"); - - file.open(QFile::ReadOnly); - QString styleSheet = QLatin1String(file.readAll()); - app.setStyleSheet(styleSheet); - MainDialog dialog; return dialog.exec(); diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index dd9f0d653..14f452fa3 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -45,6 +45,20 @@ MainDialog::MainDialog() setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); setMinimumSize(QSize(575, 575)); + // Load the stylesheet + QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "launcher.qss").string()); + QFile file(config); + + if (!file.exists()) { + file.setFileName(QString::fromStdString((mCfgMgr.getLocalPath() / "launcher.qss").string())); + } + + file.open(QFile::ReadOnly); + QString styleSheet = QLatin1String(file.readAll()); + qApp->setStyleSheet(styleSheet); + file.close(); + + connect(buttonBox, SIGNAL(rejected()), this, SLOT(close())); connect(buttonBox, SIGNAL(accepted()), this, SLOT(play())); @@ -85,116 +99,13 @@ void MainDialog::createIcons() } -QStringList MainDialog::readConfig(const QString &fileName) -{ - // We can't use QSettings directly because it - // does not support multiple keys with the same name - QFile file(fileName); - - if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QMessageBox msgBox; - msgBox.setWindowTitle("Error opening OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - QApplication::exit(); // File cannot be opened or created - } - - QTextStream in(&file); - QStringList dataDirs; - QString dataLocal; - - // Read the config line by line - while (!in.atEnd()) { - QString line = in.readLine(); - - if (line.startsWith("data=")) { - dataDirs.append(line.remove("data=")); - } - - // Read the data-local key, if more than one are found only the last is used - if (line.startsWith("data-local=")) { - dataLocal = line.remove("data-local="); - } - - // Read fs-strict key - if (line.startsWith("fs-strict=")) { - QString value = line.remove("fs-strict="); - - (value.toLower() == QLatin1String("true")) - ? mStrict = true - : mStrict = false; - - } - - } - - // Add the data-local= key to the end of the dataDirs for priority reasons - if (!dataLocal.isEmpty()) { - dataDirs.append(dataLocal); - } - - if (!dataDirs.isEmpty()) - { - // Reset the global datadirs to the newly read entries - // Else return the previous dataDirs because nothing was found in this file; - mDataDirs = dataDirs; - } - - file.close(); - - return mDataDirs; -} - void MainDialog::createPages() { mPlayPage = new PlayPage(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((mCfgMgr.getGlobalPath()/"openmw.cfg").string())); - if (file.exists()) { - dataDirs = readConfig(file.fileName()); - } - - // Local location - file.setFileName("./openmw.cfg"); - - if (file.exists()) { - dataDirs = readConfig(file.fileName()); - } - - // User location - file.setFileName(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); - if (file.exists()) { - dataDirs = readConfig(file.fileName()); - } - - file.close(); - - if (!dataDirs.isEmpty()) { - // Now pass the datadirs on to the DataFilesPage - mDataFilesPage->setupDataFiles(dataDirs, mStrict); - } else { - QMessageBox msgBox; - msgBox.setWindowTitle("Error reading OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not read the location of the data files

\ - Please make sure OpenMW is correctly configured and try again.
")); - msgBox.exec(); - - QApplication::exit(); // No data or data-local entries in openmw.cfg - } - - // Set the combobox of the play page to imitate the comobox on the datafilespage + // Set the combobox of the play page to imitate the combobox on the datafilespage mPlayPage->mProfilesComboBox->setModel(mDataFilesPage->mProfilesComboBox->model()); mPlayPage->mProfilesComboBox->setCurrentIndex(mDataFilesPage->mProfilesComboBox->currentIndex()); @@ -246,14 +157,16 @@ void MainDialog::changePage(QListWidgetItem *current, QListWidgetItem *previous) void MainDialog::closeEvent(QCloseEvent *event) { // Now write all config files - writeConfig(); + mDataFilesPage->writeConfig(); + mGraphicsPage->writeConfig(); event->accept(); } void MainDialog::play() { // First do a write of all the configs, just to be sure - writeConfig(); + mDataFilesPage->writeConfig(); + mGraphicsPage->writeConfig(); #ifdef Q_WS_WIN QString game = "./openmw.exe"; @@ -313,75 +226,3 @@ void MainDialog::play() close(); } } - -void MainDialog::writeConfig() -{ - // Write the profiles - mDataFilesPage->writeConfig(); - mDataFilesPage->mLauncherConfig->sync(); - - // Write the graphics settings - mGraphicsPage->writeConfig(); - mGraphicsPage->mOgreConfig->sync(); - - QStringList dataFiles = mDataFilesPage->selectedMasters(); - dataFiles.append(mDataFilesPage->checkedPlugins()); - - // Open the config as a QFile - QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); - - if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { - // File cannot be opened or created - QMessageBox msgBox; - msgBox.setWindowTitle("Error writing OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not open or create %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - QApplication::exit(1); - } - - QTextStream in(&file); - QByteArray buffer; - - // Remove all previous master/plugin entries from config - while (!in.atEnd()) { - QString line = in.readLine(); - if (!line.contains("master") && !line.contains("plugin")) { - buffer += line += "\n"; - } - } - - file.close(); - - // Now we write back the other config entries - if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { - QMessageBox msgBox; - msgBox.setWindowTitle("Error writing OpenMW configuration file"); - msgBox.setIcon(QMessageBox::Critical); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.setText(tr("
Could not write to %0

\ - Please make sure you have the right permissions and try again.
").arg(file.fileName())); - msgBox.exec(); - - QApplication::exit(1); - } - - file.write(buffer); - - QTextStream out(&file); - - // Write the list of game files to the config - foreach (const QString ¤tFile, dataFiles) { - - if (currentFile.endsWith(QString(".esm"), Qt::CaseInsensitive)) { - out << "master=" << currentFile << endl; - } else if (currentFile.endsWith(QString(".esp"), Qt::CaseInsensitive)) { - out << "plugin=" << currentFile << endl; - } - } - - file.close(); -} diff --git a/apps/launcher/maindialog.hpp b/apps/launcher/maindialog.hpp index 718fde4f7..d6d0e9974 100644 --- a/apps/launcher/maindialog.hpp +++ b/apps/launcher/maindialog.hpp @@ -28,15 +28,11 @@ public slots: void play(); void profileChanged(int index); - private: void createIcons(); void createPages(); - void writeConfig(); void closeEvent(QCloseEvent *event); - QStringList readConfig(const QString &fileName); - QListWidget *mIconWidget; QStackedWidget *mPagesWidget; @@ -44,9 +40,6 @@ private: GraphicsPage *mGraphicsPage; DataFilesPage *mDataFilesPage; - QStringList mDataDirs; - bool mStrict; - Files::ConfigurationManager mCfgMgr; }; diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index c5561d652..5cf2952c7 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -124,7 +124,7 @@ void ConfigurationManager::loadConfig(const boost::filesystem::path& path, if (configFileStream.is_open()) { boost::program_options::store(boost::program_options::parse_config_file( - configFileStream, description), variables); + configFileStream, description, true), variables); std::cout << "done." << std::endl; } From e0206edc44d13dfe8c78826f827f20963e684d3c Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 22 Feb 2012 20:00:17 +0100 Subject: [PATCH 32/79] Fixed stupid bug in getGlobalDataPath. Signed-off-by: Lukasz Gromanowski --- components/files/windowspath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index e81041272..cf73b3728 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -64,7 +64,7 @@ boost::filesystem::path WindowsPath::getLocalPath() const boost::filesystem::path WindowsPath::getGlobalDataPath() const { - return getGlobalConfigPath(); + return getGlobalPath(); } boost::filesystem::path WindowsPath::getInstallPath() const From d5f1d7eed7517eb4a9df03abea61060ed2c3187b Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Wed, 22 Feb 2012 23:56:07 +0100 Subject: [PATCH 33/79] Fix for processing tokens inside data-local config option. Signed-off-by: Lukasz Gromanowski --- apps/openmw/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index dd7a1e780..ec1775ac8 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -160,7 +160,6 @@ 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()) @@ -173,6 +172,8 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat dataDirs.push_back(cfgMgr.getLocalPath()); } + cfgMgr.processPaths(dataDirs); + engine.setDataDirs(dataDirs); engine.setResourceDir(variables["resources"].as()); From f6a80bfc952c1f65af7971e07c0a7f9d0bcf37c1 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Thu, 23 Feb 2012 20:06:06 +0100 Subject: [PATCH 34/79] Small define/include fixes for compiling on windows --- components/files/configurationmanager.hpp | 4 ++++ components/files/fixedpath.hpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 7d77df9c0..7fb3793c6 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -1,7 +1,11 @@ #ifndef COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP #define COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP +#ifdef _WIN32 +#include +#else #include +#endif #include #include diff --git a/components/files/fixedpath.hpp b/components/files/fixedpath.hpp index 4e054b17f..9e5c4f8f2 100644 --- a/components/files/fixedpath.hpp +++ b/components/files/fixedpath.hpp @@ -30,7 +30,7 @@ #include namespace Files { typedef LinuxPath TargetPathType; } -#elif defined(__WIN32) || defined(__WINDOWS__) +#elif defined(__WIN32) || defined(__WINDOWS__) || defined(_WIN32) #include namespace Files { typedef WindowsPath TargetPathType; } From 3da6af6e380c244a8fa2f44ba3e7d75c66e15521 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Thu, 23 Feb 2012 23:01:42 +0100 Subject: [PATCH 35/79] Bug fixes for configuration handling. Added erasing double quotes from paths, corrected retriveing installation path from wine registry. Updated doxygen comments. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 5 ++++- components/files/linuxpath.cpp | 9 +++++++-- components/files/macospath.hpp | 6 +++--- components/files/windowspath.hpp | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index c5561d652..8173c6a04 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -6,6 +6,7 @@ #include #include +#include /** * \namespace Files @@ -69,9 +70,11 @@ void ConfigurationManager::readConfiguration(boost::program_options::variables_m void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) { + std::string path; for (Files::PathContainer::iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) { - const std::string& path = it->string(); + path = it->string(); + boost::erase_all(path, "\""); // Check if path contains a token if (!path.empty() && *path.begin() == '?') diff --git a/components/files/linuxpath.cpp b/components/files/linuxpath.cpp index 0b315ccfb..92e4dce33 100644 --- a/components/files/linuxpath.cpp +++ b/components/files/linuxpath.cpp @@ -105,11 +105,16 @@ boost::filesystem::path LinuxPath::getInstallPath() const std::string line; std::string mwpath; - while (std::getline(file, line) && !line.empty()) + while (std::getline(file, line)) { if (line[0] == '[') // we found an entry { - isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + if (isRegEntry) + { + break; + } + + isRegEntry = (line.find("Softworks\\\\Morrowind]") != std::string::npos); } else if (isRegEntry) { diff --git a/components/files/macospath.hpp b/components/files/macospath.hpp index 7656538c1..0e9b3402e 100644 --- a/components/files/macospath.hpp +++ b/components/files/macospath.hpp @@ -39,21 +39,21 @@ namespace Files struct MacOsPath { /** - * \brief Return path to the local configuration directory. + * \brief Return path to the local directory. * * \return boost::filesystem::path */ boost::filesystem::path getUserPath() const; /** - * \brief Return path to the global (system) configuration directory. + * \brief Return path to the global (system) directory. * * \return boost::filesystem::path */ boost::filesystem::path getGlobalPath() const; /** - * \brief Return path to the runtime configuration directory which is the + * \brief Return path to the runtime directory which is the * place where an application was started. * * \return boost::filesystem::path diff --git a/components/files/windowspath.hpp b/components/files/windowspath.hpp index 919d087f1..d4c716c50 100644 --- a/components/files/windowspath.hpp +++ b/components/files/windowspath.hpp @@ -62,7 +62,7 @@ struct WindowsPath boost::filesystem::path getLocalPath() const; /** - * \brief Return same path like getGlobalConfigPath + * \brief Return same path like getGlobalPath * * \return boost::filesystem::path */ From d97854be004a97223be0e3241c0c534df469dceb Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Thu, 23 Feb 2012 23:21:17 +0100 Subject: [PATCH 36/79] Bug fixes for configuration handling. Corrected retrieving installation path from wine registry on MacOS. Updated doxygen comments. Signed-off-by: Lukasz Gromanowski --- components/files/linuxpath.hpp | 2 +- components/files/macospath.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/components/files/linuxpath.hpp b/components/files/linuxpath.hpp index 873f8801d..48fdbb2ff 100644 --- a/components/files/linuxpath.hpp +++ b/components/files/linuxpath.hpp @@ -46,7 +46,7 @@ struct LinuxPath boost::filesystem::path getUserPath() const; /** - * \brief Return path to the global (system) configuration directory. + * \brief Return path to the global (system) directory where game files could be placed. * * \return boost::filesystem::path */ diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index 6225fc01f..fc36e2a9c 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -105,11 +105,16 @@ boost::filesystem::path MacOsPath::getInstallPath() const std::string line; std::string mwpath; - while (std::getline(file, line) && !line.empty()) + while (std::getline(file, line)) { if (line[0] == '[') // we found an entry { - isRegEntry = (line.find("Softworks\\Morrowind]") != std::string::npos); + if (isRegEntry) + { + break; + } + + isRegEntry = (line.find("Softworks\\\\Morrowind]") != std::string::npos); } else if (isRegEntry) { From fb51b281b210f95c6bcb88de263073effad7394d Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 24 Feb 2012 01:16:30 -0500 Subject: [PATCH 37/79] Slightly better performance on animation --- apps/openmw/mwrender/animation.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 63855f3b8..1318710ee 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -443,31 +443,31 @@ namespace MWRender{ Ogre::Quaternion r; bool bTrans = translist1.size() > 0; - if(bTrans){ - Ogre::Vector3 v1 = translist1[tindexI[slot]]; - Ogre::Vector3 v2 = translist1[tindexJ]; - t = (v1 + (v2 - v1) * x); - - } + bool bQuats = quats.size() > 0; - if(bQuats){ - r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); - } - skel = base->getSkeleton(); + if(skel->hasBone(iter->getBonename())){ Ogre::Bone* bone = skel->getBone(iter->getBonename()); - if(bTrans) + if(bTrans){ + Ogre::Vector3 v1 = translist1[tindexI[slot]]; + Ogre::Vector3 v2 = translist1[tindexJ]; + t = (v1 + (v2 - v1) * x); bone->setPosition(t); - if(bQuats) + + } + if(bQuats){ + r = Ogre::Quaternion::Slerp(x2, quats[rindexI[slot]], quats[rindexJ], true); bone->setOrientation(r); + } - skel->_updateTransforms(); - base->getAllAnimationStates()->_notifyDirty(); + } + skel->_updateTransforms(); + base->getAllAnimationStates()->_notifyDirty(); slot++; } From 08f3ecf9350e06b090de8198a2a6cb3d5c91ee8c Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Fri, 24 Feb 2012 01:30:17 -0500 Subject: [PATCH 38/79] Slightly better performance on animation2 --- apps/openmw/mwrender/animation.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 1318710ee..c5b67ffc9 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -466,11 +466,12 @@ namespace MWRender{ } - skel->_updateTransforms(); - base->getAllAnimationStates()->_notifyDirty(); + slot++; } + skel->_updateTransforms(); + base->getAllAnimationStates()->_notifyDirty(); } } From 68da94c8f0efb392696752f1c91f7cabb59d5474 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 24 Feb 2012 20:19:32 +0100 Subject: [PATCH 39/79] workaround for older boost versions --- apps/openmw/main.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index ec1775ac8..b8f711b21 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -35,6 +35,23 @@ #include "config.hpp" +#include +/** + * Workaround for problems with whitespaces in paths in older versions of Boost library + */ +#if (BOOST_VERSION <= 104600) +namespace boost +{ + +template<> +inline boost::filesystem::path lexical_cast(const std::string& arg) +{ + return boost::filesystem::path(arg); +} + +} /* namespace boost */ +#endif /* (BOOST_VERSION <= 104600) */ + using namespace std; /** From 771d50fe6959ec22a1c67c7cf83229f35fab5fff Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 24 Feb 2012 20:20:32 +0100 Subject: [PATCH 40/79] removed a redundant assert and a left-over comment --- apps/openmw/engine.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 2e4beb65f..6535974a9 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -246,8 +246,6 @@ void OMW::Engine::enableFSStrict(bool fsStrict) void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs) { - /// \todo remove mDataDir, once resources system can handle multiple directories - assert (!dataDirs.empty()); mDataDirs = dataDirs; mFileCollections = Files::Collections (dataDirs, !mFSStrict); } From c9a1789db8b73dca2923afb31cb7c5d48b8a3585 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sat, 25 Feb 2012 10:20:42 +0100 Subject: [PATCH 41/79] Bug fix for processing data paths in OpenMW Launcher. Signed-off-by: Lukasz Gromanowski --- apps/launcher/datafilespage.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index fb8631f73..8100631d7 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -188,8 +188,7 @@ void DataFilesPage::setupDataFiles() // Put the paths in a boost::filesystem vector to use with Files::Collections Files::PathContainer dataDirs(variables["data"].as()); - mCfgMgr.processPaths(dataDirs); - + std::string local(variables["data-local"].as()); if (!local.empty()) { @@ -201,6 +200,8 @@ void DataFilesPage::setupDataFiles() dataDirs.push_back(mCfgMgr.getLocalPath()); } + mCfgMgr.processPaths(dataDirs); + // Create a file collection for the dataDirs Files::Collections fileCollections(dataDirs, !variables["fs-strict"].as()); From cb780720bba5391cfb1e178851431353aee15d0d Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Sat, 25 Feb 2012 17:43:30 +0400 Subject: [PATCH 42/79] fix for string.h: use our own strnlen only on OS X < 10.7 --- libs/platform/string.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/platform/string.h b/libs/platform/string.h index d4302ae78..89ac141a8 100644 --- a/libs/platform/string.h +++ b/libs/platform/string.h @@ -3,7 +3,7 @@ #define _STRING_WRAPPER_H #include -#if defined(__APPLE__) || defined(__MINGW32__) +#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070) || defined(__MINGW32__) // need our own implementation of strnlen static size_t strnlen(const char *s, size_t n) { From 1addef2cc3e3b02ec8dbd808c6f3424d39f531a6 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Sat, 25 Feb 2012 17:47:57 +0400 Subject: [PATCH 43/79] added missing include for macospath.cpp --- components/files/macospath.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/files/macospath.cpp b/components/files/macospath.cpp index fc36e2a9c..94dafe794 100644 --- a/components/files/macospath.cpp +++ b/components/files/macospath.cpp @@ -27,6 +27,7 @@ #include #include #include +#include /** * FIXME: Someone with MacOS system should check this and correct if necessary From 822f47fbac4433fe9b6f6eb92f759dd5f91b7fd1 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Sat, 25 Feb 2012 18:05:29 +0400 Subject: [PATCH 44/79] Slightly changed OIS include dir var used specially for OS X. Should not change anything on other platforms --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41da79a05..a89745468 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -190,7 +190,7 @@ find_package(OpenAL REQUIRED) find_package(Bullet REQUIRED) include_directories("." ${OGRE_INCLUDE_DIR} ${OGRE_INCLUDE_DIR}/Ogre ${OGRE_INCLUDE_DIR}/OGRE - ${OIS_INCLUDE_DIR} ${Boost_INCLUDE_DIR} + ${OIS_INCLUDE_DIRS} ${Boost_INCLUDE_DIR} ${PLATFORM_INCLUDE_DIR} ${CMAKE_HOME_DIRECTORY}/extern/caelum/include ${CMAKE_HOME_DIRECTORY}/extern/mygui_3.0.1/MyGUIEngine/include From cb5534c6083f8f47b4bf51ea0eba32fd8b315b5a Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Sun, 26 Feb 2012 12:12:00 +0100 Subject: [PATCH 45/79] Updated website URL in CMakeLists file. Signed-off-by: Lukasz Gromanowski --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41da79a05..58f4b938b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,7 +300,7 @@ if(DPKG_PROGRAM) SET(CPACK_GENERATOR "DEB") SET(CPACK_PACKAGE_NAME "openmw") - SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://openmw.com") + SET(CPACK_DEBIAN_PACKAGE_HOMEPAGE "http://openmw.org") SET(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "${PACKAGE_MAINTAINER}") SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "A reimplementation of The Elder Scrolls III: Morrowind From be8690e333d1f4757654e91616fdae8c2ba79943 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Sun, 26 Feb 2012 22:45:17 +0100 Subject: [PATCH 46/79] Fix for debug crash on windows --- apps/openmw/mwrender/actors.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index acc655404..85217b42d 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -99,12 +99,14 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ mRend.getScene()->destroySceneNode(base); base = 0; } - for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); iter++) + for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); ) { if(iter->first.getCell() == store){ delete iter->second; - mAllActors.erase(iter); + iter = mAllActors.erase(iter); } + else + ++iter; } } From 053a2996d2e487356b100c8b5782ed2a9979421f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 26 Feb 2012 23:31:16 +0100 Subject: [PATCH 47/79] fix for non-standard erase function --- apps/openmw/mwrender/actors.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwrender/actors.cpp b/apps/openmw/mwrender/actors.cpp index 85217b42d..d8ca78e3a 100644 --- a/apps/openmw/mwrender/actors.cpp +++ b/apps/openmw/mwrender/actors.cpp @@ -99,16 +99,15 @@ void Actors::removeCell(MWWorld::Ptr::CellStore* store){ mRend.getScene()->destroySceneNode(base); base = 0; } - for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); ) - { - if(iter->first.getCell() == store){ - delete iter->second; - iter = mAllActors.erase(iter); - } + for(std::map::iterator iter = mAllActors.begin(); iter != mAllActors.end(); ) + { + if(iter->first.getCell() == store){ + delete iter->second; + mAllActors.erase(iter++); + } else ++iter; - } - + } } void Actors::playAnimationGroup (const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number){ From 8d7a5f469b43f0ec1d3e5678867421cd45b78659 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 26 Feb 2012 21:27:54 -0500 Subject: [PATCH 48/79] a few changes --- apps/openmw/mwrender/animation.cpp | 26 +++++++++++++++----------- apps/openmw/mwrender/animation.hpp | 6 ++++-- apps/openmw/mwrender/npcanimation.cpp | 1 + components/nifogre/ogre_nif_loader.cpp | 3 ++- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c5b67ffc9..c30579b0f 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -276,6 +276,7 @@ namespace MWRender{ rotmult = bonePtr->getOrientation(); scale = bonePtr->getScale().x; boneSequenceIter++; + std::cout << "Entering\n"; for(; boneSequenceIter != boneSequence.end(); boneSequenceIter++) { if(creaturemodel->getSkeleton()->hasBone(*boneSequenceIter)){ @@ -330,7 +331,7 @@ namespace MWRender{ } } - bool Animation::timeIndex( float time, std::vector times, int & i, int & j, float & x ){ + bool Animation::timeIndex( float time, std::vector& times, int & i, int & j, float & x ){ int count; if ( (count = times.size()) > 0 ) { @@ -388,6 +389,8 @@ namespace MWRender{ } void Animation::handleAnimationTransforms(){ + + Ogre::SkeletonInstance* skel = base->getSkeleton(); @@ -404,10 +407,10 @@ namespace MWRender{ for(unsigned int i = 0; i < entityparts.size(); i++){ //Ogre::SkeletonInstance* skel = entityparts[i]->getSkeleton(); - Ogre::Bone* b = skel->getRootBone(); - b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick + //Ogre::Bone* b = skel->getRootBone(); + //b->setOrientation(Ogre::Real(.3),Ogre::Real(.3),Ogre::Real(.3), Ogre::Real(.3));//This is a trick - entityparts[i]->getAllAnimationStates()->_notifyDirty(); + //entityparts[i]->getAllAnimationStates()->_notifyDirty(); } @@ -424,18 +427,19 @@ namespace MWRender{ float x; float x2; - std::vector quats = iter->getQuat(); + std::vector& quats = iter->getQuat(); - std::vector ttime = iter->gettTime(); - std::vector::iterator ttimeiter = ttime.begin(); + std::vector& ttime = iter->gettTime(); + - std::vector rtime = iter->getrTime(); - int rindexJ = 0; + std::vector& rtime = iter->getrTime(); + int rindexJ = rindexI[slot]; + timeIndex(time, rtime, rindexI[slot], rindexJ, x2); - int tindexJ = 0; + int tindexJ = tindexI[slot]; - std::vector translist1 = iter->getTranslist1(); + std::vector& translist1 = iter->getTranslist1(); timeIndex(time, ttime, tindexI[slot], tindexJ, x); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index bad7eca15..63ca3da2d 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -28,6 +28,8 @@ class Animation{ MWWorld::Environment& mEnvironment; std::map vecRotPos; static std::map mUniqueIDs; + float oldHund; + bool samePlace; std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc @@ -55,11 +57,11 @@ class Animation{ Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); void handleAnimationTransforms(); - bool timeIndex( float time, std::vector times, int & i, int & j, float & x ); + bool timeIndex( float time, std::vector& times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), animate(0){}; + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), animate(0), oldHund(0){}; virtual void runAnimation(float timepassed) = 0; void startScript(std::string groupname, int mode, int loops); void stopScript(); diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 4c9c0e466..0ceb0a4c3 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -276,6 +276,7 @@ void NpcAnimation::runAnimation(float timepassed){ shapepartsiter++; entitypartsiter++; } + } } diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 8b5540019..62dbc29df 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1328,7 +1328,8 @@ void NIFLoader::loadResource(Resource *resource) (*iter)->addBoneAssignment(vba); } - mesh->_notifySkeleton(mSkel); + if(triname == "") + mesh->_notifySkeleton(mSkel); } } From 36e93228309b37ccf2019b530148b401e84ed73a Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sun, 26 Feb 2012 21:43:04 -0500 Subject: [PATCH 49/79] a few changes2 --- apps/openmw/mwrender/animation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c30579b0f..999d85414 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -276,7 +276,7 @@ namespace MWRender{ rotmult = bonePtr->getOrientation(); scale = bonePtr->getScale().x; boneSequenceIter++; - std::cout << "Entering\n"; + for(; boneSequenceIter != boneSequence.end(); boneSequenceIter++) { if(creaturemodel->getSkeleton()->hasBone(*boneSequenceIter)){ From d58b408ae11c0004840140dbd5427b9a7156a935 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Mon, 27 Feb 2012 19:00:06 +0400 Subject: [PATCH 50/79] Deploying Qt image format plugins on OS X considered useless --- apps/launcher/CMakeLists.txt | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 2879539a7..d648f4674 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -51,17 +51,6 @@ QT4_WRAP_CPP(MOC_SRCS ${LAUNCHER_HEADER_MOC}) include(${QT_USE_FILE}) -# list here plugins that can't be detected statically, but loaded in runtime -# it needed for packaging automatisation -set(USED_QT_PLUGINS imageformats/libqgif - imageformats/libqico - imageformats/libqjpeg - imageformats/libqmng - imageformats/libqsvg - imageformats/libqtga - imageformats/libqtiff) -# It seems that launcher works without this plugins, but it loads them if they exists - # Main executable add_executable(omwlauncher ${LAUNCHER} @@ -86,13 +75,6 @@ if (APPLE) "${APP_BUNDLE_DIR}/../launcher.qss") configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss "${APP_BUNDLE_DIR}/../launcher.cfg") - - # copy used QT plugins into ${APP_BUNDLE_DIR}/Contents/Plugins - foreach(PLUGIN ${USED_QT_PLUGINS}) - get_filename_component(PLUGIN_FILENAME ${PLUGIN} NAME) - configure_file("${QT_PLUGINS_DIR}/${PLUGIN}.dylib" "${APP_BUNDLE_DIR}/Contents/Plugins/${PLUGIN}.dylib" COPYONLY) - endforeach() - else() configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launcher.qss") From bfb3a4a36b3ca0c15531ef128cf2d56b20fb5e63 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Mon, 27 Feb 2012 22:22:17 +0100 Subject: [PATCH 51/79] Changed FindOGRE a bit to make it easier to find a source build of Ogre. (At least on windows) --- cmake/FindOGRE.cmake | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cmake/FindOGRE.cmake b/cmake/FindOGRE.cmake index ce3993805..3311ee220 100644 --- a/cmake/FindOGRE.cmake +++ b/cmake/FindOGRE.cmake @@ -26,13 +26,15 @@ IF (WIN32) #Windows SET(OGRE_INCLUDE_DIR ${OGRESDK}/include) SET(OGRE_LIB_DIR ${OGRESDK}/lib) SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain) - ENDIF (OGRESDK) - IF (OGRESOURCE) + ELSEIF (OGRESOURCE) MESSAGE(STATUS "Using OGRE built from source") SET(OGRE_INCLUDE_DIR $ENV{OGRE_SRC}/OgreMain/include) SET(OGRE_LIB_DIR $ENV{OGRE_SRC}/lib) SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain) - ENDIF (OGRESOURCE) + ELSE (OGRESDK) + MESSAGE(STATUS "Using OGRE paths from CMake") + SET(OGRE_LIBRARIES debug OgreMain_d optimized OgreMain) + ENDIF (OGRESDK) ENDIF (WIN32) IF (UNIX AND NOT APPLE) @@ -80,9 +82,12 @@ SET(OGRE_LIB_DIR ${OGRE_LIB_DIR} CACHE PATH "") if(OGRE_LIB_DIR) CMAKE_POLICY(SET CMP0009 NEW) - IF (NOT APPLE) + IF (WIN32) + FILE(GLOB_RECURSE OGRE_PLUGINS "${OGRE_LIB_DIR}/Plugin_*.lib") + ENDIF (WIN32) + IF (NOT APPLE AND NOT WIN32) FILE(GLOB_RECURSE OGRE_PLUGINS "${OGRE_LIB_DIR}/Plugin_*.so") - ENDIF (NOT APPLE) + ENDIF (NOT APPLE AND NOT WIN32) IF (APPLE) FILE(GLOB_RECURSE OGRE_PLUGINS "${OGRE_LIB_DIR}/Plugin_*.dylib") ENDIF (APPLE) From 9a4cd6c2b1debb5e2174e485d4476b1db3d18132 Mon Sep 17 00:00:00 2001 From: Lukasz Gromanowski Date: Mon, 27 Feb 2012 23:56:58 +0100 Subject: [PATCH 52/79] Fixes #200 - Paths with quotes for data-local option. Signed-off-by: Lukasz Gromanowski --- components/files/configurationmanager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 887a054ad..ef45b6543 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -75,6 +75,7 @@ void ConfigurationManager::processPaths(Files::PathContainer& dataDirs) { path = it->string(); boost::erase_all(path, "\""); + *it = boost::filesystem::path(path); // Check if path contains a token if (!path.empty() && *path.begin() == '?') From 4c2fffdd614b836069dd9c69e51e162666ca7c19 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 28 Feb 2012 09:27:35 +0100 Subject: [PATCH 53/79] temporarily disabled multi data path support in OpenMW --- apps/openmw/main.cpp | 9 ++++++--- files/openmw.cfg | 3 --- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/openmw/main.cpp b/apps/openmw/main.cpp index b8f711b21..cd1e0e26e 100644 --- a/apps/openmw/main.cpp +++ b/apps/openmw/main.cpp @@ -181,12 +181,15 @@ bool parseOptions (int argc, char** argv, OMW::Engine& engine, Files::Configurat std::string local(variables["data-local"].as()); if (!local.empty()) { - dataDirs.push_back(Files::PathContainer::value_type(local)); + std::cout << "Ignoring data-local (currently not supported)" << std::endl; +// dataDirs.push_back(Files::PathContainer::value_type(local)); } - if (dataDirs.empty()) + if (dataDirs.size()>1) { - dataDirs.push_back(cfgMgr.getLocalPath()); + dataDirs.resize (1); + std::cout << "Ignoring all but the first data path (multiple data paths currently not supported)" + << std::endl; } cfgMgr.processPaths(dataDirs); diff --git a/files/openmw.cfg b/files/openmw.cfg index 585b735f3..0af096e6a 100644 --- a/files/openmw.cfg +++ b/files/openmw.cfg @@ -1,5 +1,2 @@ data="?mw?Data Files" -data="?global?data" -data="?local?data" -data-local="?user?data" resources=${MORROWIND_RESOURCE_FILES} From 7aaa7f185f530e610bfeaf36f29e5f1d1335bbef Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 28 Feb 2012 09:46:48 +0100 Subject: [PATCH 54/79] same for launcher --- apps/launcher/datafilespage.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 8100631d7..d3968f2bf 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -180,7 +180,7 @@ void DataFilesPage::setupDataFiles() desc.add_options() ("data", boost::program_options::value()->default_value(Files::PathContainer(), "data")->multitoken()) - ("data-local", boost::program_options::value()->default_value("")) +// ("data-local", boost::program_options::value()->default_value("")) ("fs-strict", boost::program_options::value()->implicit_value(true)->default_value(false)) ("encoding", boost::program_options::value()->default_value("win1252")); @@ -188,17 +188,15 @@ void DataFilesPage::setupDataFiles() // Put the paths in a boost::filesystem vector to use with Files::Collections Files::PathContainer dataDirs(variables["data"].as()); - - std::string local(variables["data-local"].as()); - if (!local.empty()) - { - dataDirs.push_back(Files::PathContainer::value_type(local)); - } - if (dataDirs.empty()) - { - dataDirs.push_back(mCfgMgr.getLocalPath()); - } +// std::string local(variables["data-local"].as()); +// if (!local.empty()) +// { +// dataDirs.push_back(Files::PathContainer::value_type(local)); +// } + + if (dataDirs.size()>1) + dataDirs.resize (1); mCfgMgr.processPaths(dataDirs); From dc1fe6fb4d957f1b2330674b29c3c470461acb72 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 28 Feb 2012 09:56:12 +0100 Subject: [PATCH 55/79] adjusted readme --- readme.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/readme.txt b/readme.txt index 47dd6d3fd..d9e6cbfa4 100644 --- a/readme.txt +++ b/readme.txt @@ -141,8 +141,6 @@ Feature #45: NPC animations Feature #46: Creature Animation Feature #89: Basic Journal Window Feature #110: Automatically pick up the path of existing MW-installations -Feature #133: Handle resources across multiple data directories -Feature #134: Generate a suitable default-value for --data-local Feature #183: More FPS display settings Task #19: Refactor engine class Task #109/Feature #162: Automate Packaging From 1512481c075e8063dba59cf64d267d5b1ff22ca1 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 28 Feb 2012 17:18:01 +0100 Subject: [PATCH 56/79] Changed the way whitespace was removed from retrieved Ogre values --- apps/launcher/graphicspage.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index c9dca1879..858f3155d 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -246,13 +246,7 @@ void GraphicsPage::setupOgre() if (mOpenGLRenderSystem) { mOGLRTTComboBox->addItems(getAvailableOptions(QString("RTT Preferred Mode"), mOpenGLRenderSystem)); mOGLAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mOpenGLRenderSystem)); - - QStringList videoModes = getAvailableOptions(QString("Video Mode"), mOpenGLRenderSystem); - // Remove extraneous spaces - videoModes.replaceInStrings(QRegExp("\\s{2,}"), QString(" ")); - videoModes.replaceInStrings(QRegExp("^\\s"), QString()); - - mOGLResolutionComboBox->addItems(videoModes); + mOGLResolutionComboBox->addItems(getAvailableOptions(QString("Video Mode"), mOpenGLRenderSystem)); mOGLFrequencyComboBox->addItems(getAvailableOptions(QString("Display Frequency"), mOpenGLRenderSystem)); } @@ -261,12 +255,7 @@ void GraphicsPage::setupOgre() mD3DRenderDeviceComboBox->addItems(getAvailableOptions(QString("Rendering Device"), mDirect3DRenderSystem)); mD3DAntiAliasingComboBox->addItems(getAvailableOptions(QString("FSAA"), mDirect3DRenderSystem)); mD3DFloatingPointComboBox->addItems(getAvailableOptions(QString("Floating-point mode"), mDirect3DRenderSystem)); - - QStringList videoModes = getAvailableOptions(QString("Video Mode"), mDirect3DRenderSystem); - // Remove extraneous spaces - videoModes.replaceInStrings(QRegExp("\\s{2,}"), QString(" ")); - videoModes.replaceInStrings(QRegExp("^\\s"), QString()); - mD3DResolutionComboBox->addItems(videoModes); + mD3DResolutionComboBox->addItems(getAvailableOptions(QString("Video Mode"), mDirect3DRenderSystem)); } } @@ -481,7 +470,7 @@ QStringList GraphicsPage::getAvailableOptions(const QString &key, Ogre::RenderSy { if (strcmp (key.toStdString().c_str(), i->first.c_str()) == 0) - result << (*opt_it).c_str(); + result << QString::fromStdString((*opt_it).c_str()).simplified(); } } From 5b54a658d89d9cea14a6365278cc6828d63e503d Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 28 Feb 2012 17:19:44 +0100 Subject: [PATCH 57/79] Launcher improvements: ask for data dir and write it to cfg if none is found and prevent removal of the default profile --- CMakeLists.txt | 2 +- apps/launcher/CMakeLists.txt | 6 +- apps/launcher/datafilespage.cpp | 186 ++++++++++++++++++++++---------- apps/launcher/datafilespage.hpp | 5 + 4 files changed, 138 insertions(+), 61 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e62391c74..666522e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -428,7 +428,7 @@ if (APPLE) install(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" RENAME "openmw.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) - install(FILES "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) + set(CPACK_GENERATOR "DragNDrop") set(CPACK_PACKAGE_VERSION ${OPENMW_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR ${OPENMW_VERSION_MAJOR}) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index d648f4674..80e8f61c7 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -72,13 +72,13 @@ endif() if (APPLE) configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss - "${APP_BUNDLE_DIR}/../launcher.qss") + "${APP_BUNDLE_DIR}/resources/../launcher.qss") configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss "${APP_BUNDLE_DIR}/../launcher.cfg") else() configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss - "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launcher.qss") + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/launcher.qss") configure_file(${CMAKE_SOURCE_DIR}/files/launcher.cfg - "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launcher.cfg") + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}launcher.cfg") endif() diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 8100631d7..8c203a771 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -1,8 +1,6 @@ #include #include -#include -#include #include #include "datafilespage.hpp" @@ -120,11 +118,12 @@ DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, QWidget *parent) connect(mPluginsTable, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setCheckState(QModelIndex))); connect(mPluginsTable, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(showContextMenu(const QPoint&))); + connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&))); - + createActions(); setupConfig(); setupDataFiles(); - createActions(); + } void DataFilesPage::setupConfig() @@ -138,8 +137,7 @@ void DataFilesPage::setupConfig() // Open our config file mLauncherConfig = new QSettings(config, QSettings::IniFormat); - mLauncherConfig->sync(); - + file.close(); // Make sure we have no groups open while (!mLauncherConfig->group().isEmpty()) { @@ -162,13 +160,14 @@ void DataFilesPage::setupConfig() // No current profile selected currentProfile = "Default"; } - mProfilesComboBox->setCurrentIndex(mProfilesComboBox->findText(currentProfile)); + + const int currentIndex = mProfilesComboBox->findText(currentProfile); + if (currentIndex != -1) { + // Profile is found + mProfilesComboBox->setCurrentIndex(currentIndex); + } mLauncherConfig->endGroup(); - - // Now we connect the combobox to do something if the profile changes - // This prevents strange behaviour while reading and appending the profiles - connect(mProfilesComboBox, SIGNAL(textChanged(const QString&, const QString&)), this, SLOT(profileChanged(const QString&, const QString&))); } @@ -188,19 +187,51 @@ void DataFilesPage::setupDataFiles() // Put the paths in a boost::filesystem vector to use with Files::Collections Files::PathContainer dataDirs(variables["data"].as()); - - std::string local(variables["data-local"].as()); - if (!local.empty()) - { + mDataDirs = dataDirs; + + std::string local = variables["data-local"].as(); + if (!local.empty()) { + mDataLocal.push_back(Files::PathContainer::value_type(local)); dataDirs.push_back(Files::PathContainer::value_type(local)); } - if (dataDirs.empty()) - { - dataDirs.push_back(mCfgMgr.getLocalPath()); + mCfgMgr.processPaths(dataDirs); + + while (dataDirs.empty()) { + // No valid data files directory found + + QMessageBox msgBox; + msgBox.setWindowTitle("Error detecting Morrowind installation"); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setText(tr("
Could not find the Data Files location

\ + The directory containing the Data Files was not found.

\ + Press \"Browse...\" to specify the location manually.
")); + + QAbstractButton *dirSelectButton = + msgBox.addButton(tr("B&rowse..."), QMessageBox::ActionRole); + + msgBox.exec(); + + if (msgBox.clickedButton() == dirSelectButton) { + + QString dataDir = QFileDialog::getExistingDirectory( + this, tr("Select Data Files Directory"), + "/home", + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + + dataDirs.push_back(Files::PathContainer::value_type(dataDir.toStdString())); + mDataDirs.push_back(Files::PathContainer::value_type(dataDir.toStdString())); + } else { + // Cancel + break; + } } - mCfgMgr.processPaths(dataDirs); + // Check if cancel was clicked because we can't exit from while loop + if (dataDirs.empty()) { + QApplication::exit(1); + } // Create a file collection for the dataDirs Files::Collections fileCollections(dataDirs, !variables["fs-strict"].as()); @@ -209,15 +240,13 @@ void DataFilesPage::setupDataFiles() const Files::MultiDirCollection &esm = fileCollections.getCollection(".esm"); unsigned int i = 0; // Row number - for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter) - { + for (Files::MultiDirCollection::TIter iter(esm.begin()); iter!=esm.end(); ++iter) { QString currentMaster = QString::fromStdString( boost::filesystem::path (iter->second.filename()).string()); const QList itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly); - if (itemList.isEmpty()) // Master is not yet in the widget - { + if (itemList.isEmpty()) { // Master is not yet in the widget mMastersWidget->insertRow(i); QTableWidgetItem *item = new QTableWidgetItem(currentMaster); mMastersWidget->setItem(i, 0, item); @@ -228,8 +257,7 @@ void DataFilesPage::setupDataFiles() // Now on to the plugins const Files::MultiDirCollection &esp = fileCollections.getCollection(".esp"); - for (Files::MultiDirCollection::TIter iter(esp.begin()); iter!=esp.end(); ++iter) - { + for (Files::MultiDirCollection::TIter iter(esp.begin()); iter!=esp.end(); ++iter) { ESMReader fileReader; QStringList availableMasters; // Will contain all found masters @@ -245,8 +273,7 @@ void DataFilesPage::setupDataFiles() const QList itemList = mMastersWidget->findItems(currentMaster, Qt::MatchExactly); - if (itemList.isEmpty()) // Master is not yet in the widget - { + if (itemList.isEmpty()) { // Master is not yet in the widget mMastersWidget->insertRow(i); QTableWidgetItem *item = new QTableWidgetItem(currentMaster); @@ -435,18 +462,18 @@ void DataFilesPage::deleteProfile() return; } - QMessageBox deleteMessageBox(this); - deleteMessageBox.setWindowTitle(tr("Delete Profile")); - deleteMessageBox.setText(tr("Are you sure you want to delete %0?").arg(profile)); - deleteMessageBox.setIcon(QMessageBox::Warning); + QMessageBox msgBox(this); + msgBox.setWindowTitle(tr("Delete Profile")); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setText(tr("Are you sure you want to delete %0?").arg(profile)); + QAbstractButton *deleteButton = - deleteMessageBox.addButton(tr("Delete"), QMessageBox::ActionRole); + msgBox.addButton(tr("Delete"), QMessageBox::ActionRole); - deleteMessageBox.addButton(QMessageBox::Cancel); + msgBox.exec(); - deleteMessageBox.exec(); - - if (deleteMessageBox.clickedButton() == deleteButton) { + if (msgBox.clickedButton() == deleteButton) { // Make sure we have no groups open while (!mLauncherConfig->group().isEmpty()) { mLauncherConfig->endGroup(); @@ -503,7 +530,6 @@ void DataFilesPage::moveUp() void DataFilesPage::moveDown() { // Shift the selected plugins down one row - if (!mPluginsTable->selectionModel()->hasSelection()) { return; } @@ -919,9 +945,18 @@ void DataFilesPage::filterChanged(const QString filter) void DataFilesPage::profileChanged(const QString &previous, const QString ¤t) { + // Prevent the deletion of the default profile + if (current == "Default") { + mDeleteProfileAction->setEnabled(false); + } else { + mDeleteProfileAction->setEnabled(true); + } + if (!previous.isEmpty()) { writeConfig(previous); mLauncherConfig->sync(); + } else { + return; } uncheckPlugins(); @@ -989,22 +1024,12 @@ void DataFilesPage::readConfig() void DataFilesPage::writeConfig(QString profile) { - // Don't overwrite the config if no plugins are found - if (mPluginsModel->rowCount() < 1) { + // Don't overwrite the config if no masters are found + if (mMastersWidget->rowCount() < 1) { return; } - if (profile.isEmpty()) { - profile = mProfilesComboBox->currentText(); - } - - if (profile.isEmpty()) { - return; - } - - // Prepare the OpenMW config - - // Open the config as a QFile + // Open the OpenMW config as a QFile QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { @@ -1023,10 +1048,14 @@ void DataFilesPage::writeConfig(QString profile) QTextStream in(&file); QByteArray buffer; - // Remove all previous master/plugin entries from config + // Remove all previous entries from config while (!in.atEnd()) { QString line = in.readLine(); - if (!line.contains("master") && !line.contains("plugin")) { + if (!line.startsWith("master") && + !line.startsWith("plugin") && + !line.startsWith("data") && + !line.startsWith("data-local")) + { buffer += line += "\n"; } } @@ -1046,9 +1075,52 @@ void DataFilesPage::writeConfig(QString profile) QApplication::exit(1); } - file.write(buffer); + if (!buffer.isEmpty()) { + file.write(buffer); + } + QTextStream gameConfig(&file); + // First write the list of data dirs + mCfgMgr.processPaths(mDataDirs); + mCfgMgr.processPaths(mDataLocal); + + QString path; + + // data= directories + for (Files::PathContainer::iterator it = mDataDirs.begin(); it != mDataDirs.end(); ++it) { + path = QString::fromStdString(it->string()); + path.remove(QChar('\"')); + + // Make sure the string is quoted when it contains spaces + if (path.contains(" ")) { + gameConfig << "data=\"" << path << "\"" << endl; + } else { + gameConfig << "data=" << path << endl; + } + } + + // data-local directory + if (!mDataLocal.empty()) { + path = QString::fromStdString(mDataLocal.front().string()); + path.remove(QChar('\"')); + + if (path.contains(" ")) { + gameConfig << "data-local=\"" << path << "\"" << endl; + } else { + gameConfig << "data-local=" << path << endl; + } + } + + + if (profile.isEmpty()) { + profile = mProfilesComboBox->currentText(); + } + + if (profile.isEmpty()) { + return; + } + // Make sure we have no groups open while (!mLauncherConfig->group().isEmpty()) { mLauncherConfig->endGroup(); @@ -1061,7 +1133,7 @@ void DataFilesPage::writeConfig(QString profile) mLauncherConfig->beginGroup(profile); mLauncherConfig->remove(""); // Clear the subgroup - // First write the masters to the configs + // Now write the masters to the configs const QStringList masters = selectedMasters(); // We don't use foreach because we need i @@ -1073,11 +1145,10 @@ void DataFilesPage::writeConfig(QString profile) } - // Now write all checked plugins + // And finally write all checked plugins const QStringList plugins = checkedPlugins(); - for (int i = 0; i < plugins.size(); ++i) - { + for (int i = 0; i < plugins.size(); ++i) { const QString currentPlugin = plugins.at(i); mLauncherConfig->setValue(QString("Plugin%1").arg(i), currentPlugin); gameConfig << "plugin=" << currentPlugin << endl; @@ -1086,5 +1157,6 @@ void DataFilesPage::writeConfig(QString profile) file.close(); mLauncherConfig->endGroup(); mLauncherConfig->endGroup(); + mLauncherConfig->sync(); } diff --git a/apps/launcher/datafilespage.hpp b/apps/launcher/datafilespage.hpp index a454fa871..ad5e90511 100644 --- a/apps/launcher/datafilespage.hpp +++ b/apps/launcher/datafilespage.hpp @@ -3,6 +3,9 @@ #include #include + +#include + #include "combobox.hpp" class QTableWidget; @@ -77,6 +80,8 @@ private: QAction *mUncheckAction; Files::ConfigurationManager &mCfgMgr; + Files::PathContainer mDataDirs; + Files::PathContainer mDataLocal; QSettings *mLauncherConfig; From b320733e454452251a2c8ac552e07c1e0dabed2d Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 28 Feb 2012 21:00:02 +0100 Subject: [PATCH 58/79] Fixed Qt exits, this time for all occurrences --- apps/launcher/datafilespage.cpp | 6 ++++-- apps/launcher/graphicspage.cpp | 11 ++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index d3968f2bf..b0d9779d5 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -1015,7 +1015,8 @@ void DataFilesPage::writeConfig(QString profile) Please make sure you have the right permissions and try again.
").arg(file.fileName())); msgBox.exec(); - QApplication::exit(1); + qApp->exit(1); + return; } QTextStream in(&file); @@ -1041,7 +1042,8 @@ void DataFilesPage::writeConfig(QString profile) Please make sure you have the right permissions and try again.
").arg(file.fileName())); msgBox.exec(); - QApplication::exit(1); + qApp->exit(1); + return; } file.write(buffer); diff --git a/apps/launcher/graphicspage.cpp b/apps/launcher/graphicspage.cpp index c9dca1879..aaa54dd7f 100644 --- a/apps/launcher/graphicspage.cpp +++ b/apps/launcher/graphicspage.cpp @@ -180,7 +180,7 @@ void GraphicsPage::setupOgre() Make sure you have write access to
%1

")).arg(configDir.path())); msgBox.exec(); - QApplication::exit(1); + qApp->exit(1); return; } @@ -203,7 +203,7 @@ void GraphicsPage::setupOgre() qCritical("Error creating Ogre::Root, the error reported was:\n %s", qPrintable(ogreError)); - QApplication::exit(1); + qApp->exit(1); return; } @@ -237,7 +237,7 @@ void GraphicsPage::setupOgre() Please make sure the plugins.cfg file exists and contains a valid rendering plugin.
")); msgBox.exec(); - QApplication::exit(1); + qApp->exit(1); return; } @@ -423,7 +423,7 @@ void GraphicsPage::writeConfig() qCritical("Error validating configuration"); - QApplication::exit(1); + qApp->exit(1); return; } @@ -449,7 +449,8 @@ void GraphicsPage::writeConfig() qCritical("Error saving Ogre configuration, the error reported was:\n %s", qPrintable(ogreError)); - QApplication::exit(1); + qApp->exit(1); + return; } } From 11ec5cf2e28fd5ab6dd2a155539cd17474f9bf51 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Tue, 28 Feb 2012 22:35:29 +0100 Subject: [PATCH 59/79] Stylesheet location changed in CMakeLists and some minor fixes to the launcher --- CMakeLists.txt | 2 -- apps/launcher/CMakeLists.txt | 8 ++++++-- apps/launcher/datafilespage.cpp | 14 ++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e62391c74..4c686733b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -329,7 +329,6 @@ if(WIN32) FILE(GLOB files "${OpenMW_BINARY_DIR}/Release/*.*") INSTALL(FILES ${files} DESTINATION ".") INSTALL(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" DESTINATION "." RENAME "openmw.cfg") - INSTALL(FILES "${OpenMW_BINARY_DIR}/launcher.qss" "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION ".") INSTALL(DIRECTORY "${OpenMW_BINARY_DIR}/resources" DESTINATION ".") SET(CPACK_GENERATOR "NSIS") @@ -428,7 +427,6 @@ if (APPLE) install(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" RENAME "openmw.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) - install(FILES "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) set(CPACK_GENERATOR "DragNDrop") set(CPACK_PACKAGE_VERSION ${OPENMW_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR ${OPENMW_VERSION_MAJOR}) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index d648f4674..3a5ccdd04 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -72,10 +72,14 @@ endif() if (APPLE) configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss - "${APP_BUNDLE_DIR}/../launcher.qss") - configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss + "${APP_BUNDLE_DIR}/../resources/launcher.qss") + configure_file(${CMAKE_SOURCE_DIR}/files/launcher.cfg "${APP_BUNDLE_DIR}/../launcher.cfg") else() + configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/resources/launcher.qss") + + # Fallback in case getGlobalDataPath does not point to resources configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/launcher.qss") diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index b0d9779d5..b88664f0c 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -987,8 +987,8 @@ void DataFilesPage::readConfig() void DataFilesPage::writeConfig(QString profile) { - // Don't overwrite the config if no plugins are found - if (mPluginsModel->rowCount() < 1) { + // Don't overwrite the config if no masters are found + if (mMastersWidget->rowCount() < 1) { return; } @@ -1001,9 +1001,15 @@ void DataFilesPage::writeConfig(QString profile) } // Prepare the OpenMW config + QString config = QString::fromStdString((mCfgMgr.getLocalPath() / "openmw.cfg").string()); + QFile file(config); + + if (!file.exists()) { + config = QString::fromStdString((mCfgMgr.getUserPath() / "openmw.cfg").string()); + } // Open the config as a QFile - QFile file(QString::fromStdString((mCfgMgr.getUserPath()/"openmw.cfg").string())); + file.setFileName(config); if (!file.open(QIODevice::ReadWrite | QIODevice::Text)) { // File cannot be opened or created @@ -1086,5 +1092,5 @@ void DataFilesPage::writeConfig(QString profile) file.close(); mLauncherConfig->endGroup(); mLauncherConfig->endGroup(); - + mLauncherConfig->sync(); } From b6915a609095033fd622eec946d5a4106825103f Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Thu, 1 Mar 2012 01:03:31 +0100 Subject: [PATCH 60/79] Forgot that IsWow64Process would return false on a native 64-bit application --- components/files/windowspath.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/files/windowspath.cpp b/components/files/windowspath.cpp index cf73b3728..dfa8f20cc 100644 --- a/components/files/windowspath.cpp +++ b/components/files/windowspath.cpp @@ -75,7 +75,7 @@ boost::filesystem::path WindowsPath::getInstallPath() const BOOL f64 = FALSE; LPCTSTR regkey; - if (IsWow64Process(GetCurrentProcess(), &f64) && f64) + if ((IsWow64Process(GetCurrentProcess(), &f64) && f64) || sizeof(void*) == 8) { regkey = "SOFTWARE\\Wow6432Node\\Bethesda Softworks\\Morrowind"; } From 5ffa3264b2ad3c404f9f13d6f36a05cdfc8276a3 Mon Sep 17 00:00:00 2001 From: Pieter van der Kloet Date: Thu, 1 Mar 2012 04:38:37 +0100 Subject: [PATCH 61/79] Appended resources/ to the stylesheet path --- apps/launcher/maindialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/launcher/maindialog.cpp b/apps/launcher/maindialog.cpp index 14f452fa3..49c0bd960 100644 --- a/apps/launcher/maindialog.cpp +++ b/apps/launcher/maindialog.cpp @@ -46,7 +46,7 @@ MainDialog::MainDialog() setMinimumSize(QSize(575, 575)); // Load the stylesheet - QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "launcher.qss").string()); + QString config = QString::fromStdString((mCfgMgr.getGlobalDataPath() / "resources/launcher.qss").string()); QFile file(config); if (!file.exists()) { From 2c4ef5c6703ecf7eccb1182f31aa428a5c451110 Mon Sep 17 00:00:00 2001 From: "Alexander \"Ace\" Olofsson" Date: Thu, 1 Mar 2012 01:32:02 +0100 Subject: [PATCH 62/79] 64-bit install path on windows was easier to fix than expected. --- CMakeLists.txt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c686733b..57c582c93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,11 +347,17 @@ if(WIN32) SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\www.openmw.org") SET(CPACK_NSIS_INSTALLED_ICON_NAME "omwlauncher.exe") - SET(VCREDIST "${OpenMW_BINARY_DIR}/vcredist_x86.exe") - if(EXISTS ${VCREDIST}) - INSTALL(FILES ${VCREDIST} DESTINATION "redist") + SET(VCREDIST32 "${OpenMW_BINARY_DIR}/vcredist_x86.exe") + if(EXISTS ${VCREDIST32}) + INSTALL(FILES ${VCREDIST32} DESTINATION "redist") SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '\\\"$INSTDIR\\\\redist\\\\vcredist_x86.exe\\\" /q'" ) - endif(EXISTS ${VCREDIST}) + endif(EXISTS ${VCREDIST32}) + + SET(VCREDIST64 "${OpenMW_BINARY_DIR}/vcredist_x64.exe") + if(EXISTS ${VCREDIST64}) + INSTALL(FILES ${VCREDIST64} DESTINATION "redist") + SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "ExecWait '\\\"$INSTDIR\\\\redist\\\\vcredist_x64.exe\\\" /q'" ) + endif(EXISTS ${VCREDIST64}) SET(OALREDIST "${OpenMW_BINARY_DIR}/oalinst.exe") if(EXISTS ${OALREDIST}) @@ -360,6 +366,10 @@ if(WIN32) ExecWait '\\\"$INSTDIR\\\\redist\\\\oalinst.exe\\\" /s'" ) endif(EXISTS ${OALREDIST}) + if(CMAKE_CL_64) + SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64") + endif() + include(CPack) endif(WIN32) From a1cbc7fb429e0d482a7beb8c59eef81256c6cdd3 Mon Sep 17 00:00:00 2001 From: Michael Papageorgiou Date: Thu, 1 Mar 2012 14:00:45 +0200 Subject: [PATCH 63/79] Altered getFver to fix a warning --- components/esm/esm_reader.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esm/esm_reader.hpp b/components/esm/esm_reader.hpp index e5b230748..0420f37cd 100644 --- a/components/esm/esm_reader.hpp +++ b/components/esm/esm_reader.hpp @@ -153,7 +153,7 @@ public: *************************************************************************/ int getVer() { return mCtx.header.version; } - float getFVer() { return *((float*)&mCtx.header.version); } + float getFVer() { if(mCtx.header.version == VER_12) return 1.2; else return 1.3; } int getSpecial() { return mSpf; } const std::string getAuthor() { return mCtx.header.author.toString(); } const std::string getDesc() { return mCtx.header.desc.toString(); } From 185cd634624a2fbe9254044b63b8ebde47b9b915 Mon Sep 17 00:00:00 2001 From: Michael Papageorgiou Date: Thu, 1 Mar 2012 14:19:27 +0200 Subject: [PATCH 64/79] ESMTool set to use default Latin encoding --- apps/esmtool/esmtool.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index fe067d85d..4536dd338 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -29,6 +29,7 @@ int main(int argc, char**argv) } ESMReader esm; + esm.setEncoding("win1252"); // FIXME: This should be configurable const char* filename = info.inputs[0]; cout << "\nFile: " << filename << endl; From b283ad86fbea7ffe9d760bcaf226929d6638f9c2 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Thu, 1 Mar 2012 17:15:42 +0400 Subject: [PATCH 65/79] revert to old launcher stylesheet location on OS X --- CMakeLists.txt | 1 + apps/launcher/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c686733b..76b9595e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,6 +427,7 @@ if (APPLE) install(FILES "${OpenMW_BINARY_DIR}/openmw.cfg.install" RENAME "openmw.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) install(FILES "${OpenMW_BINARY_DIR}/plugins.cfg" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) + install(FILES "${OpenMW_BINARY_DIR}/launcher.qss" DESTINATION "${INSTALL_SUBDIR}" COMPONENT Runtime) set(CPACK_GENERATOR "DragNDrop") set(CPACK_PACKAGE_VERSION ${OPENMW_VERSION}) set(CPACK_PACKAGE_VERSION_MAJOR ${OPENMW_VERSION_MAJOR}) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 3a5ccdd04..319bbbc57 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -72,7 +72,7 @@ endif() if (APPLE) configure_file(${CMAKE_SOURCE_DIR}/files/launcher.qss - "${APP_BUNDLE_DIR}/../resources/launcher.qss") + "${APP_BUNDLE_DIR}/../launcher.qss") configure_file(${CMAKE_SOURCE_DIR}/files/launcher.cfg "${APP_BUNDLE_DIR}/../launcher.cfg") else() From b3159683a497640181a576989043fe6767bc4f50 Mon Sep 17 00:00:00 2001 From: Michael Papageorgiou Date: Fri, 2 Mar 2012 04:41:29 +0200 Subject: [PATCH 66/79] Replace gengetopt with bullet program options for esmtool's argument handling --- apps/esmtool/CMakeLists.txt | 2 - apps/esmtool/esmtool.cpp | 134 +++- apps/esmtool/esmtool.ggo | 10 - apps/esmtool/esmtool_cmd.c | 1141 ----------------------------------- apps/esmtool/esmtool_cmd.h | 179 ------ 5 files changed, 118 insertions(+), 1348 deletions(-) delete mode 100644 apps/esmtool/esmtool.ggo delete mode 100644 apps/esmtool/esmtool_cmd.c delete mode 100644 apps/esmtool/esmtool_cmd.h diff --git a/apps/esmtool/CMakeLists.txt b/apps/esmtool/CMakeLists.txt index f2ab7bce7..af3dc090e 100644 --- a/apps/esmtool/CMakeLists.txt +++ b/apps/esmtool/CMakeLists.txt @@ -1,6 +1,4 @@ set(ESMTOOL - esmtool_cmd.c - esmtool_cmd.h esmtool.cpp ) source_group(apps\\esmtool FILES ${ESMTOOL}) diff --git a/apps/esmtool/esmtool.cpp b/apps/esmtool/esmtool.cpp index 4536dd338..f417d5c60 100644 --- a/apps/esmtool/esmtool.cpp +++ b/apps/esmtool/esmtool.cpp @@ -1,36 +1,138 @@ +#include + +#include + #include #include -#include "esmtool_cmd.h" - -#include +#define ESMTOOL_VERSION 1.1 using namespace std; using namespace ESM; +// Create a local alias for brevity +namespace bpo = boost::program_options; + void printRaw(ESMReader &esm); void loadCell(Cell &cell, ESMReader &esm, bool quiet); -int main(int argc, char**argv) +// Based on the legacy struct +struct Arguments { - gengetopt_args_info info; + unsigned int raw_given; + unsigned int quiet_given; + unsigned int loadcells_given; + std::string encoding; + std::string filename; +}; - if(cmdline_parser(argc, argv, &info) != 0) - return 1; +bool parseOptions (int argc, char** argv, Arguments &info) +{ + bpo::options_description desc("Inspect and extract from Morrowind ES files (ESM, ESP, ESS)\nSyntax: esmtool [options] file \nAllowed options"); - if(info.inputs_num != 1) + desc.add_options() + ("help,h", "print help message.") + ("version,v", "print version information and quit.") + ("raw,r", "Show an unformattet list of all records and subrecords.") + ("quiet,q", "Supress all record information. Useful for speed tests.") + ("loadcells,C", "Browse through contents of all cells.") + + ( "encoding,e", bpo::value(&(info.encoding))-> + default_value("win1252"), + "Character encoding used in ESMTool:\n" + "\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n" + "\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n" + "\n\twin1252 - Western European (Latin) alphabet, used by default") + ; + + std::string finalText = "\nIf no option is given, the default action is to parse all records in the archive\nand display diagnostic information."; + + // input-file is hidden and used as a positional argument + bpo::options_description hidden("Hidden Options"); + + hidden.add_options() + ( "input-file,i", bpo::value< vector >(), "input file") + ; + + bpo::positional_options_description p; + p.add("input-file", -1); + + // there might be a better way to do this + bpo::options_description all; + all.add(desc).add(hidden); + bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv) + .options(all).positional(p).run(); + + bpo::variables_map variables; + bpo::store(valid_opts, variables); + bpo::notify(variables); + + if (variables.count ("help")) { - if(info.inputs_num == 0) - cout << "ERROR: missing ES file\n\n"; - else - cout << "ERROR: more than one ES file specified\n\n"; - cmdline_parser_print_help(); - return 1; + std::cout << desc << finalText << std::endl; + return false; + } + if (variables.count ("version")) + { + std::cout << "ESMTool version " << ESMTOOL_VERSION << std::endl; + return false; } + if ( !variables.count("input-file") ) + { + std::cout << "\nERROR: missing ES file\n\n"; + std::cout << desc << finalText << std::endl; + return false; + } + + // handling gracefully the user adding multiple files + if (variables["input-file"].as< vector >().size() > 1) + { + std::cout << "\nERROR: more than one ES file specified\n\n"; + std::cout << desc << finalText << std::endl; + return false; + } + + info.filename = variables["input-file"].as< vector >()[0]; + + info.raw_given = variables.count ("raw"); + info.quiet_given = variables.count ("quiet"); + info.loadcells_given = variables.count ("loadcells"); + + // Font encoding settings + info.encoding = variables["encoding"].as(); + if (info.encoding == "win1250") + { + std::cout << "Using Central and Eastern European font encoding." << std::endl; + } + else if (info.encoding == "win1251") + { + std::cout << "Using Cyrillic font encoding." << std::endl; + } + else + { + if(info.encoding != "win1252") + { + std::cout << info.encoding << " is not a valid encoding option." << std::endl; + info.encoding = "win1252"; + } + std::cout << "Using default (English) font encoding." << std::endl; + } + + return true; +} + + +int main(int argc, char**argv) +{ + Arguments info; + if(!parseOptions (argc, argv, info)) + return 1; + ESMReader esm; - esm.setEncoding("win1252"); // FIXME: This should be configurable - const char* filename = info.inputs[0]; + esm.setEncoding(info.encoding); + + string filename = info.filename; cout << "\nFile: " << filename << endl; try { diff --git a/apps/esmtool/esmtool.ggo b/apps/esmtool/esmtool.ggo deleted file mode 100644 index 9d0f3c189..000000000 --- a/apps/esmtool/esmtool.ggo +++ /dev/null @@ -1,10 +0,0 @@ -package "esmtool" -version "1.0" -purpose "Inspect and extract from Morrowind ES files (ESM, ESP, ESS)" -args "--unamed-opts=ES-FILE -F esmtool_cmd -G" - -option "raw" r "Show an unformattet list of all records and subrecords" optional -option "quiet" q "Supress all record information. Useful for speed tests." optional -option "loadcells" C "Browse through contents of all cells." optional - -text "\nIf no option is given, the default action is to parse all records in the archive and display diagnostic information." diff --git a/apps/esmtool/esmtool_cmd.c b/apps/esmtool/esmtool_cmd.c deleted file mode 100644 index 3fce77de2..000000000 --- a/apps/esmtool/esmtool_cmd.c +++ /dev/null @@ -1,1141 +0,0 @@ -/* - File autogenerated by gengetopt version 2.22.2 - generated with the following command: - gengetopt --unamed-opts=ES-FILE -F esmtool_cmd -G - - The developers of gengetopt consider the fixed text that goes in all - gengetopt output files to be in the public domain: - we make no copyright claims on it. -*/ - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#ifndef FIX_UNUSED -#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ -#endif - - -#include "esmtool_cmd.h" - -const char *gengetopt_args_info_purpose = "Inspect and extract from Morrowind ES files (ESM, ESP, ESS)"; - -const char *gengetopt_args_info_usage = "Usage: esmtool [OPTIONS]... [ES-FILE]..."; - -const char *gengetopt_args_info_description = ""; - -const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -r, --raw Show an unformattet list of all records and subrecords", - " -q, --quiet Supress all record information. Useful for speed tests.", - " -C, --loadcells Browse through contents of all cells.", - "\nIf no option is given, the default action is to parse all records in the \narchive and display diagnostic information.", - 0 -}; - -typedef enum {ARG_NO -} cmdline_parser_arg_type; - -static -void clear_given (struct gengetopt_args_info *args_info); -static -void clear_args (struct gengetopt_args_info *args_info); - -static int -cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error); - - -static char * -gengetopt_strdup (const char *s); - -static -void clear_given (struct gengetopt_args_info *args_info) -{ - args_info->help_given = 0 ; - args_info->version_given = 0 ; - args_info->raw_given = 0 ; - args_info->quiet_given = 0 ; - args_info->loadcells_given = 0 ; -} - -static -void clear_args (struct gengetopt_args_info *args_info) -{ - FIX_UNUSED (args_info); - -} - -static -void init_args_info(struct gengetopt_args_info *args_info) -{ - - - args_info->help_help = gengetopt_args_info_help[0] ; - args_info->version_help = gengetopt_args_info_help[1] ; - args_info->raw_help = gengetopt_args_info_help[2] ; - args_info->quiet_help = gengetopt_args_info_help[3] ; - args_info->loadcells_help = gengetopt_args_info_help[4] ; - -} - -void -cmdline_parser_print_version (void) -{ - printf ("%s %s\n", - (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), - CMDLINE_PARSER_VERSION); -} - -static void print_help_common(void) { - cmdline_parser_print_version (); - - if (strlen(gengetopt_args_info_purpose) > 0) - printf("\n%s\n", gengetopt_args_info_purpose); - - if (strlen(gengetopt_args_info_usage) > 0) - printf("\n%s\n", gengetopt_args_info_usage); - - printf("\n"); - - if (strlen(gengetopt_args_info_description) > 0) - printf("%s\n\n", gengetopt_args_info_description); -} - -void -cmdline_parser_print_help (void) -{ - int i = 0; - print_help_common(); - while (gengetopt_args_info_help[i]) - printf("%s\n", gengetopt_args_info_help[i++]); -} - -void -cmdline_parser_init (struct gengetopt_args_info *args_info) -{ - clear_given (args_info); - clear_args (args_info); - init_args_info (args_info); - - args_info->inputs = 0; - args_info->inputs_num = 0; -} - -void -cmdline_parser_params_init(struct cmdline_parser_params *params) -{ - if (params) - { - params->override = 0; - params->initialize = 1; - params->check_required = 1; - params->check_ambiguity = 0; - params->print_errors = 1; - } -} - -struct cmdline_parser_params * -cmdline_parser_params_create(void) -{ - struct cmdline_parser_params *params = - (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params)); - cmdline_parser_params_init(params); - return params; -} - - - -static void -cmdline_parser_release (struct gengetopt_args_info *args_info) -{ - unsigned int i; - - - for (i = 0; i < args_info->inputs_num; ++i) - free (args_info->inputs [i]); - - if (args_info->inputs_num) - free (args_info->inputs); - - clear_given (args_info); -} - - -static void -write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[]) -{ - FIX_UNUSED (values); - if (arg) { - fprintf(outfile, "%s=\"%s\"\n", opt, arg); - } else { - fprintf(outfile, "%s\n", opt); - } -} - - -int -cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info) -{ - int i = 0; - - if (!outfile) - { - fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE); - return EXIT_FAILURE; - } - - if (args_info->help_given) - write_into_file(outfile, "help", 0, 0 ); - if (args_info->version_given) - write_into_file(outfile, "version", 0, 0 ); - if (args_info->raw_given) - write_into_file(outfile, "raw", 0, 0 ); - if (args_info->quiet_given) - write_into_file(outfile, "quiet", 0, 0 ); - if (args_info->loadcells_given) - write_into_file(outfile, "loadcells", 0, 0 ); - - - i = EXIT_SUCCESS; - return i; -} - -int -cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) -{ - FILE *outfile; - int i = 0; - - outfile = fopen(filename, "w"); - - if (!outfile) - { - fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); - return EXIT_FAILURE; - } - - i = cmdline_parser_dump(outfile, args_info); - fclose (outfile); - - return i; -} - -void -cmdline_parser_free (struct gengetopt_args_info *args_info) -{ - cmdline_parser_release (args_info); -} - -/** @brief replacement of strdup, which is not standard */ -char * -gengetopt_strdup (const char *s) -{ - char *result = 0; - if (!s) - return result; - - result = (char*)malloc(strlen(s) + 1); - if (result == (char*)0) - return (char*)0; - strcpy(result, s); - return result; -} - -int -cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) -{ - return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); -} - -int -cmdline_parser_ext (int argc, char * const *argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params) -{ - int result; - result = cmdline_parser_internal (argc, argv, args_info, params, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) -{ - int result; - struct cmdline_parser_params params; - - params.override = override; - params.initialize = initialize; - params.check_required = check_required; - params.check_ambiguity = 0; - params.print_errors = 1; - - result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0); - - if (result == EXIT_FAILURE) - { - cmdline_parser_free (args_info); - exit (EXIT_FAILURE); - } - - return result; -} - -int -cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) -{ - FIX_UNUSED (args_info); - FIX_UNUSED (prog_name); - return EXIT_SUCCESS; -} - -/* - * Extracted from the glibc source tree, version 2.3.6 - * - * Licensed under the GPL as per the whole glibc source tree. - * - * This file was modified so that getopt_long can be called - * many times without risking previous memory to be spoiled. - * - * Modified by Andre Noll and Lorenzo Bettini for use in - * GNU gengetopt generated files. - * - */ - -/* - * we must include anything we need since this file is not thought to be - * inserted in a file already using getopt.h - * - * Lorenzo - */ - -struct option -{ - const char *name; - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; -}; - -/* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. -*/ -/* - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `custom_optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -/* Names for the values of the `has_arg' field of `struct option'. */ -#ifndef no_argument -#define no_argument 0 -#endif - -#ifndef required_argument -#define required_argument 1 -#endif - -#ifndef optional_argument -#define optional_argument 2 -#endif - -struct custom_getopt_data { - /* - * These have exactly the same meaning as the corresponding global variables, - * except that they are used for the reentrant versions of getopt. - */ - int custom_optind; - int custom_opterr; - int custom_optopt; - char *custom_optarg; - - /* True if the internal members have been initialized. */ - int initialized; - - /* - * The next char to be scanned in the option-element in which the last option - * character we returned was found. This allows us to pick up the scan where - * we left off. If this is zero, or a null string, it means resume the scan by - * advancing to the next ARGV-element. - */ - char *nextchar; - - /* - * Describe the part of ARGV that contains non-options that have been skipped. - * `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is - * the index after the last of them. - */ - int first_nonopt; - int last_nonopt; -}; - -/* - * the variables optarg, optind, opterr and optopt are renamed with - * the custom_ prefix so that they don't interfere with getopt ones. - * - * Moreover they're static so they are visible only from within the - * file where this very file will be included. - */ - -/* - * For communication from `custom_getopt' to the caller. When `custom_getopt' finds an - * option that takes an argument, the argument value is returned here. - */ -static char *custom_optarg; - -/* - * Index in ARGV of the next element to be scanned. This is used for - * communication to and from the caller and for communication between - * successive calls to `custom_getopt'. - * - * On entry to `custom_getopt', 1 means this is the first call; initialize. - * - * When `custom_getopt' returns -1, this is the index of the first of the non-option - * elements that the caller should itself scan. - * - * Otherwise, `custom_optind' communicates from one call to the next how much of ARGV - * has been scanned so far. - * - * 1003.2 says this must be 1 before any call. - */ -static int custom_optind = 1; - -/* - * Callers store zero here to inhibit the error message for unrecognized - * options. - */ -static int custom_opterr = 1; - -/* - * Set to an option character which was unrecognized. This must be initialized - * on some systems to avoid linking in the system's own getopt implementation. - */ -static int custom_optopt = '?'; - -/* - * Exchange two adjacent subsequences of ARGV. One subsequence is elements - * [first_nonopt,last_nonopt) which contains all the non-options that have been - * skipped so far. The other is elements [last_nonopt,custom_optind), which contains - * all the options processed since those non-options were skipped. - * `first_nonopt' and `last_nonopt' are relocated so that they describe the new - * indices of the non-options in ARGV after they are moved. - */ -static void exchange(char **argv, struct custom_getopt_data *d) -{ - int bottom = d->first_nonopt; - int middle = d->last_nonopt; - int top = d->custom_optind; - char *tem; - - /* - * Exchange the shorter segment with the far end of the longer segment. - * That puts the shorter segment into the right place. It leaves the - * longer segment in the right place overall, but it consists of two - * parts that need to be swapped next. - */ - while (top > middle && middle > bottom) { - if (top - middle > middle - bottom) { - /* Bottom segment is the short one. */ - int len = middle - bottom; - int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = - argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } else { - /* Top segment is the short one. */ - int len = top - middle; - int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - /* Update records for the slots the non-options now occupy. */ - d->first_nonopt += (d->custom_optind - d->last_nonopt); - d->last_nonopt = d->custom_optind; -} - -/* Initialize the internal data when the first call is made. */ -static void custom_getopt_initialize(struct custom_getopt_data *d) -{ - /* - * Start processing options with ARGV-element 1 (since ARGV-element 0 - * is the program name); the sequence of previously skipped non-option - * ARGV-elements is empty. - */ - d->first_nonopt = d->last_nonopt = d->custom_optind; - d->nextchar = NULL; - d->initialized = 1; -} - -#define NONOPTION_P (argv[d->custom_optind][0] != '-' || argv[d->custom_optind][1] == '\0') - -/* return: zero: continue, nonzero: return given value to user */ -static int shuffle_argv(int argc, char *const *argv,const struct option *longopts, - struct custom_getopt_data *d) -{ - /* - * Give FIRST_NONOPT & LAST_NONOPT rational values if CUSTOM_OPTIND has been - * moved back by the user (who may also have changed the arguments). - */ - if (d->last_nonopt > d->custom_optind) - d->last_nonopt = d->custom_optind; - if (d->first_nonopt > d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * If we have just processed some options following some - * non-options, exchange them so that the options come first. - */ - if (d->first_nonopt != d->last_nonopt && - d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->last_nonopt != d->custom_optind) - d->first_nonopt = d->custom_optind; - /* - * Skip any additional non-options and extend the range of - * non-options previously skipped. - */ - while (d->custom_optind < argc && NONOPTION_P) - d->custom_optind++; - d->last_nonopt = d->custom_optind; - /* - * The special ARGV-element `--' means premature end of options. Skip - * it like a null option, then exchange with previous non-options as if - * it were an option, then skip everything else like a non-option. - */ - if (d->custom_optind != argc && !strcmp(argv[d->custom_optind], "--")) { - d->custom_optind++; - if (d->first_nonopt != d->last_nonopt - && d->last_nonopt != d->custom_optind) - exchange((char **) argv, d); - else if (d->first_nonopt == d->last_nonopt) - d->first_nonopt = d->custom_optind; - d->last_nonopt = argc; - d->custom_optind = argc; - } - /* - * If we have done all the ARGV-elements, stop the scan and back over - * any non-options that we skipped and permuted. - */ - if (d->custom_optind == argc) { - /* - * Set the next-arg-index to point at the non-options that we - * previously skipped, so the caller will digest them. - */ - if (d->first_nonopt != d->last_nonopt) - d->custom_optind = d->first_nonopt; - return -1; - } - /* - * If we have come to a non-option and did not permute it, either stop - * the scan or describe it to the caller and pass it by. - */ - if (NONOPTION_P) { - d->custom_optarg = argv[d->custom_optind++]; - return 1; - } - /* - * We have found another option-ARGV-element. Skip the initial - * punctuation. - */ - d->nextchar = (argv[d->custom_optind] + 1 + (longopts != NULL && argv[d->custom_optind][1] == '-')); - return 0; -} - -/* - * Check whether the ARGV-element is a long option. - * - * If there's a long option "fubar" and the ARGV-element is "-fu", consider - * that an abbreviation of the long option, just like "--fu", and not "-f" with - * arg "u". - * - * This distinction seems to be the most useful approach. - * - */ -static int check_long_opt(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - int print_errors, struct custom_getopt_data *d) -{ - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = -1; - int option_index; - - for (nameend = d->nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match or abbreviated matches */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp(p->name, d->nextchar, nameend - d->nextchar)) { - if ((unsigned int) (nameend - d->nextchar) - == (unsigned int) strlen(p->name)) { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } else if (pfound == NULL) { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } else if (pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' is ambiguous\n", - argv[0], argv[d->custom_optind]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optind++; - d->custom_optopt = 0; - return '?'; - } - if (pfound) { - option_index = indfound; - d->custom_optind++; - if (*nameend) { - if (pfound->has_arg != no_argument) - d->custom_optarg = nameend + 1; - else { - if (print_errors) { - if (argv[d->custom_optind - 1][1] == '-') { - /* --option */ - fprintf(stderr, "%s: option `--%s' doesn't allow an argument\n", - argv[0], pfound->name); - } else { - /* +option or -option */ - fprintf(stderr, "%s: option `%c%s' doesn't allow an argument\n", - argv[0], argv[d->custom_optind - 1][0], pfound->name); - } - - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return '?'; - } - } else if (pfound->has_arg == required_argument) { - if (d->custom_optind < argc) - d->custom_optarg = argv[d->custom_optind++]; - else { - if (print_errors) { - fprintf(stderr, - "%s: option `%s' requires an argument\n", - argv[0], - argv[d->custom_optind - 1]); - } - d->nextchar += strlen(d->nextchar); - d->custom_optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - d->nextchar += strlen(d->nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - /* - * Can't find it as a long option. If this is not getopt_long_only, or - * the option starts with '--' or is not a valid short option, then - * it's an error. Otherwise interpret it as a short option. - */ - if (print_errors) { - if (argv[d->custom_optind][1] == '-') { - /* --option */ - fprintf(stderr, - "%s: unrecognized option `--%s'\n", - argv[0], d->nextchar); - } else { - /* +option or -option */ - fprintf(stderr, - "%s: unrecognized option `%c%s'\n", - argv[0], argv[d->custom_optind][0], - d->nextchar); - } - } - d->nextchar = (char *) ""; - d->custom_optind++; - d->custom_optopt = 0; - return '?'; -} - -static int check_short_opt(int argc, char *const *argv, const char *optstring, - int print_errors, struct custom_getopt_data *d) -{ - char c = *d->nextchar++; - const char *temp = strchr(optstring, c); - - /* Increment `custom_optind' when we start to process its last character. */ - if (*d->nextchar == '\0') - ++d->custom_optind; - if (!temp || c == ':') { - if (print_errors) - fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); - - d->custom_optopt = c; - return '?'; - } - if (temp[1] == ':') { - if (temp[2] == ':') { - /* This is an option that accepts an argument optionally. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - d->custom_optind++; - } else - d->custom_optarg = NULL; - d->nextchar = NULL; - } else { - /* This is an option that requires an argument. */ - if (*d->nextchar != '\0') { - d->custom_optarg = d->nextchar; - /* - * If we end this ARGV-element by taking the - * rest as an arg, we must advance to the next - * element now. - */ - d->custom_optind++; - } else if (d->custom_optind == argc) { - if (print_errors) { - fprintf(stderr, - "%s: option requires an argument -- %c\n", - argv[0], c); - } - d->custom_optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } else - /* - * We already incremented `custom_optind' once; - * increment it again when taking next ARGV-elt - * as argument. - */ - d->custom_optarg = argv[d->custom_optind++]; - d->nextchar = NULL; - } - } - return c; -} - -/* - * Scan elements of ARGV for option characters given in OPTSTRING. - * - * If an element of ARGV starts with '-', and is not exactly "-" or "--", - * then it is an option element. The characters of this element - * (aside from the initial '-') are option characters. If `getopt' - * is called repeatedly, it returns successively each of the option characters - * from each of the option elements. - * - * If `getopt' finds another option character, it returns that character, - * updating `custom_optind' and `nextchar' so that the next call to `getopt' can - * resume the scan with the following option character or ARGV-element. - * - * If there are no more option characters, `getopt' returns -1. - * Then `custom_optind' is the index in ARGV of the first ARGV-element - * that is not an option. (The ARGV-elements have been permuted - * so that those that are not options now come last.) - * - * OPTSTRING is a string containing the legitimate option characters. - * If an option character is seen that is not listed in OPTSTRING, - * return '?' after printing an error message. If you set `custom_opterr' to - * zero, the error message is suppressed but we still return '?'. - * - * If a char in OPTSTRING is followed by a colon, that means it wants an arg, - * so the following text in the same ARGV-element, or the text of the following - * ARGV-element, is returned in `custom_optarg'. Two colons mean an option that - * wants an optional arg; if there is text in the current ARGV-element, - * it is returned in `custom_optarg', otherwise `custom_optarg' is set to zero. - * - * If OPTSTRING starts with `-' or `+', it requests different methods of - * handling the non-option ARGV-elements. - * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - * - * Long-named options begin with `--' instead of `-'. - * Their names may be abbreviated as long as the abbreviation is unique - * or is an exact match for some defined option. If they have an - * argument, it follows the option name in the same ARGV-element, separated - * from the option name by a `=', or else the in next ARGV-element. - * When `getopt' finds a long-named option, it returns 0 if that option's - * `flag' field is nonzero, the value of the option's `val' field - * if the `flag' field is zero. - * - * The elements of ARGV aren't really const, because we permute them. - * But we pretend they're const in the prototype to be compatible - * with other systems. - * - * LONGOPTS is a vector of `struct option' terminated by an - * element containing a name which is zero. - * - * LONGIND returns the index in LONGOPT of the long-named option found. - * It is only valid when a long-named option has been found by the most - * recent call. - * - * Return the option character from OPTS just read. Return -1 when there are - * no more options. For unrecognized options, or options missing arguments, - * `custom_optopt' is set to the option letter, and '?' is returned. - * - * The OPTS string is a list of characters which are recognized option letters, - * optionally followed by colons, specifying that that letter takes an - * argument, to be placed in `custom_optarg'. - * - * If a letter in OPTS is followed by two colons, its argument is optional. - * This behavior is specific to the GNU `getopt'. - * - * The argument `--' causes premature termination of argument scanning, - * explicitly telling `getopt' that there are no more options. If OPTS begins - * with `--', then non-option arguments are treated as arguments to the option - * '\0'. This behavior is specific to the GNU `getopt'. - */ - -static int getopt_internal_r(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind, - struct custom_getopt_data *d) -{ - int ret, print_errors = d->custom_opterr; - - if (optstring[0] == ':') - print_errors = 0; - if (argc < 1) - return -1; - d->custom_optarg = NULL; - - /* - * This is a big difference with GNU getopt, since optind == 0 - * means initialization while here 1 means first call. - */ - if (d->custom_optind == 0 || !d->initialized) { - if (d->custom_optind == 0) - d->custom_optind = 1; /* Don't scan ARGV[0], the program name. */ - custom_getopt_initialize(d); - } - if (d->nextchar == NULL || *d->nextchar == '\0') { - ret = shuffle_argv(argc, argv, longopts, d); - if (ret) - return ret; - } - if (longopts && (argv[d->custom_optind][1] == '-' )) - return check_long_opt(argc, argv, optstring, longopts, - longind, print_errors, d); - return check_short_opt(argc, argv, optstring, print_errors, d); -} - -static int custom_getopt_internal(int argc, char *const *argv, const char *optstring, - const struct option *longopts, int *longind) -{ - int result; - /* Keep a global copy of all internal members of d */ - static struct custom_getopt_data d; - - d.custom_optind = custom_optind; - d.custom_opterr = custom_opterr; - result = getopt_internal_r(argc, argv, optstring, longopts, - longind, &d); - custom_optind = d.custom_optind; - custom_optarg = d.custom_optarg; - custom_optopt = d.custom_optopt; - return result; -} - -static int custom_getopt_long (int argc, char *const *argv, const char *options, - const struct option *long_options, int *opt_index) -{ - return custom_getopt_internal(argc, argv, options, long_options, - opt_index); -} - - -static char *package_name = 0; - -/** - * @brief updates an option - * @param field the generic pointer to the field to update - * @param orig_field the pointer to the orig field - * @param field_given the pointer to the number of occurrence of this option - * @param prev_given the pointer to the number of occurrence already seen - * @param value the argument for this option (if null no arg was specified) - * @param possible_values the possible values for this option (if specified) - * @param default_value the default value (in case the option only accepts fixed values) - * @param arg_type the type of this option - * @param check_ambiguity @see cmdline_parser_params.check_ambiguity - * @param override @see cmdline_parser_params.override - * @param no_free whether to free a possible previous value - * @param multiple_option whether this is a multiple option - * @param long_opt the corresponding long option - * @param short_opt the corresponding short option (or '-' if none) - * @param additional_error possible further error specification - */ -static -int update_arg(void *field, char **orig_field, - unsigned int *field_given, unsigned int *prev_given, - char *value, const char *possible_values[], - const char *default_value, - cmdline_parser_arg_type arg_type, - int check_ambiguity, int override, - int no_free, int multiple_option, - const char *long_opt, char short_opt, - const char *additional_error) -{ - //char *stop_char = 0; - //const char *val = value; - //int found; - FIX_UNUSED (field); - - //stop_char = 0; - //found = 0; - - if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given))) - { - if (short_opt != '-') - fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n", - package_name, long_opt, short_opt, - (additional_error ? additional_error : "")); - else - fprintf (stderr, "%s: `--%s' option given more than once%s\n", - package_name, long_opt, - (additional_error ? additional_error : "")); - return 1; /* failure */ - } - - FIX_UNUSED (default_value); - - if (field_given && *field_given && ! override) - return 0; - if (prev_given) - (*prev_given)++; - if (field_given) - (*field_given)++; - //if (possible_values) - //val = possible_values[found]; - - switch(arg_type) { - default: - break; - }; - - - /* store the original value */ - switch(arg_type) { - case ARG_NO: - break; - default: - if (value && orig_field) { - if (no_free) { - *orig_field = value; - } else { - if (*orig_field) - free (*orig_field); /* free previous string */ - *orig_field = gengetopt_strdup (value); - } - } - }; - - return 0; /* OK */ -} - - -int -cmdline_parser_internal ( - int argc, char * const *argv, struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params, const char *additional_error) -{ - int c; /* Character of the parsed option. */ - - int error = 0; - struct gengetopt_args_info local_args_info; - - int override; - int initialize; - //int check_required; - int check_ambiguity; - - char *optarg; - int optind; - int opterr; - int optopt; - - package_name = argv[0]; - - override = params->override; - initialize = params->initialize; - //check_required = params->check_required; - check_ambiguity = params->check_ambiguity; - - if (initialize) - cmdline_parser_init (args_info); - - cmdline_parser_init (&local_args_info); - - optarg = 0; - optind = 0; - opterr = params->print_errors; - optopt = '?'; - - while (1) - { - int option_index = 0; - - static struct option long_options[] = { - { "help", 0, NULL, 'h' }, - { "version", 0, NULL, 'V' }, - { "raw", 0, NULL, 'r' }, - { "quiet", 0, NULL, 'q' }, - { "loadcells", 0, NULL, 'C' }, - { 0, 0, 0, 0 } - }; - - custom_optarg = optarg; - custom_optind = optind; - custom_opterr = opterr; - custom_optopt = optopt; - - c = custom_getopt_long (argc, argv, "hVrqC", long_options, &option_index); - - optarg = custom_optarg; - optind = custom_optind; - opterr = custom_opterr; - optopt = custom_optopt; - - if (c == -1) break; /* Exit from `while (1)' loop. */ - - switch (c) - { - case 'h': /* Print help and exit. */ - cmdline_parser_print_help (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'V': /* Print version and exit. */ - cmdline_parser_print_version (); - cmdline_parser_free (&local_args_info); - exit (EXIT_SUCCESS); - - case 'r': /* Show an unformattet list of all records and subrecords. */ - - - if (update_arg( 0 , - 0 , &(args_info->raw_given), - &(local_args_info.raw_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "raw", 'r', - additional_error)) - goto failure; - - break; - case 'q': /* Supress all record information. Useful for speed tests.. */ - - - if (update_arg( 0 , - 0 , &(args_info->quiet_given), - &(local_args_info.quiet_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "quiet", 'q', - additional_error)) - goto failure; - - break; - case 'C': /* Browse through contents of all cells.. */ - - - if (update_arg( 0 , - 0 , &(args_info->loadcells_given), - &(local_args_info.loadcells_given), optarg, 0, 0, ARG_NO, - check_ambiguity, override, 0, 0, - "loadcells", 'C', - additional_error)) - goto failure; - - break; - - case 0: /* Long option with no short option */ - case '?': /* Invalid option. */ - /* `getopt_long' already printed an error message. */ - goto failure; - - default: /* bug: option not considered. */ - fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); - abort (); - } /* switch */ - } /* while */ - - - - - cmdline_parser_release (&local_args_info); - - if ( error ) - return (EXIT_FAILURE); - - if (optind < argc) - { - int i = 0 ; - int found_prog_name = 0; - /* whether program name, i.e., argv[0], is in the remaining args - (this may happen with some implementations of getopt, - but surely not with the one included by gengetopt) */ - - - args_info->inputs_num = argc - optind - found_prog_name; - args_info->inputs = - (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ; - while (optind < argc) - args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind++]) ; - } - - return 0; - -failure: - - cmdline_parser_release (&local_args_info); - return (EXIT_FAILURE); -} diff --git a/apps/esmtool/esmtool_cmd.h b/apps/esmtool/esmtool_cmd.h deleted file mode 100644 index 8c420c189..000000000 --- a/apps/esmtool/esmtool_cmd.h +++ /dev/null @@ -1,179 +0,0 @@ -/** @file esmtool_cmd.h - * @brief The header file for the command line option parser - * generated by GNU Gengetopt version 2.22.2 - * http://www.gnu.org/software/gengetopt. - * DO NOT modify this file, since it can be overwritten - * @author GNU Gengetopt by Lorenzo Bettini */ - -#ifndef ESMTOOL_CMD_H -#define ESMTOOL_CMD_H - -/* If we use autoconf. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for FILE */ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifndef CMDLINE_PARSER_PACKAGE -/** @brief the program name (used for printing errors) */ -#define CMDLINE_PARSER_PACKAGE "esmtool" -#endif - -#ifndef CMDLINE_PARSER_PACKAGE_NAME -/** @brief the complete program name (used for help and version) */ -#define CMDLINE_PARSER_PACKAGE_NAME "esmtool" -#endif - -#ifndef CMDLINE_PARSER_VERSION -/** @brief the program version */ -#define CMDLINE_PARSER_VERSION "1.0" -#endif - -/** @brief Where the command line options are stored */ -struct gengetopt_args_info -{ - const char *help_help; /**< @brief Print help and exit help description. */ - const char *version_help; /**< @brief Print version and exit help description. */ - const char *raw_help; /**< @brief Show an unformattet list of all records and subrecords help description. */ - const char *quiet_help; /**< @brief Supress all record information. Useful for speed tests. help description. */ - const char *loadcells_help; /**< @brief Browse through contents of all cells. help description. */ - - unsigned int help_given ; /**< @brief Whether help was given. */ - unsigned int version_given ; /**< @brief Whether version was given. */ - unsigned int raw_given ; /**< @brief Whether raw was given. */ - unsigned int quiet_given ; /**< @brief Whether quiet was given. */ - unsigned int loadcells_given ; /**< @brief Whether loadcells was given. */ - - char **inputs ; /**< @brief unamed options (options without names) */ - unsigned inputs_num ; /**< @brief unamed options number */ -} ; - -/** @brief The additional parameters to pass to parser functions */ -struct cmdline_parser_params -{ - int override; /**< @brief whether to override possibly already present options (default 0) */ - int initialize; /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ - int check_required; /**< @brief whether to check that all required options were provided (default 1) */ - int check_ambiguity; /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ - int print_errors; /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ -} ; - -/** @brief the purpose string of the program */ -extern const char *gengetopt_args_info_purpose; -/** @brief the usage string of the program */ -extern const char *gengetopt_args_info_usage; -/** @brief all the lines making the help output */ -extern const char *gengetopt_args_info_help[]; - -/** - * The command line parser - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser (int argc, char * const *argv, - struct gengetopt_args_info *args_info); - -/** - * The command line parser (version with additional parameters - deprecated) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param override whether to override possibly already present options - * @param initialize whether to initialize the option structure my_args_info - * @param check_required whether to check that all required options were provided - * @return 0 if everything went fine, NON 0 if an error took place - * @deprecated use cmdline_parser_ext() instead - */ -int cmdline_parser2 (int argc, char * const *argv, - struct gengetopt_args_info *args_info, - int override, int initialize, int check_required); - -/** - * The command line parser (version with additional parameters) - * @param argc the number of command line options - * @param argv the command line options - * @param args_info the structure where option information will be stored - * @param params additional parameters for the parser - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_ext (int argc, char * const *argv, - struct gengetopt_args_info *args_info, - struct cmdline_parser_params *params); - -/** - * Save the contents of the option struct into an already open FILE stream. - * @param outfile the stream where to dump options - * @param args_info the option struct to dump - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_dump(FILE *outfile, - struct gengetopt_args_info *args_info); - -/** - * Save the contents of the option struct into a (text) file. - * This file can be read by the config file parser (if generated by gengetopt) - * @param filename the file where to save - * @param args_info the option struct to save - * @return 0 if everything went fine, NON 0 if an error took place - */ -int cmdline_parser_file_save(const char *filename, - struct gengetopt_args_info *args_info); - -/** - * Print the help - */ -void cmdline_parser_print_help(void); -/** - * Print the version - */ -void cmdline_parser_print_version(void); - -/** - * Initializes all the fields a cmdline_parser_params structure - * to their default values - * @param params the structure to initialize - */ -void cmdline_parser_params_init(struct cmdline_parser_params *params); - -/** - * Allocates dynamically a cmdline_parser_params structure and initializes - * all its fields to their default values - * @return the created and initialized cmdline_parser_params structure - */ -struct cmdline_parser_params *cmdline_parser_params_create(void); - -/** - * Initializes the passed gengetopt_args_info structure's fields - * (also set default values for options that have a default) - * @param args_info the structure to initialize - */ -void cmdline_parser_init (struct gengetopt_args_info *args_info); -/** - * Deallocates the string fields of the gengetopt_args_info structure - * (but does not deallocate the structure itself) - * @param args_info the structure to deallocate - */ -void cmdline_parser_free (struct gengetopt_args_info *args_info); - -/** - * Checks that all the required options were specified - * @param args_info the structure to check - * @param prog_name the name of the program that will be used to print - * possible errors - * @return - */ -int cmdline_parser_required (struct gengetopt_args_info *args_info, - const char *prog_name); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* ESMTOOL_CMD_H */ From fa3fbf940c83fc789a98f916252ae6e024a9a989 Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 2 Mar 2012 14:10:11 +0400 Subject: [PATCH 67/79] Fix for OS X 10.6 support --- libs/platform/string.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/libs/platform/string.h b/libs/platform/string.h index 89ac141a8..0b67e50ea 100644 --- a/libs/platform/string.h +++ b/libs/platform/string.h @@ -2,13 +2,33 @@ #ifndef _STRING_WRAPPER_H #define _STRING_WRAPPER_H +#ifdef __APPLE__ +#include +#endif + #include -#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1070) || defined(__MINGW32__) +#if (defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070) || defined(__MINGW32__) // need our own implementation of strnlen +#ifdef __MINGW32__ static size_t strnlen(const char *s, size_t n) { - const char *p = (const char *)memchr(s, 0, n); - return(p ? p-s : n); + const char *p = (const char *)memchr(s, 0, n); + return(p ? p-s : n); } +#elif (defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1070) +static size_t mw_strnlen(const char *s, size_t n) +{ + if (strnlen != NULL) { + return strnlen(s, n); + } + else { + const char *p = (const char *)memchr(s, 0, n); + return(p ? p-s : n); + } +} +#define strnlen mw_strnlen #endif + +#endif + #endif From 70da2a2a99f3b42024f6b35763f4d7b09eb9867b Mon Sep 17 00:00:00 2001 From: Nikolay Kasyanov Date: Fri, 2 Mar 2012 14:18:10 +0400 Subject: [PATCH 68/79] removed tabs --- libs/platform/string.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/platform/string.h b/libs/platform/string.h index 0b67e50ea..5368d757c 100644 --- a/libs/platform/string.h +++ b/libs/platform/string.h @@ -21,10 +21,10 @@ static size_t mw_strnlen(const char *s, size_t n) if (strnlen != NULL) { return strnlen(s, n); } - else { - const char *p = (const char *)memchr(s, 0, n); - return(p ? p-s : n); - } + else { + const char *p = (const char *)memchr(s, 0, n); + return(p ? p-s : n); + } } #define strnlen mw_strnlen #endif From 1e998545c7f80639602f825b357192de04708e4f Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Fri, 2 Mar 2012 15:15:44 +0100 Subject: [PATCH 69/79] fixed log path --- apps/openmw/engine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index c2700752f..4765ceadc 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -316,7 +316,7 @@ void OMW::Engine::go() } mOgre->configure(!boost::filesystem::is_regular_file(mCfgMgr.getOgreConfigPath()), mCfgMgr.getOgreConfigPath().string(), - mCfgMgr.getLogPath().string() + std::string("/"), + mCfgMgr.getLogPath().string(), mCfgMgr.getPluginsConfigPath().string(), false); // This has to be added BEFORE MyGUI is initialized, as it needs From ba0365a42780ac986866701b080348c65da45f32 Mon Sep 17 00:00:00 2001 From: scrawl Date: Fri, 2 Mar 2012 16:47:39 +0100 Subject: [PATCH 70/79] collision shape scale fix --- apps/openmw/mwworld/physicssystem.cpp | 2 +- libs/openengine | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index b0da4524e..bb2f9f8a9 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -120,7 +120,7 @@ namespace MWWorld void PhysicsSystem::addObject (const std::string& handle, const std::string& mesh, const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position) { - OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle); + OEngine::Physic::RigidBody* body = mEngine->createRigidBody(mesh,handle,scale); mEngine->addRigidBody(body); btTransform tr; tr.setOrigin(btVector3(position.x,position.y,position.z)); diff --git a/libs/openengine b/libs/openengine index 21b845645..5aabf22c1 160000 --- a/libs/openengine +++ b/libs/openengine @@ -1 +1 @@ -Subproject commit 21b8456453242e132c85f92047cf9bce535c1b22 +Subproject commit 5aabf22c16dab6a2230845f90fe5fdf67eeeca32 From d74b78a302926362bdf0382bc04d1974cde95bef Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 3 Mar 2012 12:26:08 +0100 Subject: [PATCH 71/79] very minor performance improvement --- apps/openmw/mwrender/sky.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index b8bd588c4..1b324459a 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -658,9 +658,15 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather) if (weather.mNight && mStarsOpacity != weather.mNightFade) { - for (int i=0; i<7; ++i) - mStarsMaterials[i]->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, weather.mNightFade); - mStarsOpacity = weather.mNightFade; + if (weather.mNightFade == 0) + mAtmosphereNight->setVisible(false); + else + { + mAtmosphereNight->setVisible(true); + for (int i=0; i<7; ++i) + mStarsMaterials[i]->getTechnique(0)->getPass(0)->setDiffuse(0.0, 0.0, 0.0, weather.mNightFade); + mStarsOpacity = weather.mNightFade; + } } float strength; From a81ecb5f659e1d28b37e1d60d09270ef2597fb17 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Sat, 3 Mar 2012 18:26:11 -0500 Subject: [PATCH 72/79] Bug 210 fix --- apps/openmw/mwrender/npcanimation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index 0ceb0a4c3..c6fe023d6 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -42,6 +42,7 @@ NpcAnimation::NpcAnimation(const MWWorld::Ptr& ptr, MWWorld::Environment& _env,O std::string bodyRaceID = headID.substr(0, headID.find_last_of("head_") - 4); char secondtolast = bodyRaceID.at(bodyRaceID.length() - 2); bool female = tolower(secondtolast) == 'f'; + std::transform(bodyRaceID.begin(), bodyRaceID.end(), bodyRaceID.begin(), ::tolower); bool beast = bodyRaceID == "b_n_khajiit_m_" || bodyRaceID == "b_n_khajiit_f_" || bodyRaceID == "b_n_argonian_m_" || bodyRaceID == "b_n_argonian_f_"; /*std::cout << "Race: " << ref->base->race ; From 42a7375a0b83472a66d0deffbb946afb8035246a Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 4 Mar 2012 23:26:35 +0100 Subject: [PATCH 73/79] adjusted the batch region size, this was the cause for lights going on/off bug --- apps/openmw/mwrender/objects.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/objects.cpp b/apps/openmw/mwrender/objects.cpp index 4e2a3caab..717064ada 100644 --- a/apps/openmw/mwrender/objects.cpp +++ b/apps/openmw/mwrender/objects.cpp @@ -101,6 +101,14 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) sg = mRenderer.getScene()->createStaticGeometry( "sg" + Ogre::StringConverter::toString(uniqueID)); //Create the scenenode and put it in the map mStaticGeometry[ptr.getCell()] = sg; + + // This specifies the size of a single batch region. + // If it is set too high: + // - there will be problems choosing the correct lights + // - the culling will be more inefficient + // If it is set too low: + // - there will be too many batches. + sg->setRegionDimensions(Ogre::Vector3(2500,2500,2500)); } else { @@ -108,7 +116,6 @@ void Objects::insertMesh (const MWWorld::Ptr& ptr, const std::string& mesh) } sg->addEntity(ent,insert->_getDerivedPosition(),insert->_getDerivedOrientation(),insert->_getDerivedScale()); - sg->setRegionDimensions(Ogre::Vector3(100000,10000,100000)); mRenderer.getScene()->destroyEntity(ent); } From 4c240c644fc2baad0b6def265fc4b715d094e39d Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 5 Mar 2012 10:58:33 +0100 Subject: [PATCH 74/79] OpenEngine update (log fix) --- libs/openengine | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/openengine b/libs/openengine index 5aabf22c1..8f9871831 160000 --- a/libs/openengine +++ b/libs/openengine @@ -1 +1 @@ -Subproject commit 5aabf22c16dab6a2230845f90fe5fdf67eeeca32 +Subproject commit 8f98718315fe11af359740c4a025fd1ca52a9157 From 1776ede9e1155034429e0e65185523e02f410e87 Mon Sep 17 00:00:00 2001 From: Michael Papageorgiou Date: Mon, 5 Mar 2012 16:06:46 +0200 Subject: [PATCH 75/79] Broken sound path fix --- apps/openmw/mwsound/soundmanager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwsound/soundmanager.cpp b/apps/openmw/mwsound/soundmanager.cpp index 76ef23bc2..6795eff19 100644 --- a/apps/openmw/mwsound/soundmanager.cpp +++ b/apps/openmw/mwsound/soundmanager.cpp @@ -410,7 +410,12 @@ namespace MWSound if(useSound) { - mData = new SoundImpl(root, camera, store, dataDirs /* Sound */, dataDirs /* Music */, fsstrict); + Files::PathContainer soundDirs;; + for (Files::PathContainer::const_iterator it = dataDirs.begin(); it != dataDirs.end(); ++it) + { + soundDirs.push_back( *it / std::string("Sound")); + } + mData = new SoundImpl(root, camera, store, soundDirs /* Sound */, dataDirs /* Music */, fsstrict); } test.name = ""; From f7b706d24eaf5de389b42dc7696a7b5aa38caa89 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 5 Mar 2012 18:50:56 +0100 Subject: [PATCH 76/79] use the vertex colours that morrowind supplies for a lot of meshes --- components/nifogre/ogre_nif_loader.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 8b5540019..1c23b55c0 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -243,6 +243,8 @@ void NIFLoader::createMaterial(const String &name, /*TextureUnitState *txt =*/ pass->createTextureUnitState(texName); + pass->setVertexColourTracking(TVC_DIFFUSE); + // As of yet UNTESTED code from Chris: /*pass->setTextureFiltering(Ogre::TFO_ANISOTROPIC); pass->setDepthFunction(Ogre::CMPF_LESS_EQUAL); From 3ea2a9f05d4206c5f9ef0d5d7a968eea7854c659 Mon Sep 17 00:00:00 2001 From: scrawl Date: Mon, 5 Mar 2012 19:13:11 +0100 Subject: [PATCH 77/79] changeWeather bugfix --- apps/openmw/mwworld/weather.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwworld/weather.cpp b/apps/openmw/mwworld/weather.cpp index 7cb9f3dfc..059b0ec1e 100644 --- a/apps/openmw/mwworld/weather.cpp +++ b/apps/openmw/mwworld/weather.cpp @@ -758,7 +758,7 @@ unsigned int WeatherManager::getWeatherID() const return 3; else if (mCurrentWeather == "rain") return 4; - else if (mCurrentWeather == "thunder") + else if (mCurrentWeather == "thunderstorm") return 5; else if (mCurrentWeather == "ashstorm") return 6; @@ -787,7 +787,7 @@ void WeatherManager::changeWeather(const std::string& region, const unsigned int else if (id==4) weather = "rain"; else if (id==5) - weather = "thunder"; + weather = "thunderstorm"; else if (id==6) weather = "ashstorm"; else if (id==7) From 9848b6717432883683a34d0f6f2efaaf5bb2711b Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Mon, 5 Mar 2012 17:46:29 -0500 Subject: [PATCH 78/79] Fixing errors --- apps/openmw/mwrender/animation.cpp | 10 +++++----- apps/openmw/mwrender/animation.hpp | 7 +++---- components/nifogre/ogre_nif_loader.cpp | 2 ++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 999d85414..4972654fc 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -331,7 +331,7 @@ namespace MWRender{ } } - bool Animation::timeIndex( float time, std::vector& times, int & i, int & j, float & x ){ + bool Animation::timeIndex( float time, std::vector & times, int & i, int & j, float & x ){ int count; if ( (count = times.size()) > 0 ) { @@ -427,19 +427,19 @@ namespace MWRender{ float x; float x2; - std::vector& quats = iter->getQuat(); + std::vector & quats = iter->getQuat(); - std::vector& ttime = iter->gettTime(); + std::vector & ttime = iter->gettTime(); - std::vector& rtime = iter->getrTime(); + std::vector & rtime = iter->getrTime(); int rindexJ = rindexI[slot]; timeIndex(time, rtime, rindexI[slot], rindexJ, x2); int tindexJ = tindexI[slot]; - std::vector& translist1 = iter->getTranslist1(); + std::vector & translist1 = iter->getTranslist1(); timeIndex(time, ttime, tindexI[slot], tindexJ, x); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 63ca3da2d..8e3f54315 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -28,8 +28,7 @@ class Animation{ MWWorld::Environment& mEnvironment; std::map vecRotPos; static std::map mUniqueIDs; - float oldHund; - bool samePlace; + std::vector* > shapeparts; //All the NiTriShape data that we need for animating an npc @@ -57,11 +56,11 @@ class Animation{ Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); void handleAnimationTransforms(); - bool timeIndex( float time, std::vector& times, int & i, int & j, float & x ); + bool timeIndex( float time, std::vector & times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); public: - Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), animate(0), oldHund(0){}; + Animation(MWWorld::Environment& _env, OEngine::Render::OgreRenderer& _rend): mRend(_rend), mEnvironment(_env), animate(0){}; virtual void runAnimation(float timepassed) = 0; void startScript(std::string groupname, int mode, int loops); void stopScript(); diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 62dbc29df..cb626acbe 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -1328,6 +1328,8 @@ void NIFLoader::loadResource(Resource *resource) (*iter)->addBoneAssignment(vba); } + //Don't link on npc parts to eliminate redundant skeletons + //Will have to be changed later slightly for robes/skirts if(triname == "") mesh->_notifySkeleton(mSkel); } From 39ff8d6a01bd0486402aa137bb668dc649860612 Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 6 Mar 2012 18:28:41 -0500 Subject: [PATCH 79/79] Compile error retry --- apps/openmw/mwrender/animation.cpp | 10 +++++----- apps/openmw/mwrender/animation.hpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 4972654fc..9df987dc1 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -331,7 +331,7 @@ namespace MWRender{ } } - bool Animation::timeIndex( float time, std::vector & times, int & i, int & j, float & x ){ + bool Animation::timeIndex( float time, const std::vector & times, int & i, int & j, float & x ){ int count; if ( (count = times.size()) > 0 ) { @@ -427,19 +427,19 @@ namespace MWRender{ float x; float x2; - std::vector & quats = iter->getQuat(); + const std::vector & quats = iter->getQuat(); - std::vector & ttime = iter->gettTime(); + const std::vector & ttime = iter->gettTime(); - std::vector & rtime = iter->getrTime(); + const std::vector & rtime = iter->getrTime(); int rindexJ = rindexI[slot]; timeIndex(time, rtime, rindexI[slot], rindexJ, x2); int tindexJ = tindexI[slot]; - std::vector & translist1 = iter->getTranslist1(); + const std::vector & translist1 = iter->getTranslist1(); timeIndex(time, ttime, tindexI[slot], tindexJ, x); diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 8e3f54315..e08b86e8d 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -56,7 +56,7 @@ class Animation{ Ogre::Entity* base; void handleShapes(std::vector* allshapes, Ogre::Entity* creaturemodel, Ogre::SkeletonInstance *skel); void handleAnimationTransforms(); - bool timeIndex( float time, std::vector & times, int & i, int & j, float & x ); + bool timeIndex( float time, const std::vector & times, int & i, int & j, float & x ); std::string getUniqueID(std::string mesh); public: