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: |
---|
23 | * Reto Grieder |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _PathConfig_H__ |
---|
30 | #define _PathConfig_H__ |
---|
31 | |
---|
32 | #include "CorePrereqs.h" |
---|
33 | |
---|
34 | #include <string> |
---|
35 | #include "util/Singleton.h" |
---|
36 | |
---|
37 | namespace orxonox |
---|
38 | { |
---|
39 | /** |
---|
40 | @brief |
---|
41 | The PathConfig class is a singleton used to configure different paths. |
---|
42 | @details |
---|
43 | The class provides information about the data, config, log, executable, |
---|
44 | root and module path. |
---|
45 | It determines those by the use of platform specific functions. |
---|
46 | @remarks |
---|
47 | Not all paths are always available: |
---|
48 | - root only when installed copyable |
---|
49 | - externalData only for development builds in the build tree |
---|
50 | */ |
---|
51 | class _CoreExport PathConfig : public Singleton<PathConfig> |
---|
52 | { |
---|
53 | friend class Singleton<PathConfig>; |
---|
54 | friend class Core; |
---|
55 | |
---|
56 | public: |
---|
57 | /** |
---|
58 | @brief |
---|
59 | Retrievs the executable path and sets all hard coded fixed paths (currently only the module path) |
---|
60 | Also checks for "orxonox_dev_build.keep_me" in the executable diretory. |
---|
61 | If found it means that this is not an installed run, hence we |
---|
62 | don't write the logs and config files to ~/.orxonox |
---|
63 | @throw |
---|
64 | GeneralException |
---|
65 | */ |
---|
66 | PathConfig(); |
---|
67 | ~PathConfig(); |
---|
68 | |
---|
69 | //! Returns the path to the root folder as boost::filesystem::path |
---|
70 | static const boost::filesystem::path& getRootPath() |
---|
71 | { return getInstance().rootPath_; } |
---|
72 | //! Returns the path to the executable folder as boost::filesystem::path |
---|
73 | static const boost::filesystem::path& getExecutablePath() |
---|
74 | { return getInstance().executablePath_; } |
---|
75 | //! Returns the path to the data files as boost::filesystem::path |
---|
76 | static const boost::filesystem::path& getDataPath() |
---|
77 | { return getInstance().dataPath_; } |
---|
78 | //! Returns the path to the external data files as boost::filesystem::path |
---|
79 | static const boost::filesystem::path& getExternalDataPath() |
---|
80 | { return getInstance().externalDataPath_; } |
---|
81 | //! Returns the path to the config files as boost::filesystem::path |
---|
82 | static const boost::filesystem::path& getConfigPath() |
---|
83 | { return getInstance().configPath_; } |
---|
84 | //! Returns the path to the log files as boost::filesystem::path |
---|
85 | static const boost::filesystem::path& getLogPath() |
---|
86 | { return getInstance().logPath_; } |
---|
87 | //! Returns the path to the modules as boost::filesystem::path |
---|
88 | static const boost::filesystem::path& getModulePath() |
---|
89 | { return getInstance().modulePath_; } |
---|
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(); |
---|
95 | //! Returns the path to the data files as std::string |
---|
96 | static std::string getDataPathString(); |
---|
97 | //! Returns the path to the external data files as std::string |
---|
98 | static std::string getExternalDataPathString(); |
---|
99 | //! Returns the path to the config files as std::string |
---|
100 | static std::string getConfigPathString(); |
---|
101 | //! Returns the path to the log files as std::string |
---|
102 | static std::string getLogPathString(); |
---|
103 | //! Returns the path to the modules as std::string |
---|
104 | static std::string getModulePathString(); |
---|
105 | |
---|
106 | //! Return trrue for runs in the build directory (not installed) |
---|
107 | static bool isDevelopmentRun() { return getInstance().bDevRun_; } |
---|
108 | |
---|
109 | private: |
---|
110 | PathConfig(const PathConfig&); //!< Don't use (undefined symbol) |
---|
111 | |
---|
112 | /** |
---|
113 | @brief |
---|
114 | Sets config, log and media path and creates the folders if necessary. |
---|
115 | @throws |
---|
116 | GeneralException |
---|
117 | */ |
---|
118 | void setConfigurablePaths(); |
---|
119 | //! Returns a list with all modules declared by a *.module file in the module folder. |
---|
120 | std::vector<std::string> getModulePaths(); |
---|
121 | |
---|
122 | //! Path to the parent directory of the ones above if program was installed with relativ paths |
---|
123 | boost::filesystem::path& rootPath_; |
---|
124 | boost::filesystem::path& executablePath_; //!< Path to the executable |
---|
125 | boost::filesystem::path& modulePath_; //!< Path to the modules |
---|
126 | boost::filesystem::path& dataPath_; //!< Path to the data files folder |
---|
127 | boost::filesystem::path& externalDataPath_; //!< Path to the external data files folder |
---|
128 | boost::filesystem::path& configPath_; //!< Path to the config files folder |
---|
129 | boost::filesystem::path& logPath_; //!< Path to the log files folder |
---|
130 | |
---|
131 | bool bDevRun_; //!< True for runs in the build directory (not installed) |
---|
132 | static PathConfig* singletonPtr_s; |
---|
133 | }; |
---|
134 | } |
---|
135 | |
---|
136 | #endif /* _PathConfig_H__ */ |
---|