Skip to content

Commit

Permalink
Revert "Disable default file handler and Add hook so external project…
Browse files Browse the repository at this point in the history
…s can hook their own internal file handling objects"

This reverts commit e1cff96.
  • Loading branch information
SKYBOXLABS\sardana.nikolaeva committed Mar 26, 2024
1 parent 7a50197 commit aac47e0
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 86 deletions.
21 changes: 0 additions & 21 deletions CMakeLists.txt

This file was deleted.

2 changes: 1 addition & 1 deletion imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
//#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf)
//#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself.
//#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies)
#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
//#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().
//#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available

Expand Down
44 changes: 1 addition & 43 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1565,49 +1565,7 @@ bool ImFileClose(ImFileHandle f) { return fclose(f) == 0; }
ImU64 ImFileGetSize(ImFileHandle f) { long off = 0, sz = 0; return ((off = ftell(f)) != -1 && !fseek(f, 0, SEEK_END) && (sz = ftell(f)) != -1 && !fseek(f, off, SEEK_SET)) ? (ImU64)sz : (ImU64)-1; }
ImU64 ImFileRead(void* data, ImU64 sz, ImU64 count, ImFileHandle f) { return fread(data, (size_t)sz, (size_t)count, f); }
ImU64 ImFileWrite(const void* data, ImU64 sz, ImU64 count, ImFileHandle f) { return fwrite(data, (size_t)sz, (size_t)count, f); }
#else
//Functions to redirect to our hook object function calls if it exists
ImFileHandle ImFileOpen(const char* filename, const char* mode) {
if (auto context = ImGui::GetCurrentContext()) {
if (ImIFileHelper* fileHelperPtr = context->FileHelper) {
return fileHelperPtr->ImFileOpen(filename, mode);
}
}
return nullptr;
}
bool ImFileClose(ImFileHandle file) {
if (auto context = ImGui::GetCurrentContext()) {
if (ImIFileHelper* fileHelperPtr = context->FileHelper) {
return fileHelperPtr->ImFileClose(file);
}
}
return false;
}
ImU64 ImFileGetSize(ImFileHandle file) {
if (auto context = ImGui::GetCurrentContext()) {
if (ImIFileHelper* fileHelperPtr = context->FileHelper) {
return fileHelperPtr->ImFileGetSize(file);
}
}
return 0;
}
ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file) {
if (auto context = ImGui::GetCurrentContext()) {
if (ImIFileHelper* fileHelperPtr = context->FileHelper) {
return fileHelperPtr->ImFileRead(data, size, count, file);
}
}
return 0;
}
ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file) {
if (auto context = ImGui::GetCurrentContext()) {
if (ImIFileHelper* fileHelperPtr = context->FileHelper) {
return fileHelperPtr->ImFileWrite(data, size, count, file);
}
}
return 0;
}
#endif
#endif // #ifndef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS

// Helper: Load file content into memory
// Memory allocated with IM_ALLOC(), must be freed by user using IM_FREE() == ImGui::MemFree()
Expand Down
22 changes: 1 addition & 21 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,25 +372,8 @@ IMGUI_API bool ImFileClose(ImFileHandle file);
IMGUI_API ImU64 ImFileGetSize(ImFileHandle file);
IMGUI_API ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file);
IMGUI_API ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file);
#else //Bedrock File Handler Hook so we can use our own internal file handling
#else
#define IMGUI_DISABLE_TTY_FUNCTIONS // Can't use stdout, fflush if we are not using default file functions
//We'll cast this to our own internal type as needed
typedef void* ImFileHandle;
//Helper struct for hooking file operations to external systems
struct ImIFileHelper {
virtual ~ImIFileHelper() = default;
virtual ImFileHandle ImFileOpen(const char* filename, const char* mode) = 0;
virtual bool ImFileClose(ImFileHandle file) = 0;
virtual ImU64 ImFileGetSize(ImFileHandle file) = 0;
virtual ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file) = 0;
virtual ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file) = 0;
};

IMGUI_API ImFileHandle ImFileOpen(const char* filename, const char* mode);
IMGUI_API bool ImFileClose(ImFileHandle file);
IMGUI_API ImU64 ImFileGetSize(ImFileHandle file);
IMGUI_API ImU64 ImFileRead(void* data, ImU64 size, ImU64 count, ImFileHandle file);
IMGUI_API ImU64 ImFileWrite(const void* data, ImU64 size, ImU64 count, ImFileHandle file);
#endif
IMGUI_API void* ImFileLoadToMemory(const char* filename, const char* mode, size_t* out_file_size = NULL, int padding_bytes = 0);

Expand Down Expand Up @@ -1616,9 +1599,6 @@ struct ImGuiContext
ImChunkStream<ImGuiTableSettings> SettingsTables; // ImGuiTable .ini settings entries
ImVector<ImGuiContextHook> Hooks; // Hooks for extensions (e.g. test engine)
ImGuiID HookIdNext; // Next available HookId
#ifdef IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS
ImIFileHelper* FileHelper = nullptr; // Hook object for external source to implement their own fileIO
#endif

// Capture/Logging
bool LogEnabled; // Currently capturing
Expand Down

0 comments on commit aac47e0

Please sign in to comment.