InstallLayout.cpp 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 "InstallLayout.h"
  16. namespace InstallLayout{
  17. std::string DataDir(const std::string& root){return root + "data/";}
  18. std::string TempDir(const std::string& root){return root + "temp/";}
  19. const std::vector<std::string>& DataSubdirs(){
  20. static const std::vector<std::string> dirs = {
  21. "audio/musics", "audio/sounds", "fields", "fonts", "gamedata", "gamedata/enemy", "gamedata/attack",
  22. "gamedata/formation", "images/icons", "images/other", "images/characters", "images/fonts", "images/reels",
  23. "images/window", "screens", "scripts", "scripts/battle_models", "system", "texts", "models/fields",
  24. "models/battle/characters", "models/battle/scenes", "models/battle/enemies", "models/battle/attacks", "models/battle/effects",
  25. "models/world/terrain/0", "models/world/terrain/1", "models/world/terrain/2", "models/world/elements",
  26. "world/0", "world/1", "world/2", "wm"
  27. };
  28. return dirs;
  29. }
  30. const std::vector<std::string>& TempSubdirs(){
  31. static const std::vector<std::string> dirs = {"char", "battle_models", "world_models", "spell_models", "effects", "wm"};
  32. return dirs;
  33. }
  34. const std::vector<std::string>& KeptTempSubdirs(){
  35. static const std::vector<std::string> dirs = {"world_models"};
  36. return dirs;
  37. }
  38. std::vector<std::string> RemovableTempSubdirs(){
  39. std::vector<std::string> removable;
  40. for (const std::string& dir : TempSubdirs()){
  41. bool kept = false;
  42. for (const std::string& k : KeptTempSubdirs()) kept = kept || (k == dir);
  43. if (!kept) removable.push_back(dir);
  44. }
  45. return removable;
  46. }
  47. const std::vector<std::string>& GameResourceDirs(){
  48. static const std::vector<std::string> dirs = {
  49. "data/system", "data/audio", "data/fields", "data/fonts", "data/gamedata", "data/images", "data/models/fields",
  50. "data/models/world", "data/models/battle", "data/screens", "data/scripts", "data/texts", "data/wm",
  51. "temp/world_models"
  52. };
  53. return dirs;
  54. }
  55. std::string MigrateInstallDir(
  56. std::string legacy_data_dir, const std::string& legacy_config_dir, const std::string& default_dir
  57. ){
  58. while (!legacy_data_dir.empty() && legacy_data_dir.back() == '/') legacy_data_dir.pop_back();
  59. const std::string suffix = "/data";
  60. if (
  61. legacy_data_dir.size() >= suffix.size()
  62. && legacy_data_dir.compare(legacy_data_dir.size() - suffix.size(), suffix.size(), suffix) == 0
  63. ) legacy_data_dir.erase(legacy_data_dir.size() - suffix.size());
  64. if (!legacy_data_dir.empty()) return legacy_data_dir;
  65. if (!legacy_config_dir.empty()) return legacy_config_dir;
  66. return default_dir;
  67. }
  68. }