Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » al_load_bitmap and unicode characters in filename

This thread is locked; no one can reply to it. rss feed Print
al_load_bitmap and unicode characters in filename
kovarex
Member #14,203
April 2012

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.

www.factorio.com - a factory building game.

Peter Wang
Member #23
April 2000

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

kovarex
Member #14,203
April 2012

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.

www.factorio.com - a factory building game.

Audric
Member #907
January 2001

.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
Member #476
June 2000
avatar

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

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Go to: