少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "il2cpp-config.h"
 
#if IL2CPP_TARGET_WINRT || IL2CPP_TARGET_XBOXONE
 
#include <io.h>
 
#include "il2cpp-vm-support.h"
#include "os/File.h"
#include "os/Win32/WindowsHeaders.h"
 
namespace il2cpp
{
namespace os
{
    static inline std::wstring GetDirectoryForStandardOutput()
    {
#if IL2CPP_TARGET_XBOXONE
 
        return L"D:\\";
 
#elif IL2CPP_TARGET_WINRT
 
        wchar_t buffer[MAX_PATH + 2];
        uint32_t tempPathLength = GetTempPathW(MAX_PATH + 2, buffer);
        return std::wstring(buffer, tempPathLength);
 
#else
#error Unknown platform
#endif
    }
 
    static FileHandle* GetOrCreateRedirectedHandle(FILE* stdFile, const wchar_t* fileNameOnDisk)
    {
#if IL2CPP_DEBUG || IL2CPP_DEVELOPMENT
        auto stdFd = _fileno(stdFile);
        auto stdHandle = reinterpret_cast<FileHandle*>(_get_osfhandle(stdFd));
 
        if (stdHandle != INVALID_HANDLE_VALUE && !_isatty(stdFd))
            return stdHandle;
 
        std::wstring pathOnDisk = GetDirectoryForStandardOutput() + fileNameOnDisk;
        auto redirectedFile = _wfreopen(pathOnDisk.c_str(), L"w+", stdFile);
        return reinterpret_cast<FileHandle*>(_get_osfhandle(_fileno(redirectedFile)));
#else
        return NULL;
#endif
    }
 
    bool File::Isatty(FileHandle* fileHandle)
    {
        IL2CPP_VM_NOT_IMPLEMENTED(File::IsAtty);
        return false;
    }
 
    FileHandle* File::GetStdInput()
    {
        return GetOrCreateRedirectedHandle(stdin, L"stdin.txt");
    }
 
    FileHandle* File::GetStdError()
    {
        return GetOrCreateRedirectedHandle(stderr, L"stderr.txt");
    }
 
    FileHandle* File::GetStdOutput()
    {
        return GetOrCreateRedirectedHandle(stdout, L"stdout.txt");
    }
} //os
} //il2cpp
 
#endif