VCMIDirs.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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(localPath());
  17. boost::filesystem::create_directory(localPath() + "/config");
  18. boost::filesystem::create_directory(localPath() + "/Games");
  19. }
  20. VCMIDirs & VCMIDirs::get()
  21. {
  22. return VCMIDirsGlobal;
  23. }
  24. //FIXME: find way to at least decrease size of this ifdef (along with cleanup in CMake)
  25. #if defined(_WIN32)
  26. std::string VCMIDirs::localPath() const
  27. {
  28. return dataPath();
  29. }
  30. std::string VCMIDirs::libraryPath() const
  31. {
  32. return dataPath();
  33. }
  34. std::string VCMIDirs::serverPath() const
  35. {
  36. return dataPath() + "\\" + "VCMI_server.exe";
  37. }
  38. std::string VCMIDirs::dataPath() const
  39. {
  40. return ".";
  41. }
  42. std::string VCMIDirs::libraryName(std::string basename) const
  43. {
  44. return basename + ".dll";
  45. }
  46. #elif defined(__APPLE__)
  47. std::string VCMIDirs::localPath() const
  48. {
  49. // This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now...
  50. // NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
  51. // UserPath = path([urls[0] path] + "/vcmi").string();
  52. // ...so here goes a bit of hardcode instead
  53. std::string home_dir = ".";
  54. if (getenv("HOME") != NULL )
  55. home_dir = getenv("HOME");
  56. return path(home_dir + "/Library/Application Support/vcmi").string();
  57. }
  58. std::string VCMIDirs::libraryPath() const
  59. {
  60. return ".";
  61. }
  62. std::string VCMIDirs::serverPath() const
  63. {
  64. return "./vcmiserver";
  65. }
  66. std::string VCMIDirs::dataPath() const
  67. {
  68. return "../Data";
  69. }
  70. std::string VCMIDirs::libraryName(std::string basename) const
  71. {
  72. return "lib" + basename + ".dylib";
  73. }
  74. #else
  75. std::string VCMIDirs::localPath() const
  76. {
  77. if (getenv("HOME") != NULL )
  78. return std::string(getenv("HOME")) + "/.vcmi";
  79. return ".";
  80. }
  81. std::string VCMIDirs::libraryPath() const
  82. {
  83. return M_LIB_DIR;
  84. }
  85. std::string VCMIDirs::serverPath() const
  86. {
  87. return std::string(M_BIN_DIR) + "/" + "vcmiserver";
  88. }
  89. std::string VCMIDirs::dataPath() const
  90. {
  91. return M_DATA_DIR;
  92. }
  93. std::string VCMIDirs::libraryName(std::string basename) const
  94. {
  95. return "lib" + basename + ".so";
  96. }
  97. #endif