jump to last file, improved auto update, make folders if not present

This commit is contained in:
dborth 2009-12-23 00:39:48 +00:00
parent 951b0bcb60
commit 707599e09d
8 changed files with 117 additions and 94 deletions

View File

@ -473,6 +473,8 @@ int BrowserLoadFile()
if(!FindDevice(browser.dir, &device)) if(!FindDevice(browser.dir, &device))
return 0; return 0;
strcpy(loadedFile, browserList[browser.selIndex].filename);
// store the filename (w/o ext) - used for sram/freeze naming // store the filename (w/o ext) - used for sram/freeze naming
StripExt(ROMFilename, browserList[browser.selIndex].filename); StripExt(ROMFilename, browserList[browser.selIndex].filename);

View File

@ -31,6 +31,7 @@
#include "gcunzip.h" #include "gcunzip.h"
#include "menu.h" #include "menu.h"
#include "filebrowser.h" #include "filebrowser.h"
#include "gui/gui.h"
#define THREAD_SLEEP 100 #define THREAD_SLEEP 100
@ -55,6 +56,7 @@ static lwp_t parsethread = LWP_THREAD_NULL;
static DIR_ITER * dirIter = NULL; static DIR_ITER * dirIter = NULL;
static bool parseHalt = true; static bool parseHalt = true;
bool ParseDirEntries(); bool ParseDirEntries();
int selectLoadedFile = 0;
// device thread // device thread
static lwp_t devicethread = LWP_THREAD_NULL; static lwp_t devicethread = LWP_THREAD_NULL;
@ -525,10 +527,42 @@ bool ParseDirEntries()
// Sort the file list // Sort the file list
if(i >= 0) if(i >= 0)
{ {
browser.numEntries += i; qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback);
qsort(browserList, browser.numEntries, 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) if(res != 0 || parseHalt)
{ {
dirclose(dirIter); // close directory dirclose(dirIter); // close directory

View File

@ -44,5 +44,6 @@ extern unsigned char savebuffer[];
extern FILE * file; extern FILE * file;
extern bool unmountRequired[]; extern bool unmountRequired[];
extern bool isMounted[]; extern bool isMounted[];
extern int selectLoadedFile;
#endif #endif

View File

@ -929,6 +929,7 @@ static int MenuGameSelection()
#endif #endif
// populate initial directory listing // populate initial directory listing
selectLoadedFile = 1;
OpenGameList(); OpenGameList();
gameBrowser.ResetState(); gameBrowser.ResetState();
@ -939,6 +940,13 @@ static int MenuGameSelection()
{ {
usleep(THREAD_SLEEP); usleep(THREAD_SLEEP);
if(selectLoadedFile == 2)
{
selectLoadedFile = 0;
mainWindow->ChangeFocus(&gameBrowser);
gameBrowser.TriggerUpdate();
}
// update gameWindow based on arrow buttons // update gameWindow based on arrow buttons
// set MENU_EXIT if A button pressed on a game // set MENU_EXIT if A button pressed on a game
for(i=0; i < FILE_PAGESIZE; i++) for(i=0; i < FILE_PAGESIZE; i++)

View File

@ -47,7 +47,7 @@ bool updateFound = false; // true if an app update was found
void UpdateCheck() void UpdateCheck()
{ {
// we can only check for the update if we have internet + SD // 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]; static char url[128];
int retval; int retval;
@ -135,43 +135,45 @@ static bool unzipArchive(char * zipfilepath, char * unzipfolderpath)
bool DownloadUpdate() bool DownloadUpdate()
{ {
bool result = false; 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();
int device;
FindDevice(appPath, &device);
FILE * hfile;
char updateFile[50];
sprintf(updateFile, "%s%s Update.zip", pathPrefix[device], APPNAME);
hfile = fopen (updateFile, "wb");
if (hfile > 0)
{ {
// stop checking if devices were removed/inserted int retval;
// since we're saving a file retval = http_request(updateURL, hfile, NULL, (1024*1024*5));
HaltDeviceThread(); fclose (hfile);
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();
} }
result = unzipArchive(updateFile, (char *)pathPrefix[device]);
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; return result;
} }

View File

@ -11,6 +11,7 @@
#include <gccore.h> #include <gccore.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/dir.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <mxml.h> #include <mxml.h>
@ -551,7 +552,6 @@ decodePalsData ()
* Save Preferences * Save Preferences
***************************************************************************/ ***************************************************************************/
static char prefpath[MAXPATHLEN] = { 0 }; static char prefpath[MAXPATHLEN] = { 0 };
static char palpath[MAXPATHLEN] = { 0 };
bool bool
SavePrefs (bool silent) SavePrefs (bool silent)
@ -563,12 +563,13 @@ SavePrefs (bool silent)
if(prefpath[0] != 0) if(prefpath[0] != 0)
{ {
strcpy(filepath, prefpath); sprintf(filepath, "%s/%s", prefpath, PREF_FILE_NAME);
FindDevice(filepath, &device); FindDevice(filepath, &device);
} }
else if(appPath[0] != 0) else if(appPath[0] != 0)
{ {
sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME); sprintf(filepath, "%s/%s", appPath, PREF_FILE_NAME);
strcpy(prefpath, appPath);
FindDevice(filepath, &device); FindDevice(filepath, &device);
} }
else else
@ -578,7 +579,18 @@ SavePrefs (bool silent)
if(device == 0) if(device == 0)
return false; 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(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME);
sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER);
} }
if(device == 0) if(device == 0)
@ -611,10 +623,12 @@ SavePrefs (bool silent)
* Load Preferences from specified filepath * Load Preferences from specified filepath
***************************************************************************/ ***************************************************************************/
bool bool
LoadPrefsFromMethod (char * filepath) LoadPrefsFromMethod (char * path)
{ {
bool retval = false; bool retval = false;
int offset = 0; int offset = 0;
char filepath[MAXPATHLEN];
sprintf(filepath, "%s/%s", path, PREF_FILE_NAME);
AllocSaveBuffer (); AllocSaveBuffer ();
@ -648,13 +662,13 @@ bool LoadPrefs()
#ifdef HW_RVL #ifdef HW_RVL
numDevices = 3; numDevices = 3;
sprintf(filepath[0], "%s/%s", appPath, PREF_FILE_NAME); sprintf(filepath[0], "%s", appPath);
sprintf(filepath[1], "sd:/%s/%s", APPFOLDER, PREF_FILE_NAME); sprintf(filepath[1], "sd:/%s", APPFOLDER);
sprintf(filepath[2], "usb:/%s/%s", APPFOLDER, PREF_FILE_NAME); sprintf(filepath[2], "usb:/%s", APPFOLDER);
#else #else
numDevices = 2; numDevices = 2;
sprintf(filepath[0], "carda:/%s/%s", APPFOLDER, PREF_FILE_NAME); sprintf(filepath[0], "carda:/%s", APPFOLDER);
sprintf(filepath[1], "cardb:/%s/%s", APPFOLDER, PREF_FILE_NAME); sprintf(filepath[1], "cardb:/%s", APPFOLDER);
#endif #endif
for(int i=0; i<numDevices; i++) for(int i=0; i<numDevices; i++)
@ -678,31 +692,12 @@ bool SavePalettes(bool silent)
char filepath[1024]; char filepath[1024];
int datasize; int datasize;
int offset = 0; int offset = 0;
int device = 0;
if(palpath[0] != 0) if(prefpath[0] == 0)
{
strcpy(filepath, palpath);
FindDevice(filepath, &device);
}
else if(appPath[0] != 0)
{
sprintf(filepath, "%s/%s", appPath, PAL_FILE_NAME);
FindDevice(filepath, &device);
}
else
{
device = autoSaveMethod(silent);
if(device == 0)
return false;
sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PAL_FILE_NAME);
}
if(device == 0)
return false; return false;
sprintf(filepath, "%s/%s", prefpath, PAL_FILE_NAME);
// Now create the XML palette file // Now create the XML palette file
if (!silent) if (!silent)
@ -762,36 +757,15 @@ bool LoadPalettes()
{ {
bool retval = false; bool retval = false;
int offset = 0; int offset = 0;
char filepath[4][MAXPATHLEN]; char filepath[MAXPATHLEN];
int numDevices;
int i;
AllocSaveBuffer ();
#ifdef HW_RVL
numDevices = 3;
sprintf(filepath[0], "%s/%s", appPath, PAL_FILE_NAME);
sprintf(filepath[1], "sd:/%s/%s", APPFOLDER, PAL_FILE_NAME);
sprintf(filepath[2], "usb:/%s/%s", APPFOLDER, PAL_FILE_NAME);
#else
numDevices = 2;
sprintf(filepath[0], "carda:/%s/%s", APPFOLDER, PAL_FILE_NAME);
sprintf(filepath[1], "cardb:/%s/%s", APPFOLDER, PAL_FILE_NAME);
#endif
for(i=0; i<numDevices; i++) AllocSaveBuffer ();
{
offset = LoadFile(filepath[i], SILENT); sprintf(filepath, "%s/%s", prefpath, PAL_FILE_NAME);
offset = LoadFile(filepath, SILENT);
if(offset > 0)
break;
}
if (offset > 0) if (offset > 0)
retval = decodePalsData (); retval = decodePalsData ();
if(retval)
strcpy(palpath, filepath[i]);
FreeSaveBuffer (); FreeSaveBuffer ();

View File

@ -52,6 +52,7 @@ int ShutdownRequested = 0;
int ResetRequested = 0; int ResetRequested = 0;
int ExitRequested = 0; int ExitRequested = 0;
char appPath[1024] = { 0 }; char appPath[1024] = { 0 };
char loadedFile[1024] = { 0 };
extern FILE *out; extern FILE *out;

View File

@ -84,6 +84,7 @@ extern int ConfigRequested;
extern int ShutdownRequested; extern int ShutdownRequested;
extern int ExitRequested; extern int ExitRequested;
extern char appPath[]; extern char appPath[];
extern char loadedFile[];
extern FreeTypeGX *fontSystem[]; extern FreeTypeGX *fontSystem[];
#endif #endif