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 __Zip_H__
29 #define __Zip_H__
30 
31 #include "OgrePrerequisites.h"
32 
33 #include "OgreArchive.h"
34 #include "OgreArchiveFactory.h"
35 #include "OgreHeaderPrefix.h"
36 #include "Threading/OgreThreadHeaders.h"
37 
38 struct AAssetManager;
39 
40 namespace Ogre {
41 
42     /** \addtogroup Core
43     *  @{
44     */
45     /** \addtogroup Resources
46     *  @{
47     */
48 
49     /** Specialisation to allow reading of files from a zip
50         format source archive.
51 
52         This archive format supports all archives compressed in the standard
53         zip format, including iD pk3 files.
54     */
55     class _OgreExport ZipArchiveFactory : public ArchiveFactory
56     {
57     public:
~ZipArchiveFactory()58         virtual ~ZipArchiveFactory() {}
59         /// @copydoc FactoryObj::getType
60         const String& getType(void) const;
61 
62         using ArchiveFactory::createInstance;
63 
64         Archive *createInstance( const String& name, bool readOnly );
65         /// @copydoc FactoryObj::destroyInstance
destroyInstance(Archive * ptr)66         void destroyInstance( Archive* ptr) { OGRE_DELETE ptr; }
67     };
68 
69     /** Specialisation of ZipArchiveFactory for embedded Zip files. */
70     class _OgreExport EmbeddedZipArchiveFactory : public ZipArchiveFactory
71     {
72     public:
73         EmbeddedZipArchiveFactory();
74         virtual ~EmbeddedZipArchiveFactory();
75         /// @copydoc FactoryObj::getType
76         const String& getType(void) const;
77 
78         using ArchiveFactory::createInstance;
79 
80         Archive *createInstance( const String& name, bool readOnly );
81 
82         /** a function type to decrypt embedded zip file
83         @param pos pos in file
84         @param buf current buffer to decrypt
85         @param len - length of buffer
86         @return success
87         */
88         typedef bool (*DecryptEmbeddedZipFileFunc)(size_t pos, void* buf, size_t len);
89 
90         /// Add an embedded file to the embedded file list
91         static void addEmbbeddedFile(const String& name, const uint8 * fileData,
92                         size_t fileSize, DecryptEmbeddedZipFileFunc decryptFunc);
93 
94         /// Remove an embedded file to the embedded file list
95         static void removeEmbbeddedFile(const String& name);
96 
97     };
98 
99 #if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
100     class APKZipArchiveFactory : public EmbeddedZipArchiveFactory
101     {
102     protected:
103         AAssetManager* mAssetMgr;
104     public:
APKZipArchiveFactory(AAssetManager * assetMgr)105         APKZipArchiveFactory(AAssetManager* assetMgr) : mAssetMgr(assetMgr) {}
~APKZipArchiveFactory()106         virtual ~APKZipArchiveFactory() {}
107 
108         /// @copydoc FactoryObj::getType
109         const String& getType(void) const;
110 
111         /// @copydoc ArchiveFactory::createInstance
112         Archive *createInstance( const String& name, bool readOnly );
113     };
114 #endif
115 
116     /** @} */
117     /** @} */
118 
119 }
120 
121 #include "OgreHeaderSuffix.h"
122 
123 #endif
124