VCMIDirs.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #include "StdInc.h"
  2. #include "VCMIDirs.h"
  3. /*
  4. * VCMIDirs.cpp, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. static VCMIDirs VCMIDirsGlobal;
  13. VCMIDirs::VCMIDirs()
  14. {
  15. // initialize local directory and create folders to which VCMI needs write access
  16. boost::filesystem::create_directory(userDataPath());
  17. boost::filesystem::create_directory(userCachePath());
  18. boost::filesystem::create_directory(userConfigPath());
  19. boost::filesystem::create_directory(userSavePath());
  20. }
  21. VCMIDirs & VCMIDirs::get()
  22. {
  23. return VCMIDirsGlobal;
  24. }
  25. std::string VCMIDirs::userCachePath() const
  26. {
  27. return userDataPath();
  28. }
  29. std::string VCMIDirs::userConfigPath() const
  30. {
  31. return userDataPath() + "/config";
  32. }
  33. std::string VCMIDirs::userSavePath() const
  34. {
  35. return userDataPath() + "/Games";
  36. }
  37. std::vector<std::string> VCMIDirs::configPaths() const
  38. {
  39. return std::vector<std::string>(1, dataPaths()[0] + "/config");
  40. }
  41. //FIXME: find way to at least decrease size of this ifdef (along with cleanup in CMake)
  42. #if defined(_WIN32)
  43. std::string VCMIDirs::userDataPath() const
  44. {
  45. return dataPaths()[0];
  46. }
  47. std::string VCMIDirs::libraryPath() const
  48. {
  49. return userDataPath();
  50. }
  51. std::string VCMIDirs::clientPath() const
  52. {
  53. return userDataPath() + "\\" + "VCMI_client.exe";
  54. }
  55. std::string VCMIDirs::serverPath() const
  56. {
  57. return userDataPath() + "\\" + "VCMI_server.exe";
  58. }
  59. std::vector<std::string> VCMIDirs::dataPaths() const
  60. {
  61. return std::vector<std::string>(1, ".");
  62. }
  63. std::string VCMIDirs::libraryName(std::string basename) const
  64. {
  65. return basename + ".dll";
  66. }
  67. #elif defined(__APPLE__)
  68. std::string VCMIDirs::userDataPath() const
  69. {
  70. // This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now...
  71. // NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
  72. // UserPath = path([urls[0] path] + "/vcmi").string();
  73. // ...so here goes a bit of hardcode instead
  74. std::string home_dir = ".";
  75. if (getenv("HOME") != nullptr )
  76. home_dir = getenv("HOME");
  77. return boost::filesystem::path(home_dir + "/Library/Application Support/vcmi").string();
  78. }
  79. std::string VCMIDirs::libraryPath() const
  80. {
  81. return ".";
  82. }
  83. std::string VCMIDirs::clientPath() const
  84. {
  85. return "./vcmiclient";
  86. }
  87. std::string VCMIDirs::serverPath() const
  88. {
  89. return "./vcmiserver";
  90. }
  91. std::vector<std::string> VCMIDirs::dataPaths() const
  92. {
  93. return std::vector<std::string>(1, "../Data");
  94. }
  95. std::string VCMIDirs::libraryName(std::string basename) const
  96. {
  97. return "lib" + basename + ".dylib";
  98. }
  99. #else
  100. std::string VCMIDirs::userDataPath() const
  101. {
  102. if (getenv("HOME") != nullptr )
  103. return std::string(getenv("HOME")) + "/.vcmi";
  104. return ".";
  105. }
  106. std::string VCMIDirs::libraryPath() const
  107. {
  108. return M_LIB_DIR;
  109. }
  110. std::string VCMIDirs::clientPath() const
  111. {
  112. return std::string(M_BIN_DIR) + "/" + "vcmiclient";
  113. }
  114. std::string VCMIDirs::serverPath() const
  115. {
  116. return std::string(M_BIN_DIR) + "/" + "vcmiserver";
  117. }
  118. std::vector<std::string> VCMIDirs::dataPaths() const
  119. {
  120. return std::vector<std::string>(1, M_DATA_DIR);
  121. }
  122. std::string VCMIDirs::libraryName(std::string basename) const
  123. {
  124. return "lib" + basename + ".so";
  125. }
  126. #endif