DataInstaller.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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. #include <QtCore/QDir>
  16. #include <boost/filesystem.hpp>
  17. #include "DataInstaller.h"
  18. #include "InstallLayout.h"
  19. #include "InstallLog.h"
  20. #include "DiskImage.h"
  21. float DataInstaller::LINE_SCALE_FACTOR = 0.0078124970964f;
  22. DataInstaller::DataInstaller(
  23. const DiskImage& disk_image, const std::string output_dir, AdvancedOptions options,
  24. std::function<void(std::string, int, bool)> write_output_line
  25. )
  26. #ifdef _DEBUG
  27. : application_("plugins_d.cfg", "resources_d.cfg", "install_d.log"),
  28. #else
  29. : application_("plugins.cfg", "resources.cfg", "install.log"),
  30. #endif
  31. disk_image_(disk_image), output_dir_(output_dir), data_dir_(InstallLayout::DataDir(output_dir)),
  32. options_(options), write_output_line_(write_output_line)
  33. {
  34. if (!application_.initOgre(true)) throw std::runtime_error("Ogre init failure");
  35. Ogre::Log* default_log(Ogre::LogManager::getSingleton().getDefaultLog());
  36. assert( default_log );
  37. default_log->setLogDetail(Ogre::LL_LOW);
  38. // Assign weights.
  39. for (int i = IDLE; i < STATE_COUNT; i ++) step_weight_[i] = 1;
  40. step_weight_[IDLE] = 0;
  41. step_weight_[BATTLE_MODELS_CONVERT] = 2;
  42. step_weight_[SPELL_MODELS_CONVERT] = 2;
  43. step_weight_[EFFECT_MODELS_CONVERT] = 2;
  44. step_weight_[MEDIA_IMAGES] = 3;
  45. step_weight_[MEDIA_SOUNDS] = 8;
  46. step_weight_[MEDIA_MUSICS] = 9;
  47. step_weight_[MEDIA_MUSICS_HQ] = 2;
  48. step_weight_[FIELD_SPAWN_POINTS_AND_SCALE_FACTORS] = 3;
  49. step_weight_[FIELD_CONVERT] = 3;
  50. step_weight_[FIELD_WRITE] = 2;
  51. step_weight_[FIELD_CONVERT_MODELS] = 3;
  52. }
  53. DataInstaller::~DataInstaller(){}
  54. const char* DataInstaller::StepGroup(int state){
  55. if (state >= FIELD_CONVERT_MODELS_INIT && state <= FIELD_CONVERT_MODELS)
  56. return "Field models";
  57. if (state >= FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT && state <= FIELD_WRITE_END)
  58. return "Field maps";
  59. if (state == WM_MODELS) return "World map models";
  60. if (state >= WM_INIT && state <= WM_MAPS) return "World map";
  61. if (state >= MEDIA_VIDEOS && state < FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT)
  62. return "Videos";
  63. if (state >= MEDIA_MUSICS_INIT && state < MEDIA_VIDEOS) return "Music";
  64. if (state >= MEDIA_SOUNDS_INIT && state < MEDIA_MUSICS_INIT) return "Sounds";
  65. if (state == MEDIA_IMAGES) return "Images";
  66. if (state >= KERNEL_PRICES && state < MEDIA_IMAGES) return "Kernel data";
  67. if (state >= SPELL_MODELS_INIT && state < KERNEL_PRICES) return "Spell models";
  68. if (state >= BATTLE_MODELS_INIT && state < SPELL_MODELS_INIT) return "Battle models";
  69. if (state >= BATTLE_SCENES_INIT && state < BATTLE_MODELS_INIT) return "Battle data";
  70. if (state == CLEAN) return "Cleanup";
  71. return "Preparation";
  72. }
  73. float DataInstaller::Progress(){
  74. // Report each part of the installation separately in the log.
  75. const char* group = StepGroup(installation_state_);
  76. if (current_group_ != group){
  77. current_group_ = group;
  78. InstallLog::Get().BeginStep(group);
  79. }
  80. if (installation_state_ == DONE) InstallLog::Get().EndStep();
  81. switch (installation_state_){
  82. case IDLE:
  83. installation_state_ = CREATE_DIRECTORIES;
  84. return CalcProgress();
  85. case CREATE_DIRECTORIES:
  86. write_output_line_("Creating directories...", 2, true);
  87. CreateDirectories();
  88. installation_state_ = INITIALIZE;
  89. return CalcProgress();
  90. case INITIALIZE:{
  91. write_output_line_("Initializing installers...", 2, true);
  92. const auto input_dir = disk_image_.getContentPath();
  93. if (input_dir.empty()) throw std::runtime_error("Input data directory is empty");
  94. kernel_installer_ = std::make_unique<KernelDataInstaller>(disk_image_);
  95. media_installer_ = std::make_unique<MediaDataInstaller>(
  96. disk_image_, output_dir_, options_.keep_originals
  97. );
  98. field_installer_ = std::make_unique<FieldDataInstaller>(
  99. disk_image_, output_dir_, [this](std::string log_message){
  100. write_output_line_(log_message, 2, true);
  101. }
  102. );
  103. battle_installer_ = std::make_unique<BattleDataInstaller>(disk_image_, output_dir_, application_.ResMgr());
  104. world_installer_ = std::make_unique<WorldInstaller>(
  105. disk_image_, output_dir_, options_.keep_originals, application_.ResMgr()
  106. );
  107. installation_state_ = BATTLE_SCENES_INIT;
  108. return CalcProgress();
  109. }
  110. case BATTLE_SCENES_INIT:
  111. // Skip kernel data if option is set.
  112. if (!options_.battle_data){
  113. write_output_line_("Skipping battle data installation...", 2, true);
  114. installation_state_ = BATTLE_MODELS_INIT;
  115. return CalcProgress();
  116. }
  117. write_output_line_("Parsing battle scenes...", 2, true);
  118. substeps_ = battle_installer_->InitializeScenes();
  119. cur_substep_ = 0;
  120. installation_state_ = BATTLE_SCENES_PROCESS;
  121. return CalcProgress();
  122. case BATTLE_SCENES_PROCESS:
  123. cur_substep_ = battle_installer_->ProcessScene();
  124. if (cur_substep_ >= substeps_) installation_state_ = BATTLE_SCENES_WRITE_ATTACKS;
  125. return CalcProgress();
  126. case BATTLE_SCENES_WRITE_ATTACKS:
  127. write_output_line_("Saving attacks...", 2, true);
  128. cur_substep_ = 0;
  129. substeps_ = 0;
  130. battle_installer_->WriteAttacks();
  131. installation_state_ = BATTLE_SCENES_WRITE_ENEMIES;
  132. return CalcProgress();
  133. case BATTLE_SCENES_WRITE_ENEMIES:
  134. write_output_line_("Saving enemies...", 2, true);
  135. cur_substep_ = 0;
  136. substeps_ = 0;
  137. battle_installer_->WriteEnemies();
  138. installation_state_ = BATTLE_SCENES_WRITE_FORMATIONS;
  139. return CalcProgress();
  140. case BATTLE_SCENES_WRITE_FORMATIONS:
  141. write_output_line_("Saving enemy formations...", 2, true);
  142. cur_substep_ = 0;
  143. substeps_ = 0;
  144. battle_installer_->WriteFormations();
  145. // TODO: DEBUG
  146. installation_state_ = BATTLE_MODELS_INIT; // NORMAL
  147. //installation_state_ = SPELL_MODELS_INIT; // SKIP BATTLE MODELS
  148. return CalcProgress();
  149. case BATTLE_MODELS_INIT:
  150. // Skip kernel data if option is set.
  151. if (!options_.battle_models){
  152. write_output_line_("Skipping battle models installation...", 2, true);
  153. installation_state_ = KERNEL_PRICES;
  154. return CalcProgress();
  155. }
  156. write_output_line_("Extracting battle models...", 2, true);
  157. substeps_ = battle_installer_->InitializeBattleModels();
  158. cur_substep_ = 0;
  159. installation_state_ = BATTLE_MODELS_PROCESS;
  160. return CalcProgress();
  161. case BATTLE_MODELS_PROCESS:
  162. cur_substep_ = battle_installer_->ProcessBattleModel();
  163. if (cur_substep_ >= substeps_) installation_state_ = BATTLE_MODELS_CONVERT_INIT;
  164. return CalcProgress();
  165. case BATTLE_MODELS_CONVERT_INIT:
  166. cur_substep_ = 0;
  167. substeps_ = battle_installer_->ConvertBattleModelsInit();
  168. installation_state_ = BATTLE_MODELS_CONVERT;
  169. return CalcProgress();
  170. case BATTLE_MODELS_CONVERT:
  171. cur_substep_ = battle_installer_->ConvertBattleModel();
  172. if (cur_substep_ >= substeps_) installation_state_ = BATTLE_MODELS_WRITE_CHARACTERS;
  173. return CalcProgress();
  174. case BATTLE_MODELS_WRITE_CHARACTERS:
  175. write_output_line_("Writing character data...", 2, true);
  176. battle_installer_->WriteCharacterData();
  177. installation_state_ = BATTLE_MODELS_WRITE_SCENES;
  178. return CalcProgress();
  179. case BATTLE_MODELS_WRITE_SCENES:
  180. write_output_line_("Writing battle scene data...", 2, true);
  181. battle_installer_->WriteSceneData();
  182. installation_state_ = SPELL_MODELS_INIT;
  183. return CalcProgress();
  184. case SPELL_MODELS_INIT:
  185. write_output_line_("Extracting attack models...", 2, true);
  186. substeps_ = battle_installer_->InitializeSpellModels();
  187. cur_substep_ = 0;
  188. installation_state_ = SPELL_MODELS_PROCESS;
  189. return CalcProgress();
  190. case SPELL_MODELS_PROCESS:
  191. cur_substep_ = battle_installer_->ProcessSpellModel();
  192. if (cur_substep_ >= substeps_) installation_state_ = SPELL_MODELS_CONVERT_INIT;
  193. return CalcProgress();
  194. case SPELL_MODELS_CONVERT_INIT:
  195. cur_substep_ = 0;
  196. substeps_ = battle_installer_->ConvertSpellModelsInit();
  197. installation_state_ = SPELL_MODELS_CONVERT;
  198. return CalcProgress();
  199. case SPELL_MODELS_CONVERT:
  200. cur_substep_ = battle_installer_->ConvertSpellModel();
  201. if (cur_substep_ >= substeps_) installation_state_ = EFFECT_MODELS_INIT;
  202. return CalcProgress();
  203. case EFFECT_MODELS_INIT:
  204. write_output_line_("Extracting battle effects...", 2, true);
  205. substeps_ = battle_installer_->InitializeEffectModels();
  206. cur_substep_ = 0;
  207. installation_state_ = EFFECT_MODELS_CONVERT;
  208. return CalcProgress();
  209. case EFFECT_MODELS_CONVERT:
  210. cur_substep_ = battle_installer_->ConvertEffectModel();
  211. if (cur_substep_ >= substeps_){
  212. battle_installer_->WriteEffectModels();
  213. installation_state_ = KERNEL_PRICES;
  214. }
  215. return CalcProgress();
  216. case KERNEL_PRICES:
  217. // Skip kernel data if option is set.
  218. if (!options_.kernel){
  219. write_output_line_("Skipping kernel data installation...", 2, true);
  220. installation_state_ = MEDIA_SOUNDS_INIT;
  221. return CalcProgress();
  222. }
  223. write_output_line_("Parsing item and materia prices...", 2, true);
  224. kernel_installer_->ReadPrices();
  225. kernel_installer_->WriteShops(data_dir_ + "gamedata/shops.lua");
  226. installation_state_ = KERNEL_COMMANDS;
  227. return CalcProgress();
  228. case KERNEL_COMMANDS:
  229. write_output_line_("Extracting command data...", 2, true);
  230. kernel_installer_->ReadCommands();
  231. kernel_installer_->WriteCommands(data_dir_ + "gamedata/commands.lua");
  232. installation_state_ = KERNEL_ATTACKS;
  233. return CalcProgress();
  234. case KERNEL_ATTACKS:
  235. write_output_line_("Extracting attack data...", 2, true);
  236. kernel_installer_->ReadAttacks();
  237. kernel_installer_->WriteAttacks(data_dir_ + "gamedata/attacks.lua");
  238. installation_state_ = KERNEL_CHARACTERS;
  239. return CalcProgress();
  240. case KERNEL_CHARACTERS:
  241. write_output_line_("Extracting character data...", 2, true);
  242. kernel_installer_->ReadCharacters();
  243. kernel_installer_->WriteCharacters(data_dir_ + "gamedata/characters.lua");
  244. installation_state_ = KERNEL_ITEMS;
  245. return CalcProgress();
  246. case KERNEL_ITEMS:
  247. write_output_line_("Extracting item data...", 2, true);
  248. kernel_installer_->ReadItems();
  249. kernel_installer_->WriteItems(data_dir_ + "gamedata/items.lua");
  250. installation_state_ = KERNEL_GROWTH;
  251. return CalcProgress();
  252. case KERNEL_GROWTH:
  253. write_output_line_("Extracting growth data...", 2, true);
  254. kernel_installer_->ReadGrowth();
  255. kernel_installer_->WriteGrowth(data_dir_ + "gamedata/growth.lua");
  256. installation_state_ = KERNEL_WEAPONS;
  257. return CalcProgress();
  258. case KERNEL_WEAPONS:
  259. write_output_line_("Extracting weapon data...", 2, true);
  260. kernel_installer_->ReadWeapons();
  261. kernel_installer_->WriteWeapons(data_dir_ + "gamedata/weapons.lua");
  262. installation_state_ = KERNEL_ARMORS;
  263. return CalcProgress();
  264. case KERNEL_ARMORS:
  265. write_output_line_("Extracting armor data...", 2, true);
  266. kernel_installer_->ReadArmors();
  267. kernel_installer_->WriteArmors(data_dir_ + "gamedata/armors.lua");
  268. installation_state_ = KERNEL_ACCESSORIES;
  269. return CalcProgress();
  270. case KERNEL_ACCESSORIES:
  271. write_output_line_("Extracting accessory data...", 2, true);
  272. kernel_installer_->ReadAccessories();
  273. kernel_installer_->WriteAccessories(data_dir_ + "gamedata/accessories.lua");
  274. installation_state_ = KERNEL_MATERIA;
  275. return CalcProgress();
  276. case KERNEL_MATERIA:
  277. write_output_line_("Extracting materia data...", 2, true);
  278. kernel_installer_->ReadMateria();
  279. kernel_installer_->WriteMateria(data_dir_ + "gamedata/materia.lua");
  280. installation_state_ = KERNEL_KEY_ITEMS;
  281. return CalcProgress();
  282. case KERNEL_KEY_ITEMS:
  283. write_output_line_("Extracting key item data...", 2, true);
  284. kernel_installer_->ReadKeyItems();
  285. kernel_installer_->WriteKeyItems(data_dir_ + "gamedata/key_items.lua");
  286. installation_state_ = KERNEL_SUMMON_NAMES;
  287. return CalcProgress();
  288. case KERNEL_SUMMON_NAMES:
  289. write_output_line_("Extracting summon attack names data...", 2, true);
  290. kernel_installer_->ReadSummonNames();
  291. kernel_installer_->WriteSummonNames(data_dir_ + "gamedata/summons.lua");
  292. installation_state_ = KERNEL_SAVEMAP;
  293. return CalcProgress();
  294. case KERNEL_SAVEMAP:
  295. write_output_line_("Extracting the initial savemap...", 2, true);
  296. kernel_installer_->ReadInitialSaveMap();
  297. {
  298. auto exe_path = disk_image_.filePath("ff7.exe");
  299. if (exe_path) kernel_installer_->ReadRecruitRecords(*exe_path);
  300. else write_output_line_("ff7.exe not found, Cait Sith and Vincent won't have their data.", 2, true);
  301. }
  302. kernel_installer_->WriteInitialSaveMap(data_dir_ + "gamedata/initial_savemap.lua");
  303. installation_state_ = MEDIA_IMAGES;
  304. return CalcProgress();
  305. case MEDIA_IMAGES:
  306. // Skip images if option is set.
  307. if (!options_.images){
  308. write_output_line_("Skipping images installation...", 2, true);
  309. installation_state_ = MEDIA_SOUNDS_INIT;
  310. return CalcProgress();
  311. }
  312. write_output_line_("Extracting game images...", 2, true);
  313. media_installer_->InstallSprites();
  314. installation_state_ = MEDIA_SOUNDS_INIT;
  315. return CalcProgress();
  316. case MEDIA_SOUNDS_INIT:
  317. // Skip sounds if option is set.
  318. if (!options_.sounds){
  319. write_output_line_("Skipping sound effects installation...", 2, true);
  320. installation_state_ = MEDIA_MUSICS_INIT;
  321. return CalcProgress();
  322. }
  323. write_output_line_("Extracting sounds...", 2, true);
  324. substeps_ = media_installer_->InstallSoundsInit();
  325. installation_state_ = MEDIA_SOUNDS;
  326. cur_substep_ = 0;
  327. return CalcProgress();
  328. case MEDIA_SOUNDS:
  329. if (media_installer_->InstallSounds() == true) installation_state_ = MEDIA_SOUNDS_INDEX;
  330. else cur_substep_ ++;
  331. return CalcProgress();
  332. case MEDIA_SOUNDS_INDEX:
  333. // The index is written when the conversions, which run in the background, have finished.
  334. installation_state_ = MEDIA_MUSICS_INIT;
  335. return CalcProgress();
  336. case MEDIA_MUSICS_INIT:
  337. // Skip music if option is set.
  338. if (!options_.music){
  339. write_output_line_("Skipping music tracks installation...", 2, true);
  340. installation_state_ = FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT;
  341. return CalcProgress();
  342. }
  343. write_output_line_("Extracting music...", 2, true);
  344. substeps_ = media_installer_->InstallMusicsInit();
  345. installation_state_ = MEDIA_MUSICS;
  346. cur_substep_ = 0;
  347. return CalcProgress();
  348. case MEDIA_MUSICS:
  349. if (media_installer_->InstallMusics() == true) installation_state_ = MEDIA_MUSICS_HQ;
  350. else cur_substep_ ++;
  351. return CalcProgress();
  352. case MEDIA_MUSICS_HQ:
  353. substeps_ = 0;
  354. cur_substep_ = 0;
  355. media_installer_->InstallHQMusics();
  356. installation_state_ = MEDIA_MUSICS_INDEX;
  357. return CalcProgress();
  358. case MEDIA_MUSICS_INDEX:
  359. // The index is written when the conversions, which run in the background, have finished.
  360. installation_state_ = FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT;
  361. return CalcProgress();
  362. case MEDIA_VIDEOS:
  363. // Skip videos if option is set.
  364. if (!options_.videos){
  365. write_output_line_("Skipping video installation...", 2, true);
  366. installation_state_ = FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT;
  367. return CalcProgress();
  368. }
  369. write_output_line_("Extracting videos...", 2, true);
  370. media_installer_->InstallVideos();
  371. installation_state_ = FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT;
  372. return CalcProgress();
  373. case FIELD_SPAWN_POINTS_AND_SCALE_FACTORS_INIT:
  374. // Skip fields if option is set.
  375. if (!options_.fields && !options_.wm){
  376. write_output_line_("Skipping field maps installation...", 2, true);
  377. installation_state_ = WM_INIT;
  378. return CalcProgress();
  379. }
  380. // The world map scripts need the field list and scale factors even if the fields aren't converted.
  381. if (!options_.fields) write_output_line_("Collecting field data for the world map...", 2, true);
  382. else write_output_line_("Collecting spawn points and scale factors...", 2, true);
  383. substeps_ = field_installer_->CollectSpawnAndScaleFactorsInit(application_.ResMgr());
  384. cur_substep_ = 0;
  385. installation_state_ = FIELD_SPAWN_POINTS_AND_SCALE_FACTORS;
  386. return CalcProgress();
  387. case FIELD_SPAWN_POINTS_AND_SCALE_FACTORS:
  388. field_installer_->CollectSpawnAndScaleFactors(cur_substep_);
  389. cur_substep_ ++;
  390. if (cur_substep_ == substeps_){
  391. cur_substep_ = 0;
  392. if (options_.fields) installation_state_ = FIELD_CONVERT;
  393. else{
  394. // Fields are not converted: use the ones already installed.
  395. write_output_line_("Skipping field maps installation...", 2, true);
  396. field_installer_->LoadInstalledFields();
  397. installation_state_ = WM_INIT;
  398. }
  399. }
  400. return CalcProgress();
  401. case FIELD_CONVERT:
  402. field_installer_->Convert(cur_substep_);
  403. cur_substep_ ++;
  404. if (cur_substep_ == substeps_){
  405. installation_state_ = FIELD_WRITE_INIT;
  406. cur_substep_ = 0;
  407. }
  408. return CalcProgress();
  409. case FIELD_WRITE_INIT:
  410. write_output_line_("Writing fields...", 2, true);
  411. substeps_ = field_installer_->WriteInit();
  412. cur_substep_ = 0;
  413. installation_state_ = FIELD_WRITE;
  414. return CalcProgress();
  415. case FIELD_WRITE:
  416. field_installer_->Write(cur_substep_);
  417. cur_substep_ ++;
  418. if (cur_substep_ == substeps_){
  419. installation_state_ = FIELD_WRITE_END;
  420. cur_substep_ = 0;
  421. }
  422. return CalcProgress();
  423. case FIELD_WRITE_END:
  424. field_installer_->WriteEnd();
  425. installation_state_ = FIELD_CONVERT_MODELS_INIT;
  426. return CalcProgress();
  427. case FIELD_CONVERT_MODELS_INIT:
  428. // Skip fields if option is set.
  429. if (!options_.field_models){
  430. write_output_line_("Skipping field maps installation...", 2, true);
  431. installation_state_ = WM_INIT;
  432. return CalcProgress();
  433. }
  434. write_output_line_("Converting field models...", 2, true);
  435. field_model_names_ = field_installer_->ConvertModelsInit();
  436. substeps_ = field_model_names_.size();
  437. cur_substep_ = 0;
  438. installation_state_ = FIELD_CONVERT_MODELS;
  439. return CalcProgress();
  440. case FIELD_CONVERT_MODELS:
  441. field_installer_->ConvertModels(field_model_names_[cur_substep_]);
  442. cur_substep_ ++;
  443. if (cur_substep_ == substeps_){
  444. installation_state_ = WM_INIT;
  445. cur_substep_ = 0;
  446. }
  447. return CalcProgress();
  448. case WM_INIT:
  449. // Skip world map if option set
  450. if (!options_.wm){
  451. write_output_line_("Skipping world map data installation...", 2, true);
  452. installation_state_ = CLEAN;
  453. return CalcProgress();
  454. }
  455. write_output_line_("Extracting world map data...", 2, true);
  456. substeps_ = world_installer_->Initialize();
  457. cur_substep_ = 0;
  458. installation_state_ = WM_MATERIALS;
  459. return CalcProgress();
  460. case WM_MATERIALS:
  461. world_installer_->GenerateMaterials();
  462. installation_state_ = WM_MAPS;
  463. return CalcProgress();
  464. case WM_MAPS:
  465. if (world_installer_->ProcessMap() == false) cur_substep_ ++;
  466. else{
  467. std::string script_error;
  468. if (world_installer_->GenerateScripts(
  469. field_installer_->GetMapList(), field_installer_->GetFieldScaleFactors(),
  470. field_installer_->GetConvertedMapList(), script_error
  471. )){
  472. write_output_line_("Generated world-map scripts.", 2, true);
  473. }
  474. else{
  475. write_output_line_("Could not generate world-map scripts: " + script_error, 2, true);
  476. }
  477. installation_state_ = WM_MODELS;
  478. cur_substep_ = 0;
  479. }
  480. return CalcProgress();
  481. case WM_MODELS:
  482. if (!options_.wm_models) write_output_line_("Skipping world map model installation...", 2, true);
  483. else world_installer_->ProcessModels();
  484. installation_state_ = CLEAN;
  485. return CalcProgress();
  486. case CLEAN:
  487. // The audio conversions run in the background while the other steps are done.
  488. if (media_installer_){
  489. write_output_line_("Waiting for the audio conversions to finish...", 2, true);
  490. media_installer_->WaitForConversions();
  491. // Now the files that exist are known, so the indexes list only those.
  492. if (options_.sounds){
  493. write_output_line_("Building sound index...", 2, true);
  494. media_installer_->WriteSoundIndex();
  495. }
  496. if (options_.music){
  497. write_output_line_("Building music track index...", 2, true);
  498. media_installer_->WriteMusicsIndex();
  499. }
  500. }
  501. write_output_line_("Cleaning up...", 2, true);
  502. if (!options_.keep_originals) CleanInstall();
  503. installation_state_ = DONE;
  504. return CalcProgress();
  505. case DONE:
  506. write_output_line_("Installation complete", 2, true);
  507. return 100;
  508. default:
  509. return 100;
  510. }
  511. }
  512. const float DataInstaller::CalcProgress(){
  513. float weight_total = 0; // Sum of every step weight.
  514. float weight_done = 0; // Sum of every previous step weight.
  515. float weight = static_cast<float>(step_weight_[installation_state_]); // Weight of current step.
  516. float weight_substeps = 0; // Weight of the already done substeps in current step.
  517. for (int i = IDLE; i < STATE_COUNT; i ++){
  518. weight_total += step_weight_[i];
  519. if (installation_state_ > i) weight_done += step_weight_[i];
  520. }
  521. if (substeps_ > 0 && cur_substep_ < substeps_) weight_substeps = (cur_substep_ * weight) / substeps_;
  522. float progress = 100 * (weight_done + weight_substeps) / weight_total;
  523. if (progress >= 100.0f) progress = 99.9f;
  524. return progress;
  525. }
  526. void DataInstaller::CreateDirectories(){
  527. for (const std::string& dir : InstallLayout::DataSubdirs()) CreateDir(dir);
  528. CreateDir("temp", true);
  529. for (const std::string& dir : InstallLayout::TempSubdirs()) CreateDir("temp/" + dir, true);
  530. application_.ResMgr()->addResourceLocation(output_dir_ + "temp/char/", "FileSystem", "FFVII", true, true);
  531. application_.ResMgr()->addResourceLocation(output_dir_ + "temp/battle_models/", "FileSystem", "FFVII", true, true);
  532. application_.ResMgr()->addResourceLocation(output_dir_ + "temp/world_models/", "FileSystem", "FFVII", true, true);
  533. application_.ResMgr()->addResourceLocation(data_dir_ + "models/", "FileSystem", "FFVII", true, true);
  534. application_.ResMgr()->addResourceLocation(
  535. data_dir_ + "models/fields/", "FileSystem", "FFVIITextures", true, true
  536. );
  537. application_.ResMgr()->addResourceLocation(
  538. data_dir_ + "models/battle/characters/", "FileSystem", "FFVIITextures", true, true
  539. );
  540. application_.ResMgr()->addResourceLocation(
  541. data_dir_ + "models/battle/scenes/", "FileSystem", "FFVIITextures", true, true
  542. );
  543. application_.ResMgr()->addResourceLocation(
  544. data_dir_ + "models/battle/enemies/", "FileSystem", "FFVIITextures", true, true
  545. );
  546. application_.ResMgr()->addResourceLocation(
  547. data_dir_ + "models/battle/attacks/", "FileSystem", "FFVIITextures", true, true
  548. );
  549. application_.ResMgr()->addResourceLocation(
  550. data_dir_ + "models/world/", "FileSystem", "FFVIITextures", true, true
  551. );
  552. const auto fields_lgp_path = disk_image_.filePath("data/field/flevel.lgp");
  553. if (!fields_lgp_path) throw std::runtime_error("Missing required file: data/field/flevel.lgp");
  554. fields_lgp_ = std::make_unique<ScopedLgp>(application_.getRoot(), *fields_lgp_path, "LGP", "FFVIIFields");
  555. }
  556. void DataInstaller::CleanInstall(){
  557. // The game itself reads some of the temp directories, so only the rest are removed.
  558. for (const std::string& dir : InstallLayout::RemovableTempSubdirs())
  559. boost::filesystem::remove_all(InstallLayout::TempDir(output_dir_) + dir + "/");
  560. }
  561. void DataInstaller::CreateDir(const std::string& path, bool in_root){
  562. QString target = QString::fromStdString((in_root ? output_dir_ : data_dir_) + path);
  563. QDir dir(target);
  564. if (!dir.mkpath(".")) throw std::runtime_error("Failed to mkpath");
  565. }