Common: Add UWP support for helper classes

This commit is contained in:
Connor McLaughlin
2021-07-04 19:09:11 +10:00
parent 281f7c5789
commit 03ab18909a
13 changed files with 317 additions and 41 deletions

View File

@ -884,7 +884,7 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
if ((openMode & (BYTESTREAM_OPEN_CREATE | BYTESTREAM_OPEN_WRITE)) == BYTESTREAM_OPEN_WRITE)
{
// if opening with write but not create, the path must exist.
if (GetFileAttributes(fileName) == INVALID_FILE_ATTRIBUTES)
if (!FileSystem::FileExists(fileName))
return nullptr;
}
@ -895,7 +895,7 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
{
// if the file exists, use r+, otherwise w+
// HACK: if we're not truncating, and the file exists (we want to only update it), we still have to use r+
if ((openMode & BYTESTREAM_OPEN_TRUNCATE) || GetFileAttributes(fileName) == INVALID_FILE_ATTRIBUTES)
if (!FileSystem::FileExists(fileName))
{
modeString[modeStringLength++] = 'w';
if (openMode & BYTESTREAM_OPEN_READ)
@ -1013,8 +1013,15 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
DWORD desiredAccess = GENERIC_WRITE;
if (openMode & BYTESTREAM_OPEN_READ)
desiredAccess |= GENERIC_READ;
#ifndef _UWP
HANDLE hFile =
CreateFileW(wideTemporaryFileName.c_str(), desiredAccess, FILE_SHARE_DELETE, NULL, CREATE_NEW, 0, NULL);
#else
HANDLE hFile =
CreateFile2FromAppW(wideTemporaryFileName.c_str(), desiredAccess, FILE_SHARE_DELETE, CREATE_NEW, nullptr);
#endif
if (hFile == INVALID_HANDLE_VALUE)
return nullptr;
@ -1175,8 +1182,8 @@ std::unique_ptr<ByteStream> ByteStream_OpenFileStream(const char* fileName, u32
}
else // if (errno == ENOTDIR)
{
// well.. someone's trying to open a fucking weird path that is comprised of both directories and files...
// I aint sticking around here to find out what disaster awaits... let fopen deal with it
// well.. someone's trying to open a fucking weird path that is comprised of both directories and
// files... I aint sticking around here to find out what disaster awaits... let fopen deal with it
break;
}
}