Path.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINDOWS
  3. #include "WindowsHeaders.h"
  4. #undef GetTempPath
  5. #include "os/Environment.h"
  6. #include "os/Path.h"
  7. #include "utils/PathUtils.h"
  8. #include "utils/StringUtils.h"
  9. #include "WindowsHelpers.h"
  10. #include <string>
  11. EXTERN_C IMAGE_DOS_HEADER __ImageBase;
  12. namespace il2cpp
  13. {
  14. namespace os
  15. {
  16. std::string Path::GetExecutablePath()
  17. {
  18. wchar_t buffer[MAX_PATH];
  19. GetModuleFileNameW(nullptr, buffer, MAX_PATH);
  20. return utils::StringUtils::Utf16ToUtf8(buffer);
  21. }
  22. std::string Path::GetApplicationFolder()
  23. {
  24. wchar_t buffer[MAX_PATH];
  25. GetModuleFileNameW(reinterpret_cast<HMODULE>(&__ImageBase), buffer, MAX_PATH);
  26. return utils::PathUtils::DirectoryName(utils::StringUtils::Utf16ToUtf8(buffer));
  27. }
  28. std::string Path::GetTempPath()
  29. {
  30. #if IL2CPP_TARGET_GAMECORE_XBOX
  31. return "T:\\";
  32. #else
  33. WCHAR tempPath[MAX_PATH + 1];
  34. ::GetTempPathW(sizeof(tempPath) / sizeof(tempPath[0]), tempPath);
  35. #if !IL2CPP_TARGET_WINDOWS_GAMES
  36. ::GetLongPathNameW(tempPath, tempPath, sizeof(tempPath) / sizeof(tempPath[0]));
  37. #endif // !IL2CPP_TARGET_WINDOWS_GAMES
  38. return utils::StringUtils::Utf16ToUtf8(tempPath);
  39. #endif
  40. }
  41. bool Path::IsAbsolute(const std::string& path)
  42. {
  43. if (path[0] != '\0' && path[1] != '\0')
  44. {
  45. if (path[1] == ':' && path[2] != '\0' && (path[2] == '\\' || path[2] == '/'))
  46. return true;
  47. /* UNC paths */
  48. else if (path[0] == '\\' && path[1] == '\\' && path[2] != '\0')
  49. return true;
  50. }
  51. return false;
  52. }
  53. }
  54. }
  55. #endif