[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
[2896] | 23 | * Reto Grieder |
---|
[1505] | 24 | * Co-authors: |
---|
[2896] | 25 | * ... |
---|
[1505] | 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[7401] | 29 | /** |
---|
| 30 | @file |
---|
| 31 | @ingroup Management Resources |
---|
| 32 | */ |
---|
| 33 | |
---|
[5836] | 34 | #ifndef _PathConfig_H__ |
---|
| 35 | #define _PathConfig_H__ |
---|
[1505] | 36 | |
---|
| 37 | #include "CorePrereqs.h" |
---|
| 38 | |
---|
[5836] | 39 | #include <string> |
---|
[5865] | 40 | #include <vector> |
---|
[7421] | 41 | #include <QDir> |
---|
[3370] | 42 | #include "util/Singleton.h" |
---|
[1505] | 43 | |
---|
| 44 | namespace orxonox |
---|
| 45 | { |
---|
[3196] | 46 | /** |
---|
| 47 | @brief |
---|
[5836] | 48 | The PathConfig class is a singleton used to configure different paths. |
---|
[3196] | 49 | @details |
---|
[7421] | 50 | The class provides information about the data, config, log, executable |
---|
| 51 | and root path. |
---|
[3196] | 52 | It determines those by the use of platform specific functions. |
---|
[5836] | 53 | @remarks |
---|
| 54 | Not all paths are always available: |
---|
| 55 | - root only when installed copyable |
---|
[3196] | 56 | */ |
---|
[7421] | 57 | class _CoreExport PathConfig : public Singleton<PathConfig> |
---|
| 58 | { |
---|
[5836] | 59 | friend class Singleton<PathConfig>; |
---|
| 60 | friend class Core; |
---|
[3370] | 61 | |
---|
[1505] | 62 | public: |
---|
[3196] | 63 | /** |
---|
| 64 | @brief |
---|
[7421] | 65 | Retrieves the executable path and sets all hard coded fixed paths (currently only the module path) |
---|
[5836] | 66 | Also checks for "orxonox_dev_build.keep_me" in the executable diretory. |
---|
| 67 | If found it means that this is not an installed run, hence we |
---|
| 68 | don't write the logs and config files to ~/.orxonox |
---|
| 69 | @throw |
---|
[3196] | 70 | GeneralException |
---|
| 71 | */ |
---|
[5836] | 72 | PathConfig(); |
---|
| 73 | ~PathConfig(); |
---|
[2896] | 74 | |
---|
[7421] | 75 | //! Returns the path to the root folder as QDir |
---|
| 76 | static const QDir& getRootPath() |
---|
[5836] | 77 | { return getInstance().rootPath_; } |
---|
[7421] | 78 | //! Returns the path to the executable folder as QDir |
---|
| 79 | static const QDir& getExecutablePath() |
---|
[5836] | 80 | { return getInstance().executablePath_; } |
---|
[7421] | 81 | //! Returns the path to the data files as QDir |
---|
| 82 | static const QDir& getDataPath() |
---|
[5836] | 83 | { return getInstance().dataPath_; } |
---|
[7421] | 84 | //! Returns the path to the config files as QDir |
---|
| 85 | static const QDir& getConfigPath() |
---|
[5836] | 86 | { return getInstance().configPath_; } |
---|
[7421] | 87 | //! Returns the path to the log files as QDir |
---|
| 88 | static const QDir& getLogPath() |
---|
[5836] | 89 | { return getInstance().logPath_; } |
---|
| 90 | |
---|
| 91 | //! Returns the path to the root folder as std::string |
---|
| 92 | static std::string getRootPathString(); |
---|
| 93 | //! Returns the path to the executable folder as std::string |
---|
| 94 | static std::string getExecutablePathString(); |
---|
[3196] | 95 | //! Returns the path to the data files as std::string |
---|
[5695] | 96 | static std::string getDataPathString(); |
---|
[3196] | 97 | //! Returns the path to the config files as std::string |
---|
[6417] | 98 | static std::string getConfigPathString(); //tolua_export |
---|
[3196] | 99 | //! Returns the path to the log files as std::string |
---|
[2710] | 100 | static std::string getLogPathString(); |
---|
| 101 | |
---|
[5836] | 102 | //! Return trrue for runs in the build directory (not installed) |
---|
[3370] | 103 | static bool isDevelopmentRun() { return getInstance().bDevRun_; } |
---|
| 104 | |
---|
[1505] | 105 | private: |
---|
[5836] | 106 | PathConfig(const PathConfig&); //!< Don't use (undefined symbol) |
---|
[2896] | 107 | |
---|
[5836] | 108 | /** |
---|
| 109 | @brief |
---|
| 110 | Sets config, log and media path and creates the folders if necessary. |
---|
| 111 | @throws |
---|
| 112 | GeneralException |
---|
| 113 | */ |
---|
[5693] | 114 | void setConfigurablePaths(); |
---|
[2896] | 115 | |
---|
[5836] | 116 | //! Path to the parent directory of the ones above if program was installed with relativ paths |
---|
[7421] | 117 | QDir rootPath_; |
---|
| 118 | QDir executablePath_; //!< Path to the executable |
---|
| 119 | QDir dataPath_; //!< Path to the data files folder |
---|
| 120 | QDir configPath_; //!< Path to the config files folder |
---|
| 121 | QDir logPath_; //!< Path to the log files folder |
---|
[2710] | 122 | |
---|
[7421] | 123 | bool bDevRun_; //!< True for runs in the build directory (not installed) |
---|
[5836] | 124 | static PathConfig* singletonPtr_s; |
---|
[6417] | 125 | }; //tolua_export |
---|
| 126 | } //tolua_export |
---|
[1505] | 127 | |
---|
[5836] | 128 | #endif /* _PathConfig_H__ */ |
---|