4 using namespace CYB::Platform::Win32;
7 FPath(std::move(APath)),
13 auto& MM(
Core().FModuleManager);
15 const auto DesiredAccess([&]() -> DWORD {
23 return GENERIC_READ | GENERIC_WRITE;
27 }()), CreationDisposition([&]() -> DWORD {
44 FHandle = MM.Call<Modules::Kernel32::CreateFileW>(FilePath, DesiredAccess,
static_cast<DWORD
>(FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE),
nullptr, CreationDisposition, static_cast<DWORD>(FILE_ATTRIBUTE_NORMAL),
nullptr);
46 if (FHandle == INVALID_HANDLE_VALUE) {
47 const auto Error(MM.Call<Modules::Kernel32::GetLastError>());
48 API::Assert::NotEqual<DWORD>(Error, ERROR_INVALID_PARAMETER);
52 if (Error == ERROR_FILE_NOT_FOUND || Error == ERROR_PATH_NOT_FOUND || Error == ERROR_INVALID_NAME)
54 if (Error == ERROR_FILE_EXISTS)
56 if (Error == ERROR_ACCESS_DENIED) {
79 if (MM.Call<Modules::Kernel32::GetLastError>() == ERROR_ALREADY_EXISTS)
89 FHandle(AMove.FHandle)
91 AMove.FHandle = INVALID_HANDLE_VALUE;
95 if (FHandle != INVALID_HANDLE_VALUE)
101 FHandle = AMove.FHandle;
102 AMove.FHandle = INVALID_HANDLE_VALUE;
103 FOpenMode = AMove.FOpenMode;
104 FOpenMethod = AMove.FOpenMethod;
109 auto& K32(
Core().FModuleManager);
111 WIN32_FILE_ATTRIBUTE_DATA Attributes;
112 if (K32.Call<Modules::Kernel32::GetFileAttributesExW>(APath.
WidePath().
WString(), GetFileExInfoStandard, &Attributes) != 0) {
114 Size.HighPart =
static_cast<LONG
>(Attributes.nFileSizeHigh);
115 Size.LowPart = Attributes.nFileSizeLow;
116 return static_cast<unsigned long long>(Size.QuadPart);
119 const auto Error(K32.Call<Modules::Kernel32::GetLastError>());
120 if (Error == ERROR_ACCESS_DENIED || Error == ERROR_SHARING_VIOLATION)
127 if (
Core().FModuleManager.Call<Modules::Kernel32::GetFileSizeEx>(FHandle, &Size) == 0)
129 return static_cast<unsigned long long>(Size.QuadPart);
133 LARGE_INTEGER Distance, Location;
134 Distance.QuadPart = AOffset;
136 const auto WinLocation([&]() -> DWORD {
138 case SeekLocation::BEGIN:
140 case SeekLocation::CURSOR:
142 case SeekLocation::END:
149 if (
Core().FModuleManager.Call<Modules::Kernel32::SetFilePointerEx>(FHandle, Distance, &Location, WinLocation) == 0)
152 return static_cast<unsigned long long>(Location.QuadPart);
156 if (FOpenMode == Mode::WRITE)
160 Core().
FModuleManager.
Call<Modules::Kernel32::ReadFile>(FHandle, ABuffer,
static_cast<DWORD
>(AMaxAmount), &BytesRead,
nullptr);
165 if (FOpenMode == Mode::READ)
167 DWORD BytesWritten(0);
169 Core().
FModuleManager.
Call<Modules::Kernel32::WriteFile>(FHandle, ABuffer,
static_cast<DWORD
>(AAmount), &BytesWritten,
nullptr);
Method
The method of handling Files that already exist.
Mode
The available operations for the Stream. Bitset.
The File must not exist. It will be created.
SeekLocation
The location to begin a seek operation at.
Platform::Modules::Manager FModuleManager
Loads and contains required modules.
A required file was not found in the filesystem.
The File may or may not exist. It will be created if it doesn't. OpenMethod will be set to EXIST or C...
Exceptions caused by external call failures or invalid external data. Only classifies ones that can p...
static void Equal(const AType &ALHS, const AType &ARHS) noexcept
Equivalence assertion function. May not be evaluated.
The current arrangment of arguments passed the function is invalid.
const wchar_t * WString(void) const noexcept
Get the underlying const wide char array.
const Level FLevel
The type of the exception.
Generic error for read failures. See functions for further documentation.
Precompiled header for inter-engine operations.
Any existing File will be overwritten and an empty file will be created.
A file that was to be created exists.
Engine::Core & Core(void) noexcept
Retrieve the Core singleton.
Illegal call given prexisting conditions.
Exceptions indicating an API contract violation. Should not be anticipated.
Generic error for write failures. See functions for further documentation.
The base exception recognized by the entire engine.
An operation was attempted with an invalid enum code.