[*] Beyond dumb fio offset issue

This commit is contained in:
Reece Wilson 2022-06-06 22:34:49 +01:00
parent a59fc20d56
commit e29843dc7e
2 changed files with 27 additions and 9 deletions

View File

@ -103,10 +103,19 @@ namespace Aurora::IO::FS
break;
}
case EFileOpenMode::eReadWrite:
{
CreateDirectories(pathex, true);
fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE | GENERIC_READ, NtLockAdvisoryToShare(lock), NULL, OPEN_ALWAYS, flags, NULL);
if (fileHandle == INVALID_HANDLE_VALUE)
{
fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE | GENERIC_READ, NtLockAdvisoryToShare(lock), NULL, CREATE_ALWAYS, flags, NULL);
}
break;
}
case EFileOpenMode::eWrite:
{
CreateDirectories(pathex, true);
fileHandle = CreateFileW(win32Path.c_str(), (openMode == EFileOpenMode::eReadWrite) ? (GENERIC_WRITE | GENERIC_READ) : GENERIC_WRITE, NtLockAdvisoryToShare(lock), NULL, CREATE_ALWAYS, flags, NULL);
fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE, NtLockAdvisoryToShare(lock), NULL, CREATE_ALWAYS, flags, NULL);
break;
}
}

View File

@ -23,8 +23,8 @@ namespace Aurora::IO::FS
void WinFileStream::Init(HANDLE handle, const AuString &path)
{
handle_ = handle;
path_ = path;
this->handle_ = handle;
this->path_ = path;
}
AuUInt64 WinFileStream::GetOffset()
@ -32,13 +32,13 @@ namespace Aurora::IO::FS
LARGE_INTEGER distance {};
LARGE_INTEGER pos {};
if (handle_ == INVALID_HANDLE_VALUE)
if (this->handle_ == INVALID_HANDLE_VALUE)
{
SysPushErrorUninitialized();
return 0;
}
if (SetFilePointerEx(handle_, distance, &pos, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
if (SetFilePointerEx(this->handle_, distance, &pos, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
{
AuLogWarn("SetFilePointerEx IO Error: 0x{:x}, {}", GetLastError(), path_);
SysPushErrorIO();
@ -53,7 +53,7 @@ namespace Aurora::IO::FS
LARGE_INTEGER distance {};
LARGE_INTEGER pos {};
if (handle_ == INVALID_HANDLE_VALUE)
if (this->handle_ == INVALID_HANDLE_VALUE)
{
SysPushErrorUninitialized();
return false;
@ -61,7 +61,7 @@ namespace Aurora::IO::FS
distance.QuadPart = offset;
if (SetFilePointerEx(handle_, distance, &pos, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
if (SetFilePointerEx(this->handle_, distance, &pos, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
{
AuLogWarn("SetFilePointerEx IO Error: 0x{:x}, {}", GetLastError(), path_);
SysPushErrorIO();
@ -81,7 +81,7 @@ namespace Aurora::IO::FS
return 0;
}
if (!GetFileSizeEx(handle_, &length))
if (!GetFileSizeEx(this->handle_, &length))
{
SysPushErrorIO();
return 0;
@ -238,10 +238,19 @@ namespace Aurora::IO::FS
break;
}
case EFileOpenMode::eReadWrite:
{
CreateDirectories(pathex, true);
fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE | GENERIC_READ, NtLockAdvisoryToShare(lock), NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fileHandle == INVALID_HANDLE_VALUE)
{
fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE, NtLockAdvisoryToShare(lock), NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
}
break;
}
case EFileOpenMode::eWrite:
{
CreateDirectories(pathex, true);
fileHandle = CreateFileW(win32Path.c_str(), (openMode == EFileOpenMode::eReadWrite) ? (GENERIC_WRITE | GENERIC_READ) : GENERIC_WRITE, NtLockAdvisoryToShare(lock), NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
fileHandle = CreateFileW(win32Path.c_str(), GENERIC_WRITE, NtLockAdvisoryToShare(lock), NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
break;
}
}