[5653] | 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 _Core_Resource_H__ |
---|
| 30 | #define _Core_Resource_H__ |
---|
| 31 | |
---|
| 32 | #include "CorePrereqs.h" |
---|
| 33 | |
---|
| 34 | #include <boost/shared_ptr.hpp> |
---|
| 35 | #include <OgreDataStream.h> |
---|
[6417] | 36 | #include <OgreStringVector.h> |
---|
[5653] | 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
| 40 | // Import the Ogre::DataStreamList |
---|
| 41 | using Ogre::DataStreamList; |
---|
| 42 | using Ogre::DataStreamListPtr; |
---|
[6417] | 43 | using Ogre::StringVector; |
---|
| 44 | using Ogre::StringVectorPtr; |
---|
[5653] | 45 | |
---|
| 46 | //! Stores basic information about a Resource from Ogre |
---|
| 47 | struct ResourceInfo |
---|
| 48 | { |
---|
| 49 | //! The file's fully qualified name |
---|
| 50 | std::string filename; |
---|
| 51 | //! Path name; separated by '/' and ending with '/' |
---|
| 52 | std::string path; |
---|
| 53 | //! Base filename |
---|
| 54 | std::string basename; |
---|
| 55 | //! Resource group the file is in |
---|
| 56 | std::string group; |
---|
| 57 | //! Uncompressed size |
---|
| 58 | size_t size; |
---|
[6746] | 59 | //! Absolute file path ("" for files not on filesystem) |
---|
| 60 | std::string fileSystemPath; |
---|
[5653] | 61 | }; |
---|
| 62 | |
---|
[6417] | 63 | /** Provides simple functions to easily access the Ogre::ResourceGroupManager. |
---|
| 64 | The wrapper functions also avoid having to deal with resource groups. |
---|
[5653] | 65 | */ |
---|
| 66 | class _CoreExport Resource |
---|
| 67 | { |
---|
| 68 | // Docs by Ogre::ResourceGroupManager.h |
---|
| 69 | public: |
---|
[5929] | 70 | /** |
---|
[5653] | 71 | @brief |
---|
| 72 | Open a single resource by name and return a DataStream |
---|
| 73 | pointing at the source of the data. |
---|
| 74 | @param name |
---|
| 75 | The name of the resource to locate. |
---|
| 76 | Even if resource locations are added recursively, you |
---|
| 77 | must provide a fully qualified name to this method. |
---|
| 78 | @return |
---|
| 79 | Shared pointer to data stream containing the data. Will be |
---|
| 80 | destroyed automatically when no longer referenced. |
---|
[5929] | 81 | */ |
---|
[6417] | 82 | static DataStreamPtr open(const std::string& name); |
---|
[5653] | 83 | |
---|
[6417] | 84 | //! Similar to open(string, string, bool), but with a fileInfo struct |
---|
| 85 | static DataStreamPtr open(shared_ptr<ResourceInfo> fileInfo) |
---|
| 86 | { |
---|
| 87 | return open(fileInfo->filename); |
---|
| 88 | } |
---|
| 89 | |
---|
[5929] | 90 | /** |
---|
[5653] | 91 | @brief |
---|
| 92 | Open all resources matching a given pattern (which can contain |
---|
[6417] | 93 | the character '*' as a wildcard), and return a collection of |
---|
[5653] | 94 | DataStream objects on them. |
---|
| 95 | @param pattern |
---|
| 96 | The pattern to look for. If resource locations have been |
---|
| 97 | added recursively, subdirectories will be searched too so this |
---|
| 98 | does not need to be fully qualified. |
---|
| 99 | @return |
---|
| 100 | Shared pointer to a data stream list , will be |
---|
| 101 | destroyed automatically when no longer referenced |
---|
[5929] | 102 | */ |
---|
[6417] | 103 | static DataStreamListPtr openMulti(const std::string& pattern); |
---|
[5653] | 104 | |
---|
| 105 | /** |
---|
[6417] | 106 | Find out if the named file exists. |
---|
[5653] | 107 | @param filename |
---|
| 108 | Fully qualified name of the file to test for |
---|
| 109 | */ |
---|
[6417] | 110 | static bool exists(const std::string& name); |
---|
[5653] | 111 | |
---|
| 112 | /** |
---|
[6417] | 113 | Get struct with information about path and size. |
---|
[5653] | 114 | @param filename |
---|
| 115 | Fully qualified name of the file to test for |
---|
| 116 | */ |
---|
[6417] | 117 | static shared_ptr<ResourceInfo> getInfo(const std::string& name); |
---|
[5653] | 118 | |
---|
[6417] | 119 | /** |
---|
| 120 | Retrieves a list with all resources matching a certain pattern. |
---|
| 121 | @param pattern |
---|
| 122 | The pattern to look for. If resource locations have been |
---|
| 123 | added recursively, subdirectories will be searched too so this |
---|
| 124 | does not need to be fully qualified. |
---|
| 125 | */ |
---|
| 126 | static StringVectorPtr findResourceNames(const std::string& pattern); |
---|
| 127 | |
---|
[5653] | 128 | //! Name of the default resource group (usually "General") |
---|
| 129 | static std::string DEFAULT_GROUP; |
---|
| 130 | |
---|
| 131 | private: |
---|
| 132 | Resource(); |
---|
| 133 | ~Resource(); |
---|
| 134 | Resource(const Resource& instance); |
---|
| 135 | }; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | #endif /* _Core_Resource_H__ */ |
---|