tzlion / hhugboy

A Game Boy (Color) emulator for Windows, based on GEST v1.1.1 by TM, with added support for unlicensed mappers, Unicode filenames, screenshots and some other stuff.
http://hhug.me/
GNU General Public License v2.0
75 stars 10 forks source link

Read/write UTF-8 encoded filenames to config file instead of reading/writing wide characters directly #38

Closed NRS-NewRisingSun closed 3 years ago

NRS-NewRisingSun commented 3 years ago

hhugboy currently writes the config file as an ASCII file, but within that ASCII file, stores the Directories and Recent Files as "wide" characters. If that wide-character string contains the bytes $1A (End-of-File) or $0A (New Line), the file will be parsed incorrectly the next time it is read, causing all subsequent settings to be lost. Example filenames where this occurs:

Hello KittyのSweet Adventure꞉ Danielくんに会いたい.gbc 史上超強 RPG ~ 格鬥 ~ 益智版組合卡 18-in-1.gbc

With this change, the wide-character string is converted from wchar_t to UTF-8 before writing, and from UTF-8 to wchar_t after reading, to the config file. This ensures that the config file is correctly parsed regardless of the Unicode code points in the Directores and Recent Files. Config files saved by previous builds should be parsed correctly, although the Directories and Recent Files will be invalidated.