From 58ef0b460fd727ca8cdb0767d324dbc96e8c6ed6 Mon Sep 17 00:00:00 2001 From: Peter Slattery Date: Wed, 5 Feb 2020 00:03:56 -0800 Subject: [PATCH] Added memory errors for when files aren't found --- gs_libs/gs_platform.h | 10 +++++++++- src/foldhaus_app.cpp | 8 ++++++-- src/foldhaus_assembly.cpp | 5 ++++- src/foldhaus_platform.h | 10 ++++++++++ src/win32_foldhaus_fileio.h | 15 ++++++++++++--- todo.txt | 2 ++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/gs_libs/gs_platform.h b/gs_libs/gs_platform.h index b65a299..19e0162 100644 --- a/gs_libs/gs_platform.h +++ b/gs_libs/gs_platform.h @@ -53,11 +53,19 @@ struct window_info typedef struct window window; #define PLATFORM_MEMORY_NO_ERROR 0 +enum platform_memory_error +{ + PlatformMemory_NoError, + PlatformMemory_FileNotFound, + + PlatformMemory_UnknownError, // You should implement handling this when you see it +}; + struct platform_memory_result { u8* Base; s32 Size; - s32 Error; + platform_memory_error Error; }; struct texture_buffer diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index 5cd1745..88a1a30 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -93,7 +93,7 @@ INITIALIZE_APPLICATION(InitializeApplication) r32 FontSize = 14; { platform_memory_result FontFile = Context.PlatformReadEntireFile("Anonymous Pro.ttf"); - if (FontFile.Size) + if (!FontFile.Error) { bitmap_font* Font = PushStruct(&State->Permanent, bitmap_font); @@ -140,7 +140,11 @@ INITIALIZE_APPLICATION(InitializeApplication) Font->BitmapTextureHandle = Context.PlatformGetGPUTextureHandle(Font->BitmapMemory, Font->BitmapWidth, Font->BitmapHeight); - } else {} + } + else + { + // TODO(Peter): How do we want to handle not having a font? + } } State->Interface.FontSize = FontSize; diff --git a/src/foldhaus_assembly.cpp b/src/foldhaus_assembly.cpp index b3ee8ad..7d2d0fe 100644 --- a/src/foldhaus_assembly.cpp +++ b/src/foldhaus_assembly.cpp @@ -77,7 +77,10 @@ internal void LoadAssembly (app_state* State, context Context, char* Path) { platform_memory_result TestAssemblyFile = Context.PlatformReadEntireFile(Path); - Assert(TestAssemblyFile.Size > 0); + if (TestAssemblyFile.Error != PlatformMemory_NoError) + { + return; + } assembly_definition AssemblyDefinition = ParseAssemblyFile(TestAssemblyFile.Base, TestAssemblyFile.Size, &State->Transient); diff --git a/src/foldhaus_platform.h b/src/foldhaus_platform.h index ace8abf..decf64d 100644 --- a/src/foldhaus_platform.h +++ b/src/foldhaus_platform.h @@ -47,6 +47,16 @@ typedef CLEANUP_APPLICATION(cleanup_application); // Platform Functions +// File IO + +// TODO(Peter): +struct directory_listing +{ + string Path; + directory_listing* Next; +}; + +// Font typedef struct platform_font_info platform_font_info; enum font_weight diff --git a/src/win32_foldhaus_fileio.h b/src/win32_foldhaus_fileio.h index 77e431c..0388c42 100644 --- a/src/win32_foldhaus_fileio.h +++ b/src/win32_foldhaus_fileio.h @@ -11,7 +11,7 @@ PLATFORM_READ_ENTIRE_FILE(Win32ReadEntireFile) { platform_memory_result Result = {}; - Result.Error = PLATFORM_MEMORY_NO_ERROR; + Result.Error = PlatformMemory_NoError; HANDLE FileHandle = CreateFileA (Path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); @@ -30,15 +30,17 @@ PLATFORM_READ_ENTIRE_FILE(Win32ReadEntireFile) } else { + u32 Error = GetLastError(); + // TODO(Peter): Result.Size = 0; - Result.Error = 1; + Result.Error = PlatformMemory_UnknownError; } } CloseHandle(FileHandle); } else { - // TODO(Peter): failure + Result.Error = PlatformMemory_FileNotFound; } return Result; @@ -131,6 +133,13 @@ PLATFORM_GET_FILE_PATH(Win32SystemDialogueOpenFile) return Result; } +internal directory_listing +EnumerateDirectory(char* Path, memory_arena* Storage) +{ + directory_listing Result = {}; + // TODO(Peter): + return Result; +} #define WIN32_FOLDHAUS_FILEIO_H #endif // WIN32_FOLDHAUS_FILEIO_H \ No newline at end of file diff --git a/todo.txt b/todo.txt index 2f27839..7ac07e9 100644 --- a/todo.txt +++ b/todo.txt @@ -18,6 +18,8 @@ x Hot Code Reloading - Win32 Platform Layer x Capture Mouse Events that start on the window but end outside x Mouse up when mouse down was in the window + - Enumerate Directory Contents (you started this in win32_foldhaus_fileio.h) + - - File Loading - Gracefully handle File Not found