Open PyGuK213 opened 9 months ago
I briefly looked into this problem and apparently if you want to open files with Unicode names on Windows using fopen
, you must first convert them to UTF-16 (a.k.a. Wide Characters) and use _wfopen
. Imgui had (still has?) a similar issue https://github.com/ocornut/imgui/issues/917
Here I adapted an example on how to do that in pure C:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
int main(void)
{
const char *file_path = "F:\\nu11 wip works 2016-2022 (ogg)\\кириллик.ogg";
int file_path_len = strlen(file_path);
int wide_path_len = MultiByteToWideChar(CP_UTF8, 0, file_path, file_path_len, NULL, 0);
wchar_t *wide_path = (wchar_t*)malloc((wide_path_len + 1)*sizeof(wchar_t));
assert(wide_path != NULL);
MultiByteToWideChar(CP_UTF8, 0, file_path, file_path_len, wide_path, wide_path_len);
wide_path[wide_path_len] = 0;
FILE *f = _wfopen(wide_path, L"rb");
if (!f) {
printf("ERROR: could not open the file!\n");
return 1;
}
printf("Successfully opened the file!\n");
return 0;
}
It looks like a lot of external libraries that Raylib depends on simply use fopen which probably means there is no quick fix for this right now. Eventually I plan to dig deeper into each and individual dependency and see how to properly fix all of this.
For now I can only suggest to simply not use files that have any Unicode symbols in their paths. Maybe a quick stopgap solution could be to explain that to the user in the error message.
I get a:
when i try to open a mp3 file, which contains kyrilik letters.
(Win 11 System)