diff --git a/source/badges.c b/source/badges.c index 70fc8bf..b1d9c62 100644 --- a/source/badges.c +++ b/source/badges.c @@ -246,6 +246,11 @@ int install_badge_dir(FS_DirectoryEntry set_dir, int *badge_count, int set_id) } } + if (!badges_in_set) + { + goto end; + } + int set_index = set_id - 1; u32 total_count = 0xFFFF * badges_in_set; for (int i = 0; i < 16; ++i) @@ -283,6 +288,7 @@ int install_badge_dir(FS_DirectoryEntry set_dir, int *badge_count, int set_id) free(icon_buf); memcpy(badgeDataBuffer + 0x250F80 + set_index * 0x2000, rgb_buf_64x64, 64 * 64 * 2); badgeMngBuffer[0x3D8 + set_index/8] |= 0 << (set_index % 8); + end: free(badge_files); return badges_in_set; } @@ -292,7 +298,13 @@ Result backup_badges(void) char *badgeMng = NULL; char *badgeData = NULL; + DEBUG("writing badge data: making files...\n"); + remake_file(fsMakePath(PATH_ASCII, "/3ds/Anemone3DS/BadgeMngFile.dat"), ArchiveSD, BADGE_MNG_SIZE); + remake_file(fsMakePath(PATH_ASCII, "/3ds/Anemone3DS/BadgeData.dat"), ArchiveSD, BADGE_DATA_SIZE); + + DEBUG("loading existing badge mng file...\n"); u32 mngRead = file_to_buf(fsMakePath(PATH_ASCII, "/BadgeMngFile.dat"), ArchiveBadgeExt, &badgeMng); + DEBUG("loading existing badge data file\n"); u32 dataRead = file_to_buf(fsMakePath(PATH_ASCII, "/BadgeData.dat"), ArchiveBadgeExt, &badgeData); if (mngRead != BADGE_MNG_SIZE || dataRead != BADGE_DATA_SIZE) { @@ -301,22 +313,27 @@ Result backup_badges(void) if (badgeData) free(badgeData); return -1; } - remake_file(fsMakePath(PATH_ASCII, "/3ds/Anemone3DS/BadgeMngFile.dat"), ArchiveSD, mngRead); - remake_file(fsMakePath(PATH_ASCII, "/3ds/Anemone3DS/BadgeData.dat"), ArchiveSD, dataRead); + + DEBUG("writing badge data: writing BadgeMngFile...\n"); Result res = buf_to_file(mngRead, fsMakePath(PATH_ASCII, "/3ds/Anemone3DS/BadgeMngFile.dat"), ArchiveSD, badgeMng); if (R_FAILED(res)) { + DEBUG("Failed to write badgemngfile: 0x%08lx\n", res); free(badgeMng); free(badgeData); return -1; } + DEBUG("writing badge data: writing badgedata...\n"); res = buf_to_file(dataRead, fsMakePath(PATH_ASCII, "/3ds/Anemone3DS/BadgeData.dat"), ArchiveSD, badgeData); if (R_FAILED(res)) { + DEBUG("Failed to write badgedatafile: 0x%08lx\n", res); free(badgeMng); free(badgeData); return -1; } + free(badgeMng); + free(badgeData); return 0; } @@ -326,6 +343,7 @@ Result install_badges(void) Handle folder = 0; Result res = 0; + DEBUG("Backing up badges\n"); res = backup_badges(); if (R_FAILED(res)) { @@ -333,6 +351,7 @@ Result install_badges(void) return res; } + DEBUG("Initializing ACT\n"); res = actInit(); if (R_FAILED(res)) { @@ -340,6 +359,7 @@ Result install_badges(void) return res; } + DEBUG("Initializing ACTU\n"); res = ACTU_Initialize(0xB0502C8, 0, 0); if (R_FAILED(res)) { @@ -347,6 +367,7 @@ Result install_badges(void) return res; } + DEBUG("Getting NNID\n"); u32 nnidNum = 0xFFFFFFFF; res = ACTU_GetAccountDataBlock(0xFE, 4, 12, &nnidNum); if (R_FAILED(res)) @@ -362,6 +383,7 @@ Result install_badges(void) alpha_buf_64x64 = NULL; alpha_buf_32x32 = NULL; + DEBUG("Opening badge directory\n"); FS_DirectoryEntry *badge_files = calloc(1024, sizeof(FS_DirectoryEntry)); res = FSUSER_OpenDirectory(&folder, ArchiveSD, fsMakePath(PATH_ASCII, "/Badges/")); if (R_FAILED(res)) @@ -379,6 +401,44 @@ Result install_badges(void) alpha_buf_32x32 = malloc(12*6*32*32/2); badgeDataBuffer = calloc(1, BADGE_DATA_SIZE); badgeMngBuffer = calloc(1, BADGE_MNG_SIZE); + + if (!rgb_buf_64x64) + { + DEBUG("rgb_buf_64x64 alloc failed\n"); + res = -1; + goto end; + } + + if (!alpha_buf_64x64) + { + DEBUG("alpha_buf_64x64 alloc failed\n"); + goto end; + } + + if (!rgb_buf_32x32) + { + DEBUG("rgb_buf_32x32 alloc failed\n"); + goto end; + } + + if (!alpha_buf_32x32) + { + DEBUG("alpha_buf_32x32 alloc failed\n"); + goto end; + } + + if (!badgeDataBuffer) + { + DEBUG("badgeDataBuffer alloc failed\n"); + goto end; + } + + if (!badgeMngBuffer) + { + DEBUG("badgeMngBuffer alloc failed\n"); + goto end; + } + int badge_count = 0; int set_count = 0; int default_set = 0; @@ -388,6 +448,7 @@ Result install_badges(void) { if (!strcmp(badge_files[i].shortExt, "PNG")) { + DEBUG("PNG discovered\n"); if (default_set == 0) { set_count += 1; @@ -400,6 +461,7 @@ Result install_badges(void) default_set_count += install_badge_png(fsMakePath(PATH_UTF16, path), badge_files[i], &badge_count, default_set); } else if (!strcmp(badge_files[i].shortExt, "ZIP")) { + DEBUG("ZIP discovered\n"); if (default_set == 0) { set_count += 1; @@ -412,11 +474,15 @@ Result install_badges(void) default_set_count += install_badge_zip(path, &badge_count, default_set); } else if (badge_files[i].attributes & FS_ATTRIBUTE_DIRECTORY) { + DEBUG("dir discovered\n"); set_count += 1; - install_badge_dir(badge_files[i], &badge_count, set_count); + u32 count = install_badge_dir(badge_files[i], &badge_count, set_count); + if (count == 0) + set_count -= 1; } } + DEBUG("Badges installed - doing metadata\n"); if (default_set != 0) { int default_index = default_set - 1; diff --git a/source/fs.c b/source/fs.c index d6b78f6..e731a4e 100644 --- a/source/fs.c +++ b/source/fs.c @@ -210,6 +210,11 @@ u32 file_to_buf(FS_Path path, FS_Archive archive, char ** buf) if(size != 0) { *buf = calloc(1, size); + if (*buf == NULL) + { + DEBUG("Error allocating buffer - out of memory??\n"); + return 0; + } FSFILE_Read(file, NULL, 0, *buf, size); } FSFILE_Close(file); @@ -474,8 +479,13 @@ void remake_file(FS_Path path, FS_Archive archive, u32 size) } FSUSER_CreateFile(archive, path, 0, size); char * buf = calloc(size, 1); - buf_to_file(size, path, archive, buf); - free(buf); + if (buf == NULL) + { + DEBUG("out of memory - not overwriting file?\n"); + } else { + buf_to_file(size, path, archive, buf); + free(buf); + } } static SwkbdCallbackResult fat32filter(void * user, const char ** ppMessage, const char * text, size_t textlen) diff --git a/source/remote.c b/source/remote.c index be546a3..8c118e1 100644 --- a/source/remote.c +++ b/source/remote.c @@ -565,16 +565,20 @@ bool themeplaza_browser(RemoteMode mode) { extra_mode = false; } - else if (kDown & KEY_DLEFT) + else if (kDown & KEY_L) { extra_mode = false; - change_mode: - mode++; - mode %= REMOTE_MODE_AMOUNT; - + mode = REMOTE_MODE_SPLASHES; + free(current_list->tp_search); + current_list->tp_search = strdup(""); + load_remote_list(current_list, 1, mode, false); + } + else if (kDown & KEY_R) + { + extra_mode = false; + mode = REMOTE_MODE_BADGES; free(current_list->tp_search); current_list->tp_search = strdup(""); - load_remote_list(current_list, 1, mode, false); } else if (kDown & KEY_DUP) @@ -721,7 +725,13 @@ bool themeplaza_browser(RemoteMode mode) } else if (BETWEEN(320 - 24, x, 320)) { - goto change_mode; + mode++; + mode %= REMOTE_MODE_AMOUNT; + + free(current_list->tp_search); + current_list->tp_search = strdup(""); + + load_remote_list(current_list, 1, mode, false); } } else if (BETWEEN(240 - 24, y, 240) && BETWEEN(176, x, 320)) diff --git a/source/ui_strings.c b/source/ui_strings.c index 6eb7109..7b7fc3b 100644 --- a/source/ui_strings.c +++ b/source/ui_strings.c @@ -355,12 +355,12 @@ const Language_s language_english = { "\uE07A Search tags" }, { - "\uE07B Switch modes", + NULL, "\uE07C Reload without cache" }, { - NULL, - NULL + "\uE004 Switch to Splashes", + "\uE005 Switch to Badges" }, { "Exit", @@ -715,12 +715,12 @@ const Language_s language_spanish = { "\uE07A Buscar etiquetas" }, { - "\uE07B Alternar fondo/tema", + NULL, "\uE07C Recargar sin caché" }, { - NULL, - NULL + "\uE004 Switch to Splashes", + "\uE005 Switch to Badges" }, { "Salir", @@ -1077,12 +1077,12 @@ const Language_s language_french = { "\uE07A Tags de recherche" }, { - "\uE07B Splash/Thème", + NULL, "\uE07C Actualiser sans cache" }, { - NULL, - NULL + "\uE004 Switch to Splashes", + "\uE005 Switch to Badges" }, { "Quitter", @@ -1438,12 +1438,12 @@ const Language_s language_portuguese = { "\uE07A Pesquisar tags" }, { - "\uE07B Alternar splash/tema", + NULL, "\uE07C Recarregar sem cache" }, { - NULL, - NULL + "\uE004 Switch to Splashes", + "\uE005 Switch to Badges" }, { "Sair",