1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2021, assimp team
7 
8 
9 
10 All rights reserved.
11 
12 Redistribution and use of this software in source and binary forms,
13 with or without modification, are permitted provided that the following
14 conditions are met:
15 
16 * Redistributions of source code must retain the above
17   copyright notice, this list of conditions and the
18   following disclaimer.
19 
20 * Redistributions in binary form must reproduce the above
21   copyright notice, this list of conditions and the
22   following disclaimer in the documentation and/or other
23   materials provided with the distribution.
24 
25 * Neither the name of the assimp team, nor the names of its
26   contributors may be used to endorse or promote products
27   derived from this software without specific prior
28   written permission of the assimp team.
29 
30 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 ---------------------------------------------------------------------------
42 */
43 
44 /** @file ZipArchiveIOSystem.h
45  *  @brief Implementation of IOSystem to read a ZIP file from another IOSystem
46 */
47 
48 #pragma once
49 #ifndef AI_ZIPARCHIVEIOSYSTEM_H_INC
50 #define AI_ZIPARCHIVEIOSYSTEM_H_INC
51 
52 #ifdef __GNUC__
53 #   pragma GCC system_header
54 #endif
55 
56 #include <assimp/IOStream.hpp>
57 #include <assimp/IOSystem.hpp>
58 
59 namespace Assimp {
60 
61 class ZipArchiveIOSystem : public IOSystem {
62 public:
63     //! Open a Zip using the proffered IOSystem
64     ZipArchiveIOSystem(IOSystem* pIOHandler, const char *pFilename, const char* pMode = "r");
65     ZipArchiveIOSystem(IOSystem* pIOHandler, const std::string& rFilename, const char* pMode = "r");
66     virtual ~ZipArchiveIOSystem();
67     bool Exists(const char* pFilename) const override;
68     char getOsSeparator() const override;
69     IOStream* Open(const char* pFilename, const char* pMode = "rb") override;
70     void Close(IOStream* pFile) override;
71 
72     // Specific to ZIP
73     //! The file was opened and is a ZIP
74     bool isOpen() const;
75 
76     //! Get the list of all files with their simplified paths
77     //! Intended for use within Assimp library boundaries
78     void getFileList(std::vector<std::string>& rFileList) const;
79 
80     //! Get the list of all files with extension (must be lowercase)
81     //! Intended for use within Assimp library boundaries
82     void getFileListExtension(std::vector<std::string>& rFileList, const std::string& extension) const;
83 
84     static bool isZipArchive(IOSystem* pIOHandler, const char *pFilename);
85     static bool isZipArchive(IOSystem* pIOHandler, const std::string& rFilename);
86 
87 private:
88     class Implement;
89     Implement *pImpl = nullptr;
90 };
91 
92 } // Namespace Assimp
93 
94 #endif // AI_ZIPARCHIVEIOSYSTEM_H_INC
95