InstallOptions.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 "InstallOptions.h"
  16. namespace InstallRules{
  17. InstallOptions Preset(InstallPreset preset, bool videos_available){
  18. InstallOptions o;
  19. switch (preset){
  20. case InstallPreset::EVERYTHING:
  21. o.battle_data = o.battle_models = o.kernel = o.images = o.sounds = o.music = true;
  22. o.fields = o.field_models = o.wm = o.wm_models = true;
  23. o.videos = videos_available;
  24. break;
  25. case InstallPreset::FIELDS:
  26. o.kernel = o.fields = o.field_models = true;
  27. break;
  28. case InstallPreset::WORLD_MAP:
  29. o.wm = o.wm_models = true;
  30. break;
  31. case InstallPreset::BATTLE:
  32. o.kernel = o.battle_data = o.battle_models = true;
  33. break;
  34. case InstallPreset::MEDIA:
  35. o.images = o.sounds = o.music = true;
  36. o.videos = videos_available;
  37. break;
  38. case InstallPreset::CUSTOM:
  39. break;
  40. }
  41. ApplyDependencies(o);
  42. return o;
  43. }
  44. InstallOptions Selectable(const InstallOptions& options){
  45. InstallOptions s;
  46. s.battle_data = s.battle_models = s.kernel = s.images = s.sounds = s.music = s.videos = true;
  47. s.fields = s.wm = true;
  48. s.field_models = options.fields;
  49. s.wm_models = options.wm;
  50. return s;
  51. }
  52. void ApplyDependencies(InstallOptions& o){
  53. // Applied until nothing changes, in case a rule depends on the result of another.
  54. bool changed = true;
  55. while (changed){
  56. const InstallOptions before = o;
  57. const InstallOptions s = Selectable(o);
  58. o.field_models = o.field_models && s.field_models;
  59. o.wm_models = o.wm_models && s.wm_models;
  60. changed = o.field_models != before.field_models || o.wm_models != before.wm_models;
  61. }
  62. }
  63. std::vector<std::string> Problems(const InstallOptions& options, bool fields_installed){
  64. std::vector<std::string> problems;
  65. if (options.wm && !options.fields && !fields_installed){
  66. problems.push_back(
  67. "The world map scripts need the field maps: select 'Extract field maps', or install them first."
  68. );
  69. }
  70. return problems;
  71. }
  72. ToolNeeds ToolsNeeded(const InstallOptions& o){
  73. ToolNeeds needs;
  74. needs.ffmpeg = o.sounds || o.music || o.videos;
  75. needs.timidity = o.music;
  76. return needs;
  77. }
  78. std::vector<std::string> ToolConsequences(const InstallOptions& o, bool ffmpeg_usable, bool timidity_usable){
  79. std::vector<std::string> consequences;
  80. const ToolNeeds needs = ToolsNeeded(o);
  81. if (needs.ffmpeg && !ffmpeg_usable){
  82. if (o.sounds) consequences.push_back("The sound effects will not be installed: FFmpeg is needed to convert them.");
  83. if (o.music) consequences.push_back("The music will not be installed: FFmpeg is needed to convert it.");
  84. }
  85. else if (needs.timidity && !timidity_usable){
  86. consequences.push_back("The music will not be installed: TiMidity is needed to play the MIDI files.");
  87. }
  88. return consequences;
  89. }
  90. uint64_t EstimateMegabytes(const InstallOptions& o, uint64_t* temporary){
  91. uint64_t installed = 0;
  92. uint64_t temp = 0;
  93. if (o.kernel) installed += 1;
  94. if (o.battle_data) installed += 10;
  95. if (o.battle_models){
  96. installed += 220;
  97. temp += 225;
  98. }
  99. if (o.images) installed += 2;
  100. if (o.sounds) installed += 100;
  101. if (o.music) installed += 130;
  102. if (o.fields) installed += 380;
  103. if (o.field_models){
  104. installed += 190;
  105. temp += 85;
  106. }
  107. if (o.wm){
  108. installed += 30;
  109. temp += 6;
  110. }
  111. if (o.wm_models){
  112. installed += 7;
  113. temp += 6;
  114. }
  115. if (temporary) *temporary = temp;
  116. return installed;
  117. }
  118. }