Fix #3178: Precompose file name strings on macOS to prevent mojibake when displayed

* Precompose file name strings on macOS to prevent mojibake when displayed

* Ensure decomp-to-precomp string replacement is handled safely

* Add macOS non-ASCII handling to changelog; add comments to relevant block

* Fix #ifdef alignment

* Fix comment alignment
This commit is contained in:
Richard Jenkins 2017-05-23 08:30:13 +01:00 committed by Michael Steenbeek
parent 0728e6869b
commit 2f9f613201
2 changed files with 16 additions and 4 deletions

View file

@ -1,5 +1,6 @@
0.0.8 (in development)
------------------------------------------------------------------------
- Fix: [#3178, #5456] Paths with non-ASCII characters not handled properly on macOS.
- Fix: [#3681] Steel Twister rollercoaster always shows all track designs
- Fix: Track components added by OpenRCT2 are now usable in older scenarios.

View file

@ -391,6 +391,17 @@ sint32 platform_enumerate_files_begin(const utf8 *pattern)
safe_strcpy(paths[idx], dir_name, path_len);
safe_strcat_path(paths[idx], d->d_name, path_len);
log_verbose("paths[%d] = %s", idx, paths[idx]);
// macOS uses decomposed Unicode strings (e.g. an 'e' and a combining accent) in filenames
// This causes problems with the sprite font, as the font only contains precomposed characters
// The block below converts all filename strings to their precomposed form, preventing mojibake
#ifdef __MACOSX__
utf8* precomp_path = macos_str_decomp_to_precomp(paths[idx]);
size_t precomp_len = sizeof(utf8) * min(MAX_PATH, strnlen(precomp_path, MAX_PATH) + 2);
paths[idx] = malloc(precomp_len);
safe_strcpy(paths[idx], precomp_path, precomp_len);
log_verbose("macOS decomp-to-precomp fix - paths[%d] = %s", idx, paths[idx]);
#endif
}
enumFileInfo->handle = 0;
enumFileInfo->active = 1;
@ -798,12 +809,12 @@ time_t platform_file_get_modified_time(const utf8* path){
}
uint8 platform_get_locale_temperature_format(){
// LC_MEASUREMENT is GNU specific.
#ifdef LC_MEASUREMENT
// LC_MEASUREMENT is GNU specific.
#ifdef LC_MEASUREMENT
const char *langstring = setlocale(LC_MEASUREMENT, "");
#else
#else
const char *langstring = setlocale(LC_ALL, "");
#endif
#endif
if(langstring != NULL){
if (!fnmatch("*_US*", langstring, 0) ||