From: <vo...@us...> - 2009-10-29 14:22:40
|
Revision: 1314 http://opde.svn.sourceforge.net/opde/?rev=1314&view=rev Author: volca Date: 2009-10-29 14:22:29 +0000 (Thu, 29 Oct 2009) Log Message: ----------- Some more work on installation - config is now properly searched in the two specified directories. Also adding override for debugging work (needs a commandline switch though) Modified Paths: -------------- trunk/src/main/Root.cpp trunk/src/services/config/ConfigService.cpp trunk/src/services/config/ConfigService.h trunk/src/services/platform/PlatformService.cpp trunk/src/services/platform/PlatformService.h trunk/src/services/platform/UnixPlatform.cpp Modified: trunk/src/main/Root.cpp =================================================================== --- trunk/src/main/Root.cpp 2009-10-29 14:21:14 UTC (rev 1313) +++ trunk/src/main/Root.cpp 2009-10-29 14:22:29 UTC (rev 1314) @@ -52,6 +52,7 @@ #include "DrawService.h" #include "RoomService.h" #include "GUIService.h" +#include "PlatformService.h" // base #include "ManualBinFileLoader.h" @@ -300,6 +301,7 @@ mServiceFactories.push_back(new DrawServiceFactory()); mServiceFactories.push_back(new RoomServiceFactory()); // mServiceFactories.push_back(new GUIServiceFactory()); + mServiceFactories.push_back(new PlatformServiceFactory()); ServiceFactoryList::iterator it = mServiceFactories.begin(); Modified: trunk/src/services/config/ConfigService.cpp =================================================================== --- trunk/src/services/config/ConfigService.cpp 2009-10-29 14:21:14 UTC (rev 1313) +++ trunk/src/services/config/ConfigService.cpp 2009-10-29 14:22:29 UTC (rev 1314) @@ -39,7 +39,8 @@ /*----------------------------------------------------*/ template<> const size_t ServiceImpl<ConfigService>::SID = __SERVICE_ID_CONFIG; - ConfigService::ConfigService(ServiceManager *manager, const std::string& name) : ServiceImpl<ConfigService>(manager, name), mConfigFileName("opde.cfg") { + ConfigService::ConfigService(ServiceManager *manager, const std::string& name) : ServiceImpl<ConfigService>(manager, name), + mConfigPathOverride("") { } //------------------------------------------------------ @@ -48,10 +49,15 @@ //------------------------------------------------------ bool ConfigService::init() { + mPlatformService = GET_SERVICE(PlatformService); return true; } + + //------------------------------------------------------ + void ConfigService::shutdown() { + mPlatformService.setNull(); + } - //------------------------------------------------------ void ConfigService::setParamDescription(const std::string& param, const std::string& desc) { mConfigKeyDescriptions[param] = desc; @@ -111,31 +117,28 @@ //------------------------------------------------------ bool ConfigService::loadParams(const std::string& cfgfile) { - try { // load a few options - Ogre::ConfigFile cf; - cf.load(cfgfile); - - // Get the iterator over values - no section - ConfigFile::SettingsIterator it = cf.getSettingsIterator(); - - - while (it.hasMoreElements()) { - std::string key = it.peekNextKey(); - std::string val = it.peekNextValue(); - - setParam(key, val); - - it.moveNext(); - } - - return true; - } - catch (Ogre::Exception e) { - LOG_ERROR("Config file '%s' was not found", cfgfile.c_str()); - return false; - // Guess the file didn't exist - } + // do we have an override set? + if (mConfigPathOverride != "") { + return loadFromFile(mConfigPathOverride + mPlatformService->getDirectorySeparator() + cfgfile); + } else { + // first the global config is loaded + bool globalok = loadFromFile(mPlatformService->getGlobalConfigPath() + + mPlatformService->getDirectorySeparator() + + cfgfile); + + // then overriden by local one + bool userok = loadFromFile(mPlatformService->getUserConfigPath() \ + + mPlatformService->getDirectorySeparator() + + cfgfile); + + return userok || globalok; + } } + + //------------------------------------------------------ + void ConfigService::setConfigPathOverride(const std::string& cfgpath) { + mConfigPathOverride = cfgpath; + } //------------------------------------------------------ ConfigService::GameType ConfigService::getGameType() { @@ -172,10 +175,50 @@ StringUtil::splitFilename(origPath, fname, path); - return path + getLanguage() + '/' + fname; + return path + getLanguage() + mPlatformService->getDirectorySeparator() + fname; } + //------------------------------------------------------ + void ConfigService::logAllParameters() { + Parameters::const_iterator dit = mConfigKeyDescriptions.begin(); + + LOG_INFO("ConfigService: Configuration parameters:"); + + while (dit != mConfigKeyDescriptions.end()) { + LOG_INFO("ConfigService:\t%s - %s", dit->first.c_str(), dit->second.c_str()); + } + } + //------------------------------------------------------ + bool ConfigService::loadFromFile(const std::string& cfgfile) { + try { // load a few options + LOG_INFO("ConfigService: Loading config file from '%s'", cfgfile.c_str()); + + Ogre::ConfigFile cf; + cf.load(cfgfile); + + // Get the iterator over values - no section + ConfigFile::SettingsIterator it = cf.getSettingsIterator(); + + + while (it.hasMoreElements()) { + std::string key = it.peekNextKey(); + std::string val = it.peekNextValue(); + + setParam(key, val); + + it.moveNext(); + } + + return true; + } + catch (Ogre::Exception e) { + LOG_ERROR("Config file '%s' was not found", cfgfile.c_str()); + return false; + // Guess the file didn't exist + } + } + //-------------------------- Factory implementation std::string ConfigServiceFactory::mName = "ConfigService"; Modified: trunk/src/services/config/ConfigService.h =================================================================== --- trunk/src/services/config/ConfigService.h 2009-10-29 14:21:14 UTC (rev 1313) +++ trunk/src/services/config/ConfigService.h 2009-10-29 14:22:29 UTC (rev 1314) @@ -30,7 +30,7 @@ #include "OpdeServiceManager.h" #include "OpdeService.h" -#include "DatabaseService.h" +#include "PlatformService.h" #include "FileGroup.h" #include "SharedPtr.h" #include "DVariant.h" @@ -71,8 +71,17 @@ /** determine an existence of a parameter */ bool hasParam(const std::string& param); - /** Injects the settings from a specified cfg file */ + /** Injects the settings from a specified cfg file. + * This function uses PlatformService to obtain two possible config file paths. It then loads global followed by local + * version of the config file mentioned. + * @note If ConfigPathOverride is set (via setConfigPathOverride), then that path is solely used to populate the configuration + * @param cfgfile The name of the config file (without path) + * @return true if config was loaded from at least one of the paths, false otherwise */ bool loadParams(const std::string& cfgfile); + + /** Sets an override for the config file loading paths. Used to enable debugging without installation, etc. + */ + void setConfigPathOverride(const std::string& cfgpath); /** returns the set game type. This should normally be the cam.cfg's game dark/game shock, but we also need to differentiate t1/t2 * @note Uses the game_type = t1/t2/ss2 config key */ @@ -80,6 +89,7 @@ /** Language, as parsed from the install.cfg file * @todo Parse the install.cfg - now we read it from opde.cfg + * @return Language name string (to be used with localized resource version reader code) * */ std::string getLanguage(); @@ -91,16 +101,27 @@ */ std::string getLocalisedResourcePath(const std::string& origPath); + /** Helper method that logs all the config parameters with descriptions to LOG */ + void logAllParameters(); + protected: /** initializes the service. Tries to load opde.cfg */ bool init(); + void shutdown(); - std::string mConfigFileName; + /** Loads additional parameters from the specified file name */ + bool loadFromFile(const std::string& cfgfile); + private: typedef std::map< std::string, std::string > Parameters; Parameters mParameters; Parameters mConfigKeyDescriptions; + + PlatformServicePtr mPlatformService; + + /// If set, the hierarchical loading from global+local is not used, this path is used instead + std::string mConfigPathOverride; }; /// Shared pointer to Config service Modified: trunk/src/services/platform/PlatformService.cpp =================================================================== --- trunk/src/services/platform/PlatformService.cpp 2009-10-29 14:21:14 UTC (rev 1313) +++ trunk/src/services/platform/PlatformService.cpp 2009-10-29 14:22:29 UTC (rev 1314) @@ -61,7 +61,24 @@ } //------------------------------------------------------ + std::string PlatformService::getGlobalConfigPath() const { + return mPlatform->getGlobalConfigPath(); + } + + //------------------------------------------------------ + std::string PlatformService::getUserConfigPath() const { + return mPlatform->getUserConfigPath(); + } + + //------------------------------------------------------ + std::string PlatformService::getDirectorySeparator() const { + return mPlatform->getDirectorySeparator(); + } + + //------------------------------------------------------ bool PlatformService::init() { + LOG_INFO("PlatformService: Global config path : '%s'", getGlobalConfigPath().c_str()); + LOG_INFO("PlatformService: User config path : '%s'", getUserConfigPath().c_str()); return true; } Modified: trunk/src/services/platform/PlatformService.h =================================================================== --- trunk/src/services/platform/PlatformService.h 2009-10-29 14:21:14 UTC (rev 1313) +++ trunk/src/services/platform/PlatformService.h 2009-10-29 14:22:29 UTC (rev 1314) @@ -36,13 +36,23 @@ // Forward decl. class Platform; - /** @brief Platform service. Service that gives the engine an abstracted way to work with various OSes and File Systems they introduce. + /** @brief Platform service. Service that gives the engine an abstracted way to work with various OSes and + * File Systems they introduce. Wrapper around Platform class implementation */ class OPDELIB_EXPORT PlatformService : public ServiceImpl<PlatformService> { public: PlatformService(ServiceManager *manager, const std::string& name); virtual ~PlatformService(); + /// @see Platform::getGlobalConfigPath + std::string getGlobalConfigPath() const; + + /// @see Platform::getUserConfigPath + std::string getUserConfigPath() const; + + /// @see Platform::getDirectorySeparator + std::string getDirectorySeparator() const; + protected: bool init(); void bootstrapFinished(); Modified: trunk/src/services/platform/UnixPlatform.cpp =================================================================== --- trunk/src/services/platform/UnixPlatform.cpp 2009-10-29 14:21:14 UTC (rev 1313) +++ trunk/src/services/platform/UnixPlatform.cpp 2009-10-29 14:22:29 UTC (rev 1314) @@ -53,7 +53,7 @@ // respectively the .opde directory inside it std::string home = getenv("HOME"); - return home + getDirectorySeparator() + msOpdeHomeDirName + getDirectorySeparator(); + return home + getDirectorySeparator() + msOpdeHomeDirName; } //------------------------------------------------------ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |