From 88ad579fe90cddd46a0982c634c7e1e30d8fc72f Mon Sep 17 00:00:00 2001 From: "fix94.1" Date: Wed, 18 Sep 2013 23:59:14 +0000 Subject: [PATCH] -fixed the missing pointer and right stick movement detections for the screensaver -made our cover loader much safer (thanks ALOT seam for all the help getting that done) -fixed a cleanup bug in cover png loading which might caused some memory leak --- source/btnmap.h | 3 ++- source/gui/coverflow.cpp | 41 ++++++++++++++++++++++++++++++++------ source/menu/menu.cpp | 15 ++++++++------ source/menu/menu_input.cpp | 7 +++++-- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/source/btnmap.h b/source/btnmap.h index d451739c..d288fcd3 100644 --- a/source/btnmap.h +++ b/source/btnmap.h @@ -133,7 +133,8 @@ enum #define RIGHT_STICK_DOWN rStick_Down() #define RIGHT_STICK_LEFT rStick_Left() #define RIGHT_STICK_RIGHT rStick_Right() - +#define RIGHT_STICK_MOVE (RIGHT_STICK_UP || RIGHT_STICK_DOWN \ + || RIGHT_STICK_LEFT || RIGHT_STICK_RIGHT) #define WROLL_LEFT wRoll_Left() #define WROLL_RIGHT wRoll_Right() diff --git a/source/gui/coverflow.cpp b/source/gui/coverflow.cpp index 619df897..a7dab453 100644 --- a/source/gui/coverflow.cpp +++ b/source/gui/coverflow.cpp @@ -2622,14 +2622,23 @@ bool CCoverFlow::_loadCoverTexPNG(u32 i, bool box, bool hq, bool blankBoxCover) mainMenu.getBoxPath(m_items[i].hdr)) : mainMenu.getFrontPath(m_items[i].hdr); if(path == NULL) return false; + size_t path_len = strlen(path); + char *path_place = (char*)MEM2_alloc(path_len+1); + if(path_place == NULL) + return false; + memset(path_place, 0, path_len+1); + memcpy(path_place, path, path_len); + DCFlushRange(path_place, path_len+1); TexData tex; tex.thread = true; m_renderingTex = &tex; - if(TexHandle.fromImageFile(tex, path, textureFmt, 32) != TE_OK) + if(TexHandle.fromImageFile(tex, path_place, textureFmt, 32) != TE_OK) { + MEM2_free(path_place); m_renderingTex = NULL; return false; } + MEM2_free(path_place); m_renderingTex = NULL; if(!m_loadingCovers) return false; @@ -2647,7 +2656,7 @@ bool CCoverFlow::_loadCoverTexPNG(u32 i, bool box, bool hq, bool blankBoxCover) u32 bufSize = fixGX_GetTexBufferSize(tex.width, tex.height, tex.format, tex.maxLOD > 0 ? GX_TRUE : GX_FALSE, tex.maxLOD); uLongf zBufferSize = m_compressCache ? bufSize + bufSize / 100 + 12 : bufSize; u8 *zBuffer = m_compressCache ? (u8*)MEM2_alloc(zBufferSize) : tex.data; - if(!!zBuffer && (!m_compressCache || compress(zBuffer, &zBufferSize, tex.data, bufSize) == Z_OK)) + if(zBuffer != NULL && (!m_compressCache || compress(zBuffer, &zBufferSize, tex.data, bufSize) == Z_OK)) { const char *gamePath = NULL; const char *coverDir = NULL; @@ -2674,8 +2683,16 @@ bool CCoverFlow::_loadCoverTexPNG(u32 i, bool box, bool hq, bool blankBoxCover) FILE *file = NULL; if(gamePath != NULL) { + char *full_path = (char*)MEM2_alloc(MAX_FAT_PATH+1); + if(full_path == NULL) + { + if(zBuffer != NULL && m_compressCache) + MEM2_free(zBuffer); + return false; + } + memset(full_path, 0, MAX_FAT_PATH+1); if(coverDir == NULL || strlen(coverDir) == 0) - file = fopen(fmt("%s/%s.wfc", m_cachePath.c_str(), gamePath), "wb"); + strncpy(full_path, fmt("%s/%s.wfc", m_cachePath.c_str(), gamePath), MAX_FAT_PATH); else { if(strchr(coverDir, '/') != NULL) @@ -2694,8 +2711,11 @@ bool CCoverFlow::_loadCoverTexPNG(u32 i, bool box, bool hq, bool blankBoxCover) MEM2_free(tmp); } fsop_MakeFolder(fmt("%s/%s", m_cachePath.c_str(), coverDir)); - file = fopen(fmt("%s/%s/%s.wfc", m_cachePath.c_str(), coverDir, gamePath), "wb"); + strncpy(full_path, fmt("%s/%s/%s.wfc", m_cachePath.c_str(), coverDir, gamePath), MAX_FAT_PATH); } + DCFlushRange(full_path, MAX_FAT_PATH+1); + file = fopen(full_path, "wb"); + MEM2_free(full_path); } if(file != NULL) { @@ -2706,6 +2726,8 @@ bool CCoverFlow::_loadCoverTexPNG(u32 i, bool box, bool hq, bool blankBoxCover) if (m_deletePicsAfterCaching) fsop_deleteFile(path); } + if(zBuffer != NULL && m_compressCache) + MEM2_free(zBuffer); } } if (!hq) _dropHQLOD(i); @@ -2791,10 +2813,17 @@ CCoverFlow::CLRet CCoverFlow::_loadCoverTex(u32 i, bool box, bool hq, bool blank FILE *fp = NULL; if(gamePath != NULL) { + char *full_path = (char*)MEM2_alloc(MAX_FAT_PATH+1); + if(full_path == NULL) + return CL_NOMEM; + memset(full_path, 0, MAX_FAT_PATH+1); if(coverDir == NULL || strlen(coverDir) == 0) - fp = fopen(fmt("%s/%s.wfc", m_cachePath.c_str(), gamePath), "rb"); + strncpy(full_path, fmt("%s/%s.wfc", m_cachePath.c_str(), gamePath), MAX_FAT_PATH); else - fp = fopen(fmt("%s/%s/%s.wfc", m_cachePath.c_str(), coverDir, gamePath), "rb"); + strncpy(full_path, fmt("%s/%s/%s.wfc", m_cachePath.c_str(), coverDir, gamePath), MAX_FAT_PATH); + DCFlushRange(full_path, MAX_FAT_PATH+1); + fp = fopen(full_path, "rb"); + MEM2_free(full_path); } if(fp != NULL) { diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 68c1ea08..d74d0573 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -2470,20 +2470,24 @@ void CMenu::_cleanupDefaultFont() m_wbf2_font = NULL; } -char tmp[256]; const char *CMenu::_getId() { + char tmp[MAX_FAT_PATH]; + memset(tmp, 0, MAX_FAT_PATH); const char *id = NULL; const dir_discHdr *hdr = CoverFlow.getHdr(); if(hdr->type == TYPE_HOMEBREW) id = strrchr(hdr->path, '/') + 1; else if(hdr->type == TYPE_PLUGIN) { - tmp[0] = '\0'; - if(strrchr(hdr->path, ':') != NULL) + if(strstr(hdr->path, ":/") != NULL) { - strcat(tmp, strchr(hdr->path, '/') + 1); - *(strchr(tmp, '/') + 1) = '\0'; + if(*(strchr(hdr->path, '/') + 1) != '\0') + strcat(tmp, strchr(hdr->path, '/') + 1); + else + strcat(tmp, hdr->path); + if(strchr(tmp, '/') != NULL) + *(strchr(tmp, '/') + 1) = '\0'; } strcat(tmp, fmt("%ls",hdr->title)); id = tmp; @@ -2493,7 +2497,6 @@ const char *CMenu::_getId() id = hdr->id; if(hdr->type == TYPE_GC_GAME && hdr->settings[0] == 1) /* disc 2 */ { - tmp[0] = '\0'; strcat(tmp, fmt("%.6s_2", hdr->id)); id = tmp; } diff --git a/source/menu/menu_input.cpp b/source/menu/menu_input.cpp index b08c6314..6621ec71 100644 --- a/source/menu/menu_input.cpp +++ b/source/menu/menu_input.cpp @@ -588,14 +588,17 @@ void CMenu::ShowGameZone() u32 CMenu::NoInputTime() { bool input_found = false; - if(gc_btnsPressed != 0) + if(ShowPointer() == true || RIGHT_STICK_MOVE == true || gc_btnsPressed != 0) input_found = true; else { for(int chan = WPAD_MAX_WIIMOTES-1; chan >= 0; chan--) { - if(wii_btnsPressed[chan] != 0 || wii_btnsHeld[chan] != 0 || m_show_pointer[chan] == true) + if(wii_btnsPressed[chan] != 0 || wii_btnsHeld[chan] != 0) + { input_found = true; + break; + } } } if(input_found == false)