[Orxonox-commit 5849] r10509 - in code/branches/core7/src: libraries/core libraries/core/command libraries/core/commandline libraries/core/config libraries/core/input libraries/tools modules/designtools orxonox/chat
landauf at orxonox.net
landauf at orxonox.net
Sat May 30 12:22:28 CEST 2015
Author: landauf
Date: 2015-05-30 12:22:27 +0200 (Sat, 30 May 2015)
New Revision: 10509
Added:
code/branches/core7/src/libraries/core/ApplicationPaths.cc
code/branches/core7/src/libraries/core/ApplicationPaths.h
code/branches/core7/src/libraries/core/ConfigurablePaths.cc
code/branches/core7/src/libraries/core/ConfigurablePaths.h
Removed:
code/branches/core7/src/libraries/core/PathConfig.cc
code/branches/core7/src/libraries/core/PathConfig.h
Modified:
code/branches/core7/src/libraries/core/CMakeLists.txt
code/branches/core7/src/libraries/core/Core.cc
code/branches/core7/src/libraries/core/Core.h
code/branches/core7/src/libraries/core/CoreConfig.cc
code/branches/core7/src/libraries/core/CorePrereqs.h
code/branches/core7/src/libraries/core/GUIManager.cc
code/branches/core7/src/libraries/core/GraphicsManager.cc
code/branches/core7/src/libraries/core/Language.cc
code/branches/core7/src/libraries/core/command/Shell.cc
code/branches/core7/src/libraries/core/command/TclBind.cc
code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc
code/branches/core7/src/libraries/core/config/ConfigFile.cc
code/branches/core7/src/libraries/core/input/KeyBinder.cc
code/branches/core7/src/libraries/tools/ResourceLocation.cc
code/branches/core7/src/modules/designtools/ScreenshotManager.cc
code/branches/core7/src/modules/designtools/SkyboxGenerator.cc
code/branches/core7/src/orxonox/chat/ChatHistory.cc
code/branches/core7/src/orxonox/chat/ChatHistory.h
Log:
moved static application paths (root, executable, modules) into new class named ApplicationPaths
moved configurable data paths (data, log, config) into new class named ConfigurablePaths
removed PathConfig
Copied: code/branches/core7/src/libraries/core/ApplicationPaths.cc (from rev 10457, code/branches/core7/src/libraries/core/PathConfig.cc)
===================================================================
--- code/branches/core7/src/libraries/core/ApplicationPaths.cc (rev 0)
+++ code/branches/core7/src/libraries/core/ApplicationPaths.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -0,0 +1,216 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "ApplicationPaths.h"
+
+#include <cassert>
+#include <cstdlib>
+#include <cstdio>
+#include <vector>
+#include <boost/filesystem.hpp>
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# undef min
+# undef max
+#elif defined(ORXONOX_PLATFORM_APPLE)
+# include <sys/param.h>
+# include <mach-o/dyld.h>
+#else /* Linux */
+# include <sys/types.h>
+# include <unistd.h>
+#endif
+
+#include "SpecialConfig.h"
+#include "util/Output.h"
+#include "util/Exception.h"
+
+// Differentiate Boost Filesystem v2 and v3
+#if (BOOST_FILESYSTEM_VERSION < 3)
+# define BF_LEAF leaf
+# define BF_GENERIC_STRING string
+#else
+# define BF_LEAF path().filename().string
+# define BF_GENERIC_STRING generic_string
+#endif
+
+namespace orxonox
+{
+ namespace bf = boost::filesystem;
+
+ //! Static pointer to the singleton
+ ApplicationPaths* ApplicationPaths::singletonPtr_s = 0;
+
+ ApplicationPaths::ApplicationPaths()
+ : rootPath_(*(new bf::path()))
+ , executablePath_(*(new bf::path()))
+ , modulePath_(*(new bf::path()))
+ , bBuildDirectoryRun_(false)
+ {
+ //////////////////////////
+ // FIND EXECUTABLE PATH //
+ //////////////////////////
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+ // get executable module
+ TCHAR buffer[1024];
+ if (GetModuleFileName(NULL, buffer, 1024) == 0)
+ ThrowException(General, "Could not retrieve executable path.");
+
+#elif defined(ORXONOX_PLATFORM_APPLE)
+ char buffer[1024];
+ uint32_t path_len = 1023;
+ if (_NSGetExecutablePath(buffer, &path_len))
+ ThrowException(General, "Could not retrieve executable path.");
+
+#else /* Linux */
+ /* written by Nicolai Haehnle <prefect_ at gmx.net> */
+
+ /* Get our PID and build the name of the link in /proc */
+ char linkname[64]; /* /proc/<pid>/exe */
+ if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
+ {
+ /* This should only happen on large word systems. I'm not sure
+ what the proper response is here.
+ Since it really is an assert-like condition, aborting the
+ program seems to be in order. */
+ assert(false);
+ }
+
+ /* Now read the symbolic link */
+ char buffer[1024];
+ int ret;
+ ret = readlink(linkname, buffer, 1024);
+ /* In case of an error, leave the handling up to the caller */
+ if (ret == -1)
+ ThrowException(General, "Could not retrieve executable path.");
+
+ /* Ensure proper NUL termination */
+ buffer[ret] = 0;
+#endif
+
+ // Remove executable filename
+ executablePath_ = bf::path(buffer).branch_path();
+
+ /////////////////////
+ // SET MODULE PATH //
+ /////////////////////
+
+ if (bf::exists(executablePath_ / "orxonox_dev_build.keep_me"))
+ {
+ orxout(internal_info) << "Running from the build tree." << endl;
+ ApplicationPaths::bBuildDirectoryRun_ = true;
+ modulePath_ = specialConfig::moduleDevDirectory;
+ }
+ else
+ {
+
+#ifdef INSTALL_COPYABLE // --> relative paths
+
+ // Also set the root path
+ bf::path relativeExecutablePath(specialConfig::defaultRuntimePath);
+ rootPath_ = executablePath_;
+ while (!bf::equivalent(rootPath_ / relativeExecutablePath, executablePath_) && !rootPath_.empty())
+ rootPath_ = rootPath_.branch_path();
+ if (rootPath_.empty())
+ ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
+
+ // Module path is fixed as well
+ modulePath_ = rootPath_ / specialConfig::defaultModulePath;
+
+#else
+
+ // There is no root path, so don't set it at all
+ // Module path is fixed as well
+ modulePath_ = specialConfig::moduleInstallDirectory;
+
+#endif
+ }
+ }
+
+ ApplicationPaths::~ApplicationPaths()
+ {
+ delete &rootPath_;
+ delete &executablePath_;
+ delete &modulePath_;
+ }
+
+ std::vector<std::string> ApplicationPaths::getModulePaths()
+ {
+ std::vector<std::string> modulePaths;
+
+ // We search for helper files with the following extension
+ const std::string& moduleextension = specialConfig::moduleExtension;
+ size_t moduleextensionlength = moduleextension.size();
+
+ // Make sure the path exists, otherwise don't load modules
+ if (!boost::filesystem::exists(modulePath_))
+ return modulePaths;
+
+ boost::filesystem::directory_iterator file(modulePath_);
+ boost::filesystem::directory_iterator end;
+
+ // Iterate through all files
+ while (file != end)
+ {
+ std::string filename = file->BF_LEAF();
+
+ // Check if the file ends with the extension in question
+ if (filename.size() > moduleextensionlength)
+ {
+ if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
+ {
+ // We've found a helper file
+ const std::string& library = filename.substr(0, filename.size() - moduleextensionlength);
+ modulePaths.push_back(getModulePathString() + library);
+ }
+ }
+ ++file;
+ }
+
+ return modulePaths;
+ }
+
+ /*static*/ std::string ApplicationPaths::getRootPathString()
+ {
+ return getInstance().rootPath_.BF_GENERIC_STRING() + '/';
+ }
+
+ /*static*/ std::string ApplicationPaths::getExecutablePathString()
+ {
+ return getInstance().executablePath_.BF_GENERIC_STRING() + '/';
+ }
+
+ /*static*/ std::string ApplicationPaths::getModulePathString()
+ {
+ return getInstance().modulePath_.BF_GENERIC_STRING() + '/';
+ }
+}
Copied: code/branches/core7/src/libraries/core/ApplicationPaths.h (from rev 10457, code/branches/core7/src/libraries/core/PathConfig.h)
===================================================================
--- code/branches/core7/src/libraries/core/ApplicationPaths.h (rev 0)
+++ code/branches/core7/src/libraries/core/ApplicationPaths.h 2015-05-30 10:22:27 UTC (rev 10509)
@@ -0,0 +1,111 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Management Resources
+*/
+
+#ifndef _ApplicationPaths_H__
+#define _ApplicationPaths_H__
+
+#include "CorePrereqs.h"
+
+#include <string>
+#include <vector>
+#include "util/Singleton.h"
+
+//tolua_begin
+namespace orxonox
+{
+//tolua_end
+ /**
+ @brief
+ The ApplicationPaths class is a singleton which provides static paths of the application.
+ @details
+ The class provides information about the executable, root and module path.
+ It determines those by the use of platform specific functions.
+ @remarks
+ Not all paths are always available:
+ - root only when installed copyable
+ */
+ class _CoreExport ApplicationPaths //tolua_export
+ : public Singleton<ApplicationPaths>
+ { //tolua_export
+ friend class Singleton<ApplicationPaths>;
+
+ public:
+ /**
+ @brief
+ Retrieves the executable path and sets all hard coded fixed paths (currently only the module path)
+ Also checks for "orxonox_dev_build.keep_me" in the executable directory.
+ If found it means that this is not an installed run, hence we
+ don't write the logs and config files to ~/.orxonox
+ @throw
+ GeneralException
+ */
+ ApplicationPaths();
+ ~ApplicationPaths();
+
+ //! Returns the path to the root folder as boost::filesystem::path
+ static const boost::filesystem::path& getRootPath()
+ { return getInstance().rootPath_; }
+ //! Returns the path to the executable folder as boost::filesystem::path
+ static const boost::filesystem::path& getExecutablePath()
+ { return getInstance().executablePath_; }
+ //! Returns the path to the modules as boost::filesystem::path
+ static const boost::filesystem::path& getModulePath()
+ { return getInstance().modulePath_; }
+
+ //! Returns the path to the root folder as std::string
+ static std::string getRootPathString();
+ //! Returns the path to the executable folder as std::string
+ static std::string getExecutablePathString();
+ //! Returns the path to the modules as std::string
+ static std::string getModulePathString();
+
+ //! Return true for runs in the build directory (not installed)
+ static bool buildDirectoryRun() { return getInstance().bBuildDirectoryRun_; }
+
+ //! Returns a list with all modules declared by a *.module file in the module folder.
+ std::vector<std::string> getModulePaths();
+
+ private:
+ ApplicationPaths(const ApplicationPaths&); //!< Don't use (undefined symbol)
+
+ //! Path to the parent directory of the ones above if program was installed with relative paths
+ boost::filesystem::path& rootPath_;
+ boost::filesystem::path& executablePath_; //!< Path to the executable
+ boost::filesystem::path& modulePath_; //!< Path to the modules
+
+ bool bBuildDirectoryRun_; //!< True for runs in the build directory (not installed)
+ static ApplicationPaths* singletonPtr_s;
+ }; //tolua_export
+} //tolua_export
+
+#endif /* _ApplicationPaths_H__ */
Modified: code/branches/core7/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/core7/src/libraries/core/CMakeLists.txt 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/CMakeLists.txt 2015-05-30 10:22:27 UTC (rev 10509)
@@ -54,7 +54,8 @@
BUILD_UNIT FilesystemBuildUnit.cc
command/ArgumentCompletionFunctions.cc
config/ConfigFile.cc
- PathConfig.cc
+ ApplicationPaths.cc
+ Configurablepaths.cc
END_BUILD_UNIT
BUILD_UNIT ThreadBuildUnit.cc
@@ -83,13 +84,14 @@
TOLUA_FILES
command/CommandExecutor.h
config/SettingsConfigFile.h
+ ApplicationPaths.h
+ ConfigurablePaths.h
Game.h
GameMode.h
GraphicsManager.h
GUIManager.h
Loader.h
LuaState.h
- PathConfig.h
input/InputManager.h
input/KeyBinder.h
input/KeyBinderManager.h
Copied: code/branches/core7/src/libraries/core/ConfigurablePaths.cc (from rev 10457, code/branches/core7/src/libraries/core/PathConfig.cc)
===================================================================
--- code/branches/core7/src/libraries/core/ConfigurablePaths.cc (rev 0)
+++ code/branches/core7/src/libraries/core/ConfigurablePaths.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -0,0 +1,183 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "ConfigurablePaths.h"
+
+#include <cassert>
+#include <cstdlib>
+#include <cstdio>
+#include <vector>
+#include <boost/filesystem.hpp>
+
+#ifdef ORXONOX_PLATFORM_WINDOWS
+# ifndef WIN32_LEAN_AND_MEAN
+# define WIN32_LEAN_AND_MEAN
+# endif
+# include <windows.h>
+# undef min
+# undef max
+#elif defined(ORXONOX_PLATFORM_APPLE)
+# include <sys/param.h>
+# include <mach-o/dyld.h>
+#else /* Linux */
+# include <sys/types.h>
+# include <unistd.h>
+#endif
+
+#include "SpecialConfig.h"
+#include "util/Output.h"
+#include "util/Exception.h"
+#include "commandline/CommandLineIncludes.h"
+
+// Differentiate Boost Filesystem v2 and v3
+#if (BOOST_FILESYSTEM_VERSION < 3)
+# define BF_GENERIC_STRING string
+#else
+# define BF_GENERIC_STRING generic_string
+#endif
+
+namespace orxonox
+{
+ namespace bf = boost::filesystem;
+
+ //! Static pointer to the singleton
+ ConfigurablePaths* ConfigurablePaths::singletonPtr_s = 0;
+
+ SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
+ SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
+
+ ConfigurablePaths::ConfigurablePaths()
+ : dataPath_(*(new bf::path()))
+ , externalDataPath_(*(new bf::path()))
+ , configPath_(*(new bf::path()))
+ , logPath_(*(new bf::path()))
+ {
+ }
+
+ ConfigurablePaths::~ConfigurablePaths()
+ {
+ delete &dataPath_;
+ delete &externalDataPath_;
+ delete &configPath_;
+ delete &logPath_;
+ }
+
+ void ConfigurablePaths::setConfigurablePaths(const ApplicationPaths& applicationPaths)
+ {
+ if (applicationPaths.buildDirectoryRun())
+ {
+ dataPath_ = specialConfig::dataDevDirectory;
+ configPath_ = specialConfig::configDevDirectory;
+ logPath_ = specialConfig::logDevDirectory;
+
+ // Check for data path override by the command line
+ if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue())
+ externalDataPath_ = CommandLineParser::getValue("externalDataPath").get<std::string>();
+ else
+ externalDataPath_ = specialConfig::externalDataDevDirectory;
+ }
+ else
+ {
+
+#ifdef INSTALL_COPYABLE // --> relative paths
+
+ // Using paths relative to the install prefix, complete them
+ dataPath_ = applicationPaths.getRootPath() / specialConfig::defaultDataPath;
+ configPath_ = applicationPaths.getRootPath() / specialConfig::defaultConfigPath;
+ logPath_ = applicationPaths.getRootPath() / specialConfig::defaultLogPath;
+
+#else
+
+ dataPath_ = specialConfig::dataInstallDirectory;
+
+ // Get user directory
+#ifdef ORXONOX_PLATFORM_UNIX
+ char* userDataPathPtr(getenv("HOME"));
+#else
+ char* userDataPathPtr(getenv("APPDATA"));
+#endif
+ if (userDataPathPtr == NULL)
+ ThrowException(General, "Could not retrieve user data path.");
+ bf::path userDataPath(userDataPathPtr);
+ userDataPath /= ".orxonox";
+
+ configPath_ = userDataPath / specialConfig::defaultConfigPath;
+ logPath_ = userDataPath / specialConfig::defaultLogPath;
+
+#endif
+
+ }
+
+ // Option to put all the config and log files in a separate folder
+ if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue())
+ {
+ const std::string& directory(CommandLineParser::getValue("writingPathSuffix").get<std::string>());
+ configPath_ = configPath_ / directory;
+ logPath_ = logPath_ / directory;
+ }
+
+ // Create directories to avoid problems when opening files in non existent folders.
+ std::vector<std::pair<bf::path, std::string> > directories;
+ directories.push_back(std::make_pair(bf::path(configPath_), std::string("config")));
+ directories.push_back(std::make_pair(bf::path(logPath_), std::string("log")));
+
+ for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin();
+ it != directories.end(); ++it)
+ {
+ if (bf::exists(it->first) && !bf::is_directory(it->first))
+ {
+ ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
+ Please remove " + it->first.BF_GENERIC_STRING());
+ }
+ if (bf::create_directories(it->first)) // function may not return true at all (bug?)
+ {
+ orxout(internal_info) << "Created " << it->second << " directory" << endl;
+ }
+ }
+ }
+
+ /*static*/ std::string ConfigurablePaths::getDataPathString()
+ {
+ return getInstance().dataPath_.BF_GENERIC_STRING() + '/';
+ }
+
+ /*static*/ std::string ConfigurablePaths::getExternalDataPathString()
+ {
+ return getInstance().externalDataPath_.BF_GENERIC_STRING() + '/';
+ }
+
+ /*static*/ std::string ConfigurablePaths::getConfigPathString()
+ {
+ return getInstance().configPath_.BF_GENERIC_STRING() + '/';
+ }
+
+ /*static*/ std::string ConfigurablePaths::getLogPathString()
+ {
+ return getInstance().logPath_.BF_GENERIC_STRING() + '/';
+ }
+}
Copied: code/branches/core7/src/libraries/core/ConfigurablePaths.h (from rev 10457, code/branches/core7/src/libraries/core/PathConfig.h)
===================================================================
--- code/branches/core7/src/libraries/core/ConfigurablePaths.h (rev 0)
+++ code/branches/core7/src/libraries/core/ConfigurablePaths.h 2015-05-30 10:22:27 UTC (rev 10509)
@@ -0,0 +1,106 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+/**
+ @file
+ @ingroup Management Resources
+*/
+
+#ifndef _ConfigurablePaths_H__
+#define _ConfigurablePaths_H__
+
+#include "CorePrereqs.h"
+
+#include <string>
+#include "util/Singleton.h"
+
+//tolua_begin
+namespace orxonox
+{
+//tolua_end
+ /**
+ @brief
+ The ConfigurablePaths class is a singleton used to configure different paths.
+ @details
+ The class provides information about the data, config, and log path.
+ @remarks
+ Not all paths are always available:
+ - externalData only for development builds in the build tree
+ */
+ class _CoreExport ConfigurablePaths //tolua_export
+ : public Singleton<ConfigurablePaths>
+ { //tolua_export
+ friend class Singleton<ConfigurablePaths>;
+
+ public:
+ ConfigurablePaths();
+ ~ConfigurablePaths();
+
+ //! Returns the path to the data files as boost::filesystem::path
+ static const boost::filesystem::path& getDataPath()
+ { return getInstance().dataPath_; }
+ //! Returns the path to the external data files as boost::filesystem::path
+ static const boost::filesystem::path& getExternalDataPath()
+ { return getInstance().externalDataPath_; }
+ //! Returns the path to the config files as boost::filesystem::path
+ static const boost::filesystem::path& getConfigPath()
+ { return getInstance().configPath_; }
+ //! Returns the path to the log files as boost::filesystem::path
+ static const boost::filesystem::path& getLogPath()
+ { return getInstance().logPath_; }
+
+ //! Returns the path to the data files as std::string
+ static std::string getDataPathString();
+ //! Returns the path to the external data files as std::string
+ static std::string getExternalDataPathString();
+ //! Returns the path to the config files as std::string
+ static std::string getConfigPathString(); //tolua_export
+ //! Returns the path to the log files as std::string
+ static std::string getLogPathString();
+
+ /**
+ @brief
+ Sets config, log and media path and creates the folders if necessary.
+ @throws
+ GeneralException
+ */
+ void setConfigurablePaths(const ApplicationPaths& applicationPaths);
+
+ private:
+ ConfigurablePaths(const ConfigurablePaths&); //!< Don't use (undefined symbol)
+
+ boost::filesystem::path& dataPath_; //!< Path to the data files folder
+ boost::filesystem::path& externalDataPath_; //!< Path to the external data files folder
+ boost::filesystem::path& configPath_; //!< Path to the config files folder
+ boost::filesystem::path& logPath_; //!< Path to the log files folder
+
+ static ConfigurablePaths* singletonPtr_s;
+ }; //tolua_export
+} //tolua_export
+
+#endif /* _ConfigurablePaths_H__ */
Modified: code/branches/core7/src/libraries/core/Core.cc
===================================================================
--- code/branches/core7/src/libraries/core/Core.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/Core.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -58,7 +58,8 @@
#include "core/singleton/Scope.h"
#include "core/singleton/ScopedSingletonIncludes.h"
#include "util/SignalHandler.h"
-#include "PathConfig.h"
+#include "ApplicationPaths.h"
+#include "ConfigurablePaths.h"
#include "commandline/CommandLineIncludes.h"
#include "config/ConfigFileManager.h"
#include "DynLibManager.h"
@@ -93,7 +94,8 @@
#endif
Core::Core(const std::string& cmdLine)
- : pathConfig_(NULL)
+ : applicationPaths_(NULL)
+ , configurablePaths_(NULL)
, dynLibManager_(NULL)
, signalHandler_(NULL)
, configFileManager_(NULL)
@@ -114,14 +116,14 @@
orxout(internal_status) << "initializing Core object..." << endl;
// Set the hard coded fixed paths
- this->pathConfig_ = new PathConfig();
+ this->applicationPaths_ = new ApplicationPaths();
// Create a new dynamic library manager
this->dynLibManager_ = new DynLibManager();
// Load modules
orxout(internal_info) << "Loading modules:" << endl;
- const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths();
+ const std::vector<std::string>& modulePaths = ApplicationPaths::getInstance().getModulePaths();
for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it)
{
try
@@ -145,20 +147,22 @@
CommandLineParser::parse(cmdLine);
// Set configurable paths like log, config and media
- this->pathConfig_->setConfigurablePaths();
+ this->configurablePaths_ = new ConfigurablePaths();
+ this->configurablePaths_->setConfigurablePaths(ApplicationPaths::getInstance());
- orxout(internal_info) << "Root path: " << PathConfig::getRootPathString() << endl;
- orxout(internal_info) << "Executable path: " << PathConfig::getExecutablePathString() << endl;
- orxout(internal_info) << "Data path: " << PathConfig::getDataPathString() << endl;
- orxout(internal_info) << "Ext. data path: " << PathConfig::getExternalDataPathString() << endl;
- orxout(internal_info) << "Config path: " << PathConfig::getConfigPathString() << endl;
- orxout(internal_info) << "Log path: " << PathConfig::getLogPathString() << endl;
- orxout(internal_info) << "Modules path: " << PathConfig::getModulePathString() << endl;
+ orxout(internal_info) << "Root path: " << ApplicationPaths::getRootPathString() << endl;
+ orxout(internal_info) << "Executable path: " << ApplicationPaths::getExecutablePathString() << endl;
+ orxout(internal_info) << "Modules path: " << ApplicationPaths::getModulePathString() << endl;
- // create a signal handler (only active for Linux)
+ orxout(internal_info) << "Data path: " << ConfigurablePaths::getDataPathString() << endl;
+ orxout(internal_info) << "Ext. data path: " << ConfigurablePaths::getExternalDataPathString() << endl;
+ orxout(internal_info) << "Config path: " << ConfigurablePaths::getConfigPathString() << endl;
+ orxout(internal_info) << "Log path: " << ConfigurablePaths::getLogPathString() << endl;
+
+ // create a signal handler
// This call is placed as soon as possible, but after the directories are set
this->signalHandler_ = new SignalHandler();
- this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log");
+ this->signalHandler_->doCatch(ApplicationPaths::getExecutablePathString(), ConfigurablePaths::getLogPathString() + "orxonox_crash.log");
#ifdef ORXONOX_PLATFORM_WINDOWS
// limit the main thread to the first core so that QueryPerformanceCounter doesn't jump
@@ -185,7 +189,7 @@
this->config_ = new CoreConfig();
// Set the correct log path and rewrite the log file with the correct log levels
- OutputManager::getInstance().getLogWriter()->setLogDirectory(PathConfig::getLogPathString());
+ OutputManager::getInstance().getLogWriter()->setLogDirectory(ConfigurablePaths::getLogPathString());
#if !defined(ORXONOX_PLATFORM_APPLE) && !defined(ORXONOX_USE_WINMAIN)
// Create persistent IO console
@@ -208,7 +212,7 @@
this->graphicsManager_ = new GraphicsManager(false);
// initialise Tcl
- this->tclBind_ = new TclBind(PathConfig::getDataPathString());
+ this->tclBind_ = new TclBind(ConfigurablePaths::getDataPathString());
this->tclThreadManager_ = new TclThreadManager(tclBind_->getTclInterpreter());
// Create singletons that always exist (in other libraries)
@@ -254,7 +258,8 @@
IdentifierManager::getInstance().destroyAllIdentifiers();
safeObjectDelete(&signalHandler_);
safeObjectDelete(&dynLibManager_);
- safeObjectDelete(&pathConfig_);
+ safeObjectDelete(&configurablePaths_);
+ safeObjectDelete(&applicationPaths_);
orxout(internal_status) << "finished destroying Core object" << endl;
}
Modified: code/branches/core7/src/libraries/core/Core.h
===================================================================
--- code/branches/core7/src/libraries/core/Core.h 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/Core.h 2015-05-30 10:22:27 UTC (rev 10509)
@@ -90,7 +90,8 @@
void setThreadAffinity(int limitToCPU);
- PathConfig* pathConfig_;
+ ApplicationPaths* applicationPaths_;
+ ConfigurablePaths* configurablePaths_;
DynLibManager* dynLibManager_;
SignalHandler* signalHandler_;
ConfigFileManager* configFileManager_;
Modified: code/branches/core7/src/libraries/core/CoreConfig.cc
===================================================================
--- code/branches/core7/src/libraries/core/CoreConfig.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/CoreConfig.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -33,7 +33,7 @@
#include "core/CoreIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/Language.h"
-#include "core/PathConfig.h"
+#include "core/ApplicationPaths.h"
namespace orxonox
{
@@ -71,7 +71,7 @@
.description("Additional output contexts shown in the log file")
.callback(static_cast<BaseWriter*>(OutputManager::getInstance().getLogWriter()), &BaseWriter::changedConfigurableAdditionalContexts);
- SetConfigValue(bDevMode_, PathConfig::buildDirectoryRun())
+ SetConfigValue(bDevMode_, ApplicationPaths::buildDirectoryRun())
.description("Developer mode. If not set, hides some things from the user to not confuse him.")
.callback(this, &CoreConfig::devModeChanged);
SetConfigValue(language_, Language::getInstance().defaultLanguage_)
Modified: code/branches/core7/src/libraries/core/CorePrereqs.h
===================================================================
--- code/branches/core7/src/libraries/core/CorePrereqs.h 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/CorePrereqs.h 2015-05-30 10:22:27 UTC (rev 10509)
@@ -131,6 +131,7 @@
template <class T, class U>
T orxonox_cast(U*);
+ class ApplicationPaths;
class BaseObject;
template <class T>
class ClassFactory;
@@ -151,6 +152,7 @@
class ConfigFileManager;
class ConfigFileSection;
class Configurable;
+ class ConfigurablePaths;
class ConfigValueContainer;
class Context;
class Core;
@@ -195,7 +197,6 @@
class OgreWindowEventListener;
class OrxonoxClass;
class OrxonoxInterface;
- class PathConfig;
struct ResourceInfo;
template <ScopeID::Value>
class Scope;
Modified: code/branches/core7/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/GUIManager.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/GUIManager.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -105,7 +105,7 @@
#include "Game.h"
#include "GraphicsManager.h"
#include "LuaState.h"
-#include "PathConfig.h"
+#include "ConfigurablePaths.h"
#include "Resource.h"
#include "command/ConsoleCommandIncludes.h"
#include "input/InputManager.h"
@@ -330,7 +330,7 @@
// Create our own logger to specify the filepath
std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger());
- ceguiLogger->setLogFilename(PathConfig::getLogPathString() + "cegui.log");
+ ceguiLogger->setLogFilename(ConfigurablePaths::getLogPathString() + "cegui.log");
ceguiLogger->setLoggingLevel(static_cast<CEGUI::LoggingLevel>(this->outputLevelCeguiLog_));
this->ceguiLogger_ = ceguiLogger.release();
Modified: code/branches/core7/src/libraries/core/GraphicsManager.cc
===================================================================
--- code/branches/core7/src/libraries/core/GraphicsManager.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/GraphicsManager.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -58,7 +58,8 @@
#include "GameMode.h"
#include "GUIManager.h"
#include "Loader.h"
-#include "PathConfig.h"
+#include "ApplicationPaths.h"
+#include "ConfigurablePaths.h"
#include "ViewportEventListener.h"
#include "WindowEventListener.h"
#include "XMLFile.h"
@@ -112,15 +113,15 @@
this->loadOgreRoot();
// At first, add the root paths of the data directories as resource locations
- Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem");
+ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(ConfigurablePaths::getDataPathString(), "FileSystem");
// Load resources
resources_.reset(new XMLFile("DefaultResources.oxr"));
resources_->setLuaSupport(false);
Loader::getInstance().load(resources_.get(), ClassTreeMask(), false);
// Only for runs in the build directory (not installed)
- if (PathConfig::buildDirectoryRun())
- Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem");
+ if (ApplicationPaths::buildDirectoryRun())
+ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(ConfigurablePaths::getExternalDataPathString(), "FileSystem");
extResources_.reset(new XMLFile("resources.oxr"));
extResources_->setLuaSupport(false);
@@ -219,8 +220,8 @@
ModifyConfigValue(ogreLogFile_, tset, "ogre.log");
}
- boost::filesystem::path ogreConfigFilepath(PathConfig::getConfigPath() / this->ogreConfigFile_);
- boost::filesystem::path ogreLogFilepath(PathConfig::getLogPath() / this->ogreLogFile_);
+ boost::filesystem::path ogreConfigFilepath(ConfigurablePaths::getConfigPath() / this->ogreConfigFile_);
+ boost::filesystem::path ogreLogFilepath(ConfigurablePaths::getLogPath() / this->ogreLogFile_);
// create a new logManager
// Ogre::Root will detect that we've already created a Log
@@ -259,13 +260,13 @@
// Plugin path can have many different locations...
std::string pluginPath = specialConfig::ogrePluginsDirectory;
#ifdef DEPENDENCY_PACKAGE_ENABLE
- if (!PathConfig::buildDirectoryRun())
+ if (!ApplicationPaths::buildDirectoryRun())
{
# if defined(ORXONOX_PLATFORM_WINDOWS)
- pluginPath = PathConfig::getExecutablePathString();
+ pluginPath = ApplicationPaths::getExecutablePathString();
# elif defined(ORXONOX_PLATFORM_APPLE)
// TODO: Where are the plugins being installed to?
- pluginPath = PathConfig::getExecutablePathString();
+ pluginPath = ApplicationPaths::getExecutablePathString();
# endif
}
#endif
@@ -558,6 +559,6 @@
void GraphicsManager::printScreen()
{
assert(this->renderWindow_);
- this->renderWindow_->writeContentsToTimestampedFile(PathConfig::getLogPathString() + "screenShot_", ".png");
+ this->renderWindow_->writeContentsToTimestampedFile(ConfigurablePaths::getLogPathString() + "screenShot_", ".png");
}
}
Modified: code/branches/core7/src/libraries/core/Language.cc
===================================================================
--- code/branches/core7/src/libraries/core/Language.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/Language.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -36,7 +36,7 @@
#include <fstream>
#include "util/Output.h"
#include "util/StringUtils.h"
-#include "PathConfig.h"
+#include "ConfigurablePaths.h"
namespace orxonox
{
@@ -201,7 +201,7 @@
{
orxout(internal_info, context::language) << "Read default language file." << endl;
- const std::string& filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_);
+ const std::string& filepath = ConfigurablePaths::getConfigPathString() + getFilename(this->defaultLanguage_);
// This creates the file if it's not existing
std::ofstream createFile;
@@ -251,7 +251,7 @@
{
orxout(internal_info, context::language) << "Read translated language file (" << language << ")." << endl;
- const std::string& filepath = PathConfig::getConfigPathString() + getFilename(language);
+ const std::string& filepath = ConfigurablePaths::getConfigPathString() + getFilename(language);
// Open the file
std::ifstream file;
@@ -304,7 +304,7 @@
{
orxout(verbose, context::language) << "Write default language file." << endl;
- const std::string& filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_);
+ const std::string& filepath = ConfigurablePaths::getConfigPathString() + getFilename(this->defaultLanguage_);
// Open the file
std::ofstream file;
Deleted: code/branches/core7/src/libraries/core/PathConfig.cc
===================================================================
--- code/branches/core7/src/libraries/core/PathConfig.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/PathConfig.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -1,324 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-#include "PathConfig.h"
-
-#include <cassert>
-#include <cstdlib>
-#include <cstdio>
-#include <vector>
-#include <boost/filesystem.hpp>
-
-#ifdef ORXONOX_PLATFORM_WINDOWS
-# ifndef WIN32_LEAN_AND_MEAN
-# define WIN32_LEAN_AND_MEAN
-# endif
-# include <windows.h>
-# undef min
-# undef max
-#elif defined(ORXONOX_PLATFORM_APPLE)
-# include <sys/param.h>
-# include <mach-o/dyld.h>
-#else /* Linux */
-# include <sys/types.h>
-# include <unistd.h>
-#endif
-
-#include "SpecialConfig.h"
-#include "util/Output.h"
-#include "util/Exception.h"
-#include "commandline/CommandLineIncludes.h"
-
-// Differentiate Boost Filesystem v2 and v3
-#if (BOOST_FILESYSTEM_VERSION < 3)
-# define BF_LEAF leaf
-# define BF_GENERIC_STRING string
-# define BF_NATIVE_STRING file_string
-#else
-# define BF_LEAF path().filename().string
-# define BF_GENERIC_STRING generic_string
-# define BF_NATIVE_STRING string
-#endif
-
-namespace orxonox
-{
- namespace bf = boost::filesystem;
-
- //! Static pointer to the singleton
- PathConfig* PathConfig::singletonPtr_s = 0;
-
- SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");
- SetCommandLineArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");
-
- PathConfig::PathConfig()
- : rootPath_(*(new bf::path()))
- , executablePath_(*(new bf::path()))
- , modulePath_(*(new bf::path()))
- , dataPath_(*(new bf::path()))
- , externalDataPath_(*(new bf::path()))
- , configPath_(*(new bf::path()))
- , logPath_(*(new bf::path()))
- , bBuildDirectoryRun_(false)
- {
- //////////////////////////
- // FIND EXECUTABLE PATH //
- //////////////////////////
-
-#ifdef ORXONOX_PLATFORM_WINDOWS
- // get executable module
- TCHAR buffer[1024];
- if (GetModuleFileName(NULL, buffer, 1024) == 0)
- ThrowException(General, "Could not retrieve executable path.");
-
-#elif defined(ORXONOX_PLATFORM_APPLE)
- char buffer[1024];
- uint32_t path_len = 1023;
- if (_NSGetExecutablePath(buffer, &path_len))
- ThrowException(General, "Could not retrieve executable path.");
-
-#else /* Linux */
- /* written by Nicolai Haehnle <prefect_ at gmx.net> */
-
- /* Get our PID and build the name of the link in /proc */
- char linkname[64]; /* /proc/<pid>/exe */
- if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)
- {
- /* This should only happen on large word systems. I'm not sure
- what the proper response is here.
- Since it really is an assert-like condition, aborting the
- program seems to be in order. */
- assert(false);
- }
-
- /* Now read the symbolic link */
- char buffer[1024];
- int ret;
- ret = readlink(linkname, buffer, 1024);
- /* In case of an error, leave the handling up to the caller */
- if (ret == -1)
- ThrowException(General, "Could not retrieve executable path.");
-
- /* Ensure proper NUL termination */
- buffer[ret] = 0;
-#endif
-
- // Remove executable filename
- executablePath_ = bf::path(buffer).branch_path();
-
- /////////////////////
- // SET MODULE PATH //
- /////////////////////
-
- if (bf::exists(executablePath_ / "orxonox_dev_build.keep_me"))
- {
- orxout(internal_info) << "Running from the build tree." << endl;
- PathConfig::bBuildDirectoryRun_ = true;
- modulePath_ = specialConfig::moduleDevDirectory;
- }
- else
- {
-
-#ifdef INSTALL_COPYABLE // --> relative paths
-
- // Also set the root path
- bf::path relativeExecutablePath(specialConfig::defaultRuntimePath);
- rootPath_ = executablePath_;
- while (!bf::equivalent(rootPath_ / relativeExecutablePath, executablePath_) && !rootPath_.empty())
- rootPath_ = rootPath_.branch_path();
- if (rootPath_.empty())
- ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");
-
- // Module path is fixed as well
- modulePath_ = rootPath_ / specialConfig::defaultModulePath;
-
-#else
-
- // There is no root path, so don't set it at all
- // Module path is fixed as well
- modulePath_ = specialConfig::moduleInstallDirectory;
-
-#endif
- }
- }
-
- PathConfig::~PathConfig()
- {
- delete &rootPath_;
- delete &executablePath_;
- delete &modulePath_;
- delete &dataPath_;
- delete &externalDataPath_;
- delete &configPath_;
- delete &logPath_;
- }
-
- void PathConfig::setConfigurablePaths()
- {
- if (bBuildDirectoryRun_)
- {
- dataPath_ = specialConfig::dataDevDirectory;
- configPath_ = specialConfig::configDevDirectory;
- logPath_ = specialConfig::logDevDirectory;
-
- // Check for data path override by the command line
- if (!CommandLineParser::getArgument("externalDataPath")->hasDefaultValue())
- externalDataPath_ = CommandLineParser::getValue("externalDataPath").get<std::string>();
- else
- externalDataPath_ = specialConfig::externalDataDevDirectory;
- }
- else
- {
-
-#ifdef INSTALL_COPYABLE // --> relative paths
-
- // Using paths relative to the install prefix, complete them
- dataPath_ = rootPath_ / specialConfig::defaultDataPath;
- configPath_ = rootPath_ / specialConfig::defaultConfigPath;
- logPath_ = rootPath_ / specialConfig::defaultLogPath;
-
-#else
-
- dataPath_ = specialConfig::dataInstallDirectory;
-
- // Get user directory
-#ifdef ORXONOX_PLATFORM_UNIX
- char* userDataPathPtr(getenv("HOME"));
-#else
- char* userDataPathPtr(getenv("APPDATA"));
-#endif
- if (userDataPathPtr == NULL)
- ThrowException(General, "Could not retrieve user data path.");
- bf::path userDataPath(userDataPathPtr);
- userDataPath /= ".orxonox";
-
- configPath_ = userDataPath / specialConfig::defaultConfigPath;
- logPath_ = userDataPath / specialConfig::defaultLogPath;
-
-#endif
-
- }
-
- // Option to put all the config and log files in a separate folder
- if (!CommandLineParser::getArgument("writingPathSuffix")->hasDefaultValue())
- {
- const std::string& directory(CommandLineParser::getValue("writingPathSuffix").get<std::string>());
- configPath_ = configPath_ / directory;
- logPath_ = logPath_ / directory;
- }
-
- // Create directories to avoid problems when opening files in non existent folders.
- std::vector<std::pair<bf::path, std::string> > directories;
- directories.push_back(std::make_pair(bf::path(configPath_), std::string("config")));
- directories.push_back(std::make_pair(bf::path(logPath_), std::string("log")));
-
- for (std::vector<std::pair<bf::path, std::string> >::iterator it = directories.begin();
- it != directories.end(); ++it)
- {
- if (bf::exists(it->first) && !bf::is_directory(it->first))
- {
- ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \
- Please remove " + it->first.BF_GENERIC_STRING());
- }
- if (bf::create_directories(it->first)) // function may not return true at all (bug?)
- {
- orxout(internal_info) << "Created " << it->second << " directory" << endl;
- }
- }
- }
-
- std::vector<std::string> PathConfig::getModulePaths()
- {
- std::vector<std::string> modulePaths;
-
- // We search for helper files with the following extension
- const std::string& moduleextension = specialConfig::moduleExtension;
- size_t moduleextensionlength = moduleextension.size();
-
- // Make sure the path exists, otherwise don't load modules
- if (!boost::filesystem::exists(modulePath_))
- return modulePaths;
-
- boost::filesystem::directory_iterator file(modulePath_);
- boost::filesystem::directory_iterator end;
-
- // Iterate through all files
- while (file != end)
- {
- std::string filename = file->BF_LEAF();
-
- // Check if the file ends with the extension in question
- if (filename.size() > moduleextensionlength)
- {
- if (filename.substr(filename.size() - moduleextensionlength) == moduleextension)
- {
- // We've found a helper file
- const std::string& library = filename.substr(0, filename.size() - moduleextensionlength);
- modulePaths.push_back(getModulePathString() + library);
- }
- }
- ++file;
- }
-
- return modulePaths;
- }
-
- /*static*/ std::string PathConfig::getRootPathString()
- {
- return getInstance().rootPath_.BF_GENERIC_STRING() + '/';
- }
-
- /*static*/ std::string PathConfig::getExecutablePathString()
- {
- return getInstance().executablePath_.BF_GENERIC_STRING() + '/';
- }
-
- /*static*/ std::string PathConfig::getDataPathString()
- {
- return getInstance().dataPath_.BF_GENERIC_STRING() + '/';
- }
-
- /*static*/ std::string PathConfig::getExternalDataPathString()
- {
- return getInstance().externalDataPath_.BF_GENERIC_STRING() + '/';
- }
-
- /*static*/ std::string PathConfig::getConfigPathString()
- {
- return getInstance().configPath_.BF_GENERIC_STRING() + '/';
- }
-
- /*static*/ std::string PathConfig::getLogPathString()
- {
- return getInstance().logPath_.BF_GENERIC_STRING() + '/';
- }
-
- /*static*/ std::string PathConfig::getModulePathString()
- {
- return getInstance().modulePath_.BF_GENERIC_STRING() + '/';
- }
-}
Deleted: code/branches/core7/src/libraries/core/PathConfig.h
===================================================================
--- code/branches/core7/src/libraries/core/PathConfig.h 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/PathConfig.h 2015-05-30 10:22:27 UTC (rev 10509)
@@ -1,145 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * 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 2
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Reto Grieder
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @ingroup Management Resources
-*/
-
-#ifndef _PathConfig_H__
-#define _PathConfig_H__
-
-#include "CorePrereqs.h"
-
-#include <string>
-#include <vector>
-#include "util/Singleton.h"
-
-//tolua_begin
-namespace orxonox
-{
-//tolua_end
- /**
- @brief
- The PathConfig class is a singleton used to configure different paths.
- @details
- The class provides information about the data, config, log, executable,
- root and module path.
- It determines those by the use of platform specific functions.
- @remarks
- Not all paths are always available:
- - root only when installed copyable
- - externalData only for development builds in the build tree
- */
- class _CoreExport PathConfig //tolua_export
- : public Singleton<PathConfig>
- { //tolua_export
- friend class Singleton<PathConfig>;
- friend class Core;
-
- public:
- /**
- @brief
- Retrieves the executable path and sets all hard coded fixed paths (currently only the module path)
- Also checks for "orxonox_dev_build.keep_me" in the executable diretory.
- If found it means that this is not an installed run, hence we
- don't write the logs and config files to ~/.orxonox
- @throw
- GeneralException
- */
- PathConfig();
- ~PathConfig();
-
- //! Returns the path to the root folder as boost::filesystem::path
- static const boost::filesystem::path& getRootPath()
- { return getInstance().rootPath_; }
- //! Returns the path to the executable folder as boost::filesystem::path
- static const boost::filesystem::path& getExecutablePath()
- { return getInstance().executablePath_; }
- //! Returns the path to the data files as boost::filesystem::path
- static const boost::filesystem::path& getDataPath()
- { return getInstance().dataPath_; }
- //! Returns the path to the external data files as boost::filesystem::path
- static const boost::filesystem::path& getExternalDataPath()
- { return getInstance().externalDataPath_; }
- //! Returns the path to the config files as boost::filesystem::path
- static const boost::filesystem::path& getConfigPath()
- { return getInstance().configPath_; }
- //! Returns the path to the log files as boost::filesystem::path
- static const boost::filesystem::path& getLogPath()
- { return getInstance().logPath_; }
- //! Returns the path to the modules as boost::filesystem::path
- static const boost::filesystem::path& getModulePath()
- { return getInstance().modulePath_; }
-
- //! Returns the path to the root folder as std::string
- static std::string getRootPathString();
- //! Returns the path to the executable folder as std::string
- static std::string getExecutablePathString();
- //! Returns the path to the data files as std::string
- static std::string getDataPathString();
- //! Returns the path to the external data files as std::string
- static std::string getExternalDataPathString();
- //! Returns the path to the config files as std::string
- static std::string getConfigPathString(); //tolua_export
- //! Returns the path to the log files as std::string
- static std::string getLogPathString();
- //! Returns the path to the modules as std::string
- static std::string getModulePathString();
-
- //! Return true for runs in the build directory (not installed)
- static bool buildDirectoryRun() { return getInstance().bBuildDirectoryRun_; }
-
- private:
- PathConfig(const PathConfig&); //!< Don't use (undefined symbol)
-
- /**
- @brief
- Sets config, log and media path and creates the folders if necessary.
- @throws
- GeneralException
- */
- void setConfigurablePaths();
- //! Returns a list with all modules declared by a *.module file in the module folder.
- std::vector<std::string> getModulePaths();
-
- //! Path to the parent directory of the ones above if program was installed with relative paths
- boost::filesystem::path& rootPath_;
- boost::filesystem::path& executablePath_; //!< Path to the executable
- boost::filesystem::path& modulePath_; //!< Path to the modules
- boost::filesystem::path& dataPath_; //!< Path to the data files folder
- boost::filesystem::path& externalDataPath_; //!< Path to the external data files folder
- boost::filesystem::path& configPath_; //!< Path to the config files folder
- boost::filesystem::path& logPath_; //!< Path to the log files folder
-
- bool bBuildDirectoryRun_; //!< True for runs in the build directory (not installed)
- static PathConfig* singletonPtr_s;
- }; //tolua_export
-} //tolua_export
-
-#endif /* _PathConfig_H__ */
Modified: code/branches/core7/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/core7/src/libraries/core/command/Shell.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/command/Shell.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -41,7 +41,7 @@
#include "core/CoreIncludes.h"
#include "core/config/ConfigFileManager.h"
#include "core/config/ConfigValueIncludes.h"
-#include "core/PathConfig.h"
+#include "core/ApplicationPaths.h"
#include "core/input/InputBuffer.h"
#include "CommandExecutor.h"
@@ -83,7 +83,7 @@
ConfigFileManager::getInstance().setFilename(ConfigFileType::CommandHistory, "commandHistory.ini");
// Choose the default level according to the path Orxonox was started (build directory or not)
- OutputLevel defaultDebugLevel = (PathConfig::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
+ OutputLevel defaultDebugLevel = (ApplicationPaths::buildDirectoryRun() ? DefaultLogLevel::Dev : DefaultLogLevel::User);
this->setLevelMax(defaultDebugLevel);
this->setConfigValues();
@@ -163,7 +163,7 @@
*/
void Shell::devModeChanged(bool value)
{
- bool isNormal = (value == PathConfig::buildDirectoryRun());
+ bool isNormal = (value == ApplicationPaths::buildDirectoryRun());
if (isNormal)
{
ModifyConfigValueExternal(this->configurableMaxLevel_, this->getConfigurableMaxLevelName(), update);
Modified: code/branches/core7/src/libraries/core/command/TclBind.cc
===================================================================
--- code/branches/core7/src/libraries/core/command/TclBind.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/command/TclBind.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -36,7 +36,7 @@
#include "util/Output.h"
#include "util/Exception.h"
#include "util/StringUtils.h"
-#include "core/PathConfig.h"
+#include "core/ApplicationPaths.h"
#include "CommandExecutor.h"
#include "ConsoleCommandIncludes.h"
#include "TclThreadManager.h"
@@ -142,10 +142,10 @@
std::string TclBind::getTclLibraryPath()
{
#ifdef DEPENDENCY_PACKAGE_ENABLE
- if (PathConfig::buildDirectoryRun())
+ if (ApplicationPaths::buildDirectoryRun())
return (std::string(specialConfig::dependencyLibraryDirectory) + "/tcl");
else
- return (PathConfig::getRootPathString() + specialConfig::defaultLibraryPath + "/tcl");
+ return (ApplicationPaths::getRootPathString() + specialConfig::defaultLibraryPath + "/tcl");
#else
return "";
#endif
Modified: code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc
===================================================================
--- code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/commandline/CommandLineParser.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -36,7 +36,6 @@
#include "util/Exception.h"
#include "util/StringUtils.h"
#include "util/SubString.h"
-#include "core/PathConfig.h"
namespace orxonox
{
Modified: code/branches/core7/src/libraries/core/config/ConfigFile.cc
===================================================================
--- code/branches/core7/src/libraries/core/config/ConfigFile.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/config/ConfigFile.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -37,7 +37,7 @@
#include "util/Convert.h"
#include "util/StringUtils.h"
-#include "core/PathConfig.h"
+#include "core/ConfigurablePaths.h"
#include "ConfigFileEntryComment.h"
#include "ConfigFileEntryValue.h"
@@ -80,13 +80,13 @@
boost::filesystem::path filepath(this->filename_);
if (!filepath.is_complete())
{
- filepath = PathConfig::getConfigPath() / filepath;
+ filepath = ConfigurablePaths::getConfigPath() / filepath;
if (this->bCopyFallbackFile_)
{
// Look for default file in the data folder
if (!boost::filesystem::exists(filepath))
{
- boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / DEFAULT_CONFIG_FOLDER / this->filename_);
+ boost::filesystem::path defaultFilepath(ConfigurablePaths::getDataPath() / DEFAULT_CONFIG_FOLDER / this->filename_);
if (boost::filesystem::exists(defaultFilepath))
{
// Try to copy default file from the data folder
@@ -215,7 +215,7 @@
{
boost::filesystem::path filepath(filename);
if (!filepath.is_complete())
- filepath = PathConfig::getConfigPath() / filename;
+ filepath = ConfigurablePaths::getConfigPath() / filename;
std::ofstream file;
file.open(filepath.string().c_str(), std::fstream::out);
file.setf(std::ios::fixed, std::ios::floatfield);
Modified: code/branches/core7/src/libraries/core/input/KeyBinder.cc
===================================================================
--- code/branches/core7/src/libraries/core/input/KeyBinder.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/core/input/KeyBinder.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -36,7 +36,8 @@
#include "core/CoreIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/config/ConfigFile.h"
-#include "core/PathConfig.h"
+#include "core/ApplicationPaths.h"
+#include "core/ConfigurablePaths.h"
#include "InputCommands.h"
#include "JoyStick.h"
@@ -254,13 +255,13 @@
{
orxout(internal_info, context::input) << "KeyBinder: Loading key bindings..." << endl;
- this->configFile_ = new ConfigFile(this->filename_, !PathConfig::buildDirectoryRun());
+ this->configFile_ = new ConfigFile(this->filename_, !ApplicationPaths::buildDirectoryRun());
this->configFile_->load();
- if (PathConfig::buildDirectoryRun())
+ if (ApplicationPaths::buildDirectoryRun())
{
// Dev users should have combined key bindings files
- std::string defaultFilepath(PathConfig::getDataPathString() + ConfigFile::DEFAULT_CONFIG_FOLDER + '/' + this->filename_);
+ std::string defaultFilepath(ConfigurablePaths::getDataPathString() + ConfigFile::DEFAULT_CONFIG_FOLDER + '/' + this->filename_);
std::ifstream file(defaultFilepath.c_str());
if (file.is_open())
{
@@ -288,7 +289,7 @@
{
addButtonToCommand(binding, it->second);
std::string str = binding;
- if (PathConfig::buildDirectoryRun() && binding.empty())
+ if (ApplicationPaths::buildDirectoryRun() && binding.empty())
str = "NoBinding";
it->second->setBinding(this->configFile_, this->fallbackConfigFile_, binding, bTemporary);
return true;
Modified: code/branches/core7/src/libraries/tools/ResourceLocation.cc
===================================================================
--- code/branches/core7/src/libraries/tools/ResourceLocation.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/libraries/tools/ResourceLocation.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -34,7 +34,8 @@
#include "util/Exception.h"
#include "core/CoreIncludes.h"
-#include "core/PathConfig.h"
+#include "core/ApplicationPaths.h"
+#include "core/ConfigurablePaths.h"
#include "core/XMLFile.h"
#include "core/XMLPort.h"
@@ -73,10 +74,10 @@
// Find the path
namespace bf = boost::filesystem;
bf::path path;
- if (bf::exists(PathConfig::getDataPath() / this->getPath()))
- path = PathConfig::getDataPath() / this->getPath();
- else if (PathConfig::buildDirectoryRun() && bf::exists(PathConfig::getExternalDataPath() / this->getPath()))
- path = PathConfig::getExternalDataPath() / this->getPath();
+ if (bf::exists(ConfigurablePaths::getDataPath() / this->getPath()))
+ path = ConfigurablePaths::getDataPath() / this->getPath();
+ else if (ApplicationPaths::buildDirectoryRun() && bf::exists(ConfigurablePaths::getExternalDataPath() / this->getPath()))
+ path = ConfigurablePaths::getExternalDataPath() / this->getPath();
else
{
orxout(internal_warning) << "ResourceLocation '" << this->getPath() << "' does not seem to exist" << endl;
Modified: code/branches/core7/src/modules/designtools/ScreenshotManager.cc
===================================================================
--- code/branches/core7/src/modules/designtools/ScreenshotManager.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/modules/designtools/ScreenshotManager.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -44,7 +44,7 @@
#include "core/CoreIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/GraphicsManager.h"
-#include "core/PathConfig.h"
+#include "core/ConfigurablePaths.h"
#include "core/Resource.h"
#include "core/command/ConsoleCommandIncludes.h"
#include "core/singleton/ScopedSingletonIncludes.h"
@@ -153,7 +153,7 @@
if(finalImage != NULL)
{
// Save it.
- finalImage->save(PathConfig::getInstance().getLogPathString() + "screenshot_" + getTimestamp() + this->fileExtension_);
+ finalImage->save(ConfigurablePaths::getLogPathString() + "screenshot_" + getTimestamp() + this->fileExtension_);
delete finalImage;
orxout(user_info) << "Finished taking " << this->gridSize_*this->windowWidth_ << "x" << this->gridSize_*this->windowHeight_ << " pixel HD screenshot. Storing in log/." << endl;
}
Modified: code/branches/core7/src/modules/designtools/SkyboxGenerator.cc
===================================================================
--- code/branches/core7/src/modules/designtools/SkyboxGenerator.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/modules/designtools/SkyboxGenerator.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -40,7 +40,7 @@
#include "core/CoreIncludes.h"
#include "core/config/ConfigValueIncludes.h"
#include "core/GraphicsManager.h"
-#include "core/PathConfig.h"
+#include "core/ConfigurablePaths.h"
#include "core/Resource.h"
#include "core/command/ConsoleCommandIncludes.h"
#include "core/command/CommandExecutor.h"
@@ -174,7 +174,7 @@
// Setup the render window.
this->setupRenderWindow(renderWindow);
// Add the log path to the standard resource group.
- Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getInstance().getLogPathString(), "FileSystem", Resource::getDefaultResourceGroup());
+ Ogre::ResourceGroupManager::getSingleton().addResourceLocation(ConfigurablePaths::getLogPathString(), "FileSystem", Resource::getDefaultResourceGroup());
orxout(internal_status) << "Setting up SkyboxGenerator..." << endl;
@@ -209,7 +209,7 @@
// Restore the render window.
this->restoreRenderWindow(renderWindow);
// Remove the log path from the standard resource group.
- Ogre::ResourceGroupManager::getSingleton().removeResourceLocation(PathConfig::getInstance().getLogPathString(), Resource::getDefaultResourceGroup());
+ Ogre::ResourceGroupManager::getSingleton().removeResourceLocation(ConfigurablePaths::getLogPathString(), Resource::getDefaultResourceGroup());
// Reset the flow parameters for the next skybox generation.
this->bGenerateSkybox_ = false;
@@ -307,14 +307,14 @@
*/
void SkyboxGenerator::saveImage(Ogre::Image* image, const std::string& name) const
{
- image->save(PathConfig::getInstance().getLogPathString()+name);
+ image->save(ConfigurablePaths::getLogPathString()+name);
delete image;
// Loading the resizing, then saving again. This seems stupid, but resizing doesn't seem to work otherwise.
// If someone figures this out, feel free to adjust.
image = new Ogre::Image();
image->load(name, Resource::getDefaultResourceGroup());
image->resize(this->size_, this->size_);
- image->save(PathConfig::getInstance().getLogPathString()+name);
+ image->save(ConfigurablePaths::getLogPathString()+name);
delete image;
ScreenshotManager::getInstance().cleanup(); // Free memory in ScreenshotManager.
}
Modified: code/branches/core7/src/orxonox/chat/ChatHistory.cc
===================================================================
--- code/branches/core7/src/orxonox/chat/ChatHistory.cc 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/orxonox/chat/ChatHistory.cc 2015-05-30 10:22:27 UTC (rev 10509)
@@ -28,6 +28,7 @@
#include "ChatHistory.h"
#include "core/singleton/ScopedSingletonIncludes.h"
+#include "core/ConfigurablePaths.h"
#ifndef CHATTEST
namespace orxonox
@@ -120,7 +121,7 @@
* and set the this->hist_logfile_path variable to it
*/
#ifndef CHATTEST
- this->hist_logfile.open( (PathConfig::getInstance().getLogPathString() +
+ this->hist_logfile.open( (ConfigurablePaths::getLogPathString() +
"chatlog.log").c_str(),
std::fstream::out | std::fstream::app );
#else
Modified: code/branches/core7/src/orxonox/chat/ChatHistory.h
===================================================================
--- code/branches/core7/src/orxonox/chat/ChatHistory.h 2015-05-30 08:18:07 UTC (rev 10508)
+++ code/branches/core7/src/orxonox/chat/ChatHistory.h 2015-05-30 10:22:27 UTC (rev 10509)
@@ -40,7 +40,6 @@
#include "util/Singleton.h"
#include "core/BaseObject.h"
-#include "core/PathConfig.h"
#include "chat/ChatListener.h"
#include "infos/PlayerInfo.h"
#include "PlayerManager.h"
More information about the Orxonox-commit
mailing list