From b004685b7f91d3c26812cd2cfad3699055b8224c Mon Sep 17 00:00:00 2001 From: Steveice10 Date: Fri, 27 Jan 2017 16:09:25 -0800 Subject: [PATCH] Fall back to region-based language if SMDH title for language setting is empty. --- source/core/util.c | 54 +++++++++++++++++++++++- source/core/util.h | 3 ++ source/ui/section/task/listextsavedata.c | 11 +++-- source/ui/section/task/listfiles.c | 9 ++-- source/ui/section/task/listtitles.c | 16 +++---- 5 files changed, 70 insertions(+), 23 deletions(-) diff --git a/source/core/util.c b/source/core/util.c index 5cb1786..ca5dafd 100644 --- a/source/core/util.c +++ b/source/core/util.c @@ -586,7 +586,7 @@ void util_escape_file_name(char* out, const char* in, size_t size) { #define SMDH_NUM_REGIONS 7 #define SMDH_ALL_REGIONS 0x7F -static const char* regionStrings[SMDH_NUM_REGIONS] = { +static const char* smdh_region_strings[SMDH_NUM_REGIONS] = { "Japan", "North America", "Europe", @@ -614,12 +614,62 @@ void util_smdh_region_to_string(char* out, u32 region, size_t size) { pos += snprintf(out + pos, size - pos, ", "); } - pos += snprintf(out + pos, size - pos, regionStrings[i]); + pos += snprintf(out + pos, size - pos, smdh_region_strings[i]); } } } } +static CFG_Language region_default_language[] = { + CFG_LANGUAGE_JP, + CFG_LANGUAGE_EN, + CFG_LANGUAGE_EN, + CFG_LANGUAGE_EN, + CFG_LANGUAGE_ZH, + CFG_LANGUAGE_KO, + CFG_LANGUAGE_ZH +}; + +SMDH_title* util_select_smdh_title(SMDH* smdh) { + char shortDescription[0x100] = {'\0'}; + + CFG_Language systemLanguage; + if(R_SUCCEEDED(CFGU_GetSystemLanguage((u8*) &systemLanguage))) { + utf16_to_utf8((uint8_t*) shortDescription, smdh->titles[systemLanguage].shortDescription, sizeof(shortDescription) - 1); + } + + if(util_is_string_empty(shortDescription)) { + CFG_Region systemRegion; + if(R_SUCCEEDED(CFGU_SecureInfoGetRegion((u8*) &systemRegion))) { + systemLanguage = region_default_language[systemRegion]; + } else { + systemLanguage = CFG_LANGUAGE_JP; + } + } + + return &smdh->titles[systemLanguage]; +} + +u16* util_select_bnr_title(BNR* bnr) { + char title[0x100] = {'\0'}; + + CFG_Language systemLanguage; + if(R_SUCCEEDED(CFGU_GetSystemLanguage((u8*) &systemLanguage))) { + utf16_to_utf8((uint8_t*) title, bnr->titles[systemLanguage], sizeof(title) - 1); + } + + if(util_is_string_empty(title)) { + CFG_Region systemRegion; + if(R_SUCCEEDED(CFGU_SecureInfoGetRegion((u8*) &systemRegion))) { + systemLanguage = region_default_language[systemRegion]; + } else { + systemLanguage = CFG_LANGUAGE_JP; + } + } + + return bnr->titles[systemLanguage]; +} + static char util_http_redirect_buffer[1024]; Result util_http_open(httpcContext* context, u32* responseCode, const char* url, bool userAgent) { diff --git a/source/core/util.h b/source/core/util.h index ad6b713..c251184 100644 --- a/source/core/util.h +++ b/source/core/util.h @@ -83,6 +83,9 @@ void util_escape_file_name(char* out, const char* in, size_t size); void util_smdh_region_to_string(char* out, u32 region, size_t size); +SMDH_title* util_select_smdh_title(SMDH* smdh); +u16* util_select_bnr_title(BNR* bnr); + Result util_http_open(httpcContext* context, u32* responseCode, const char* url, bool userAgent); Result util_http_open_ranged(httpcContext* context, u32* responseCode, const char* url, bool userAgent, u32 rangeStart, u32 rangeEnd); Result util_http_get_size(httpcContext* context, u32* size); diff --git a/source/ui/section/task/listextsavedata.c b/source/ui/section/task/listextsavedata.c index 4418a9a..3a98fde 100644 --- a/source/ui/section/task/listextsavedata.c +++ b/source/ui/section/task/listextsavedata.c @@ -52,15 +52,14 @@ static Result task_populate_ext_save_data_from(populate_ext_save_data_data* data u32 smdhBytesRead = 0; if(R_SUCCEEDED(FSUSER_ReadExtSaveDataIcon(&smdhBytesRead, info, sizeof(SMDH), (u8*) smdh)) && smdhBytesRead == sizeof(SMDH)) { if(smdh->magic[0] == 'S' && smdh->magic[1] == 'M' && smdh->magic[2] == 'D' && smdh->magic[3] == 'H') { - u8 systemLanguage = CFG_LANGUAGE_EN; - CFGU_GetSystemLanguage(&systemLanguage); + SMDH_title* smdhTitle = util_select_smdh_title(smdh); - utf16_to_utf8((uint8_t*) item->name, smdh->titles[systemLanguage].shortDescription, LIST_ITEM_NAME_MAX - 1); + utf16_to_utf8((uint8_t*) item->name, smdhTitle->shortDescription, LIST_ITEM_NAME_MAX - 1); extSaveDataInfo->hasMeta = true; - utf16_to_utf8((uint8_t*) extSaveDataInfo->meta.shortDescription, smdh->titles[systemLanguage].shortDescription, sizeof(extSaveDataInfo->meta.shortDescription) - 1); - utf16_to_utf8((uint8_t*) extSaveDataInfo->meta.longDescription, smdh->titles[systemLanguage].longDescription, sizeof(extSaveDataInfo->meta.longDescription) - 1); - utf16_to_utf8((uint8_t*) extSaveDataInfo->meta.publisher, smdh->titles[systemLanguage].publisher, sizeof(extSaveDataInfo->meta.publisher) - 1); + utf16_to_utf8((uint8_t*) extSaveDataInfo->meta.shortDescription, smdhTitle->shortDescription, sizeof(extSaveDataInfo->meta.shortDescription) - 1); + utf16_to_utf8((uint8_t*) extSaveDataInfo->meta.longDescription, smdhTitle->longDescription, sizeof(extSaveDataInfo->meta.longDescription) - 1); + utf16_to_utf8((uint8_t*) extSaveDataInfo->meta.publisher, smdhTitle->publisher, sizeof(extSaveDataInfo->meta.publisher) - 1); extSaveDataInfo->meta.region = smdh->region; extSaveDataInfo->meta.texture = screen_allocate_free_texture(); screen_load_texture_tiled(extSaveDataInfo->meta.texture, smdh->largeIcon, sizeof(smdh->largeIcon), 48, 48, GPU_RGB565, false); diff --git a/source/ui/section/task/listfiles.c b/source/ui/section/task/listfiles.c index 32bcba1..008e0ae 100644 --- a/source/ui/section/task/listfiles.c +++ b/source/ui/section/task/listfiles.c @@ -76,13 +76,12 @@ Result task_create_file_item(list_item** out, FS_Archive archive, const char* pa if(smdh != NULL) { if(R_SUCCEEDED(util_get_cia_file_smdh(smdh, fileHandle))) { if(smdh->magic[0] == 'S' && smdh->magic[1] == 'M' && smdh->magic[2] == 'D' && smdh->magic[3] == 'H') { - u8 systemLanguage = CFG_LANGUAGE_EN; - CFGU_GetSystemLanguage(&systemLanguage); + SMDH_title* smdhTitle = util_select_smdh_title(smdh); fileInfo->ciaInfo.hasMeta = true; - utf16_to_utf8((uint8_t*) fileInfo->ciaInfo.meta.shortDescription, smdh->titles[systemLanguage].shortDescription, sizeof(fileInfo->ciaInfo.meta.shortDescription) - 1); - utf16_to_utf8((uint8_t*) fileInfo->ciaInfo.meta.longDescription, smdh->titles[systemLanguage].longDescription, sizeof(fileInfo->ciaInfo.meta.longDescription) - 1); - utf16_to_utf8((uint8_t*) fileInfo->ciaInfo.meta.publisher, smdh->titles[systemLanguage].publisher, sizeof(fileInfo->ciaInfo.meta.publisher) - 1); + utf16_to_utf8((uint8_t*) fileInfo->ciaInfo.meta.shortDescription, smdhTitle->shortDescription, sizeof(fileInfo->ciaInfo.meta.shortDescription) - 1); + utf16_to_utf8((uint8_t*) fileInfo->ciaInfo.meta.longDescription, smdhTitle->longDescription, sizeof(fileInfo->ciaInfo.meta.longDescription) - 1); + utf16_to_utf8((uint8_t*) fileInfo->ciaInfo.meta.publisher, smdhTitle->publisher, sizeof(fileInfo->ciaInfo.meta.publisher) - 1); fileInfo->ciaInfo.meta.region = smdh->region; fileInfo->ciaInfo.meta.texture = screen_allocate_free_texture(); screen_load_texture_tiled(fileInfo->ciaInfo.meta.texture, smdh->largeIcon, sizeof(smdh->largeIcon), 48, 48, GPU_RGB565, false); diff --git a/source/ui/section/task/listtitles.c b/source/ui/section/task/listtitles.c index cf0e60d..4cb6a75 100644 --- a/source/ui/section/task/listtitles.c +++ b/source/ui/section/task/listtitles.c @@ -42,14 +42,13 @@ static Result task_populate_titles_add_ctr(populate_titles_data* data, FS_MediaT if(smdh->magic[0] == 'S' && smdh->magic[1] == 'M' && smdh->magic[2] == 'D' && smdh->magic[3] == 'H') { titleInfo->hasMeta = true; - u8 systemLanguage = CFG_LANGUAGE_EN; - CFGU_GetSystemLanguage(&systemLanguage); + SMDH_title* smdhTitle = util_select_smdh_title(smdh); - utf16_to_utf8((uint8_t*) item->name, smdh->titles[systemLanguage].shortDescription, NAME_MAX - 1); + utf16_to_utf8((uint8_t*) item->name, smdhTitle->shortDescription, NAME_MAX - 1); - utf16_to_utf8((uint8_t*) titleInfo->meta.shortDescription, smdh->titles[systemLanguage].shortDescription, sizeof(titleInfo->meta.shortDescription) - 1); - utf16_to_utf8((uint8_t*) titleInfo->meta.longDescription, smdh->titles[systemLanguage].longDescription, sizeof(titleInfo->meta.longDescription) - 1); - utf16_to_utf8((uint8_t*) titleInfo->meta.publisher, smdh->titles[systemLanguage].publisher, sizeof(titleInfo->meta.publisher) - 1); + utf16_to_utf8((uint8_t*) titleInfo->meta.shortDescription, smdhTitle->shortDescription, sizeof(titleInfo->meta.shortDescription) - 1); + utf16_to_utf8((uint8_t*) titleInfo->meta.longDescription, smdhTitle->longDescription, sizeof(titleInfo->meta.longDescription) - 1); + utf16_to_utf8((uint8_t*) titleInfo->meta.publisher, smdhTitle->publisher, sizeof(titleInfo->meta.publisher) - 1); titleInfo->meta.region = smdh->region; titleInfo->meta.texture = screen_allocate_free_texture(); screen_load_texture_tiled(titleInfo->meta.texture, smdh->largeIcon, sizeof(smdh->largeIcon), 48, 48, GPU_RGB565, false); @@ -140,11 +139,8 @@ static Result task_populate_titles_add_twl(populate_titles_data* data, FS_MediaT if(R_SUCCEEDED(FSUSER_GetLegacyBannerData(mediaType, titleId, (u8*) bnr))) { titleInfo->hasMeta = true; - u8 systemLanguage = CFG_LANGUAGE_EN; - CFGU_GetSystemLanguage(&systemLanguage); - char title[0x100] = {'\0'}; - utf16_to_utf8((uint8_t*) title, bnr->titles[systemLanguage], sizeof(title) - 1); + utf16_to_utf8((uint8_t*) title, util_select_bnr_title(bnr), sizeof(title) - 1); if(strchr(title, '\n') == NULL) { size_t len = strlen(title);