Coverage Report

Created: 2025-07-18 07:04

/src/ogre/OgreMain/include/OgreArchive.h
Line
Count
Source (jump to first uncovered line)
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-2014 Torus Knot Software Ltd
8
9
Permission is hereby granted, free of charge, to any person obtaining a copy
10
of this software and associated documentation files (the "Software"), to deal
11
in the Software without restriction, including without limitation the rights
12
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
copies of the Software, and to permit persons to whom the Software is
14
furnished to do so, subject to the following conditions:
15
16
The above copyright notice and this permission notice shall be included in
17
all copies or substantial portions of the Software.
18
19
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
THE SOFTWARE.
26
-----------------------------------------------------------------------------
27
*/
28
#ifndef _Archive_H__
29
#define _Archive_H__
30
31
#include "OgrePrerequisites.h"
32
#include "OgreDataStream.h"
33
#include "OgreStringVector.h"
34
#include <ctime>
35
#include "OgreHeaderPrefix.h"
36
37
namespace Ogre {
38
39
    /** \addtogroup Core
40
    *  @{
41
    */
42
    /** \addtogroup Resources
43
    *  @{
44
    */
45
    /** Information about a file/directory within the archive will be
46
    returned using a FileInfo struct.
47
    @see
48
    Archive
49
    */
50
    struct FileInfo {
51
        /// The archive in which the file has been found (for info when performing
52
        /// multi-Archive searches, note you should still open through ResourceGroupManager)
53
        const Archive* archive;
54
        /// The file's fully qualified name
55
        String filename;
56
        /// Path name; separated by '/' and ending with '/'
57
        String path;
58
        /// Base filename
59
        String basename;
60
        /// Compressed size
61
        size_t compressedSize;
62
        /// Uncompressed size
63
        size_t uncompressedSize;
64
    };
65
66
    typedef std::vector<FileInfo> FileInfoList;
67
    typedef SharedPtr<FileInfoList> FileInfoListPtr;
68
69
    /** Archive-handling class.
70
71
        An archive is a generic term for a container of files. This may be a
72
        filesystem folder, it may be a compressed archive, it may even be 
73
        a remote location shared on the web. This class is designed to be 
74
        subclassed to provide access to a range of file locations. 
75
    @par
76
        Instances of this class are never constructed or even handled by end-user
77
        applications. They are constructed by custom ArchiveFactory classes, 
78
        which plugins can register new instances of using ArchiveManager. 
79
        End-user applications will typically use ResourceManager or 
80
        ResourceGroupManager to manage resources at a higher level, rather than 
81
        reading files directly through this class. Doing it this way allows you
82
        to benefit from OGRE's automatic searching of multiple file locations 
83
        for the resources you are looking for.
84
    */
85
    class _OgreExport Archive : public ArchiveAlloc
86
    {
87
    protected:
88
        /// Archive name
89
        String mName; 
90
        /// Archive type code
91
        String mType;
92
        /// Read-only flag
93
        bool mReadOnly;
94
    public:
95
96
97
        /** Constructor - don't call direct, used by ArchiveFactory.
98
        */
99
        Archive( const String& name, const String& archType )
100
            : mName(name), mType(archType), mReadOnly(true) {}
101
102
        /** Default destructor.
103
        */
104
        virtual ~Archive() {}
105
106
        /// Get the name of this archive
107
0
        const String& getName(void) const { return mName; }
108
109
        /// Returns whether this archive is case sensitive in the way it matches files
110
        virtual bool isCaseSensitive(void) const = 0;
111
112
        /** Loads the archive.
113
114
            This initializes all the internal data of the class.
115
        @warning
116
            Do not call this function directly, it is meant to be used
117
            only by the ArchiveManager class.
118
        */
119
        virtual void load() = 0;
120
121
        /** Unloads the archive.
122
        @warning
123
            Do not call this function directly, it is meant to be used
124
            only by the ArchiveManager class.
125
        */
126
        virtual void unload() = 0;
127
128
        /** Reports whether this Archive is read-only, or whether the contents
129
            can be updated. 
130
        */
131
0
        virtual bool isReadOnly() const { return mReadOnly; }
132
133
        /** Open a stream on a given file. 
134
        @note
135
            There is no equivalent 'close' method; the returned stream
136
            controls the lifecycle of this file operation.
137
        @param filename The fully qualified name of the file
138
        @param readOnly Whether to open the file in read-only mode or not (note, 
139
            if the archive is read-only then this cannot be set to false)
140
        @return A shared pointer to a DataStream which can be used to 
141
            read / write the file. If the file is not present, returns a null
142
            shared pointer.
143
        */
144
        virtual DataStreamPtr open(const String& filename, bool readOnly = true) const = 0;
145
146
        /** Create a new file (or overwrite one already there). 
147
        @note If the archive is read-only then this method will fail.
148
        @param filename The fully qualified name of the file
149
        @return A shared pointer to a DataStream which can be used to 
150
        read / write the file. 
151
        */
152
        virtual DataStreamPtr create(const String& filename);
153
154
        /** Delete a named file.
155
        @remarks Not possible on read-only archives
156
        @param filename The fully qualified name of the file
157
        */
158
        virtual void remove(const String& filename);
159
160
        /** List all file names in the archive.
161
        @note
162
            This method only returns filenames, you can also retrieve other
163
            information using listFileInfo.
164
        @param recursive Whether all paths of the archive are searched (if the 
165
            archive has a concept of that)
166
        @param dirs Set to true if you want the directories to be listed
167
            instead of files
168
        @return A list of filenames matching the criteria, all are fully qualified
169
        */
170
        virtual StringVectorPtr list(bool recursive = true, bool dirs = false) const = 0;
171
        
172
        /** List all files in the archive with accompanying information.
173
        @param recursive Whether all paths of the archive are searched (if the 
174
            archive has a concept of that)
175
        @param dirs Set to true if you want the directories to be listed
176
            instead of files
177
        @return A list of structures detailing quite a lot of information about
178
            all the files in the archive.
179
        */
180
        virtual FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false) const = 0;
181
182
        /** Find all file or directory names matching a given pattern
183
            in this archive.
184
        @note
185
            This method only returns filenames, you can also retrieve other
186
            information using findFileInfo.
187
        @param pattern The pattern to search for; wildcards (*) are allowed
188
        @param recursive Whether all paths of the archive are searched (if the 
189
            archive has a concept of that)
190
        @param dirs Set to true if you want the directories to be listed
191
            instead of files
192
        @return A list of filenames matching the criteria, all are fully qualified
193
        */
194
        virtual StringVectorPtr find(const String& pattern, bool recursive = true,
195
            bool dirs = false) const = 0;
196
197
        /** Find out if the named file exists (note: fully qualified filename required) */
198
        virtual bool exists(const String& filename) const = 0;
199
200
        /** Retrieve the modification time of a given file */
201
        virtual time_t getModifiedTime(const String& filename) const = 0;
202
203
204
        /** Find all files or directories matching a given pattern in this
205
            archive and get some detailed information about them.
206
        @param pattern The pattern to search for; wildcards (*) are allowed
207
        @param recursive Whether all paths of the archive are searched (if the 
208
        archive has a concept of that)
209
        @param dirs Set to true if you want the directories to be listed
210
            instead of files
211
        @return A list of file information structures for all files matching 
212
            the criteria.
213
        */
214
        virtual FileInfoListPtr findFileInfo(const String& pattern, 
215
            bool recursive = true, bool dirs = false) const = 0;
216
217
        /// Return the type code of this Archive
218
0
        const String& getType(void) const { return mType; }
219
        
220
    };
221
    /** @} */
222
    /** @} */
223
224
}
225
226
#include "OgreHeaderSuffix.h"
227
228
#endif