From 04821154e0c72b08cfab98239b46b4c0e7a527be Mon Sep 17 00:00:00 2001 From: dborth Date: Wed, 23 Dec 2009 00:26:54 +0000 Subject: [PATCH] jump to last file, improved auto update, make folders if not present --- source/ngc/fceugx.cpp | 1 + source/ngc/fceugx.h | 1 + source/ngc/filebrowser.cpp | 2 + source/ngc/fileop.cpp | 38 +++++++++++++++++- source/ngc/fileop.h | 1 + source/ngc/menu.cpp | 8 ++++ source/ngc/networkop.cpp | 81 +++++++++++++++++++++----------------- source/ngc/preferences.cpp | 35 ++++++++++------ 8 files changed, 118 insertions(+), 49 deletions(-) diff --git a/source/ngc/fceugx.cpp b/source/ngc/fceugx.cpp index 4c9b429..31dd7d7 100644 --- a/source/ngc/fceugx.cpp +++ b/source/ngc/fceugx.cpp @@ -62,6 +62,7 @@ int ShutdownRequested = 0; int ResetRequested = 0; int ExitRequested = 0; char appPath[1024] = { 0 }; +char loadedFile[1024] = { 0 }; int frameskip = 0; int turbomode = 0; unsigned char * nesrom = NULL; diff --git a/source/ngc/fceugx.h b/source/ngc/fceugx.h index 169be39..f11efdf 100644 --- a/source/ngc/fceugx.h +++ b/source/ngc/fceugx.h @@ -102,6 +102,7 @@ extern int ConfigRequested; extern int ShutdownRequested; extern int ExitRequested; extern char appPath[]; +extern char loadedFile[]; extern int frameskip; extern int turbomode; extern bool romLoaded; diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 9d3b9df..5ed934f 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -481,6 +481,8 @@ int BrowserLoadFile() if(!IsValidROM()) goto done; + strcpy(loadedFile, browserList[browser.selIndex].filename); + // store the filename (w/o ext) - used for ram/state naming StripExt(romFilename, browserList[browser.selIndex].filename); diff --git a/source/ngc/fileop.cpp b/source/ngc/fileop.cpp index a4081f1..6b9d615 100644 --- a/source/ngc/fileop.cpp +++ b/source/ngc/fileop.cpp @@ -32,6 +32,7 @@ #include "gcunzip.h" #include "menu.h" #include "filebrowser.h" +#include "gui/gui.h" #define THREAD_SLEEP 100 @@ -56,6 +57,7 @@ static lwp_t parsethread = LWP_THREAD_NULL; static DIR_ITER * dirIter = NULL; static bool parseHalt = true; bool ParseDirEntries(); +int selectLoadedFile = 0; // device thread static lwp_t devicethread = LWP_THREAD_NULL; @@ -526,9 +528,41 @@ bool ParseDirEntries() // Sort the file list if(i >= 0) { - browser.numEntries += i; - qsort(browserList, browser.numEntries, sizeof(BROWSERENTRY), FileSortCallback); + qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback); } + + // try to find and select the last loaded file + if(selectLoadedFile == 1 && res != 0 && loadedFile[0] != 0 && browser.dir[0] != 0) + { + int indexFound = -1; + + for(int j=1; j < browser.numEntries + i; j++) + { + if(strcmp(browserList[j].filename, loadedFile) == 0) + { + indexFound = j; + break; + } + } + + // move to this file + if(indexFound > 0) + { + if(indexFound > FILE_PAGESIZE) + { + browser.pageIndex = (ceil(indexFound/FILE_PAGESIZE*1.0)) * FILE_PAGESIZE; + + if(browser.pageIndex + FILE_PAGESIZE > browser.numEntries + i) + { + browser.pageIndex = browser.numEntries + i - FILE_PAGESIZE; + } + } + browser.selIndex = indexFound; + } + selectLoadedFile = 2; // selecting done + } + + browser.numEntries += i; if(res != 0 || parseHalt) { diff --git a/source/ngc/fileop.h b/source/ngc/fileop.h index 60e590a..49186b6 100644 --- a/source/ngc/fileop.h +++ b/source/ngc/fileop.h @@ -45,5 +45,6 @@ extern unsigned char savebuffer[]; extern FILE * file; extern bool unmountRequired[]; extern bool isMounted[]; +extern int selectLoadedFile; #endif diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index 214d319..16fce40 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -971,6 +971,7 @@ static int MenuGameSelection() #endif // populate initial directory listing + selectLoadedFile = 1; OpenGameList(); gameBrowser.ResetState(); @@ -981,6 +982,13 @@ static int MenuGameSelection() { usleep(THREAD_SLEEP); + if(selectLoadedFile == 2) + { + selectLoadedFile = 0; + mainWindow->ChangeFocus(&gameBrowser); + gameBrowser.TriggerUpdate(); + } + // update gameWindow based on arrow buttons // set MENU_EXIT if A button pressed on a game for(i=0; i < FILE_PAGESIZE; i++) diff --git a/source/ngc/networkop.cpp b/source/ngc/networkop.cpp index df47fc3..65db6cd 100644 --- a/source/ngc/networkop.cpp +++ b/source/ngc/networkop.cpp @@ -48,7 +48,7 @@ bool updateFound = false; // true if an app update was found void UpdateCheck() { // we can only check for the update if we have internet + SD - if(!updateChecked && networkInit && isMounted[DEVICE_SD]) + if(!updateChecked && networkInit && (isMounted[DEVICE_SD] || isMounted[DEVICE_USB])) { static char url[128]; int retval; @@ -136,43 +136,52 @@ static bool unzipArchive(char * zipfilepath, char * unzipfolderpath) bool DownloadUpdate() { bool result = false; - if(strlen(updateURL) > 0) + + if(strlen(updateURL) == 0 || strlen(appPath) == 0) + goto done; + + if(!ChangeInterface(appPath, NOTSILENT)) + goto done; + + // stop checking if devices were removed/inserted + // since we're saving a file + HaltDeviceThread(); + + // find devoptab name + char dev[10]; + int i; + for(i=0; i < 8; i++) { - // stop checking if devices were removed/inserted - // since we're saving a file - HaltDeviceThread(); - - FILE * hfile; - char updateFile[50]; - sprintf(updateFile, "sd:/%s Update.zip", APPNAME); - hfile = fopen (updateFile, "wb"); - - if (hfile > 0) - { - int retval; - retval = http_request(updateURL, hfile, NULL, (1024*1024*5)); - fclose (hfile); - } - - bool unzipResult = unzipArchive(updateFile, (char *)"sd:/"); - remove(updateFile); // delete update file - - if(unzipResult) - { - result = true; - InfoPrompt("Update successful!"); - } - else - { - result = false; - ErrorPrompt("Update failed!"); - } - - updateFound = false; // updating is finished (successful or not!) - - // go back to checking if devices were inserted/removed - ResumeDeviceThread(); + dev[i] = appPath[i]; + if(appPath[i] == '/') break; } + dev[i+1] = 0; + + FILE * hfile; + char updateFile[50]; + sprintf(updateFile, "%s%s Update.zip", dev, APPNAME); + hfile = fopen (updateFile, "wb"); + + if (hfile > 0) + { + int retval; + retval = http_request(updateURL, hfile, NULL, (1024*1024*5)); + fclose (hfile); + } + + result = unzipArchive(updateFile, dev); + remove(updateFile); // delete update file + + // go back to checking if devices were inserted/removed + ResumeDeviceThread(); + +done: + if(result) + InfoPrompt("Update successful!"); + else + ErrorPrompt("Update failed!"); + + updateFound = false; // updating is finished (successful or not!) return result; } diff --git a/source/ngc/preferences.cpp b/source/ngc/preferences.cpp index 4d62cb2..1fbd741 100644 --- a/source/ngc/preferences.cpp +++ b/source/ngc/preferences.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -360,12 +361,13 @@ SavePrefs (bool silent) if(prefpath[0] != 0) { - strcpy(filepath, prefpath); + sprintf(filepath, "%s/%s", prefpath, PREF_FILE_NAME); FindDevice(filepath, &device); } else if(appPath[0] != 0) { sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME); + strcpy(prefpath, appPath); FindDevice(filepath, &device); } else @@ -375,7 +377,18 @@ SavePrefs (bool silent) if(device == 0) return false; + sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER); + + if (!diropen(filepath)) + { + mkdir(filepath, 0777); + sprintf(filepath, "%s%s/roms", pathPrefix[device], APPFOLDER); + mkdir(filepath, 0777); + sprintf(filepath, "%s%s/saves", pathPrefix[device], APPFOLDER); + mkdir(filepath, 0777); + } sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME); + sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER); } if(device == 0) @@ -407,10 +420,12 @@ SavePrefs (bool silent) * Load Preferences from specified filepath ***************************************************************************/ bool -LoadPrefsFromMethod (char * filepath) +LoadPrefsFromMethod (char * path) { bool retval = false; int offset = 0; + char filepath[MAXPATHLEN]; + sprintf(filepath, "%s/%s", path, PREF_FILE_NAME); AllocSaveBuffer (); @@ -420,11 +435,9 @@ LoadPrefsFromMethod (char * filepath) retval = decodePrefsData (); FreeSaveBuffer (); - + if(retval) - { - strcpy(prefpath, filepath); - } + strcpy(prefpath, path); return retval; } @@ -446,13 +459,13 @@ bool LoadPrefs() #ifdef HW_RVL numDevices = 3; - sprintf(filepath[0], "%s/%s", appPath, PREF_FILE_NAME); - sprintf(filepath[1], "sd:/%s/%s", APPFOLDER, PREF_FILE_NAME); - sprintf(filepath[2], "usb:/%s/%s", APPFOLDER, PREF_FILE_NAME); + sprintf(filepath[0], "%s", appPath); + sprintf(filepath[1], "sd:/%s", APPFOLDER); + sprintf(filepath[2], "usb:/%s", APPFOLDER); #else numDevices = 2; - sprintf(filepath[0], "carda:/%s/%s", APPFOLDER, PREF_FILE_NAME); - sprintf(filepath[1], "cardb:/%s/%s", APPFOLDER, PREF_FILE_NAME); + sprintf(filepath[0], "carda:/%s", APPFOLDER); + sprintf(filepath[1], "cardb:/%s", APPFOLDER); #endif for(int i=0; i