al_load_bitmap and unicode characters in filename
kovarex

Hello,

when I try to load images with unicode characters in the file name, it fails.
I did little digging, and found out, that the code should handle wide char conversion for the file name actually breaks it.

#SelectExpand
1static void *file_stdio_fopen(const char *path, const char *mode) 2{ 3 FILE *fp; 4 5#ifdef ALLEGRO_WINDOWS 6 { 7 wchar_t *wpath = _al_win_utf16(path); 8 wchar_t *wmode = _al_win_utf16(mode); 9 fp = _wfopen(wpath, wmode); 10 al_free(wpath); 11 al_free(wmode); 12 } 13#else 14 fp = fopen(path, mode); 15#endif 16 17 if (!fp) { 18 al_set_errno(errno); 19 return NULL; 20 } 21 22 return fp; 23}

When I changed the ifdef ALLEGRO_WINDOWS to #if 0 (sing the non-windows variant), it started working, and I could load those files.

I'm probably doing something the wrong way, but not sure what is it, I'm no expert of wide string/utf 8.

Peter Wang

Then you're probably not providing a UTF-8 path. Sample code?

kovarex

The part of the filename that contains invalid characteres (User name on windows, while accessing the User/<Username>/AppData/Roaming ...

#SelectExpand
1boost::filesystem::path Paths::getSystemWriteData() 2{ 3 TCHAR szPath[MAX_PATH]; 4 5 if (SUCCEEDED(SHGetFolderPath(NULL, 6 CSIDL_APPDATA | CSIDL_FLAG_CREATE, 7 NULL, 8 0, 9 szPath))) 10 { 11 boost::filesystem::path result = boost::filesystem::path(szPath) / "Factorio"; 12 boost::filesystem::create_directories(result); 13 return result; 14 } 15 else 16 throw std::runtime_error("Couldn't get application data directory"); 17}

Later I just make string out of the path (path / "preview image path").string() and send it to the allegro.

You can see, that boost has no problem with creating the directory that contains the unicode character.

Audric

.string() returns a std::string, you still need to convert it to a sequence of UTF-8 to pass it to al_load_bitmap()

Thomas Fjellstrom

Also have to make sure its in UTF-8, rather than the UTF-16 that windows returns.

Thread #612072. Printed from Allegro.cc