Win32ApiWindowsGamesEmulation.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINDOWS_GAMES
  3. #include "Win32ApiWindowsGamesEmulation.h"
  4. #include "os/Win32/WindowsHeaders.h"
  5. #undef GetFileAttributes
  6. #include "os/File.h"
  7. #include "utils/StringUtils.h"
  8. namespace il2cpp
  9. {
  10. namespace os
  11. {
  12. UnityPalFileAttributes File::GetFileAttributes(const std::string& path, int *error)
  13. {
  14. const UTF16String utf16Path(utils::StringUtils::Utf8ToUtf16(path.c_str()));
  15. // HACK: DLC api returns these funky long form UNC paths (\\?\GLOBALROOT\)
  16. // For some reason even though many of the file APIs on Xbox understand such a path
  17. // GetFileAttributesEx does not, so we check explicitly for such a path, and fake it.
  18. wchar_t * p = (wchar_t*)utf16Path.c_str();
  19. size_t len = wcslen(p);
  20. if (((len > 3 && (p[0] == L'\\' && p[1] == L'?' && p[2] == L'\\'))
  21. || (len > 4 && (p[0] == L'\\' && p[1] == L'\\' && p[2] == L'?' && p[3] == L'\\'))
  22. ) && NULL != wcsstr(p, L"GLOBALROOT\\Device\\Harddisk"))
  23. {
  24. size_t diff = len - (wcsstr(p, L"Partition") - p);
  25. if (diff <= 11)
  26. return static_cast<UnityPalFileAttributes>(FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_HIDDEN);
  27. }
  28. WIN32_FILE_ATTRIBUTE_DATA fileAttributes;
  29. BOOL result = ::GetFileAttributesExW((LPCWSTR)utf16Path.c_str(), GetFileExInfoStandard, &fileAttributes);
  30. if (result == FALSE)
  31. {
  32. *error = ::GetLastError();
  33. return static_cast<UnityPalFileAttributes>(INVALID_FILE_ATTRIBUTES);
  34. }
  35. *error = kErrorCodeSuccess;
  36. return static_cast<UnityPalFileAttributes>(fileAttributes.dwFileAttributes);
  37. }
  38. } //os
  39. } //il2cpp
  40. #endif