7#include "core/fxcrt/cfx_fileaccess_windows.h"
11#include "core/fxcrt/fx_stream.h"
12#include "core/fxcrt/fx_string.h"
16 return std::make_unique<CFX_FileAccess_Windows>();
25bool CFX_FileAccess_Windows::
Open(ByteStringView fileName) {
30 m_hFile = ::CreateFileW(wname.c_str(), GENERIC_READ,
31 FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
32 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
nullptr);
33 if (m_hFile == INVALID_HANDLE_VALUE)
39void CFX_FileAccess_Windows::
Close() {
43 ::CloseHandle(m_hFile);
51 LARGE_INTEGER size = {};
52 if (!::GetFileSizeEx(m_hFile, &size))
62 LARGE_INTEGER dist = {};
63 LARGE_INTEGER newPos = {};
64 if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_CURRENT))
76 LARGE_INTEGER newPos = {};
77 if (!::SetFilePointerEx(m_hFile, dist, &newPos, FILE_BEGIN))
83size_t CFX_FileAccess_Windows::
Read(
void* pBuffer, size_t szBuffer) {
88 if (!::ReadFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szRead,
95size_t CFX_FileAccess_Windows::
Write(
const void* pBuffer, size_t szBuffer) {
100 if (!::WriteFile(m_hFile, pBuffer, (DWORD)szBuffer, (LPDWORD)&szWrite,
119 return Read(pBuffer, szBuffer);
131 return Write(pBuffer, szBuffer);
134bool CFX_FileAccess_Windows::
Flush() {
138 return !!::FlushFileBuffers(m_hFile);
145 return !!::SetEndOfFile(m_hFile);
size_t WritePos(const void *pBuffer, size_t szBuffer, FX_FILESIZE pos) override
size_t Write(const void *pBuffer, size_t szBuffer) override
bool Open(ByteStringView fileName) override
size_t Read(void *pBuffer, size_t szBuffer) override
FX_FILESIZE GetSize() const override
FX_FILESIZE SetPosition(FX_FILESIZE pos) override
FX_FILESIZE GetPosition() const override
bool Truncate(FX_FILESIZE szFile) override
size_t ReadPos(void *pBuffer, size_t szBuffer, FX_FILESIZE pos) override
~CFX_FileAccess_Windows() override
static WideString FromUTF8(ByteStringView str)