BinGZipFile.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include "common/File.h"
  17. /**
  18. * Handles GZip-compressed BIn files.
  19. */
  20. class BinGZipFile : public File{
  21. public:
  22. /**
  23. * Constructor.
  24. *
  25. * @param[in] file Path to the BIN file.
  26. */
  27. BinGZipFile(const Ogre::String& file);
  28. /**
  29. * Constructor.
  30. *
  31. * @param[in] file The BIN file.
  32. */
  33. BinGZipFile(File* file);
  34. /**
  35. * Constructor.
  36. *
  37. * @param[in] file The BIN file.
  38. * @param[in] offset The offset at which to start reading the file.
  39. * @param[in] length Length of the data to read.
  40. */
  41. BinGZipFile(File* file, u32 offset, u32 length);
  42. /**
  43. * Constructor.
  44. *
  45. * @param[in] buffer Buffer with the contents of the BIN file.
  46. * @param[in] offset The offset at which to start reading the file.
  47. * @param[in] length Length of the data to read.
  48. */
  49. BinGZipFile(u8* buffer, u32 offset, u32 length);
  50. /**
  51. * Destructor.
  52. */
  53. virtual ~BinGZipFile();
  54. /**
  55. * Extracts a file from the compressed BIN file.
  56. *
  57. * @param[in] file_index The index of the file to extract.
  58. * @return The extracted file, or NULL if there is no file at the
  59. * specified index.
  60. */
  61. File* ExtractGZip(u32 file_index);
  62. /**
  63. * Counts the number of files packed in the compressed BIN file.
  64. *
  65. * @return The number of files.
  66. */
  67. u32 GetNumberOfFiles();
  68. private:
  69. /**
  70. * Counts the number of packed files and sets {@see file_count_}.
  71. */
  72. void InnerGetNumberOfFiles();
  73. /**
  74. * Retrieves a file offset.
  75. *
  76. * @param[in] file_index The file which offset to calculate.
  77. * @return The offset to the specified file, or 0 if there is no such
  78. * file.
  79. */
  80. u32 InnerGetFileOffset(u32 file_index);
  81. /**
  82. * The number of files in the archive.
  83. */
  84. u32 file_count_;
  85. };