fixes #128 Configuration cleanup.

Signed-off-by: Lukasz Gromanowski <lgromanowski@gmail.com>
actorid
Lukasz Gromanowski 14 years ago
parent a931124a2f
commit ea7eb7a62d

3
.gitignore vendored

@ -4,3 +4,6 @@ Doxygen
prebuilt prebuilt
apps/openmw/config.hpp apps/openmw/config.hpp
Docs/mainpage.hpp Docs/mainpage.hpp
CMakeFiles
*/CMakeFiles
CMakeCache.txt

@ -90,6 +90,14 @@ set(BSA_HEADER
${COMP_DIR}/bsa/bsa_file.hpp) ${COMP_DIR}/bsa/bsa_file.hpp)
source_group(components\\bsa FILES ${BSA} ${BSA_HEADER}) source_group(components\\bsa FILES ${BSA} ${BSA_HEADER})
set(CFG
${COMP_DIR}/cfg/configurationmanager.cpp
)
set(CFG_HEADER
${COMP_DIR}/cfg/configurationmanager.hpp
)
source_group(components\\cfg FILES ${CFG} ${CFG_HEADER})
set(NIF set(NIF
${COMP_DIR}/nif/nif_file.cpp) ${COMP_DIR}/nif/nif_file.cpp)
set(NIF_HEADER set(NIF_HEADER
@ -189,22 +197,29 @@ source_group(components\\esm FILES ${ESM_HEADER} ${ESM})
set(MISC set(MISC
${COMP_DIR}/misc/stringops.cpp ${COMP_DIR}/misc/stringops.cpp
${COMP_DIR}/misc/fileops.cpp) )
set(MISC_HEADER set(MISC_HEADER
${COMP_DIR}/misc/fileops.hpp
${COMP_DIR}/misc/slice_array.hpp ${COMP_DIR}/misc/slice_array.hpp
${COMP_DIR}/misc/stringops.hpp) ${COMP_DIR}/misc/stringops.hpp
)
source_group(components\\misc FILES ${MISC} ${MISC_HEADER}) source_group(components\\misc FILES ${MISC} ${MISC_HEADER})
set(FILES set(FILES
${COMP_DIR}/files/path.cpp ${COMP_DIR}/files/linuxpath.cpp
${COMP_DIR}/files/windowspath.cpp
${COMP_DIR}/files/macospath.cpp
${COMP_DIR}/files/multidircollection.cpp ${COMP_DIR}/files/multidircollection.cpp
${COMP_DIR}/files/collections.cpp ${COMP_DIR}/files/collections.cpp
${COMP_DIR}/files/fileops.cpp
) )
set(FILES_HEADER set(FILES_HEADER
${COMP_DIR}/files/linuxpath.hpp
${COMP_DIR}/files/windowspath.hpp
${COMP_DIR}/files/macospath.hpp
${COMP_DIR}/files/path.hpp ${COMP_DIR}/files/path.hpp
${COMP_DIR}/files/multidircollection.hpp ${COMP_DIR}/files/multidircollection.hpp
${COMP_DIR}/files/collections.hpp ${COMP_DIR}/files/collections.hpp
${COMP_DIR}/files/fileops.hpp
) )
source_group(components\\files FILES ${FILES} ${FILES_HEADER}) source_group(components\\files FILES ${FILES} ${FILES_HEADER})
@ -217,10 +232,14 @@ file(GLOB INTERPRETER_HEADER ${COMP_DIR}/interpreter/*.hpp)
source_group(components\\interpreter FILES ${INTERPRETER} ${INTERPRETER_HEADER}) source_group(components\\interpreter FILES ${INTERPRETER} ${INTERPRETER_HEADER})
set(COMPONENTS ${BSA} ${NIF} ${NIFOGRE} ${ESM_STORE} ${MISC} ${TO_UTF8} set(COMPONENTS ${BSA} ${NIF} ${NIFOGRE} ${ESM_STORE} ${MISC} ${TO_UTF8}
${COMPILER} ${INTERPRETER} ${ESM} ${FILE_FINDER} ${NIFBULLET} ${FILES}) ${COMPILER} ${INTERPRETER} ${ESM} ${FILE_FINDER} ${NIFBULLET} ${FILES}
${CFG}
)
set(COMPONENTS_HEADER ${BSA_HEADER} ${NIF_HEADER} ${NIFOGRE_HEADER} ${ESM_STORE_HEADER} set(COMPONENTS_HEADER ${BSA_HEADER} ${NIF_HEADER} ${NIFOGRE_HEADER} ${ESM_STORE_HEADER}
${ESM_HEADER} ${MISC_HEADER} ${COMPILER_HEADER} ${TO_UTF8_HEADER} ${ESM_HEADER} ${MISC_HEADER} ${COMPILER_HEADER} ${TO_UTF8_HEADER}
${INTERPRETER_HEADER} ${FILE_FINDER_HEADER} ${NIFBULLET_HEADER} ${FILES_HEADER}) ${INTERPRETER_HEADER} ${FILE_FINDER_HEADER} ${NIFBULLET_HEADER} ${FILES_HEADER}
${CFG_HEADER}
)
# source directory: libs # source directory: libs

@ -52,6 +52,7 @@ add_executable(omwlauncher
${LAUNCHER} ${LAUNCHER}
${MISC} ${MISC_HEADER} ${MISC} ${MISC_HEADER}
${FILES} ${FILES_HEADER} ${FILES} ${FILES_HEADER}
${CFG} ${CFG_HEADER}
${TO_UTF8} ${TO_UTF8}
${ESM} ${ESM}
${RCC_SRCS} ${RCC_SRCS}

@ -1,9 +1,9 @@
#include <QtGui> #include <QtGui>
#include <components/esm/esm_reader.hpp> #include <components/esm/esm_reader.hpp>
#include <components/files/path.hpp>
#include <components/files/collections.hpp> #include <components/files/collections.hpp>
#include <components/files/multidircollection.hpp> #include <components/files/multidircollection.hpp>
#include <components/cfg/configurationmanager.hpp>
#include "datafilespage.hpp" #include "datafilespage.hpp"
#include "lineedit.hpp" #include "lineedit.hpp"
@ -211,12 +211,13 @@ void DataFilesPage::setupDataFiles(const QStringList &paths, bool strict)
void DataFilesPage::setupConfig() void DataFilesPage::setupConfig()
{ {
QString config = "./launcher.cfg"; Cfg::ConfigurationManager cfg;
QString config = (cfg.getRuntimeConfigPath() / "launcher.cfg").string().c_str();
QFile file(config); QFile file(config);
if (!file.exists()) { if (!file.exists()) {
config = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, config = QString::fromStdString((cfg.getLocalConfigPath() / "launcher.cfg").string());
"openmw", "launcher.cfg"));
} }
file.setFileName(config); // Just for displaying information file.setFileName(config); // Just for displaying information

@ -1,7 +1,5 @@
#include <QtGui> #include <QtGui>
#include <components/files/path.hpp>
#include "graphicspage.hpp" #include "graphicspage.hpp"
GraphicsPage::GraphicsPage(QWidget *parent) : QWidget(parent) GraphicsPage::GraphicsPage(QWidget *parent) : QWidget(parent)
@ -149,13 +147,11 @@ void GraphicsPage::createPages()
void GraphicsPage::setupConfig() void GraphicsPage::setupConfig()
{ {
QString ogreCfg = "./ogre.cfg"; QString ogreCfg = (mCfg.getRuntimeConfigPath() / "ogre.cfg").string().c_str();
QFile file(ogreCfg); QFile file(ogreCfg);
if (!file.exists()) { if (!file.exists()) {
ogreCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, ogreCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "ogre.cfg").string());
"openmw", "ogre.cfg"));
} }
mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat); mOgreConfig = new QSettings(ogreCfg, QSettings::IniFormat);
@ -164,12 +160,11 @@ void GraphicsPage::setupConfig()
void GraphicsPage::setupOgre() void GraphicsPage::setupOgre()
{ {
QString pluginCfg = "./plugins.cfg"; QString pluginCfg = (mCfg.getRuntimeConfigPath() / "plugins.cfg").string().c_str();
QFile file(pluginCfg); QFile file(pluginCfg);
if (!file.exists()) { if (!file.exists()) {
pluginCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, pluginCfg = QString::fromStdString((mCfg.getLocalConfigPath() / "plugins.cfg").string());
"openmw", "plugins.cfg"));
} }
// Reopen the file from user directory // Reopen the file from user directory
@ -177,8 +172,7 @@ void GraphicsPage::setupOgre()
if (!file.exists()) { if (!file.exists()) {
// There's no plugins.cfg in the user directory, use global directory // There's no plugins.cfg in the user directory, use global directory
pluginCfg = QString::fromStdString(Files::getPath(Files::Path_ConfigGlobal, pluginCfg = QString::fromStdString((mCfg.getGlobalConfigPath() / "plugins.cfg").string());
"openmw", "plugins.cfg"));
} }
// Create a log manager so we can surpress debug text to stdout/stderr // Create a log manager so we can surpress debug text to stdout/stderr

@ -7,6 +7,7 @@
#include <OgreRenderSystem.h> #include <OgreRenderSystem.h>
#include <OgreConfigFile.h> #include <OgreConfigFile.h>
#include <OgreConfigDialog.h> #include <OgreConfigDialog.h>
#include <components/cfg/configurationmanager.hpp>
class QComboBox; class QComboBox;
class QCheckBox; class QCheckBox;
@ -28,6 +29,7 @@ public slots:
void rendererChanged(const QString &renderer); void rendererChanged(const QString &renderer);
private: private:
Cfg::ConfigurationManager mCfg;
Ogre::Root *mOgre; Ogre::Root *mOgre;
Ogre::RenderSystem *mSelectedRenderSystem; Ogre::RenderSystem *mSelectedRenderSystem;
Ogre::RenderSystem *mOpenGLRenderSystem; Ogre::RenderSystem *mOpenGLRenderSystem;

@ -1,7 +1,5 @@
#include <QtGui> #include <QtGui>
#include <components/files/path.hpp>
#include "maindialog.hpp" #include "maindialog.hpp"
#include "playpage.hpp" #include "playpage.hpp"
#include "graphicspage.hpp" #include "graphicspage.hpp"
@ -268,13 +266,14 @@ void MainDialog::play()
void MainDialog::setupConfig() void MainDialog::setupConfig()
{ {
Cfg::ConfigurationManager cfg;
// First we read the OpenMW config // First we read the OpenMW config
QString config = "./openmw.cfg"; QString config = (cfg.getRuntimeConfigPath() / "openmw.cfg").string().c_str();
QFile file(config); QFile file(config);
if (!file.exists()) { if (!file.exists()) {
config = QString::fromStdString(Files::getPath(Files::Path_ConfigUser, config = QString::fromStdString((cfg.getLocalConfigPath() / "openmw.cfg").string());
"openmw", "openmw.cfg"));
} }
file.close(); file.close();

@ -11,7 +11,7 @@
#include "components/esm/records.hpp" #include "components/esm/records.hpp"
#include <components/esm_store/cell_store.hpp> #include <components/esm_store/cell_store.hpp>
#include <components/misc/fileops.hpp> #include <components/files/fileops.hpp>
#include <components/bsa/bsa_archive.hpp> #include <components/bsa/bsa_archive.hpp>
#include <components/esm/loadregn.hpp> #include <components/esm/loadregn.hpp>
#include <components/esm/esm_reader.hpp> #include <components/esm/esm_reader.hpp>
@ -209,7 +209,7 @@ bool OMW::Engine::frameRenderingQueued (const Ogre::FrameEvent& evt)
return true; return true;
} }
OMW::Engine::Engine() OMW::Engine::Engine(Cfg::ConfigurationManager& configurationManager)
: mPhysicEngine (0) : mPhysicEngine (0)
, mShowFPS (false) , mShowFPS (false)
, mDebug (false) , mDebug (false)
@ -221,6 +221,7 @@ OMW::Engine::Engine()
, mScriptContext (0) , mScriptContext (0)
, mGuiManager (0) , mGuiManager (0)
, mFSStrict (false) , mFSStrict (false)
, mCfgMgr(configurationManager)
{ {
MWClass::registerClasses(); MWClass::registerClasses();
} }
@ -265,9 +266,9 @@ void OMW::Engine::addResourcesDirectory (const boost::filesystem::path& path)
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true); Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true);
} }
void OMW::Engine::enableFSStrict() void OMW::Engine::enableFSStrict(bool fsStrict)
{ {
mFSStrict = true; mFSStrict = fsStrict;
} }
// Set data dir // Set data dir
@ -311,21 +312,40 @@ void OMW::Engine::addMaster (const std::string& master)
} }
} }
void OMW::Engine::enableDebugMode() void OMW::Engine::setDebugMode(bool debugMode)
{ {
mDebug = true; mDebug = debugMode;
} }
void OMW::Engine::enableVerboseScripts() void OMW::Engine::setScriptsVerbosity(bool scriptsVerbosity)
{ {
mVerboseScripts = true; mVerboseScripts = scriptsVerbosity;
} }
void OMW::Engine::setNewGame() void OMW::Engine::setNewGame(bool newGame)
{ {
mNewGame = true; mNewGame = newGame;
} }
std::string OMW::Engine::getOgreFilesDir(const std::string& ogreFile)
{
boost::filesystem::path cfgPath(mCfgMgr.getRuntimeConfigPath());
if (!boost::filesystem::exists(cfgPath / ogreFile))
{
cfgPath = mCfgMgr.getLocalConfigPath();
if (!boost::filesystem::exists(cfgPath / ogreFile ))
{
cfgPath = mCfgMgr.getGlobalConfigPath();
if (!boost::filesystem::exists(cfgPath / ogreFile))
{
cfgPath.clear();
}
}
}
return (!cfgPath.empty()) ? cfgPath.string() + std::string("/") : std::string();
}
// Initialise and enter main loop. // Initialise and enter main loop.
void OMW::Engine::go() void OMW::Engine::go()
@ -337,19 +357,11 @@ void OMW::Engine::go()
test.name = ""; test.name = "";
total = 0; total = 0;
std::string cfgDir = Files::getPath (Files::Path_ConfigGlobal, "openmw", "");
std::string cfgUserDir = Files::getPath (Files::Path_ConfigUser, "openmw", "");
std::string plugCfg = "plugins.cfg";
std::string ogreCfg = "ogre.cfg";
ogreCfg.insert(0, cfgUserDir);
//A local plugins.cfg will be used if it exist, otherwise look in the default path std::string cfgDir(getOgreFilesDir("ogre.cfg"));
if(!Misc::isFile(plugCfg.c_str())) std::string pluginsFile(getOgreFilesDir("plugins.cfg") + std::string("plugins.cfg"));
{
plugCfg.insert(0, cfgDir);
}
mOgre.configure(!Misc::isFile(ogreCfg.c_str()), cfgUserDir, plugCfg, false); mOgre.configure(cfgDir.empty(), cfgDir, pluginsFile, false);
// This has to be added BEFORE MyGUI is initialized, as it needs // This has to be added BEFORE MyGUI is initialized, as it needs
// to find core.xml here. // to find core.xml here.
@ -516,7 +528,17 @@ void OMW::Engine::setCompileAll (bool all)
mCompileAll = all; mCompileAll = all;
} }
void OMW::Engine::setSoundUsage(bool soundUsage)
{
mUseSound = soundUsage;
}
void OMW::Engine::showFPS(bool showFps)
{
mShowFPS = showFps;
}
void OMW::Engine::setEncoding(const std::string& encoding) void OMW::Engine::setEncoding(const std::string& encoding)
{ {
mEncoding = encoding; mEncoding = encoding;
} }

@ -15,7 +15,7 @@
#include "mwworld/environment.hpp" #include "mwworld/environment.hpp"
#include "mwworld/ptr.hpp" #include "mwworld/ptr.hpp"
#include <boost/timer.hpp> #include <boost/timer.hpp>
#include <components/cfg/configurationmanager.hpp>
namespace Compiler namespace Compiler
{ {
@ -53,7 +53,6 @@ namespace OEngine
namespace OMW namespace OMW
{ {
/// \brief Main engine class, that brings together all the components of OpenMW /// \brief Main engine class, that brings together all the components of OpenMW
class Engine : private Ogre::FrameListener class Engine : private Ogre::FrameListener
{ {
std::string mEncoding; std::string mEncoding;
@ -106,49 +105,44 @@ namespace OMW
/// Process pending commands /// Process pending commands
public: public:
Engine(Cfg::ConfigurationManager& configurationManager);
Engine(); virtual ~Engine();
~Engine();
/// Enable strict filesystem mode (do not fold case) /// Enable strict filesystem mode (do not fold case)
/// ///
/// \attention The strict mode must be specified before any path-related settings /// \attention The strict mode must be specified before any path-related settings
/// are given to the engine. /// are given to the engine.
void enableFSStrict(); void enableFSStrict(bool fsStrict);
/// Set data dirs /// Set data dirs
void setDataDirs (const std::vector<boost::filesystem::path>& dataDirs); void setDataDirs(const Files::Collections::PathContainer& dataDirs);
/// Set resource dir /// Set resource dir
void setResourceDir (const boost::filesystem::path& parResDir); void setResourceDir(const boost::filesystem::path& parResDir);
/// Set start cell name (only interiors for now) /// Set start cell name (only interiors for now)
void setCell (const std::string& cellName); void setCell(const std::string& cellName);
/// Set master file (esm) /// Set master file (esm)
/// - If the given name does not have an extension, ".esm" is added automatically /// - If the given name does not have an extension, ".esm" is added automatically
/// - Currently OpenMW only supports one master at the same time. /// - Currently OpenMW only supports one master at the same time.
void addMaster (const std::string& master); void addMaster(const std::string& master);
/// Enable fps counter /// Enable fps counter
void showFPS() { mShowFPS = true; } void showFPS(bool showFps);
/// Enable debug mode: /// Enable debug mode:
/// - non-exclusive input /// - non-exclusive input
void enableDebugMode(); void setDebugMode(bool debugMode);
/// Enable the command server so external apps can send commands to the console. /// Enable or disable verbose script output
/// Must be set before go(). void setScriptsVerbosity(bool scriptsVerbosity);
/// Enable verbose script output /// Disable or enable all sounds
void enableVerboseScripts(); void setSoundUsage(bool soundUsage);
/// Disable all sound
void disableSound() { mUseSound = false; }
/// Start as a new game. /// Start as a new game.
void setNewGame(); void setNewGame(bool newGame);
/// Initialise and enter main loop. /// Initialise and enter main loop.
void go(); void go();
@ -161,7 +155,12 @@ namespace OMW
/// Font encoding /// Font encoding
void setEncoding(const std::string& encoding); void setEncoding(const std::string& encoding);
private:
std::string getOgreFilesDir(const std::string& ogreFile);
Cfg::ConfigurationManager& mCfgMgr;
}; };
} }
#endif #endif /* ENGINE_H */

@ -5,8 +5,10 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <components/misc/fileops.hpp> #include <components/files/fileops.hpp>
#include <components/files/path.hpp> #include <components/files/path.hpp>
#include <components/files/collections.hpp>
#include <components/cfg/configurationmanager.hpp>
#include "engine.hpp" #include "engine.hpp"
@ -35,56 +37,64 @@
using namespace std; using namespace std;
/// Parse command line options and openmw.cfg file (if one exists). Results are directly /**
/// written to \a engine. * \brief Parses application command line and calls \ref Cfg::ConfigurationManager
/// \return Run OpenMW? * to parse configuration files.
*
bool parseOptions (int argc, char**argv, OMW::Engine& engine) * Results are directly written to \ref Engine class.
*
* \retval true - Everything goes OK
* \retval false - Error
*/
bool parseOptions (int argc, char** argv, OMW::Engine& engine, Cfg::ConfigurationManager& cfgMgr)
{ {
// Create a local alias for brevity // Create a local alias for brevity
namespace bpo = boost::program_options; namespace bpo = boost::program_options;
typedef std::vector<std::string> StringsVector;
bpo::options_description desc ( bpo::options_description desc("Syntax: openmw <options>\nAllowed options");
"Syntax: openmw <options>\nAllowed options");
desc.add_options() desc.add_options()
("help", "print help message and quit") ("help", "print help message")
("version", "print version information and quit") ("version", "print version information and quit")
("data", bpo::value<std::vector<std::string> >() ("data", bpo::value<Files::Collections::PathContainer>()->default_value(Files::Collections::PathContainer(), "data")
->default_value (std::vector<std::string>(), "data") ->multitoken(), "set data directories (later directories have higher priority)")
->multitoken(),
"set data directories (later directories have higher priority)") ("data-local", bpo::value<std::string>()->default_value(""),
("data-local", bpo::value<std::string>()->default_value (""),
"set local data directory (highest priority)") "set local data directory (highest priority)")
("resources", bpo::value<std::string>()->default_value ("resources"),
("resources", bpo::value<std::string>()->default_value("resources"),
"set resources directory") "set resources directory")
("start", bpo::value<std::string>()->default_value ("Beshara"),
("start", bpo::value<std::string>()->default_value("Beshara"),
"set initial cell") "set initial cell")
("master", bpo::value<std::vector<std::string> >()
->default_value (std::vector<std::string>(), "") ("master", bpo::value<StringsVector>()->default_value(StringsVector(), "")
->multitoken(), ->multitoken(), "master file(s)")
"master file(s)")
("plugin", bpo::value<std::vector<std::string> >() ("plugin", bpo::value<StringsVector>()->default_value(StringsVector(), "")
->default_value (std::vector<std::string>(), "") ->multitoken(), "plugin file(s)")
->multitoken(),
"plugin file(s)") ("fps", boost::program_options::value<bool>()->implicit_value(true)
( "fps", boost::program_options::value<bool>()-> ->default_value(false), "show fps counter")
implicit_value (true)->default_value (false), "show fps counter")
( "debug", boost::program_options::value<bool>()-> ("debug", boost::program_options::value<bool>()->implicit_value(true)
implicit_value (true)->default_value (false), "debug mode" ) ->default_value(false), "debug mode")
( "nosound", boost::program_options::value<bool>()->
implicit_value (true)->default_value (false), "disable all sound" ) ("nosound", boost::program_options::value<bool>()->implicit_value(true)
( "script-verbose", boost::program_options::value<bool>()-> ->default_value(false), "disable all sounds")
implicit_value (true)->default_value (false), "verbose script output" )
( "new-game", boost::program_options::value<bool>()-> ("script-verbose", boost::program_options::value<bool>()->implicit_value(true)
implicit_value (true)->default_value (false), ->default_value(false), "verbose script output")
"activate char gen/new game mechanics" )
( "script-all", boost::program_options::value<bool>()-> ("new-game", boost::program_options::value<bool>()->implicit_value(true)
implicit_value (true)->default_value (false), ->default_value(false), "activate char gen/new game mechanics")
"compile all scripts (excluding dialogue scripts) at startup")
( "fs-strict", boost::program_options::value<bool>()-> ("script-all", boost::program_options::value<bool>()->implicit_value(true)
implicit_value (true)->default_value (false), ->default_value(false), "compile all scripts (excluding dialogue scripts) at startup")
"strict file system handling (no case folding)")
("fs-strict", boost::program_options::value<bool>()->implicit_value(true)
->default_value(false), "strict file system handling (no case folding)")
( "encoding", boost::program_options::value<std::string>()-> ( "encoding", boost::program_options::value<std::string>()->
default_value("win1252"), default_value("win1252"),
@ -94,32 +104,17 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
"\n\twin1252 - Western European (Latin) alphabet, used by default") "\n\twin1252 - Western European (Latin) alphabet, used by default")
; ;
bpo::variables_map variables; bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv)
.options(desc).allow_unregistered().run();
//If there is an openmw.cfg in the current path use that as global config
//Otherwise try getPath
std::string cfgFile = "openmw.cfg";
if(!Misc::isFile(cfgFile.c_str()))
{
cfgFile = Files::getPath (Files::Path_ConfigGlobal, "openmw", "openmw.cfg");
}
std::cout << "Using global config file: " << cfgFile << std::endl;
std::ifstream globalConfigFile(cfgFile.c_str());
cfgFile = Files::getPath (Files::Path_ConfigUser, "openmw", "openmw.cfg"); bpo::variables_map variables;
std::cout << "Using user config file: " << cfgFile << std::endl;
std::ifstream userConfigFile(cfgFile.c_str());
bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); cfgMgr.readConfiguration(variables, desc);
// Runtime options override settings from all configs
bpo::store(valid_opts, variables); bpo::store(valid_opts, variables);
bpo::notify(variables); bpo::notify(variables);
if (userConfigFile.is_open())
bpo::store ( bpo::parse_config_file (userConfigFile, desc), variables);
if (globalConfigFile.is_open())
bpo::store ( bpo::parse_config_file (globalConfigFile, desc), variables);
bool run = true; bool run = true;
if (variables.count ("help")) if (variables.count ("help"))
@ -156,63 +151,57 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
} }
// directory settings // directory settings
if (variables["fs-strict"].as<bool>()==true) engine.enableFSStrict(variables["fs-strict"].as<bool>());
engine.enableFSStrict();
std::vector<std::string> dataDirs = variables["data"].as<std::vector<std::string> >(); Files::Collections::PathContainer dataDirs = variables["data"].as<Files::Collections::PathContainer>();
std::vector<boost::filesystem::path> dataDirs2 (dataDirs.begin(), dataDirs.end());
std::string local = variables["data-local"].as<std::string>(); std::string local(variables["data-local"].as<std::string>());
if (!local.empty()) if (!local.empty())
dataDirs.push_back (local); {
dataDirs.push_back(local);
}
engine.setDataDirs (dataDirs2); if (dataDirs.empty())
{
dataDirs.push_back(cfgMgr.getLocalDataPath().string());
}
engine.setResourceDir (variables["resources"].as<std::string>()); engine.setDataDirs(dataDirs);
engine.setResourceDir(variables["resources"].as<std::string>());
// master and plugin // master and plugin
std::vector<std::string> master = variables["master"].as<std::vector<std::string> >(); StringsVector master = variables["master"].as<StringsVector>();
if (master.empty()) if (master.empty())
{ {
std::cout << "No master file given. Assuming Morrowind.esm" << std::endl; std::cout << "No master file given. Assuming Morrowind.esm" << std::endl;
master.push_back ("Morrowind"); master.push_back("Morrowind");
} }
if (master.size()>1) if (master.size() > 1)
{ {
std::cout std::cout
<< "Ignoring all but the first master file (multiple master files not yet supported)." << "Ignoring all but the first master file (multiple master files not yet supported)."
<< std::endl; << std::endl;
} }
engine.addMaster(master[0]);
engine.addMaster (master[0]); StringsVector plugin = variables["plugin"].as<StringsVector>();
std::vector<std::string> plugin = variables["plugin"].as<std::vector<std::string> >();
if (!plugin.empty()) if (!plugin.empty())
{
std::cout << "Ignoring plugin files (plugins not yet supported)." << std::endl; std::cout << "Ignoring plugin files (plugins not yet supported)." << std::endl;
}
// startup-settings // startup-settings
engine.setCell (variables["start"].as<std::string>()); engine.setCell(variables["start"].as<std::string>());
engine.setNewGame(variables["new-game"].as<bool>());
if (variables["new-game"].as<bool>()==true)
engine.setNewGame();
// other settings // other settings
if (variables["fps"].as<bool>()==true) engine.showFPS(variables["fps"].as<bool>());
engine.showFPS(); engine.setDebugMode(variables["debug"].as<bool>());
engine.setSoundUsage(!variables["nosound"].as<bool>());
if (variables["debug"].as<bool>()==true) engine.setScriptsVerbosity(variables["script-verbose"].as<bool>());
engine.enableDebugMode(); engine.setCompileAll(variables["script-all"].as<bool>());
if (variables["nosound"].as<bool>()==true)
engine.disableSound();
if (variables["script-verbose"].as<bool>()==true)
engine.enableVerboseScripts();
if (variables["script-all"].as<bool>()==true)
engine.setCompileAll (true);
return true; return true;
} }
@ -227,16 +216,17 @@ int main(int argc, char**argv)
try try
{ {
OMW::Engine engine; Cfg::ConfigurationManager cfgMgr;
OMW::Engine engine(cfgMgr);
if (parseOptions (argc, argv, engine)) if (parseOptions(argc, argv, engine, cfgMgr))
{ {
engine.go(); engine.go();
} }
} }
catch(exception &e) catch (std::exception &e)
{ {
cout << "\nERROR: " << e.what() << endl; std::cout << "\nERROR: " << e.what() << std::endl;
return 1; return 1;
} }

