From a4532b0f3dc294245305e2af46b356de97574050 Mon Sep 17 00:00:00 2001 From: Alex Taber Date: Fri, 12 Jun 2020 12:02:13 -0400 Subject: [PATCH] Various fixes Stop loading themes missing smdh files - this was causing scroll crashes due to how the icon loading code was working. In the future we will include a message about how themes are skipped due to lacking smdh files. Invalid zips also caused the same issue and are also now being properly ignored Fix memory leak in the zip file loading code --- source/fs.c | 1 + source/loading.c | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/source/fs.c b/source/fs.c index 015cb2c..2b954f6 100644 --- a/source/fs.c +++ b/source/fs.c @@ -176,6 +176,7 @@ u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf) archive_read_support_format_zip(a); int r = archive_read_open_filename(a, path, 0x4000); + free(path); if(r != ARCHIVE_OK) { DEBUG("Invalid zip being opened\n"); diff --git a/source/loading.c b/source/loading.c index acfe931..61556c5 100644 --- a/source/loading.c +++ b/source/loading.c @@ -187,9 +187,27 @@ Result load_entries(const char * loading_path, Entry_List_s * list) if(R_FAILED(res) || entries_read == 0) break; - if(!(dir_entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(dir_entry.shortExt, "ZIP")) + if(!(dir_entry.attributes & FS_ATTRIBUTE_DIRECTORY) && strcmp(dir_entry.shortExt, "ZIP")) continue; + u16 path[0x106] = {0}; + struacat(path, loading_path); + strucat(path, dir_entry.name); + char * buf = NULL; + + if (!strcmp(dir_entry.shortExt, "ZIP")) + { + u32 size = zip_file_to_buf("info.smdh", path, &buf); + if (size == 0) continue; + } + else + { + struacat(path, "/info.smdh"); + u32 size = file_to_buf(fsMakePath(PATH_UTF16, path), ArchiveSD, &buf); + if (size == 0) continue; + } + + free(buf); list->entries_count++; Entry_s * new_list = realloc(list->entries, list->entries_count * sizeof(Entry_s)); if(new_list == NULL) @@ -645,4 +663,4 @@ Result load_audio(Entry_s entry, audio_s *audio) DEBUG(" fmemopen failed!\n"); return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_APPLICATION, RD_NOT_FOUND); } -} \ No newline at end of file +}