1 /*!
2  * \file   ResourceManager.h
3  * \date   12 April 2011
4  * \author StefanP.MUC
5  * \brief  Header for the ResourceManager
6  *
7  *  Copyright (C) 2011-2016  OpenDungeons Team
8  *
9  *  This program is free software: you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation, either version 3 of the License, or
12  *  (at your option) any later version.
13  *
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef RESOURCEMANAGER_H_
24 #define RESOURCEMANAGER_H_
25 
26 #include <string>
27 
28 #include <OgreSingleton.h>
29 #include <OgreStringVector.h>
30 
31 namespace Ogre {
32   class RenderTarget;
33 }
34 
35 namespace boost
36 {
37 namespace program_options
38 {
39 class options_description;
40 class variables_map;
41 }
42 }
43 
44 enum class LogMessageLevel;
45 
46 //!\brief class that handle OD ressources. Note that this class might be created before the
47 //! LogManager because it handles the log filename. Thus, it should not use LogManager.
48 class ResourceManager : public Ogre::Singleton<ResourceManager>
49 {
50 public:
51     ResourceManager(boost::program_options::variables_map& options);
~ResourceManager()52     ~ResourceManager()
53     {}
54 
55     //! Helper function for building options descriptions. Note that it has to be static because
56     //! the ResourceManager singleton will not be built when this list is constructed
57     static void buildCommandOptions(boost::program_options::options_description& desc);
58 
59     //! \brief Initializes the Ogre resources path
60     //! \note Used after the Ogre Root initialization
61     //! \param shaderLanguageVersion The shader language version to use.
62     void setupOgreResources(uint16_t shaderLanguageVersion);
63 
64     /*! \brief check if a filename has a specific extension
65      *  \param filename The filename, like "filename.ext"
66      *  \param ending   The extension, like ".ext"
67      *  \return true or false depending if the filename has the extension or not
68      */
69     static bool hasFileEnding(const std::string& filename, const std::string& ending);
70 
71     /*! \brief gets all files within a directory
72      *  \param directoryName the directory to scan for files
73      *  \return a vector with all file names
74      */
75     static std::vector<std::string> listAllFiles(const std::string& directoryName);
76 
77     /*! \brief returns all music files that Ogre knows of
78      *  \return a vector with all file names
79      */
80     Ogre::StringVectorPtr listAllMusicFiles();
81 
82     //! \brief saves a screenshot
83     void takeScreenshot(Ogre::RenderTarget* renderTarget);
84 
85     std::string buildReplayFilename();
86 
getGameDataPath()87     inline const std::string& getGameDataPath() const
88     { return mGameDataPath; }
89 
getUserDataPath()90     inline const std::string& getUserDataPath() const
91     { return mUserDataPath; }
92 
getReplayDataPath()93     inline const std::string& getReplayDataPath() const
94     { return mReplayPath; }
95 
getSaveGamePath()96     inline const std::string& getSaveGamePath() const
97     { return mSaveGamePath; }
98 
getUserConfigPath()99     inline const std::string& getUserConfigPath() const
100     { return mUserConfigPath; }
101 
getPluginsPath()102     inline const std::string& getPluginsPath() const
103     { return mPluginsPath; }
104 
getMusicPath()105     inline const std::string& getMusicPath() const
106     { return mMusicPath; }
107 
getConfigPath()108     inline const std::string& getConfigPath() const
109     { return mConfigPath; }
110 
getScriptPath()111     inline const std::string& getScriptPath() const
112     { return mScriptPath; }
113 
getSoundPath()114     inline const std::string& getSoundPath() const
115     { return mSoundPath; }
116 
getLanguagePath()117     inline const std::string& getLanguagePath() const
118     { return mLanguagePath; }
119 
getShaderCachePath()120     inline const std::string& getShaderCachePath() const
121     { return mShaderCachePath; }
122 
getUserCfgFile()123     inline const std::string& getUserCfgFile() const
124     { return mUserConfigFile; }
125 
getLogFile()126     inline const std::string& getLogFile() const
127     { return mOgreLogFile; }
128 
getCeguiLogFile()129     inline const std::string& getCeguiLogFile() const
130     { return mCeguiLogFile; }
131 
132     std::string getGameLevelPathSkirmish() const;
getUserLevelPathSkirmish()133     std::string getUserLevelPathSkirmish() const
134     { return mUserSkirmishLevelsPath; }
135     std::string getGameLevelPathMultiplayer() const;
getUserLevelPathMultiplayer()136     std::string getUserLevelPathMultiplayer() const
137     { return mUserMultiplayerLevelsPath; }
138 
isServerMode()139     inline bool isServerMode() const
140     { return mServerMode; }
141 
getServerModeLevel()142     inline const std::string& getServerModeLevel() const
143     { return mServerModeLevel; }
144 
getServerModeCreator()145     inline const std::string& getServerModeCreator() const
146     { return mServerModeCreator; }
147 
getForcedNetworkPort()148     inline int32_t getForcedNetworkPort() const
149     { return mForcedNetworkPort; }
150 
getLogLevel()151     inline LogMessageLevel getLogLevel() const
152     { return mLogLevel; }
153 
154 private:
155     //! \brief used when the executable is launched in server mode
156     bool mServerMode;
157     std::string mServerModeLevel;
158     std::string mServerModeCreator;
159 
160     //! \brief used when the network port is forced
161     int32_t mForcedNetworkPort;
162 
163     //! \brief The log level
164     LogMessageLevel mLogLevel;
165 
166     //! \brief The application data path
167     //! \example "/usr/share/game/opendungeons" on linux
168     //! \example "C:/opendungeons" on windows
169     std::string mGameDataPath;
170 
171     //! \brief Specific mac bundle path
172     std::string mMacBundlePath;
173 
174     //! \brief The user custom data path
175     //! \example "~/.local/share/opendungeons" on linux
176     //! \example %APPDATA% "%USERPROFILE%\Application Data\opendungeons" on windows
177     std::string mUserDataPath;
178 
179     //! \brief The user custom config path
180     //! \example "~/.config/opendungeons" on linux
181     //! Same as home path + "cfg/" on Windows.
182     std::string mUserConfigPath;
183 
184     //! \brief Main files in the user data path
185     std::string mUserConfigFile;
186     std::string mOgreLogFile;
187     std::string mCeguiLogFile;
188     std::string mShaderCachePath;
189 
190     //! \brief Specific data sub-paths.
191     std::string mConfigPath;
192     std::string mPluginsPath;
193     std::string mMusicPath;
194     std::string mSoundPath;
195     std::string mScriptPath;
196     std::string mLanguagePath;
197     std::string mReplayPath;
198     std::string mSaveGamePath;
199     std::string mUserSkirmishLevelsPath;
200     std::string mUserMultiplayerLevelsPath;
201 
202     static const std::string PLUGINSCFG;
203     static const std::string RESOURCECFG;
204     static const std::string MUSICSUBPATH;
205     static const std::string SOUNDSUBPATH;
206     static const std::string SCRIPTSUBPATH;
207     static const std::string CONFIGSUBPATH;
208     static const std::string LANGUAGESUBPATH;
209     static const std::string SHADERCACHESUBPATH;
210     static const std::string LOGFILENAME;
211     static const std::string CEGUILOGFILENAME;
212     static const std::string USERCFGFILENAME;
213 
214     static const std::string RESOURCEGROUPMUSIC;
215     static const std::string RESOURCEGROUPSOUND;
216 
217     //! \brief Setup user data and config path
218     void setupUserDataFolders(boost::program_options::variables_map& options);
219 
220     //! \brief Setup the game data path
221     //! \note If game data path is found in the current folder,
222     //! then the local data path will be used.
223     void setupDataPath(boost::program_options::variables_map& options);
224 };
225 
226 #endif // RESOURCEMANAGER_H_
227