@ -0,0 +1,118 @@
#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")
{
}
ConfigurationManager::~ConfigurationManager()
{
}
void ConfigurationManager::readConfiguration(boost::program_options::variables_map& variables,
boost::program_options::options_description& description)
{
loadConfig(mPath.getGlobalConfigPath(), variables, description);
loadConfig(mPath.getLocalConfigPath(), variables, description);
loadConfig(mPath.getRuntimeConfigPath(), 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);
}
} /* namespace Cfg */

@ -0,0 +1,54 @@
#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);
private:
void loadConfig(const boost::filesystem::path& path,
boost::program_options::variables_map& variables,
boost::program_options::options_description& description);
Files::Path<> mPath;
};
} /* namespace Cfg */
#endif /* COMPONENTS_CFG_CONFIGURATIONMANAGER_HPP */

@ -3,21 +3,27 @@
namespace Files namespace Files
{ {
Collections::Collections() : mFoldCase (false) {} Collections::Collections()
: mDirectories()
Collections::Collections (const std::vector<boost::filesystem::path>& directories, bool foldCase) , mFoldCase(false)
: mDirectories (directories), mFoldCase (foldCase) , mCollections()
{} {
}
const MultiDirCollection& Collections::getCollection (const std::string& extension) const Collections::Collections(const std::vector<boost::filesystem::path>& directories, bool foldCase)
: mDirectories(directories)
, mFoldCase(foldCase)
, mCollections()
{ {
std::map<std::string, MultiDirCollection>::iterator iter = mCollections.find (extension); }
const MultiDirCollection& Collections::getCollection(const std::string& extension) const
{
MultiDirCollectionContainer::iterator iter = mCollections.find(extension);
if (iter==mCollections.end()) if (iter==mCollections.end())
{ {
std::pair<std::map<std::string, MultiDirCollection>::iterator, bool> result = std::pair<MultiDirCollectionContainer::iterator, bool> result =
mCollections.insert (std::make_pair (extension, mCollections.insert(std::make_pair(extension, MultiDirCollection(mDirectories, extension, mFoldCase)));
MultiDirCollection (mDirectories, extension, mFoldCase)));
iter = result.first; iter = result.first;
} }

@ -1,27 +1,35 @@
#ifndef COMPONENTS_FILES_COLLECTION_HPP #ifndef COMPONENTS_FILES_COLLECTION_HPP
#define COMPONENTS_FILES_COLLECTION_HPP #define COMPONENTS_FILES_COLLECTION_HPP
#include <vector>
#include <string>
#include <map>
#include <boost/filesystem.hpp>
#include "multidircollection.hpp" #include "multidircollection.hpp"
namespace Files namespace Files
{ {
class Collections class Collections
{ {
std::vector<boost::filesystem::path> mDirectories;
bool mFoldCase;
mutable std::map<std::string, MultiDirCollection> mCollections;
public: public:
typedef std::vector<boost::filesystem::path> PathContainer;
Collections(); Collections();
Collections (const std::vector<boost::filesystem::path>& directories, bool foldCase);
///< Directories are listed with increasing priority. ///< Directories are listed with increasing priority.
Collections(const PathContainer& directories, bool foldCase);
const MultiDirCollection& getCollection (const std::string& extension) const;
///< Return a file collection for the given extension. Extension must contain the ///< Return a file collection for the given extension. Extension must contain the
/// leading dot and must be all lower-case. /// leading dot and must be all lower-case.
const MultiDirCollection& getCollection(const std::string& extension) const;
private:
typedef std::map<std::string, MultiDirCollection> MultiDirCollectionContainer;
PathContainer mDirectories;
bool mFoldCase;
mutable MultiDirCollectionContainer mCollections;
}; };
} }

@ -0,0 +1,12 @@
#include "fileops.hpp"
#include <boost/filesystem.hpp>
namespace Files
{
bool isFile(const char *name)
{
return boost::filesystem::exists(boost::filesystem::path(name));
}
}

@ -0,0 +1,13 @@
#ifndef COMPONENTS_FILES_FILEOPS_HPP
#define COMPONENTS_FILES_FILEOPS_HPP
namespace Files
{
///\brief Check if a given path is an existing file (not a directory)
///\param [in] name - filename
bool isFile(const char *name);
}
#endif /* COMPONENTS_FILES_FILEOPS_HPP */

@ -0,0 +1,159 @@
/**
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
* engine implementation.
*
* Copyright (C) 2011 Open Morrowind Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file components/files/linuxpath.cpp */
#include "linuxpath.hpp"
#if defined(__linux__)
#include <cstdlib>
#include <pwd.h>
#include <unistd.h>
/**
* \namespace Files
*/
namespace Files
{
boost::filesystem::path LinuxPath::getLocalConfigPath() const
{
boost::filesystem::path localConfigPath(".");
boost::filesystem::path suffix("/");
const char* theDir = getenv("OPENMW_CONFIG");
if (theDir == NULL)
{
theDir = getenv("XDG_CONFIG_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("/.config/");
}
}
}
if (theDir != NULL) {
localConfigPath = boost::filesystem::path(theDir);
}
localConfigPath /= suffix;
return localConfigPath;
}
boost::filesystem::path LinuxPath::getGlobalConfigPath() const
{
boost::filesystem::path globalConfigPath("/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)
{
globalConfigPath = boost::filesystem::path(ptr);
globalConfigPath /= boost::filesystem::path("/");
}
}
return globalConfigPath;
}
boost::filesystem::path LinuxPath::getRuntimeConfigPath() 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__) */

@ -0,0 +1,90 @@
/**
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
* engine implementation.
*
* Copyright (C) 2011 Open Morrowind Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file components/files/linuxpath.hpp */
#ifndef COMPONENTS_FILES_LINUXPATH_H
#define COMPONENTS_FILES_LINUXPATH_H
#if defined(__linux__)
#include <boost/filesystem.hpp>
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct LinuxPath
*/
struct LinuxPath
{
/**
* \brief Return path to the local configuration directory.
*
* \return boost::filesystem::path
*/
boost::filesystem::path getLocalConfigPath() const;
/**
* \brief Return path to the global (system) configuration directory.
*
* \return boost::filesystem::path
*/
boost::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return path to the runtime configuration directory which is the
* place where an application was started.
*
* \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;
};
} /* namespace Files */
#endif /* defined(__linux__) */
#endif /* COMPONENTS_FILES_LINUXPATH_H */

@ -0,0 +1,118 @@
/**
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
* engine implementation.
*
* Copyright (C) 2011 Open Morrowind Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file components/files/macospath.cpp */
#include "macospath.hpp"
#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
#include <cstdlib>
#include <pwd.h>
#include <unistd.h>
/**
* \namespace Files
*/
namespace Files
{
boost::filesystem::path MacOsPath::getLocalConfigPath() const
{
boost::filesystem::path localConfigPath(".");
boost::filesystem::path suffix("/");
const char* theDir = getenv("HOME");
if (theDir == NULL)
{
struct passwd* pwd = getpwuid(getuid());
if (pwd != NULL)
{
theDir = pwd->pw_dir;
}
}
if (theDir != NULL)
{
localConfigPath = boost::filesystem::path(theDir) / "Library/Preferences/";
}
localConfigPath /= suffix;
return localConfigPath;
}
boost::filesystem::path MacOsPath::getGlobalConfigPath() const
{
boost::filesystem::path globalConfigPath("/Library/Preferences/");
return globalConfigPath;
}
boost::filesystem::path MacOsPath::getRuntimeConfigPath() 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__) */

@ -0,0 +1,90 @@
/**
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
* engine implementation.
*
* Copyright (C) 2011 Open Morrowind Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file components/files/macospath.hpp */
#ifndef COMPONENTS_FILES_MACOSPATH_H
#define COMPONENTS_FILES_MACOSPATH_H
#if defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
#include <boost/filesystem.hpp>
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct MacOsPath
*/
struct MacOsPath
{
/**
* \brief Return path to the local configuration directory.
*
* \return boost::filesystem::path
*/
boost::filesystem::path getLocalConfigPath() const;
/**
* \brief Return path to the global (system) configuration directory.
*
* \return boost::filesystem::path
*/
boost::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return path to the runtime configuration directory which is the
* place where an application was started.
*
* \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;
};
} /* namespace Files */
#endif /* defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__) */
#endif /* COMPONENTS_FILES_MACOSPATH_H */

@ -1,61 +0,0 @@
#include "path.hpp"
#include <boost/filesystem.hpp>
#include <OgrePlatform.h>
#include <string>
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include <OSX/macUtils.h>
#endif
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
#include <stdlib.h> //getenv
#endif
std::string Files::getPath (PathTypeEnum parType, const std::string parApp, const std::string parFile)
{
std::string theBasePath;
if (parType==Path_ConfigGlobal)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
boost::filesystem::path path(Ogre::macBundlePath());
path = path.parent_path();
theBasePath = path.string() + "/";
#elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
theBasePath = "/etc/"+parApp+"/";
#else
theBasePath = "";
#endif
}
else if (parType==Path_ConfigUser)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
const char* theDir;
if ((theDir = getenv("OPENMW_HOME")) != NULL)
{
theBasePath = std::string(theDir)+"/";
}
else
{
if ((theDir = getenv("XDG_CONFIG_HOME")))
{
theBasePath = std::string(theDir)+"/"+parApp+"/";
}
else
{
if ((theDir = getenv("HOME")) == NULL)
return parFile;
theBasePath = std::string(theDir)+"/.config/"+parApp+"/";
}
}
boost::filesystem::create_directories(boost::filesystem::path(theBasePath));
#else
theBasePath = "";
#endif
}
theBasePath.append(parFile);
return theBasePath;
}

