mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-10-31 13:56:38 +00:00 
			
		
		
		
	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 <lgromanowski@gmail.com>
This commit is contained in:
		
							parent
							
								
									6b3242f514
								
							
						
					
					
						commit
						7c24ae9ac7
					
				
					 21 changed files with 354 additions and 538 deletions
				
			
		|  | @ -3,7 +3,7 @@ | |||
| #include <components/esm/esm_reader.hpp> | ||||
| #include <components/files/collections.hpp> | ||||
| #include <components/files/multidircollection.hpp> | ||||
| #include <components/cfg/configurationmanager.hpp> | ||||
| #include <components/files/configurationmanager.hpp> | ||||
| 
 | ||||
| #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
 | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -1,8 +1,11 @@ | |||
| #include <QtGui> | ||||
| 
 | ||||
| #include "graphicspage.hpp" | ||||
| #include <components/files/configurationmanager.hpp> | ||||
| 
 | ||||
| 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
 | ||||
|  |  | |||
|  | @ -7,19 +7,20 @@ | |||
| #include <OgreRenderSystem.h> | ||||
| #include <OgreConfigFile.h> | ||||
| #include <OgreConfigDialog.h> | ||||
| #include <components/cfg/configurationmanager.hpp> | ||||
| 
 | ||||
| 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; | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ | |||
| 
 | ||||
| #include <QDialog> | ||||
| 
 | ||||
| #include <components/cfg/configurationmanager.hpp> | ||||
| #include <components/files/configurationmanager.hpp> | ||||
| 
 | ||||
| class QListWidget; | ||||
| class QListWidgetItem; | ||||
|  | @ -47,7 +47,7 @@ private: | |||
|     QStringList mDataDirs; | ||||
|     bool mStrict; | ||||
| 
 | ||||
|     Cfg::ConfigurationManager mCfg; | ||||
|     Files::ConfigurationManager mCfgMgr; | ||||
| }; | ||||
| 
 | ||||
| #endif | ||||
|  |  | |||
|  | @ -17,7 +17,9 @@ | |||
| #include <components/esm_store/cell_store.hpp> | ||||
| #include <components/bsa/bsa_archive.hpp> | ||||
| #include <components/esm/esm_reader.hpp> | ||||
| #include <components/files/path.hpp> | ||||
| #include <components/files/fixedpath.hpp> | ||||
| #include <components/files/configurationmanager.hpp> | ||||
| 
 | ||||
| #include <components/nifbullet/bullet_nif_loader.hpp> | ||||
| 
 | ||||
| #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) | ||||
|  |  | |||
|  | @ -11,7 +11,6 @@ | |||
| 
 | ||||
| #include <components/compiler/extensions.hpp> | ||||
| #include <components/files/collections.hpp> | ||||
| #include <components/cfg/configurationmanager.hpp> | ||||
| 
 | ||||
| #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; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,9 +6,9 @@ | |||
| #include <boost/program_options.hpp> | ||||
| 
 | ||||
| #include <components/files/fileops.hpp> | ||||
| #include <components/files/path.hpp> | ||||
| #include <components/files/fixedpath.hpp> | ||||
| #include <components/files/collections.hpp> | ||||
| #include <components/cfg/configurationmanager.hpp> | ||||
| #include <components/files/configurationmanager.hpp> | ||||
| 
 | ||||
| #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)) | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -1,157 +0,0 @@ | |||
| #include "configurationmanager.hpp" | ||||
| 
 | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iostream> | ||||
| 
 | ||||
| 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 */ | ||||
|  | @ -1,62 +0,0 @@ | |||
| #ifndef COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP | ||||
| #define COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP | ||||
| 
 | ||||
| #include <boost/program_options.hpp> | ||||
| #include <boost/filesystem.hpp> | ||||
| 
 | ||||
| #include <components/files/path.hpp> | ||||
| 
 | ||||
| /**
 | ||||
|  * \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 */ | ||||
							
								
								
									
										177
									
								
								components/files/configurationmanager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										177
									
								
								components/files/configurationmanager.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,177 @@ | |||
| #include "configurationmanager.hpp" | ||||
| 
 | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iostream> | ||||
| #include <functional> | ||||
| 
 | ||||
| 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 */ | ||||
							
								
								
									
										65
									
								
								components/files/configurationmanager.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								components/files/configurationmanager.hpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,65 @@ | |||
| #ifndef COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP | ||||
| #define COMPONENTS_FILES_CONFIGURATIONMANAGER_HPP | ||||
| 
 | ||||
| #include <tr1/unordered_map> | ||||
| 
 | ||||
| #include <boost/program_options.hpp> | ||||
| #include <boost/filesystem.hpp> | ||||
| 
 | ||||
| #include <components/files/fixedpath.hpp> | ||||
| 
 | ||||
| /**
 | ||||
|  * \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<std::string, path_type_f> 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 */ | ||||
|  | @ -18,10 +18,10 @@ | |||
|  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | ||||
|  */ | ||||
| 
 | ||||
| /** \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 <string> | ||||
| #include <boost/filesystem.hpp> | ||||
|  | @ -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 */ | ||||
|  | @ -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__) */ | ||||
|  |  | |||
|  | @ -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 */ | ||||
|  |  | |||
|  | @ -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__) */ | ||||
|  |  | |||
|  | @ -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 */ | ||||
|  |  | |||
|  | @ -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__) */ | ||||
|  |  | |||
|  | @ -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 */ | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue