DataInstaller.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 <string>
  17. #include <vector>
  18. #include <iostream>
  19. #include "common/VGearsApplication.h"
  20. #include "FieldDataInstaller.h"
  21. #include "KernelDataInstaller.h"
  22. #include "MediaDataInstaller.h"
  23. #include "ModelsAndAnimationsDb.h"
  24. /**
  25. * The data installer.
  26. */
  27. class DataInstaller{
  28. public:
  29. /**
  30. * Advanced options available in the installer.
  31. */
  32. struct AdvancedOptions{
  33. /**
  34. * Option to skip kernel data installation.
  35. */
  36. bool skip_kernel;
  37. /**
  38. * Option to skip image installation.
  39. */
  40. bool skip_images;
  41. /**
  42. * Option to skip sound effects installation.
  43. */
  44. bool skip_sounds;
  45. /**
  46. * Option to skip music tracks installation.
  47. */
  48. bool skip_music;
  49. /**
  50. * Option to skip field maps installation.
  51. */
  52. bool skip_fields;
  53. /**
  54. * Option to skip field models installation.
  55. */
  56. bool skip_field_models;
  57. /**
  58. * Option to keep original data after installation.
  59. */
  60. bool keep_originals;
  61. /**
  62. * Option to avoid calls to the ffmpeg executable.
  63. */
  64. bool no_ffmpeg;
  65. /**
  66. * Option to avoid calls to the timidity executable
  67. */
  68. bool no_timidity;
  69. };
  70. /**
  71. * The scale factor for line point coordinates.
  72. *
  73. * When a LINE opcode is found in the game scripts, the line points X and Y coordinates
  74. * must be scaled down by this factor.
  75. */
  76. static float LINE_SCALE_FACTOR;
  77. /**
  78. * Installer constructor
  79. *
  80. * @param[in] input_dir Path to the directory containing the original data to parse.
  81. * @param[in] output_dir Path to the directory to write generated data to.
  82. * @param[in] options Adavanced options for the installer.
  83. * @param[in] write_output_line Pointer to function to write output.
  84. */
  85. DataInstaller(
  86. const std::string input_dir, const std::string output_dir, AdvancedOptions options,
  87. std::function<void(std::string, int, bool)> write_output_line
  88. );
  89. /**
  90. * Installer destructor.
  91. */
  92. ~DataInstaller();
  93. /**
  94. * Handle the installation progress.
  95. *
  96. * @return Installation progress [0-100].
  97. */
  98. float Progress();
  99. private:
  100. /**
  101. * Calculates the installation progress.
  102. *
  103. * @return Installation progress [0-100]
  104. */
  105. const float CalcProgress();
  106. /**
  107. * Creates a directory in the outputh path.
  108. *
  109. * @param[in] dir Path of the directory to create, relative to the output path.
  110. * @throws std::runtime_error If the directory can't be created.
  111. */
  112. void CreateDir(const std::string& dir);
  113. /**
  114. * Creates all directories required for the installation.
  115. *
  116. * It also adds certain location to the resource group manager.
  117. */
  118. void CreateDirectories();
  119. /**
  120. * Cleans up after the installation is complete.
  121. */
  122. void CleanInstall();
  123. /**
  124. * Installation steps.
  125. */
  126. enum InstallationSteps{
  127. /**
  128. * Installation not started.
  129. */
  130. IDLE = 0,
  131. /**
  132. * Create all directories required for the installation.
  133. */
  134. CREATE_DIRECTORIES,
  135. /**
  136. * Initialize data for installation.
  137. */
  138. INITIALIZE,
  139. /**
  140. * Parses item and materia prices from ff7.exe.
  141. */
  142. KERNEL_PRICES,
  143. /**
  144. * Parses command data from KERNEL.BIN.
  145. */
  146. KERNEL_COMMANDS,
  147. /**
  148. * Parses attack data from KERNEL.BIN.
  149. */
  150. KERNEL_ATTACKS,
  151. /**
  152. * Parses characters data from KERNEL.BIN.
  153. */
  154. KERNEL_CHARACTERS,
  155. /**
  156. * Parses item data from KERNEL.BIN.
  157. */
  158. KERNEL_ITEMS,
  159. /**
  160. * Parses growth data from KERNEL.BIN.
  161. */
  162. KERNEL_GROWTH,
  163. /**
  164. * Parses weapon data from KERNEL.BIN.
  165. */
  166. KERNEL_WEAPONS,
  167. /**
  168. * Parses armor data from KERNEL.BIN.
  169. */
  170. KERNEL_ARMORS,
  171. /**
  172. * Parses accessory data from KERNEL.BIN.
  173. */
  174. KERNEL_ACCESSORIES,
  175. /**
  176. * Parses materia data from KERNEL.BIN.
  177. */
  178. KERNEL_MATERIA,
  179. /**
  180. * Parses key item data data from KERNEL.BIN.
  181. */
  182. KERNEL_KEY_ITEMS,
  183. /**
  184. * Parses summon names data from KERNEL.BIN.
  185. */
  186. KERNEL_SUMMON_NAMES,
  187. /**
  188. * Parses the initial savemap from KERNEL.BIN.
  189. */
  190. KERNEL_SAVEMAP,
  191. /**
  192. * Extract game images and icons from menu.lgp.
  193. */
  194. MEDIA_IMAGES,
  195. /**
  196. * Prepares the installer for sound extraction.
  197. */
  198. MEDIA_SOUNDS_INIT,
  199. /**
  200. * Extract game sounds.
  201. */
  202. MEDIA_SOUNDS,
  203. /**
  204. * Build sounds index.
  205. */
  206. MEDIA_SOUNDS_INDEX,
  207. /**
  208. * Prepares the installer for music extraction.
  209. */
  210. MEDIA_MUSICS_INIT,
  211. /**
  212. * Extracts the game music.
  213. */
  214. MEDIA_MUSICS,
  215. /**
  216. * Extracts the game high quality music.
  217. */
  218. MEDIA_MUSICS_HQ,
  219. /**
  220. * Build the music index.
  221. */
  222. MEDIA_MUSICS_INDEX,
  223. /**
  224. * Initializer for {@see SPAWN_POINTS_AND_SCALE_FACTORS}.
  225. */
  226. FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT,
  227. /**
  228. * Step that collects spawn points and sclae factors.
  229. */
  230. FIELD_SPAWN_POINTS_AND_SCALE_FACTORS,
  231. /**
  232. * Step that convets fields to V-Gears format.
  233. */
  234. FIELD_CONVERT,
  235. /**
  236. * Initializer for {@see WRITE_MAPS}.
  237. */
  238. FIELD_WRITE_INIT,
  239. /**
  240. * Step that writes XML maps.
  241. */
  242. FIELD_WRITE,
  243. /**
  244. * Clean up after {@see WRITE_MAPS}.
  245. */
  246. FIELD_WRITE_END,
  247. /**
  248. * Initializer for {@see CONVERT_FIELD_MODELS}.
  249. */
  250. FIELD_CONVERT_MODELS_INIT,
  251. /**
  252. * Step that converts field models.
  253. */
  254. FIELD_CONVERT_MODELS,
  255. /**
  256. * Cleans up after the installation.
  257. */
  258. CLEAN,
  259. /**
  260. * Number of installation steps.
  261. */
  262. STATE_COUNT,
  263. /**
  264. * Installation finished.
  265. */
  266. DONE = 100,
  267. };
  268. /**
  269. * Current installation status.
  270. */
  271. InstallationSteps installation_state_ = IDLE;
  272. /**
  273. * Substeps in the current installation step.
  274. */
  275. int substeps_;
  276. /**
  277. * Current substep in the current installation step.
  278. */
  279. int cur_substep_;
  280. /**
  281. * Weight of each installation step.
  282. *
  283. * Used to calculate current progress.
  284. */
  285. int step_weight_[STATE_COUNT];
  286. /**
  287. * List of field model names.
  288. */
  289. std::vector<std::string> field_model_names_;
  290. /**
  291. * The path to the directory from which to read the PC game data.
  292. */
  293. std::string input_dir_;
  294. /**
  295. * The path to the directory where to save the V-Gears data.
  296. */
  297. std::string output_dir_;
  298. /**
  299. * Advanced options.
  300. */
  301. AdvancedOptions options_;
  302. /**
  303. * The installer application.
  304. *
  305. * It's a singleton so it can't be recreated. It will crash the second
  306. * time round.
  307. */
  308. VGears::Application application_;
  309. /**
  310. * LGP archive with field data.
  311. */
  312. std::unique_ptr<ScopedLgp> fields_lgp_;
  313. /**
  314. * The installer for fiel maps data.
  315. */
  316. std::unique_ptr<FieldDataInstaller> field_installer_;
  317. /**
  318. * The installer for kernel data.
  319. */
  320. std::unique_ptr<KernelDataInstaller> kernel_installer_;
  321. /**
  322. * The installer for media files.
  323. */
  324. std::unique_ptr<MediaDataInstaller> media_installer_;
  325. /**
  326. * Function used to print text to the log output, line by line.
  327. *
  328. * @param[in] msg the message to write.
  329. * @param[in] level Log level for the message.
  330. * @param[in] as_progress If true, the text will also be set as the current text behind the
  331. * progress bar.
  332. */
  333. std::function<void(std::string msg, int level, bool progress)> write_output_line_;
  334. };