mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Using _wfopen() under Windows+MSVC because fopen() doesn't support UTF-8 encoding. Wrapped as ImFileOpen(). (#917)
This commit is contained in:
22
imgui.cpp
22
imgui.cpp
@ -1293,6 +1293,22 @@ void ImGui::ColorConvertHSVtoRGB(float h, float s, float v, float& out_r, float&
|
||||
}
|
||||
}
|
||||
|
||||
FILE* ImFileOpen(const char* filename, const char* mode)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
// We need a fopen() wrapper because MSVC/Windows fopen doesn't handle UTF-8 filenames. Converting both strings from UTF-8 to wchar format (using a single allocation, because we can)
|
||||
const int filename_wsize = ImTextCountCharsFromUtf8(filename, NULL) + 1;
|
||||
const int mode_wsize = ImTextCountCharsFromUtf8(mode, NULL) + 1;
|
||||
ImVector<ImWchar> buf;
|
||||
buf.resize(filename_wsize + mode_wsize);
|
||||
ImTextStrFromUtf8(&buf[0], filename_wsize, filename, NULL);
|
||||
ImTextStrFromUtf8(&buf[filename_wsize], mode_wsize, mode, NULL);
|
||||
return _wfopen((wchar_t*)&buf[0], (wchar_t*)&buf[filename_wsize]);
|
||||
#else
|
||||
return fopen(filename, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Load file content into memory
|
||||
// Memory allocated with ImGui::MemAlloc(), must be freed by user using ImGui::MemFree()
|
||||
void* ImLoadFileToMemory(const char* filename, const char* file_open_mode, int* out_file_size, int padding_bytes)
|
||||
@ -1302,7 +1318,7 @@ void* ImLoadFileToMemory(const char* filename, const char* file_open_mode, int*
|
||||
*out_file_size = 0;
|
||||
|
||||
FILE* f;
|
||||
if ((f = fopen(filename, file_open_mode)) == NULL)
|
||||
if ((f = ImFileOpen(filename, file_open_mode)) == NULL)
|
||||
return NULL;
|
||||
|
||||
long file_size_signed;
|
||||
@ -2501,7 +2517,7 @@ static void SaveSettings()
|
||||
|
||||
// Write .ini file
|
||||
// If a window wasn't opened in this session we preserve its settings
|
||||
FILE* f = fopen(filename, "wt");
|
||||
FILE* f = ImFileOpen(filename, "wt");
|
||||
if (!f)
|
||||
return;
|
||||
for (int i = 0; i != g.Settings.Size; i++)
|
||||
@ -5784,7 +5800,7 @@ void ImGui::LogToFile(int max_depth, const char* filename)
|
||||
return;
|
||||
}
|
||||
|
||||
g.LogFile = fopen(filename, "ab");
|
||||
g.LogFile = ImFileOpen(filename, "ab");
|
||||
if (!g.LogFile)
|
||||
{
|
||||
IM_ASSERT(g.LogFile != NULL); // Consider this an error
|
||||
|
Reference in New Issue
Block a user