Store configuration in /etc/openmw/ and ~/.openmw/ on linux

Requires new openengine version.
actorid
Jan-Peter Nilsson 14 years ago
parent 940554b5fc
commit 429775d485

@ -41,6 +41,7 @@
#include <MyGUI_WidgetManager.h>
#include "mwgui/class.hpp"
#include "path.hpp"
//using namespace ESM;
@ -245,6 +246,12 @@ void OMW::Engine::setDataDir (const boost::filesystem::path& dataDir)
mDataDir = boost::filesystem::system_complete (dataDir);
}
// Set resource dir
void OMW::Engine::setResourceDir (const boost::filesystem::path& parResDir)
{
mResDir = boost::filesystem::system_complete(parResDir);
}
// Set start cell name (only interiors for now)
void OMW::Engine::setCell (const std::string& cellName)
@ -300,16 +307,20 @@ void OMW::Engine::go()
std::cout << "Data directory: " << mDataDir << "\n";
const char* plugCfg = "plugins.cfg";
std::string cfgDir = OMW::Path::getPath(OMW::Path::USER_CFG_PATH, "openmw", "");
std::string plugCfg = "plugins.cfg";
std::string ogreCfg = "ogre.cfg";
ogreCfg.insert(0, cfgDir);
plugCfg.insert(0, cfgDir);
mOgre.configure(!isFile("ogre.cfg"), plugCfg, false);
mOgre.configure(!isFile(ogreCfg.c_str()), cfgDir, plugCfg, false);
addResourcesDirectory (mDataDir / "Meshes");
addResourcesDirectory (mDataDir / "Textures");
// This has to be added BEFORE MyGUI is initialized, as it needs
// to find core.xml here.
addResourcesDirectory("resources/mygui/");
addResourcesDirectory(mResDir / "mygui");
// Create the window
mOgre.createWindow("OpenMW");
@ -317,11 +328,10 @@ void OMW::Engine::go()
loadBSA();
// Create the world
mEnvironment.mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mNewGame, mEnvironment);
mEnvironment.mWorld = new MWWorld::World (mOgre, mDataDir, mMaster, mResDir, mNewGame, mEnvironment);
// Set up the GUI system
mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(),
mOgre.getScene());
mGuiManager = new OEngine::GUI::MyGUIManager(mOgre.getWindow(), mOgre.getScene(), false, cfgDir);
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWAttribute>("Widget");
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSpell>("Widget");

@ -57,6 +57,7 @@ namespace OMW
//int nFiles;
boost::filesystem::path mDataDir;
boost::filesystem::path mResDir;
OEngine::Render::OgreRenderer mOgre;
std::string mCellName;
std::string mMaster;
@ -107,6 +108,9 @@ namespace OMW
/// Set data dir
void setDataDir (const boost::filesystem::path& dataDir);
/// Set resource dir
void setResourceDir (const boost::filesystem::path& parResDir);
/// Set start cell name (only interiors for now)
void setCell (const std::string& cellName);

