1
0

ungzip.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * ungzip.h
  3. * --------
  4. * Purpose: Header file for .gz loader
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "openmpt/base/Endian.hpp"
  12. #include "archive.h"
  13. OPENMPT_NAMESPACE_BEGIN
  14. #if defined(MPT_WITH_ZLIB) || defined(MPT_WITH_MINIZ)
  15. class CGzipArchive : public ArchiveBase
  16. {
  17. public:
  18. struct GZheader
  19. {
  20. uint8le magic1; // 0x1F
  21. uint8le magic2; // 0x8B
  22. uint8le method; // 0-7 = reserved, 8 = deflate
  23. uint8le flags; // See GZ_F* constants
  24. uint32le mtime; // UNIX time
  25. uint8le xflags; // Available for use by specific compression methods. We ignore this.
  26. uint8le os; // Which OS was used to compress the file? We also ignore this.
  27. };
  28. struct GZtrailer
  29. {
  30. uint32le crc32_; // CRC32 of decompressed data
  31. uint32le isize; // Size of decompressed data modulo 2^32
  32. };
  33. protected:
  34. enum MagicBytes
  35. {
  36. GZ_HMAGIC1 = 0x1F,
  37. GZ_HMAGIC2 = 0x8B,
  38. GZ_HMDEFLATE = 0x08,
  39. };
  40. enum HeaderFlags
  41. {
  42. GZ_FTEXT = 0x01, // File is probably ASCII text (who cares)
  43. GZ_FHCRC = 0x02, // CRC16 present
  44. GZ_FEXTRA = 0x04, // Extra fields present
  45. GZ_FNAME = 0x08, // Original filename present
  46. GZ_FCOMMENT = 0x10, // Comment is present
  47. GZ_FRESERVED = (~(GZ_FTEXT | GZ_FHCRC | GZ_FEXTRA | GZ_FNAME | GZ_FCOMMENT))
  48. };
  49. GZheader header;
  50. public:
  51. bool ExtractFile(std::size_t index) override;
  52. CGzipArchive(const FileReader &file);
  53. ~CGzipArchive() override;
  54. };
  55. MPT_BINARY_STRUCT(CGzipArchive::GZheader, 10)
  56. MPT_BINARY_STRUCT(CGzipArchive::GZtrailer, 8)
  57. #endif // MPT_WITH_ZLIB || MPT_WITH_MINIZ
  58. OPENMPT_NAMESPACE_END