zip_manager.hpp 3.7 KB

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