@ -7,9 +7,10 @@
#include <components/misc/fileops.hpp>
#include "engine.hpp"
#include "path.hpp"
#if defined(_WIN32) && !defined(_CONSOLE)
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/concepts.hpp>
#include <boost/iostreams/stream_buffer.hpp>
# if !defined(_DEBUG)
@ -42,6 +43,8 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
("help", "print help message")
("data", bpo::value<std::string>()->default_value ("data"),
"set data directory")
("resources", bpo::value<std::string>()->default_value ("resources"),
"set resources directory")
("start", bpo::value<std::string>()->default_value ("Beshara"),
"set initial cell")
("master", bpo::value<std::string>()->default_value ("Morrowind"),
@ -55,20 +58,23 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
bpo::variables_map variables;
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
std::string configFilePath(macBundlePath() + "/Contents/MacOS/openmw.cfg");
std::ifstream configFile (configFilePath.c_str());
#else
std::ifstream configFile ("openmw.cfg");
#endif
std::string cfgFile = OMW::Path::getPath(OMW::Path::GLOBAL_CFG_PATH, "openmw", "openmw.cfg");
std::cout << "Using global config file: " << cfgFile << std::endl;
std::ifstream globalConfigFile(cfgFile.c_str());
cfgFile = OMW::Path::getPath(OMW::Path::USER_CFG_PATH, "openmw", "openmw.cfg");
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();
bpo::store(valid_opts, variables);
bpo::notify(variables);
if (configFile.is_open())
bpo::store ( bpo::parse_config_file (configFile, desc), 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);
if (variables.count ("help"))
{
@ -77,6 +83,7 @@ bool parseOptions (int argc, char**argv, OMW::Engine& engine)
}
engine.setDataDir (variables["data"].as<std::string>());
engine.setResourceDir (variables["resources"].as<std::string>());
engine.setCell (variables["start"].as<std::string>());
engine.addMaster (variables["master"].as<std::string>());

@ -19,7 +19,8 @@ namespace MWRender
public:
CaelumManager (Ogre::RenderWindow* pRenderWindow,
Ogre::Camera* pCamera);
Ogre::Camera* pCamera,
const boost::filesystem::path& resDir);
virtual ~CaelumManager ();
virtual void enable() {}
@ -44,7 +45,8 @@ namespace MWRender
};
CaelumManager::CaelumManager (Ogre::RenderWindow* pRenderWindow,
Ogre::Camera* pCamera)
Ogre::Camera* pCamera,
const boost::filesystem::path& resDir)
: mpCaelumSystem (NULL)
{
using namespace Ogre;
@ -55,7 +57,7 @@ namespace MWRender
// Load the Caelum resources
//
ResourceGroupManager::getSingleton().addResourceLocation("resources/caelum", "FileSystem", "Caelum");
ResourceGroupManager::getSingleton().addResourceLocation((resDir / "caelum").string(), "FileSystem", "Caelum");
ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
// Load the Caelum resources
@ -89,13 +91,14 @@ namespace MWRender
/// \return NULL on failure.
///
SkyManager* SkyManager::create (Ogre::RenderWindow* pRenderWindow,
Ogre::Camera* pCamera)
Ogre::Camera* pCamera,
const boost::filesystem::path& resDir)
{
SkyManager* pSkyManager = NULL;
try
{
pSkyManager = new CaelumManager(pRenderWindow, pCamera);
pSkyManager = new CaelumManager(pRenderWindow, pCamera, resDir);
}
catch (Ogre::Exception& e)
{

@ -1,6 +1,8 @@
#ifndef _GAME_RENDER_SKY_H
#define _GAME_RENDER_SKY_H
#include <boost/filesystem.hpp>
namespace Ogre
{
class RenderWindow;
@ -16,7 +18,8 @@ namespace MWRender
{
public:
static SkyManager* create (Ogre::RenderWindow* pRenderWindow,
Ogre::Camera* pCamera);
Ogre::Camera* pCamera,
const boost::filesystem::path& resDir);
virtual ~SkyManager() {}
virtual void enable() = 0;

@ -316,7 +316,7 @@ namespace MWWorld
}
World::World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
const std::string& master, bool newGame, Environment& environment)
const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment)
: mSkyManager (0), mScene (renderer), mPlayer (0), mCurrentCell (0), mGlobalVariables (0),
mSky (false), mCellChanged (false), mEnvironment (environment)
{
@ -341,7 +341,7 @@ namespace MWWorld
}
mSkyManager =
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera());
MWRender::SkyManager::create(renderer.getWindow(), mScene.getCamera(), resDir);
}
World::~World()

@ -89,8 +89,8 @@ namespace MWWorld
public:
World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& master,
const std::string& dataDir, bool newGame, Environment& environment);
World (OEngine::Render::OgreRenderer& renderer, const boost::filesystem::path& dataDir,
const std::string& master, const boost::filesystem::path& resDir, bool newGame, Environment& environment);
~World();

@ -0,0 +1,59 @@
#ifndef PATH__HPP
#define PATH__HPP
#include <OgrePlatform.h>
#include <string>
#if OGRE_PLATFORM_LINUX
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h> //getenv
#endif
namespace OMW
{
class Path
{
public:
enum PathTypeEnum
{
USER_CFG_PATH,
GLOBAL_CFG_PATH
};
//TODO use application data dir on windows?
static std::string getPath(PathTypeEnum parType, const std::string parApp, const std::string parFile)
{
std::string theBasePath;
if(parType == GLOBAL_CFG_PATH)
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
theBasePath = macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
#elif OGRE_PLATFORM_LINUX
theBasePath = "/etc/"+parApp+"/";
#else
theBasePath = "";
#endif
}
else
{
#if OGRE_PLATFORM == OGRE_PLATFORM_APPLE
theBasePath = macBundlePath() + "/Contents/MacOS/"; //FIXME do we have global/local with OSX?
#elif OGRE_PLATFORM_LINUX
const char* homedir;
if ((homedir = getenv("HOME")) == NULL)
return NULL;
theBasePath = std::string(homedir)+"/."+parApp+"/";
mkdir(theBasePath.c_str(), 0777);
#else
theBasePath = "";
#endif
}
theBasePath.append(parFile);
return theBasePath;
}
};
}
#endif
Loading…
Cancel
Save