@ -1,17 +1,232 @@
/**
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
* engine implementation.
*
* Copyright (C) 2011 Open Morrowind Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file components/files/path.hpp */
#ifndef COMPONENTS_FILES_PATH_HPP #ifndef COMPONENTS_FILES_PATH_HPP
#define COMPONENTS_FILES_PATH_HPP #define COMPONENTS_FILES_PATH_HPP
#include <string> #include <string>
#include <boost/filesystem.hpp>
#if defined(__linux__)
#include <components/files/linuxpath.hpp>
namespace Files { typedef LinuxPath TargetPathType; }
#elif defined(__WIN32) || defined(__WINDOWS__)
#include <components/files/windowspath.hpp>
namespace Files { typedef WindowsPath TargetPathType; }
#elif defined(macintosh) || defined(Macintosh) || defined(__APPLE__) || defined(__MACH__)
#include <components/files/macospath.hpp>
namespace Files { typedef MacOsPath TargetPathType; }
#else
#error "Unknown platform!"
#endif
/**
* \namespace Files
*/
namespace Files namespace Files
{ {
enum PathTypeEnum
/**
* \struct Path
*
* \tparam P - Path strategy class type (depends on target system)
*
*/
template
<
class P = TargetPathType
>
struct Path
{
typedef P PathType;
/**
* \brief Path constructor.
*
* \param [in] application_name - Name of the application
*/
Path(const std::string& application_name)
: mPath()
, mLocalConfigPath(mPath.getLocalConfigPath())
, mGlobalConfigPath(mPath.getGlobalConfigPath())
, mRuntimeConfigPath(mPath.getRuntimeConfigPath())
, mLocalDataPath(mPath.getLocalDataPath())
, mGlobalDataPath(mPath.getGlobalDataPath())
, mRuntimeDataPath(mPath.getRuntimeDataPath())
{ {
Path_ConfigUser, if (!application_name.empty())
Path_ConfigGlobal {
}; boost::filesystem::path suffix(application_name + std::string("/"));
std::string getPath (PathTypeEnum parType, const std::string parApp, const std::string parFile); mLocalConfigPath /= suffix;
} mGlobalConfigPath /= suffix;
#endif mLocalDataPath /= suffix;
mGlobalDataPath /= suffix;
}
}
/**
* \brief Return path pointing to the user local configuration directory.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getLocalConfigPath() const
{
return mLocalConfigPath;
}
/**
* \brief Sets new local configuration path.
*
* \param [in] path - New path
*/
void setLocalConfigPath(const boost::filesystem::path& path)
{
mLocalConfigPath = path;
}
/**
* \brief Return path pointing to the global (system) configuration directory.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getGlobalConfigPath() const
{
return mGlobalConfigPath;
}
/**
* \brief Sets new global configuration path.
*
* \param [in] path - New path
*/
void setGlobalConfigPath(const boost::filesystem::path& path)
{
mGlobalConfigPath = path;
}
/**
* \brief Return path pointing to the directory where application was started.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getRuntimeConfigPath() const
{
return mRuntimeConfigPath;
}
/**
* \brief Sets new runtime configuration path.
*
* \param [in] path - New path
*/
void setRuntimeConfigPath(const boost::filesystem::path& path)
{
mRuntimeConfigPath = path;
}
/**
* \brief Return path pointing to the user local data directory.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getLocalDataPath() const
{
return mLocalDataPath;
}
/**
* \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)
{
mGlobalDataPath = path;
}
/**
* \brief Return path pointing to the directory where application was started.
*
* \return boost::filesystem::path
*/
const boost::filesystem::path& getRuntimeDataPath() const
{
return mRuntimeDataPath;
}
/**
* \brief Sets new runtime data directory.
*
* \param [in] path - New path
*/
void setRuntimeDataPath(const boost::filesystem::path& path)
{
mRuntimeDataPath = 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 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.
By default it is a 'data' directory in same
directory where application was run */
};
} /* namespace Files */
#endif /* COMPONENTS_FILES_PATH_HPP */

@ -0,0 +1,72 @@
#include "windowspath.hpp"
#if defined(_WIN32) || defined(__WINDOWS__)
#include <cstring>
#include <windows.h>
#include <shobj.h>
namespace Files
{
boost::filesystem::path WindowsPath::getLocalConfigPath() const
{
boost::filesystem::path localConfigPath(".");
boost::filesystem::path suffix("/");
TCHAR path[MAX_PATH];
memset(path, 0, sizeof(path));
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, path)))
{
PathAppend(path, TEXT("My Games"));
localConfigPath = boost::filesystem::path(path);
}
localConfigPath /= suffix;
return localConfigPath;
}
boost::filesystem::path WindowsPath::getGlobalConfigPath() const
{
boost::filesystem::path globalConfigPath(".");
boost::filesystem::path suffix("/");
TCHAR path[MAX_PATH];
memset(path, 0, sizeof(path));
if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES | CSIDL_FLAG_CREATE, NULL, 0, path)))
{
globalConfigPath = boost::filesystem::path(path);
}
globalConfigPath /= suffix;
return globalConfigPath;
}
boost::filesystem::path WindowsPath::getRuntimeConfigPath() 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__) */

