From 5d1944b43c9be1f60f7bd13ef4fe171ad7669b1a Mon Sep 17 00:00:00 2001 From: Pablo Curiel Date: Thu, 30 Jul 2020 18:40:02 -0400 Subject: [PATCH] Move title info dump code to a template. --- code_templates/dump_title_infos.c | 79 +++++++++++++++++++++++++ source/title.c | 95 ------------------------------- todo.txt | 1 - 3 files changed, 79 insertions(+), 96 deletions(-) create mode 100644 code_templates/dump_title_infos.c diff --git a/code_templates/dump_title_infos.c b/code_templates/dump_title_infos.c new file mode 100644 index 0000000..3943815 --- /dev/null +++ b/code_templates/dump_title_infos.c @@ -0,0 +1,79 @@ + if (g_titleInfo && g_titleInfoCount) + { + mkdir("sdmc:/records", 0777); + + FILE *title_infos_txt = NULL, *icon_jpg = NULL; + char icon_path[FS_MAX_PATH] = {0}; + + title_infos_txt = fopen("sdmc:/records/title_infos.txt", "wb"); + if (title_infos_txt) + { + for(u32 i = 0; i < g_titleInfoCount; i++) + { + fprintf(title_infos_txt, "Storage ID: 0x%02X\r\n", g_titleInfo[i].storage_id); + fprintf(title_infos_txt, "Title ID: %016lX\r\n", g_titleInfo[i].meta_key.id); + fprintf(title_infos_txt, "Version: %u (%u.%u.%u-%u.%u)\r\n", g_titleInfo[i].meta_key.version, g_titleInfo[i].dot_version.TitleVersion_Major, \ + g_titleInfo[i].dot_version.TitleVersion_Minor, g_titleInfo[i].dot_version.TitleVersion_Micro, g_titleInfo[i].dot_version.TitleVersion_MajorRelstep, \ + g_titleInfo[i].dot_version.TitleVersion_MinorRelstep); + fprintf(title_infos_txt, "Type: 0x%02X\r\n", g_titleInfo[i].meta_key.type); + fprintf(title_infos_txt, "Install Type: 0x%02X\r\n", g_titleInfo[i].meta_key.install_type); + fprintf(title_infos_txt, "Title Size: %s (0x%lX)\r\n", g_titleInfo[i].title_size_str, g_titleInfo[i].title_size); + + fprintf(title_infos_txt, "Content Count: %u\r\n", g_titleInfo[i].content_count); + for(u32 j = 0; j < g_titleInfo[i].content_count; j++) + { + char content_id_str[SHA256_HASH_SIZE + 1] = {0}; + utilsGenerateHexStringFromData(content_id_str, sizeof(content_id_str), g_titleInfo[i].content_infos[j].content_id.c, SHA256_HASH_SIZE / 2); + + u64 content_size = 0; + titleConvertNcmContentSizeToU64(g_titleInfo[i].content_infos[j].size, &content_size); + + char content_size_str[32] = {0}; + utilsGenerateFormattedSizeString(content_size, content_size_str, sizeof(content_size_str)); + + fprintf(title_infos_txt, " Content #%u:\r\n", j + 1); + fprintf(title_infos_txt, " Content ID: %s\r\n", content_id_str); + fprintf(title_infos_txt, " Content Size: %s (0x%lX)\r\n", content_size_str, content_size); + fprintf(title_infos_txt, " Content Type: 0x%02X\r\n", g_titleInfo[i].content_infos[j].content_type); + fprintf(title_infos_txt, " ID Offset: 0x%02X\r\n", g_titleInfo[i].content_infos[j].id_offset); + } + + if ((g_titleInfo[i].meta_key.type == NcmContentMetaType_Application && g_titleInfo[i].app_metadata) || ((g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch || \ + g_titleInfo[i].meta_key.type == NcmContentMetaType_AddOnContent) && g_titleInfo[i].parent && g_titleInfo[i].parent->app_metadata)) + { + TitleApplicationMetadata *app_metadata = (g_titleInfo[i].meta_key.type == NcmContentMetaType_Application ? g_titleInfo[i].app_metadata : g_titleInfo[i].parent->app_metadata); + + if (strlen(app_metadata->lang_entry.name)) fprintf(title_infos_txt, "Name: %s\r\n", app_metadata->lang_entry.name); + if (strlen(app_metadata->lang_entry.author)) fprintf(title_infos_txt, "Author: %s\r\n", app_metadata->lang_entry.author); + + if (g_titleInfo[i].meta_key.type == NcmContentMetaType_Application && app_metadata->icon_size && app_metadata->icon) + { + fprintf(title_infos_txt, "JPEG Icon Size: 0x%X\r\n", app_metadata->icon_size); + + sprintf(icon_path, "sdmc:/records/%016lX.jpg", app_metadata->title_id); + + icon_jpg = fopen(icon_path, "wb"); + if (icon_jpg) + { + fwrite(app_metadata->icon, 1, app_metadata->icon_size, icon_jpg); + fclose(icon_jpg); + icon_jpg = NULL; + } + } + } + + if (g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch || g_titleInfo[i].meta_key.type == NcmContentMetaType_AddOnContent) + { + if (g_titleInfo[i].previous) fprintf(title_infos_txt, "Previous %s ID: %016lX\r\n", g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch ? "Patch" : "AOC", g_titleInfo[i].previous->meta_key.id); + if (g_titleInfo[i].next) fprintf(title_infos_txt, "Next %s ID: %016lX\r\n", g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch ? "Patch" : "AOC", g_titleInfo[i].next->meta_key.id); + } + + fprintf(title_infos_txt, "\r\n"); + + fflush(title_infos_txt); + } + + fclose(title_infos_txt); + title_infos_txt = NULL; + } + } \ No newline at end of file diff --git a/source/title.c b/source/title.c index 69fafab..c64497b 100644 --- a/source/title.c +++ b/source/title.c @@ -460,101 +460,6 @@ bool titleInitialize(void) /* Create gamecard title info thread. */ if (!(g_titleGameCardInfoThreadCreated = titleCreateGameCardInfoThread())) goto end; - - /* - - - if (g_titleInfo && g_titleInfoCount) - { - mkdir("sdmc:/records", 0777); - - FILE *title_infos_txt = NULL, *icon_jpg = NULL; - char icon_path[FS_MAX_PATH] = {0}; - - title_infos_txt = fopen("sdmc:/records/title_infos.txt", "wb"); - if (title_infos_txt) - { - for(u32 i = 0; i < g_titleInfoCount; i++) - { - fprintf(title_infos_txt, "Storage ID: 0x%02X\r\n", g_titleInfo[i].storage_id); - fprintf(title_infos_txt, "Title ID: %016lX\r\n", g_titleInfo[i].meta_key.id); - fprintf(title_infos_txt, "Version: %u (%u.%u.%u-%u.%u)\r\n", g_titleInfo[i].meta_key.version, g_titleInfo[i].dot_version.TitleVersion_Major, \ - g_titleInfo[i].dot_version.TitleVersion_Minor, g_titleInfo[i].dot_version.TitleVersion_Micro, g_titleInfo[i].dot_version.TitleVersion_MajorRelstep, \ - g_titleInfo[i].dot_version.TitleVersion_MinorRelstep); - fprintf(title_infos_txt, "Type: 0x%02X\r\n", g_titleInfo[i].meta_key.type); - fprintf(title_infos_txt, "Install Type: 0x%02X\r\n", g_titleInfo[i].meta_key.install_type); - fprintf(title_infos_txt, "Title Size: %s (0x%lX)\r\n", g_titleInfo[i].title_size_str, g_titleInfo[i].title_size); - - fprintf(title_infos_txt, "Content Count: %u\r\n", g_titleInfo[i].content_count); - for(u32 j = 0; j < g_titleInfo[i].content_count; j++) - { - char content_id_str[SHA256_HASH_SIZE + 1] = {0}; - utilsGenerateHexStringFromData(content_id_str, sizeof(content_id_str), g_titleInfo[i].content_infos[j].content_id.c, SHA256_HASH_SIZE / 2); - - u64 content_size = 0; - titleConvertNcmContentSizeToU64(g_titleInfo[i].content_infos[j].size, &content_size); - - char content_size_str[32] = {0}; - utilsGenerateFormattedSizeString(content_size, content_size_str, sizeof(content_size_str)); - - fprintf(title_infos_txt, " Content #%u:\r\n", j + 1); - fprintf(title_infos_txt, " Content ID: %s\r\n", content_id_str); - fprintf(title_infos_txt, " Content Size: %s (0x%lX)\r\n", content_size_str, content_size); - fprintf(title_infos_txt, " Content Type: 0x%02X\r\n", g_titleInfo[i].content_infos[j].content_type); - fprintf(title_infos_txt, " ID Offset: 0x%02X\r\n", g_titleInfo[i].content_infos[j].id_offset); - } - - if ((g_titleInfo[i].meta_key.type == NcmContentMetaType_Application && g_titleInfo[i].app_metadata) || ((g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch || \ - g_titleInfo[i].meta_key.type == NcmContentMetaType_AddOnContent) && g_titleInfo[i].parent && g_titleInfo[i].parent->app_metadata)) - { - TitleApplicationMetadata *app_metadata = (g_titleInfo[i].meta_key.type == NcmContentMetaType_Application ? g_titleInfo[i].app_metadata : g_titleInfo[i].parent->app_metadata); - - if (strlen(app_metadata->lang_entry.name)) fprintf(title_infos_txt, "Name: %s\r\n", app_metadata->lang_entry.name); - if (strlen(app_metadata->lang_entry.author)) fprintf(title_infos_txt, "Author: %s\r\n", app_metadata->lang_entry.author); - - if (g_titleInfo[i].meta_key.type == NcmContentMetaType_Application && app_metadata->icon_size && app_metadata->icon) - { - fprintf(title_infos_txt, "JPEG Icon Size: 0x%X\r\n", app_metadata->icon_size); - - sprintf(icon_path, "sdmc:/records/%016lX.jpg", app_metadata->title_id); - - icon_jpg = fopen(icon_path, "wb"); - if (icon_jpg) - { - fwrite(app_metadata->icon, 1, app_metadata->icon_size, icon_jpg); - fclose(icon_jpg); - icon_jpg = NULL; - } - } - } - - if (g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch || g_titleInfo[i].meta_key.type == NcmContentMetaType_AddOnContent) - { - if (g_titleInfo[i].previous) fprintf(title_infos_txt, "Previous %s ID: %016lX\r\n", g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch ? "Patch" : "AOC", g_titleInfo[i].previous->meta_key.id); - if (g_titleInfo[i].next) fprintf(title_infos_txt, "Next %s ID: %016lX\r\n", g_titleInfo[i].meta_key.type == NcmContentMetaType_Patch ? "Patch" : "AOC", g_titleInfo[i].next->meta_key.id); - } - - fprintf(title_infos_txt, "\r\n"); - - fflush(title_infos_txt); - } - - fclose(title_infos_txt); - title_infos_txt = NULL; - } - } - - - - */ - - - - - - - - ret = g_titleInterfaceInit = true; end: diff --git a/todo.txt b/todo.txt index dbf9fe7..3895adc 100644 --- a/todo.txt +++ b/todo.txt @@ -21,6 +21,5 @@ todo: title: more functions for title lookup (filters, patches / aoc, etc.) title: more functions for content lookup (based on id?) - title: find a nice way to deal with *true* orphan content (no ns records from parent base game) \ No newline at end of file