[692] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of OGRE
|
---|
| 4 | (Object-oriented Graphics Rendering Engine)
|
---|
| 5 | For the latest info, see http://www.ogre3d.org/
|
---|
| 6 |
|
---|
| 7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
| 8 | Also see acknowledgements in Readme.html
|
---|
| 9 |
|
---|
| 10 | This program is free software; you can redistribute it and/or modify it under
|
---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
| 13 | version.
|
---|
| 14 |
|
---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
| 22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
| 23 | -----------------------------------------------------------------------------
|
---|
| 24 | */
|
---|
| 25 | #ifndef _Archive_H__
|
---|
| 26 | #define _Archive_H__
|
---|
| 27 |
|
---|
| 28 | #include "OgrePrerequisites.h"
|
---|
| 29 | #include "OgreString.h"
|
---|
| 30 | #include "OgreDataStream.h"
|
---|
| 31 | #include "OgreSharedPtr.h"
|
---|
| 32 | #include "OgreStringVector.h"
|
---|
| 33 |
|
---|
| 34 | namespace Ogre {
|
---|
| 35 |
|
---|
| 36 | /** Information about a file/directory within the archive will be
|
---|
| 37 | returned using a FileInfo struct.
|
---|
| 38 | @see
|
---|
| 39 | Archive
|
---|
| 40 | */
|
---|
| 41 | struct FileInfo {
|
---|
| 42 | /// The archive in which the file has been found (for info when performing
|
---|
| 43 | /// multi-Archive searches, note you should still open through ResourceGroupManager)
|
---|
| 44 | Archive* archive;
|
---|
| 45 | /// The file's fully qualified name
|
---|
| 46 | String filename;
|
---|
| 47 | /// Path name; separated by '/' and ending with '/'
|
---|
| 48 | String path;
|
---|
| 49 | /// Base filename
|
---|
| 50 | String basename;
|
---|
| 51 | /// Compressed size
|
---|
| 52 | size_t compressedSize;
|
---|
| 53 | /// Uncompressed size
|
---|
| 54 | size_t uncompressedSize;
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 | typedef std::vector<FileInfo> FileInfoList;
|
---|
| 58 | typedef SharedPtr<FileInfoList> FileInfoListPtr;
|
---|
| 59 |
|
---|
| 60 | /** Archive-handling class.
|
---|
| 61 | @remarks
|
---|
| 62 | An archive is a generic term for a container of files. This may be a
|
---|
| 63 | filesystem folder, it may be a compressed archive, it may even be
|
---|
| 64 | a remote location shared on the web. This class is designed to be
|
---|
| 65 | subclassed to provide access to a range of file locations.
|
---|
| 66 | @par
|
---|
| 67 | Instances of this class are never constructed or even handled by end-user
|
---|
| 68 | applications. They are constructed by custom ArchiveFactory classes,
|
---|
| 69 | which plugins can register new instances of using ArchiveManager.
|
---|
| 70 | End-user applications will typically use ResourceManager or
|
---|
| 71 | ResourceGroupManager to manage resources at a higher level, rather than
|
---|
| 72 | reading files directly through this class. Doing it this way allows you
|
---|
| 73 | to benefit from OGRE's automatic searching of multiple file locations
|
---|
| 74 | for the resources you are looking for.
|
---|
| 75 | */
|
---|
| 76 | class _OgreExport Archive
|
---|
| 77 | {
|
---|
| 78 | protected:
|
---|
| 79 | /// Archive name
|
---|
| 80 | String mName;
|
---|
| 81 | /// Archive type code
|
---|
| 82 | String mType;
|
---|
| 83 | public:
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | /** Constructor - don't call direct, used by ArchiveFactory.
|
---|
| 87 | */
|
---|
| 88 | Archive( const String& name, const String& archType )
|
---|
| 89 | : mName(name), mType(archType) {}
|
---|
| 90 |
|
---|
| 91 | /** Default destructor.
|
---|
| 92 | */
|
---|
| 93 | virtual ~Archive() {}
|
---|
| 94 |
|
---|
| 95 | /// Get the name of this archive
|
---|
| 96 | const String& getName(void) const { return mName; }
|
---|
| 97 |
|
---|
| 98 | /// Returns whether this archive is case sensitive in the way it matches files
|
---|
| 99 | virtual bool isCaseSensitive(void) const = 0;
|
---|
| 100 |
|
---|
| 101 | /** Loads the archive.
|
---|
| 102 | @remarks
|
---|
| 103 | This initializes all the internal data of the class.
|
---|
| 104 | @warning
|
---|
| 105 | Do not call this function directly, it is ment to be used
|
---|
| 106 | only by the ArchiveManager class.
|
---|
| 107 | */
|
---|
| 108 | virtual void load() = 0;
|
---|
| 109 |
|
---|
| 110 | /** Unloads the archive.
|
---|
| 111 | @warning
|
---|
| 112 | Do not call this function directly, it is ment to be used
|
---|
| 113 | only by the ArchiveManager class.
|
---|
| 114 | */
|
---|
| 115 | virtual void unload() = 0;
|
---|
| 116 |
|
---|
| 117 | /** Open a stream on a given file.
|
---|
| 118 | @note
|
---|
| 119 | There is no equivalent 'close' method; the returned stream
|
---|
| 120 | controls the lifecycle of this file operation.
|
---|
| 121 | @param filename The fully qualified name of the file
|
---|
| 122 | @returns A shared pointer to a DataStream which can be used to
|
---|
| 123 | read / write the file. If the file is not present, returns a null
|
---|
| 124 | shared pointer.
|
---|
| 125 | */
|
---|
| 126 | virtual DataStreamPtr open(const String& filename) const = 0;
|
---|
| 127 |
|
---|
| 128 | /** List all file names in the archive.
|
---|
| 129 | @note
|
---|
| 130 | This method only returns filenames, you can also retrieve other
|
---|
| 131 | information using listFileInfo.
|
---|
| 132 | @param recursive Whether all paths of the archive are searched (if the
|
---|
| 133 | archive has a concept of that)
|
---|
| 134 | @returns A list of filenames matching the criteria, all are fully qualified
|
---|
| 135 | */
|
---|
| 136 | virtual StringVectorPtr list(bool recursive = true ) = 0;
|
---|
| 137 |
|
---|
| 138 | /** List all files in the archive with accompanying information.
|
---|
| 139 | @param recursive Whether all paths of the archive are searched (if the
|
---|
| 140 | archive has a concept of that)
|
---|
| 141 | @returns A list of structures detailing quite a lot of information about
|
---|
| 142 | all the files in the archive.
|
---|
| 143 | */
|
---|
| 144 | virtual FileInfoListPtr listFileInfo(bool recursive = true ) = 0;
|
---|
| 145 |
|
---|
| 146 | /** Find all file names matching a given pattern in this archive.
|
---|
| 147 | @note
|
---|
| 148 | This method only returns filenames, you can also retrieve other
|
---|
| 149 | information using findFileInfo.
|
---|
| 150 | @param pattern The pattern to search for; wildcards (*) are allowed
|
---|
| 151 | @param recursive Whether all paths of the archive are searched (if the
|
---|
| 152 | archive has a concept of that)
|
---|
| 153 | @returns A list of filenames matching the criteria, all are fully qualified
|
---|
| 154 | */
|
---|
| 155 | virtual StringVectorPtr find(const String& pattern, bool recursive = true) = 0;
|
---|
| 156 |
|
---|
| 157 | /** Find out if the named file exists (note: fully qualified filename required) */
|
---|
| 158 | virtual bool exists(const String& filename) = 0;
|
---|
| 159 |
|
---|
| 160 | /** Find all files matching a given pattern in this archive and get
|
---|
| 161 | some detailed information about them.
|
---|
| 162 | @param pattern The pattern to search for; wildcards (*) are allowed
|
---|
| 163 | @param recursive Whether all paths of the archive are searched (if the
|
---|
| 164 | archive has a concept of that)
|
---|
| 165 | @returns A list of file information structures for all files matching
|
---|
| 166 | the criteria.
|
---|
| 167 | */
|
---|
| 168 | virtual FileInfoListPtr findFileInfo(const String& pattern,
|
---|
| 169 | bool recursive = true) = 0;
|
---|
| 170 |
|
---|
| 171 | /// Return the type code of this Archive
|
---|
| 172 | const String& getType(void) const { return mType; }
|
---|
| 173 |
|
---|
| 174 | };
|
---|
| 175 | }
|
---|
| 176 |
|
---|
| 177 | #endif
|
---|