mirror of
https://github.com/NoelFB/blah.git
synced 2025-07-15 18:51:53 +08:00
refactored FileMode to make more sense
This commit is contained in:
@ -647,11 +647,25 @@ void PlatformBackend::dir_explore(const char* path)
|
||||
|
||||
bool PlatformBackend::file_open(const char* path, PlatformBackend::FileHandle* handle, FileMode mode)
|
||||
{
|
||||
const char* sdlMode = "rb";
|
||||
if (mode == FileMode::Write)
|
||||
sdlMode = "wb";
|
||||
const char* sdl_mode = "";
|
||||
|
||||
auto ptr = SDL_RWFromFile(path, sdlMode);
|
||||
switch (mode)
|
||||
{
|
||||
case FileMode::OpenRead:
|
||||
sdl_mode = "rb";
|
||||
break;
|
||||
case FileMode::OpenReadWrite:
|
||||
sdl_mode = "r+b";
|
||||
break;
|
||||
case FileMode::CreateWrite:
|
||||
sdl_mode = "wb";
|
||||
break;
|
||||
case FileMode::CreateReadWrite:
|
||||
sdl_mode = "w+b";
|
||||
break;
|
||||
}
|
||||
|
||||
auto ptr = SDL_RWFromFile(path, sdl_mode);
|
||||
*handle = (PlatformBackend::FileHandle)ptr;
|
||||
return ptr != nullptr;
|
||||
}
|
||||
|
@ -489,16 +489,24 @@ bool PlatformBackend::file_open(const char* path, PlatformBackend::FileHandle* h
|
||||
int access = 0;
|
||||
int creation = 0;
|
||||
|
||||
if (((int)mode & (int)FileMode::Read) == (int)FileMode::Read)
|
||||
switch (mode)
|
||||
{
|
||||
access |= GENERIC_READ;
|
||||
case FileMode::OpenRead:
|
||||
access = GENERIC_READ;
|
||||
creation = OPEN_EXISTING;
|
||||
}
|
||||
|
||||
if (((int)mode & (int)FileMode::Write) == (int)FileMode::Write)
|
||||
{
|
||||
access |= GENERIC_WRITE;
|
||||
creation = OPEN_ALWAYS;
|
||||
break;
|
||||
case FileMode::Open:
|
||||
access = GENERIC_READ | GENERIC_WRITE;
|
||||
creation = OPEN_EXISTING;
|
||||
break;
|
||||
case FileMode::CreateWrite:
|
||||
access = GENERIC_WRITE;
|
||||
creation = CREATE_ALWAYS;
|
||||
break;
|
||||
case FileMode::Create:
|
||||
access = GENERIC_READ | GENERIC_WRITE;
|
||||
creation = CREATE_ALWAYS;
|
||||
break;
|
||||
}
|
||||
|
||||
auto result = CreateFile(path, access, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
Reference in New Issue
Block a user