Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

filesystem.cpp 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. * \file src/utils/filesystem.cpp
  3. * \brief file-system utilities
  4. *
  5. * \author xythobuz
  6. */
  7. #include "global.h"
  8. #include "utils/filesystem.h"
  9. #if defined(HAVE_UNISTD_H) && defined(HAVE_GETCWD)
  10. #include <unistd.h>
  11. #endif
  12. #if defined(HAVE_STDLIB_H) && defined(HAVE_GETENV)
  13. #include <stdlib.h>
  14. #endif
  15. #ifdef _WIN32
  16. #include <windows.h>
  17. #include <shlobj.h>
  18. #endif
  19. std::string getCurrentWorkingDirectory() {
  20. #if defined(HAVE_UNISTD_H) && defined(HAVE_GETCWD)
  21. char path[1024];
  22. orAssertEqual(getcwd(path, 1024), path);
  23. return std::string(path);
  24. #else
  25. orAssert(false);
  26. return "";
  27. #endif
  28. }
  29. std::string getHomeDirectory() {
  30. #if defined(HAVE_STDLIB_H) && defined(HAVE_GETENV)
  31. char* path = getenv("HOME");
  32. orAssert(path != nullptr);
  33. return path;
  34. #elif defined(_WIN32)
  35. char path[MAX_PATH];
  36. orAssertEqual(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, path), S_OK);
  37. size_t lenPath = strlen(path);
  38. for (unsigned int i = 0; i < lenPath; i++)
  39. if (path[i] == '\\')
  40. path[i] = '/';
  41. return std::string(path);
  42. #else
  43. orAssert(false);
  44. return "";
  45. #endif
  46. }