VCMIDirs.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #pragma once
  2. #include "GameConstants.h"
  3. /*
  4. * VCMIDirs.h, 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. #ifndef _WIN32 //we need boost here only on non-win platforms
  13. #include <boost/filesystem.hpp>
  14. using namespace boost::filesystem;
  15. #endif
  16. /// Where to find the various VCMI files. This is mostly useful for linux.
  17. class VCMIDirs {
  18. public:
  19. std::string UserPath;
  20. VCMIDirs()
  21. {
  22. #ifdef _WIN32
  23. UserPath = GameConstants::DATA_DIR;
  24. #else
  25. try {
  26. #ifdef ANDROID
  27. UserPath = DATA_DIR;
  28. #elif defined(__APPLE__)
  29. // This is Cocoa code that should be normally used to get path to Application Support folder but can't use it here for now...
  30. // NSArray* urls = [[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask];
  31. // UserPath = path([urls[0] path] + "/vcmi").string();
  32. // ...so here goes a bit of hardcode instead
  33. std::string home_dir = ".";
  34. if (getenv("HOME") != NULL )
  35. home_dir = getenv("HOME");
  36. UserPath = path(home_dir + "/Library/Application Support/vcmi").string();
  37. #else
  38. // Find vcmi user directory and create it if necessary
  39. std::string home_dir = ".";
  40. if (getenv("HOME") != NULL )
  41. home_dir = getenv("HOME");
  42. UserPath = path(home_dir + "/.vcmi").string();
  43. #endif
  44. create_directory(UserPath);
  45. create_directory(UserPath + "/config");
  46. create_directory(UserPath + "/Games");
  47. /* Home directory can contain some extra maps. */
  48. create_directory(UserPath + "/Maps");
  49. }
  50. catch(const std::exception & e)
  51. {
  52. }
  53. #endif
  54. }
  55. };
  56. extern DLL_LINKAGE VCMIDirs GVCMIDirs;