From 6d6fb4e3a329d2213aad37e799c63f720ac35e5c Mon Sep 17 00:00:00 2001 From: yellows8 Date: Sat, 20 Oct 2018 12:54:03 -0400 Subject: [PATCH] Allow aborting the netloader transfer when the user presses B. When decompress() aborts/fails, delete the file. When returning to HBMENU_DEFAULT from netloader, reload the menu since the netloader NRO may have been deleted due to transfer abort/failure. Minor adjustments. --- common/menu.c | 5 ++++- common/netloader.c | 17 ++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/common/menu.c b/common/menu.c index b532985..fdad9dd 100644 --- a/common/menu.c +++ b/common/menu.c @@ -496,7 +496,7 @@ void drawButtons(menu_s* menu, bool emptyDir, int *x_image_out) { void menuLoop(void) { menuEntry_s* me; menuEntry_s* netloader_me = NULL; - menu_s* menu = menuGetCurrent(); + menu_s* menu = NULL; int i; int x, y; int menupath_x_endpos = 918 + 40; @@ -539,8 +539,11 @@ void menuLoop(void) { hbmenu_state = HBMENU_NETLOADER_ACTIVE; } else if(hbmenu_state == HBMENU_NETLOADER_ACTIVE && !netloader_activated && !netloader_launch_app) { hbmenu_state = HBMENU_DEFAULT; + menuScan(".");//Reload the menu since netloader may have deleted the NRO if the transfer aborted. } + menu = menuGetCurrent(); + if (netloader_errormsg[0]) menuCreateMsgBox(780,300, netloader_errormsg); if (menu->nEntries==0 || hbmenu_state == HBMENU_NETLOADER_ACTIVE) diff --git a/common/netloader.c b/common/netloader.c index 86ca3cf..0b42e96 100644 --- a/common/netloader.c +++ b/common/netloader.c @@ -51,6 +51,8 @@ static bool netloader_activated = 0, netloader_launchapp = 0; static menuEntry_s netloader_me; static char netloader_errortext[1024]; +static bool netloaderGetExit(void); + //--------------------------------------------------------------------------------- static void netloader_error(const char *func, int err) { //--------------------------------------------------------------------------------- @@ -230,6 +232,10 @@ static int decompress(int sock, FILE *fh, size_t filesize) { size_t total = 0; /* decompress until deflate stream ends or end of file */ do { + if (netloaderGetExit()) { + ret = Z_DATA_ERROR; + break; + } int len = recvall(sock, &chunksize, 4, 0); @@ -394,6 +400,7 @@ int loadnro(menuEntry_s *me, int sock, struct in_addr remote) { fflush(file); fclose(file); + if (response == -1) unlink(me->path); } return response; @@ -600,8 +607,7 @@ void netloaderSignalExit(void) { mtx_unlock(&netloader_mtx); } -bool netloaderInit(void) -{ +bool netloaderInit(void) { if (netloader_initialized) return 1; if (mtx_init(&netloader_mtx, mtx_plain) != thrd_success) return 0; @@ -610,17 +616,14 @@ bool netloaderInit(void) return 1; } -void netloaderExit(void) -{ +void netloaderExit(void) { if (!netloader_initialized) return; netloader_initialized = 0; mtx_destroy(&netloader_mtx); } -//--------------------------------------------------------------------------------- void netloaderTask(void* arg) { -//--------------------------------------------------------------------------------- int ret=0; menuEntryInit(&netloader_me,ENTRY_TYPE_FILE); @@ -646,7 +649,7 @@ void netloaderTask(void* arg) { mtx_lock(&netloader_mtx); netloader_exitflag = 0; netloader_activated = 0; - if (ret==1) netloader_launchapp = 1; + if (ret==1 && !netloader_exitflag) netloader_launchapp = 1;//Access netloader_exitflag directly since the mutex is already locked. mtx_unlock(&netloader_mtx); }