暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

File.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "il2cpp-config.h"
  2. #if IL2CPP_TARGET_WINRT
  3. #include <io.h>
  4. #include "os/File.h"
  5. #include "os/Win32/WindowsHeaders.h"
  6. #include "utils/Expected.h"
  7. #include "utils/Il2CppError.h"
  8. namespace il2cpp
  9. {
  10. namespace os
  11. {
  12. static inline std::wstring GetDirectoryForStandardOutput()
  13. {
  14. wchar_t buffer[MAX_PATH + 2];
  15. uint32_t tempPathLength = GetTempPathW(MAX_PATH + 2, buffer);
  16. return std::wstring(buffer, tempPathLength);
  17. }
  18. static FileHandle* GetOrCreateRedirectedHandle(FILE* stdFile, const wchar_t* fileNameOnDisk)
  19. {
  20. #if IL2CPP_DEBUG || IL2CPP_DEVELOPMENT
  21. auto stdFd = _fileno(stdFile);
  22. auto stdHandle = reinterpret_cast<FileHandle*>(_get_osfhandle(stdFd));
  23. if (stdHandle != INVALID_HANDLE_VALUE && !_isatty(stdFd))
  24. return stdHandle;
  25. std::wstring pathOnDisk = GetDirectoryForStandardOutput() + fileNameOnDisk;
  26. auto redirectedFile = _wfreopen(pathOnDisk.c_str(), L"w+", stdFile);
  27. return reinterpret_cast<FileHandle*>(_get_osfhandle(_fileno(redirectedFile)));
  28. #else
  29. return NULL;
  30. #endif
  31. }
  32. utils::Expected<bool> File::Isatty(FileHandle* fileHandle)
  33. {
  34. return utils::Il2CppError(utils::NotSupported, "File::Isatty is not supported on WinRT");
  35. }
  36. FileHandle* File::GetStdInput()
  37. {
  38. return GetOrCreateRedirectedHandle(stdin, L"stdin.txt");
  39. }
  40. FileHandle* File::GetStdError()
  41. {
  42. return GetOrCreateRedirectedHandle(stderr, L"stderr.txt");
  43. }
  44. FileHandle* File::GetStdOutput()
  45. {
  46. return GetOrCreateRedirectedHandle(stdout, L"stdout.txt");
  47. }
  48. } //os
  49. } //il2cpp
  50. #endif // IL2CPP_TARGET_WINRT