DiskImage.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 <functional>
  17. #include <memory>
  18. #include <string>
  19. /**
  20. * Information about a Final Fantasy VII disk image.
  21. */
  22. struct DiskImage{
  23. public:
  24. /**
  25. * The platform for which the disk image is for.
  26. */
  27. enum Platform{
  28. /** The disk image is for PC. */
  29. PLATFORM_PC,
  30. /** The disk image is for PS1. */
  31. PLATFORM_PS1,
  32. /** The disk image is for an unknown platform. */
  33. PLATFORM_UNKNOWN
  34. };
  35. /**
  36. * The region for which the disk image is for.
  37. */
  38. enum Region{
  39. /** The disk image is for Japan. */
  40. REGION_JAPAN,
  41. /** The disk image is for North America. */
  42. REGION_NORTH_AMERICA,
  43. /** The disk image is for Europe. */
  44. REGION_EUROPE,
  45. /** The disk image is for an unknown region. */
  46. REGION_UNKNOWN
  47. };
  48. /**
  49. * The language for which the disk image is in.
  50. */
  51. enum Language{
  52. /** The disk image is in Japanese. */
  53. LANGUAGE_JAPANESE,
  54. /** The disk image is in English. */
  55. LANGUAGE_ENGLISH,
  56. /** The disk image is in French. */
  57. LANGUAGE_FRENCH,
  58. /** The disk image is in Spanish. */
  59. LANGUAGE_SPANISH,
  60. /** The disk image is in German. */
  61. LANGUAGE_GERMAN,
  62. /** The disk image is in Italian. */
  63. LANGUAGE_ITALIAN,
  64. /** The disk image is for an unknown language. */
  65. LANGUAGE_UNKNOWN
  66. };
  67. /**
  68. * The disk for which the disk image corresponds to.
  69. */
  70. enum Disk{
  71. /** The disk image is for the install disk (PC only). */
  72. DISK_INSTALL,
  73. /** The disk image is for disk 1. */
  74. DISK_1,
  75. /** The disk image is for disk 2. */
  76. DISK_2,
  77. /** The disk image is for disk 3. */
  78. DISK_3,
  79. /** The disk image is for disk 4. */
  80. DISK_4,
  81. /** The disk image is for an unknown disk. */
  82. DISK_UNKNOWN
  83. };
  84. /**
  85. * Constructs a new disk image.
  86. */
  87. DiskImage();
  88. /**
  89. * Constructs a new disk image from an ISO path.
  90. *
  91. * @param[in] path The path to the ISO file.
  92. */
  93. DiskImage(std::string path);
  94. /**
  95. * Destroys the disk image.
  96. */
  97. ~DiskImage();
  98. /**
  99. * Gets the path to the disk image file.
  100. *
  101. * @return The path to the disk image file.
  102. */
  103. std::string const getPath();
  104. /**
  105. * Gets the human readable ID of the disk image.
  106. *
  107. * @return The ID of the disk image.
  108. */
  109. std::string const getId();
  110. /**
  111. * Gets the platform for which the disk image is intended.
  112. *
  113. * @return The platform of the disk image.
  114. */
  115. Platform const getPlatform();
  116. /**
  117. * Gets the region for which the disk image is intended.
  118. *
  119. * @return The region of the disk image.
  120. */
  121. Region const getRegion();
  122. /**
  123. * Gets the language for which the disk image is intended.
  124. *
  125. * @return The language of the disk image.
  126. */
  127. Language const getLanguage();
  128. /**
  129. * Gets the disk for which the disk image is intended.
  130. *
  131. * @return The disk of the disk image.
  132. */
  133. Disk const getDisk();
  134. /**
  135. * Checks if the disk image is a valid Final Fantasy VII release.
  136. *
  137. * @return True if the disk image is valid, false otherwise.
  138. */
  139. bool const isValid();
  140. /**
  141. * Checks if the disk image is a PC game disk (1, 2 or 3). They only have the videos of the game, so they
  142. * can't be installed like the install disk: use {@see extractVideos}.
  143. */
  144. bool const isVideoDisk();
  145. /**
  146. * Extracts the videos of a game disk.
  147. *
  148. * They are written to "<output_dir>/video/" with lower case names. Videos that already exist with the same
  149. * size (several disks have the same ones) are skipped.
  150. *
  151. * @param[in] output_dir Directory where the game data is installed (ending with '/').
  152. * @param[in] progress Receives the progress [0-100].
  153. * @param[in] log Receives messages. Those that start with "[ERROR]" are problems.
  154. * @param[out] extracted Number of videos copied. Optional.
  155. * @param[out] skipped Number of videos that were already installed. Optional.
  156. * @return True if every video was extracted.
  157. */
  158. bool extractVideos(
  159. const std::string& output_dir, const std::function<void(float)>& progress,
  160. const std::function<void(const std::string&)>& log, int* extracted = nullptr, int* skipped = nullptr
  161. );
  162. /**
  163. * Gets the error message for the disk image.
  164. *
  165. * @return The error message.
  166. */
  167. std::string const getErrorMessage();
  168. /**
  169. * Checks if the disk image is supported and tested in V-Gears.
  170. *
  171. * @return True if the disk image is supported, false otherwise.
  172. */
  173. bool const isSupported();
  174. /**
  175. * Gets a warning in case the disk image is not fully supported.
  176. *
  177. * @return The warning message.
  178. */
  179. std::string const getWarningMessage();
  180. /**
  181. * Gets the path where the content of the disk image has been extracted.
  182. *
  183. * @return The path to the extracted content, null if the content has
  184. * not been extracted yet.
  185. */
  186. std::string const getContentPath();
  187. /**
  188. * Extracts the disk image file to the specified output path. The files
  189. * will be extracted to the "original_data" subdirectory of the output
  190. * path.
  191. *
  192. * @param[in] installation_path The v-gears installation directory.
  193. * @return True if the extraction was successful, false otherwise.
  194. */
  195. bool extractImage(std::string installation_path);
  196. /**
  197. * Finds a file in the extracted content of the disk image.
  198. *
  199. * It handles differnt name cases and differnt path separators. It also
  200. * handles the case where the file is in a subdirectory of the extracted
  201. * content.
  202. *
  203. * @param[in] file_path The relative path to the file within the
  204. * extracted content.
  205. * @return A pointer to the full path of the matched file, or nullptr
  206. * if no matching file exists. If the image has not been extracted yet,
  207. * this function will always return nullptr.
  208. */
  209. std::unique_ptr<std::string> filePath(std::string file_path);
  210. private:
  211. /**
  212. * The path to the image file.
  213. */
  214. std::string path;
  215. /**
  216. * A human readable ID of the disk image.
  217. */
  218. std::string id;
  219. /**
  220. * The platform for which the disk image is intended.
  221. */
  222. Platform platform;
  223. /**
  224. * The region for which the disk image is intended.
  225. */
  226. Region region;
  227. /**
  228. * The language for which the disk image is intended.
  229. */
  230. Language language;
  231. /**
  232. * The disk for which the disk image is intended.
  233. */
  234. Disk disk;
  235. /**
  236. * Whether the disk image is valid.
  237. */
  238. bool valid;
  239. /**
  240. * Whether the disk image is supported.
  241. */
  242. bool supported;
  243. /**
  244. * The error message for the disk image. Empty if no error.
  245. */
  246. std::string error_message;
  247. /**
  248. * The warning message for the disk image. Empty if no warning.
  249. */
  250. std::string warning_message;
  251. /**
  252. * The path where the content has been extracted.
  253. */
  254. std::string content_path;
  255. /**
  256. * Whether the content has been extracted.
  257. */
  258. bool is_extracted;
  259. };