@ -0,0 +1,90 @@
/**
* Open Morrowind - an opensource Elder Scrolls III: Morrowind
* engine implementation.
*
* Copyright (C) 2011 Open Morrowind Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file components/files/windowspath.hpp */
#ifndef COMPONENTS_FILES_WINDOWSPATH_HPP
#define COMPONENTS_FILES_WINDOWSPATH_HPP
#if defined(_WIN32) || defined(__WINDOWS__)
#include <boost/filesystem.hpp>
/**
* \namespace Files
*/
namespace Files
{
/**
* \struct WindowsPath
*/
struct WindowsPath
{
/**
* \brief Returns "X:\Documents And Settings\<User name>\My Documents\My Games\"
*
* \return boost::filesystem::path
*/
boost::filesystem::path getLocalConfigPath() const;
/**
* \brief Returns "X:\Program Files\"
*
* \return boost::filesystem::path
*/
boost::filesystem::path getGlobalConfigPath() const;
/**
* \brief Return runtime configuration 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;
};
} /* namespace Files */
#endif /* defined(_WIN32) || defined(__WINDOWS__) */
#endif /* COMPONENTS_FILES_WINDOWSPATH_HPP */

@ -1,16 +0,0 @@
#include "fileops.hpp"
#include <boost/filesystem.hpp>
#include <string>
#include <OgrePrerequisites.h>
namespace Misc
{
bool isFile(const char *name)
{
boost::filesystem::path cfg_file_path(name);
return boost::filesystem::exists(cfg_file_path);
}
}

@ -1,18 +0,0 @@
#ifndef MISC_FILEOPS_H
#define MISC_FILEOPS_H
#include <string>
namespace Misc
{
/// Check if a given path is an existing file (not a directory)
bool isFile(const char *name);
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
std::string macBundlePath();
#endif
}
#endif
Loading…
Cancel
Save