Q3BSPZipArchive.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. #ifndef AI_Q3BSP_ZIPARCHIVE_H_INC
  34. #define AI_Q3BSP_ZIPARCHIVE_H_INC
  35. #include <contrib/unzip/unzip.h>
  36. #include <assimp/IOStream.hpp>
  37. #include <assimp/IOSystem.hpp>
  38. #include <string>
  39. #include <vector>
  40. #include <map>
  41. #include <cassert>
  42. namespace Assimp {
  43. namespace Q3BSP {
  44. // ------------------------------------------------------------------------------------------------
  45. /// \class IOSystem2Unzip
  46. /// \ingroup Assimp::Q3BSP
  47. ///
  48. /// \brief
  49. // ------------------------------------------------------------------------------------------------
  50. class IOSystem2Unzip {
  51. public:
  52. static voidpf open(voidpf opaque, const char* filename, int mode);
  53. static uLong read(voidpf opaque, voidpf stream, void* buf, uLong size);
  54. static uLong write(voidpf opaque, voidpf stream, const void* buf, uLong size);
  55. static long tell(voidpf opaque, voidpf stream);
  56. static long seek(voidpf opaque, voidpf stream, uLong offset, int origin);
  57. static int close(voidpf opaque, voidpf stream);
  58. static int testerror(voidpf opaque, voidpf stream);
  59. static zlib_filefunc_def get(IOSystem* pIOHandler);
  60. };
  61. // ------------------------------------------------------------------------------------------------
  62. /// \class ZipFile
  63. /// \ingroup Assimp::Q3BSP
  64. ///
  65. /// \brief
  66. // ------------------------------------------------------------------------------------------------
  67. class ZipFile : public IOStream {
  68. friend class Q3BSPZipArchive;
  69. public:
  70. explicit ZipFile(size_t size);
  71. ~ZipFile();
  72. size_t Read(void* pvBuffer, size_t pSize, size_t pCount );
  73. size_t Write(const void* /*pvBuffer*/, size_t /*pSize*/, size_t /*pCount*/);
  74. size_t FileSize() const;
  75. aiReturn Seek(size_t /*pOffset*/, aiOrigin /*pOrigin*/);
  76. size_t Tell() const;
  77. void Flush();
  78. private:
  79. void* m_Buffer;
  80. size_t m_Size;
  81. };
  82. // ------------------------------------------------------------------------------------------------
  83. /// \class Q3BSPZipArchive
  84. /// \ingroup Assimp::Q3BSP
  85. ///
  86. /// \brief IMplements a zip archive like the WinZip archives. Will be also used to import data
  87. /// from a P3K archive ( Quake level format ).
  88. // ------------------------------------------------------------------------------------------------
  89. class Q3BSPZipArchive : public Assimp::IOSystem {
  90. public:
  91. static const unsigned int FileNameSize = 256;
  92. public:
  93. Q3BSPZipArchive(IOSystem* pIOHandler, const std::string & rFile);
  94. ~Q3BSPZipArchive();
  95. bool Exists(const char* pFile) const;
  96. char getOsSeparator() const;
  97. IOStream* Open(const char* pFile, const char* pMode = "rb");
  98. void Close(IOStream* pFile);
  99. bool isOpen() const;
  100. void getFileList(std::vector<std::string> &rFileList);
  101. private:
  102. bool mapArchive();
  103. private:
  104. unzFile m_ZipFileHandle;
  105. std::map<std::string, ZipFile*> m_ArchiveMap;
  106. };
  107. // ------------------------------------------------------------------------------------------------
  108. } // Namespace Q3BSP
  109. } // Namespace Assimp
  110. #endif // AI_Q3BSP_ZIPARCHIVE_H_INC