VCMIDirs.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. const std::string homeDir = std::getenv("userprofile");
  46. return homeDir + "\\vcmi";
  47. //return dataPaths()[0];
  48. }
  49. std::string VCMIDirs::libraryPath() const
  50. {
  51. return ".";
  52. }
  53. std::string VCMIDirs::clientPath() const
  54. {
  55. return libraryPath() + "\\" + "VCMI_client.exe";
  56. }
  57. std::string VCMIDirs::serverPath() const
  58. {
  59. return libraryPath() + "\\" + "VCMI_server.exe";
  60. }
  61. std::vector<std::string> VCMIDirs::dataPaths() const
  62. {
  63. return std::vector<std::string>(1, ".");
  64. }
  65. std::string VCMIDirs::libraryName(std::string basename) const
  66. {
  67. return basename + ".dll";
  68. }
  69. #elif defined(__APPLE__)
  70. std::string VCMIDirs::userDataPath() const
  71. {
  72. // This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now...
  73. // NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
  74. // UserPath = path([urls[0] path] + "/vcmi").string();
  75. // ...so here goes a bit of hardcode instead
  76. std::string home_dir = ".";
  77. if (getenv("HOME") != nullptr )
  78. home_dir = getenv("HOME");
  79. return boost::filesystem::path(home_dir + "/Library/Application Support/vcmi").string();
  80. }
  81. std::string VCMIDirs::libraryPath() const
  82. {
  83. return ".";
  84. }
  85. std::string VCMIDirs::clientPath() const
  86. {
  87. return "./vcmiclient";
  88. }
  89. std::string VCMIDirs::serverPath() const
  90. {
  91. return "./vcmiserver";
  92. }
  93. std::vector<std::string> VCMIDirs::dataPaths() const
  94. {
  95. return std::vector<std::string>(1, "../Data");
  96. }
  97. std::string VCMIDirs::libraryName(std::string basename) const
  98. {
  99. return "lib" + basename + ".dylib";
  100. }
  101. #else
  102. std::string VCMIDirs::userDataPath() const
  103. {
  104. if (getenv("HOME") != nullptr )
  105. return std::string(getenv("HOME")) + "/.vcmi";
  106. return ".";
  107. }
  108. std::string VCMIDirs::libraryPath() const
  109. {
  110. return M_LIB_DIR;
  111. }
  112. std::string VCMIDirs::clientPath() const
  113. {
  114. return std::string(M_BIN_DIR) + "/" + "vcmiclient";
  115. }
  116. std::string VCMIDirs::serverPath() const
  117. {
  118. return std::string(M_BIN_DIR) + "/" + "vcmiserver";
  119. }
  120. std::vector<std::string> VCMIDirs::dataPaths() const
  121. {
  122. return std::vector<std::string>(1, M_DATA_DIR);
  123. }
  124. std::string VCMIDirs::libraryName(std::string basename) const
  125. {
  126. return "lib" + basename + ".so";
  127. }
  128. #endif