Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

filesystem.cpp 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #if defined(HAVE_DIRECT_H) && defined(HAVE__GETCWD)
  16. #include <direct.h>
  17. #endif
  18. #ifdef _WIN32
  19. #include <windows.h>
  20. #include <shlobj.h>
  21. #endif
  22. std::string getCurrentWorkingDirectory() {
  23. #if defined(HAVE_UNISTD_H) && defined(HAVE_GETCWD)
  24. char path[1024];
  25. orAssertEqual(getcwd(path, 1024), path);
  26. return std::string(path);
  27. #elif defined(HAVE_DIRECT_H) && defined(HAVE__GETCWD)
  28. char path[1024];
  29. orAssertEqual(_getcwd(path, 1024), path);
  30. return std::string(path);
  31. #else
  32. orAssert(false);
  33. return "";
  34. #endif
  35. }
  36. std::string getHomeDirectory() {
  37. #if defined(_WIN32)
  38. char path[MAX_PATH];
  39. orAssertEqual(SHGetFolderPath(nullptr, CSIDL_PROFILE, nullptr, 0, path), S_OK);
  40. size_t lenPath = strlen(path);
  41. for (unsigned int i = 0; i < lenPath; i++)
  42. if (path[i] == '\\')
  43. path[i] = '/';
  44. return std::string(path);
  45. #elif defined(HAVE_STDLIB_H) && defined(HAVE_GETENV)
  46. char* path = getenv("HOME");
  47. orAssert(path != nullptr);
  48. return path;
  49. #else
  50. orAssert(false);
  51. return "";
  52. #endif
  53. }