QGearsLGPArchive.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 <OgreArchive.h>
  17. #include "common/TypeDefine.h"
  18. namespace QGears{
  19. /**
  20. * Handles LZS compressed archives.
  21. */
  22. class LGPArchive : public Ogre::Archive{
  23. public:
  24. /**
  25. * Constructor.
  26. *
  27. * @param name[in] Name for the archive.
  28. * @param arch_type[in] Archive type code.
  29. */
  30. LGPArchive(const String &name, const String &arch_type);
  31. /**
  32. * Destructor.
  33. */
  34. virtual ~LGPArchive();
  35. /**
  36. * Checks whether this archive is case sensitive.
  37. *
  38. * @return Always true.
  39. */
  40. bool isCaseSensitive() const{return true;}
  41. /**
  42. * Loads the archive.
  43. */
  44. void load();
  45. /**
  46. * Unloads the archive.
  47. */
  48. void unload();
  49. /**
  50. * Opens a stream on a LGP compressed file.
  51. *
  52. * @param filename[in] Path to open the stream on.
  53. * @param readOnly[in] TRue to open the stream in read-only mode,
  54. * false to allow writting.
  55. */
  56. Ogre::DataStreamPtr open(
  57. const String& filename, bool readOnly = true
  58. ) const;
  59. /**
  60. * Creates a new file (or overwrite one already there).
  61. *
  62. * If the archive is read-only then this method will fail.
  63. *
  64. * @param filename[in] Path to the file.
  65. */
  66. Ogre::DataStreamPtr create(const String& filename) const;
  67. /**
  68. * Deletes a named file.
  69. *
  70. * Not possible on read-only archives
  71. *
  72. * @param filename[in] Path to the file.
  73. */
  74. void remove(const String& filename) const;
  75. /**
  76. * Lists all file names in the archive.
  77. *
  78. * @param rercursive[in] Whether all paths of the archive are
  79. * to be searched (if the archive has a concept of that).
  80. * @param dirs[in] True to list only directories, false to list
  81. * only files.
  82. * @return A list of filenames matching the criteria, all fully
  83. * qualified.
  84. */
  85. Ogre::StringVectorPtr list(
  86. bool recursive = true, bool dirs = false
  87. ) const;
  88. /**
  89. * Lists all files in the archive with accompanying information.
  90. *
  91. * @param rercursive[in] Whether all paths of the archive are
  92. * to be searched (if the archive has a concept of that).
  93. * @param dirs[in] True to list only directories, false to list
  94. * only files.
  95. * @return A list of structures detailing quite a lot of
  96. * information about all the files in the archive.
  97. */
  98. Ogre::FileInfoListPtr listFileInfo(
  99. bool recursive = true, bool dirs = false
  100. ) const;
  101. /**
  102. * Finds all file or directory names matching a given pattern in the
  103. * archive.
  104. *
  105. * @param pattern[in] The pattern to search for; wildcards (*) are
  106. * allowed
  107. * @param recursive[in ]Whether all paths of the archive are
  108. * searched (if the archive has a concept of that).
  109. * @param dirs[in] True to list only directories, false to list
  110. * only files.
  111. * @return A list of filenames matching the criteria, all fully
  112. * qualified.
  113. */
  114. Ogre::StringVectorPtr find(
  115. const String& pattern, bool recursive = true, bool dirs = false
  116. ) const;
  117. /**
  118. * Finds all files or directories matching a given pattern in this
  119. * archive and get some detailed information about them.
  120. *
  121. * @param pattern[in] The pattern to search for; wildcards (*) are
  122. * allowed
  123. * @param recursive[in ]Whether all paths of the archive are
  124. * searched (if the archive has a concept of that).
  125. * @param dirs[in] True to list only directories, false to list
  126. * only files.
  127. * @return A list of file information structures for all files
  128. * matching the criteria.
  129. */
  130. Ogre::FileInfoListPtr findFileInfo(
  131. const String& pattern, bool recursive = true, bool dirs = false
  132. ) const;
  133. /**
  134. * checks if the named file exists.
  135. *
  136. * @param filename[in] Fully qualified filename.
  137. * @return True if FILENAME exists in the archive, false otherwise.
  138. */
  139. bool exists(const String& filename) const;
  140. /**
  141. * Retrieve the modification time of a given file.
  142. *
  143. * @param filename[in] Fully qualified filename.
  144. * @return Last-modified timestamp.
  145. */
  146. time_t getModifiedTime(const String& filename) const;
  147. /**
  148. * A file in a LGP archive.
  149. */
  150. struct FileEntry{
  151. /**
  152. * The file name.
  153. */
  154. String file_name;
  155. /**
  156. * The file offset from the beginning of the archive.
  157. */
  158. uint32 file_offset;
  159. /**
  160. * Unknown data.
  161. */
  162. uint8 unknown1;
  163. /**
  164. * Unknown data.
  165. */
  166. uint16 unknown2;
  167. /**
  168. * NAme of the data file
  169. */
  170. String datafile_name;
  171. /**
  172. * Size of the data, in bytes.
  173. */
  174. uint32 data_size;
  175. /**
  176. * Data offset.
  177. */
  178. uint32 data_offset;
  179. };
  180. typedef std::vector<FileEntry> FileList;
  181. /**
  182. * Retrieves the files in the archive.
  183. *
  184. * @return The list of files.
  185. */
  186. virtual FileList& GetFiles();
  187. protected:
  188. /**
  189. * Loads a LGP archive.
  190. *
  191. * @param lgp[in] The contents of the archive.
  192. */
  193. void Load(Ogre::DataStream* lgp);
  194. private:
  195. /**
  196. * List of file sin the archive.
  197. */
  198. FileList files_;
  199. /**
  200. * The LGP archive file.
  201. */
  202. Ogre::DataStreamPtr lgp_file_;
  203. /**
  204. * List of information blocks about about the files in the LGP.
  205. */
  206. Ogre::FileInfoList file_infos_;
  207. };
  208. }