Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Could not load file' Error (Win 11) - using kyrilik letters in the filename #57

Open
PyGuK213 opened this issue Nov 26, 2023 · 1 comment

Comments

@PyGuK213
Copy link

PyGuK213 commented Nov 26, 2023

I get a:
image

when i try to open a mp3 file, which contains kyrilik letters.

(Win 11 System)

@PyGuK213 PyGuK213 changed the title 'Could not load file' Error - using kyrilik letters in the filename 'Could not load file' Error (Win 11) - using kyrilik letters in the filename Nov 26, 2023
@rexim
Copy link
Member

rexim commented Feb 22, 2024

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 ocornut/imgui#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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants