zip_manager.hpp 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SOURCE: https://github.com/wdas/partio/blob/main/src/lib/io/ZIP.h
  2. /*
  3. NOTE: This file was edited for purposes of compatibility with SuperTux.
  4. PARTIO SOFTWARE
  5. Copyright 2010 Disney Enterprises, Inc. All rights reserved
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are
  8. met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright
  12. notice, this list of conditions and the following disclaimer in
  13. the documentation and/or other materials provided with the
  14. distribution.
  15. * The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
  16. Studios" or the names of its contributors may NOT be used to
  17. endorse or promote products derived from this software without
  18. specific prior written permission from Walt Disney Pictures.
  19. Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
  20. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  21. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
  22. FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
  23. IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
  24. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED 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 DAMAGES.
  31. */
  32. #ifndef __ZIP__
  33. #define __ZIP__
  34. #include <fstream>
  35. #include <iostream>
  36. #include <map>
  37. #include <string>
  38. #include <stdexcept>
  39. #include <vector>
  40. namespace Partio{
  41. struct ZipFileHeader;
  42. //#####################################################################
  43. // Functions Gzip_Out/Gzip_In - Create streams that read/write .gz
  44. //#####################################################################
  45. std::istream* Gzip_In(const std::string& filename,std::ios::openmode mode);
  46. std::ostream* Gzip_Out(const std::string& filename,std::ios::openmode mode);
  47. //#####################################################################
  48. // Class ZipFileWriter
  49. //#####################################################################
  50. class ZipFileWriter
  51. {
  52. std::ofstream ostream;
  53. std::vector<ZipFileHeader*> files;
  54. public:
  55. //#####################################################################
  56. ZipFileWriter(const std::string& filename);
  57. virtual ~ZipFileWriter();
  58. std::unique_ptr<std::ostream> Add_File(const std::string& filename,const bool binary=true);
  59. //#####################################################################
  60. };
  61. //#####################################################################
  62. // Class ZipFileReader
  63. //#####################################################################
  64. class ZipFileReader
  65. {
  66. std::ifstream istream;
  67. public:
  68. std::map<std::string,ZipFileHeader*> filename_to_header;
  69. //#####################################################################
  70. ZipFileReader(const std::string& filename);
  71. virtual ~ZipFileReader();
  72. std::unique_ptr<std::istream> Get_File(const std::string& filename,const bool binary=true);
  73. void Get_File_List(std::vector<std::string>& filenames) const;
  74. private:
  75. bool Find_And_Read_Central_Header();
  76. //#####################################################################
  77. };
  78. }
  79. #endif