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