2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* FCE Ultra 0.98.12
|
|
|
|
* Nintendo Wii/Gamecube Port
|
|
|
|
*
|
|
|
|
* Tantric September 2008
|
|
|
|
*
|
|
|
|
* filesel.c
|
|
|
|
*
|
|
|
|
* Generic file routines - reading, writing, browsing
|
|
|
|
****************************************************************************/
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#include <sys/dir.h>
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
#ifdef HW_RVL
|
2008-09-02 03:57:21 +02:00
|
|
|
#include <di/di.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common.h"
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "dvd.h"
|
|
|
|
#include "menudraw.h"
|
|
|
|
#include "filesel.h"
|
2008-12-24 08:58:23 +01:00
|
|
|
#include "networkop.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
#include "fileop.h"
|
|
|
|
#include "memcardop.h"
|
|
|
|
#include "pad.h"
|
|
|
|
#include "fceuload.h"
|
2008-10-05 23:34:06 +02:00
|
|
|
#include "gcunzip.h"
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
BROWSERINFO browser;
|
|
|
|
BROWSERENTRY * browserList = NULL; // list of files/folders in browser
|
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
char rootdir[10];
|
2008-12-30 01:05:57 +01:00
|
|
|
static char szpath[MAXPATHLEN];
|
|
|
|
static bool inSz = false;
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
char romFilename[200];
|
2008-10-01 07:25:38 +02:00
|
|
|
int nesGameType;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* autoLoadMethod()
|
|
|
|
* Auto-determines and sets the load method
|
|
|
|
* Returns method set
|
|
|
|
****************************************************************************/
|
|
|
|
int autoLoadMethod()
|
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
ShowAction ("Attempting to determine load method...");
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-22 09:38:49 +01:00
|
|
|
int method = 0;
|
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
if(ChangeInterface(METHOD_SD, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_SD;
|
2008-12-19 23:04:55 +01:00
|
|
|
else if(ChangeInterface(METHOD_USB, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_USB;
|
2008-12-19 23:04:55 +01:00
|
|
|
else if(ChangeInterface(METHOD_DVD, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_DVD;
|
2008-12-19 23:04:55 +01:00
|
|
|
else if(ChangeInterface(METHOD_SMB, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_SMB;
|
2008-09-02 03:57:21 +02:00
|
|
|
else
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Unable to auto-determine load method!");
|
2008-12-22 09:38:49 +01:00
|
|
|
|
2008-12-24 08:58:23 +01:00
|
|
|
if(GCSettings.LoadMethod == METHOD_AUTO)
|
|
|
|
GCSettings.LoadMethod = method; // save method found for later use
|
2008-12-22 09:38:49 +01:00
|
|
|
return method;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* autoSaveMethod()
|
|
|
|
* Auto-determines and sets the save method
|
|
|
|
* Returns method set
|
|
|
|
****************************************************************************/
|
2008-12-22 09:38:49 +01:00
|
|
|
int autoSaveMethod(bool silent)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-22 09:38:49 +01:00
|
|
|
if(!silent)
|
|
|
|
ShowAction ("Attempting to determine save method...");
|
|
|
|
|
|
|
|
int method = 0;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
if(ChangeInterface(METHOD_SD, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_SD;
|
2008-12-19 23:04:55 +01:00
|
|
|
else if(ChangeInterface(METHOD_USB, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_USB;
|
2008-09-02 03:57:21 +02:00
|
|
|
else if(TestCard(CARD_SLOTA, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_MC_SLOTA;
|
2008-09-02 03:57:21 +02:00
|
|
|
else if(TestCard(CARD_SLOTB, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_MC_SLOTB;
|
2008-12-19 23:04:55 +01:00
|
|
|
else if(ChangeInterface(METHOD_SMB, SILENT))
|
2008-12-22 09:38:49 +01:00
|
|
|
method = METHOD_SMB;
|
|
|
|
else if(!silent)
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Unable to auto-determine save method!");
|
2008-12-22 09:38:49 +01:00
|
|
|
|
2008-12-24 08:58:23 +01:00
|
|
|
if(GCSettings.SaveMethod == METHOD_AUTO)
|
|
|
|
GCSettings.SaveMethod = method; // save method found for later use
|
2008-12-22 09:38:49 +01:00
|
|
|
return method;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* ResetBrowser()
|
|
|
|
* Clears the file browser memory, and allocates one initial entry
|
|
|
|
***************************************************************************/
|
|
|
|
void ResetBrowser()
|
|
|
|
{
|
|
|
|
browser.selIndex = browser.pageIndex = 0;
|
|
|
|
|
|
|
|
// Clear any existing values
|
|
|
|
if(browserList != NULL)
|
|
|
|
{
|
|
|
|
free(browserList);
|
|
|
|
browserList = NULL;
|
|
|
|
}
|
|
|
|
// set aside space for 1 entry
|
|
|
|
browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY));
|
|
|
|
memset(browserList, 0, sizeof(BROWSERENTRY));
|
|
|
|
}
|
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* UpdateDirName()
|
|
|
|
* Update curent directory name for file browser
|
2008-09-02 03:57:21 +02:00
|
|
|
***************************************************************************/
|
|
|
|
int UpdateDirName(int method)
|
|
|
|
{
|
|
|
|
int size=0;
|
2008-11-12 09:40:09 +01:00
|
|
|
char * test;
|
2008-09-02 03:57:21 +02:00
|
|
|
char temp[1024];
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
// update DVD directory
|
2008-09-02 03:57:21 +02:00
|
|
|
if(method == METHOD_DVD)
|
2008-12-30 01:05:57 +01:00
|
|
|
SetDVDdirectory(browserList[browser.selIndex].offset, browserList[browser.selIndex].length);
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
/* current directory doesn't change */
|
2008-12-30 01:05:57 +01:00
|
|
|
if (strcmp(browserList[browser.selIndex].filename,".") == 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* go up to parent directory */
|
2008-12-30 01:05:57 +01:00
|
|
|
else if (strcmp(browserList[browser.selIndex].filename,"..") == 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
/* determine last subdirectory namelength */
|
2008-12-30 01:05:57 +01:00
|
|
|
sprintf(temp,"%s",browser.dir);
|
2008-09-02 03:57:21 +02:00
|
|
|
test = strtok(temp,"/");
|
|
|
|
while (test != NULL)
|
|
|
|
{
|
|
|
|
size = strlen(test);
|
|
|
|
test = strtok(NULL,"/");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove last subdirectory name */
|
2008-12-30 01:05:57 +01:00
|
|
|
size = strlen(browser.dir) - size - 1;
|
|
|
|
browser.dir[size] = 0;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
/* Open a directory */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* test new directory namelength */
|
2008-12-30 01:05:57 +01:00
|
|
|
if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
/* update current directory name */
|
2008-12-30 01:05:57 +01:00
|
|
|
sprintf(browser.dir, "%s/%s",browser.dir, browserList[browser.selIndex].filename);
|
2008-09-02 03:57:21 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Directory name is too long!");
|
2008-09-02 03:57:21 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
bool MakeFilePath(char filepath[], int type, int method)
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
char file[512];
|
|
|
|
char folder[1024];
|
2008-10-13 20:15:03 +02:00
|
|
|
char temppath[MAXPATHLEN];
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
if(type == FILE_ROM)
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
// Check path length
|
2008-12-30 01:05:57 +01:00
|
|
|
if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) >= MAXPATHLEN)
|
2008-11-12 09:40:09 +01:00
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Maximum filepath length reached!");
|
2008-11-12 09:40:09 +01:00
|
|
|
filepath[0] = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2008-10-13 20:15:03 +02:00
|
|
|
else
|
2008-11-12 09:40:09 +01:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
sprintf(temppath, "%s/%s",browser.dir,browserList[browser.selIndex].filename);
|
2008-11-12 09:40:09 +01:00
|
|
|
}
|
2008-10-13 20:15:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FILE_RAM:
|
|
|
|
sprintf(folder, GCSettings.SaveFolder);
|
|
|
|
sprintf(file, "%s.sav", romFilename);
|
|
|
|
break;
|
|
|
|
case FILE_STATE:
|
|
|
|
sprintf(folder, GCSettings.SaveFolder);
|
|
|
|
sprintf(file, "%s.fcs", romFilename);
|
|
|
|
break;
|
|
|
|
case FILE_FDSBIOS:
|
|
|
|
sprintf(folder, GCSettings.LoadFolder);
|
|
|
|
sprintf(file, "disksys.rom");
|
|
|
|
break;
|
|
|
|
case FILE_PREF:
|
2008-11-17 08:59:24 +01:00
|
|
|
sprintf(folder, appPath);
|
2008-11-12 09:40:09 +01:00
|
|
|
sprintf(file, "%s", PREF_FILE_NAME);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch(method)
|
|
|
|
{
|
|
|
|
case METHOD_MC_SLOTA:
|
|
|
|
case METHOD_MC_SLOTB:
|
|
|
|
sprintf (temppath, "%s", file);
|
|
|
|
temppath[31] = 0; // truncate filename
|
|
|
|
break;
|
2008-12-19 23:04:55 +01:00
|
|
|
default:
|
|
|
|
sprintf (temppath, "%s/%s", folder, file);
|
|
|
|
break;
|
2008-11-12 09:40:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
strcpy(filepath, temppath);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
/***************************************************************************
|
|
|
|
* FileSortCallback
|
|
|
|
*
|
|
|
|
* Quick sort callback to sort file entries with the following order:
|
|
|
|
* .
|
|
|
|
* ..
|
|
|
|
* <dirs>
|
|
|
|
* <files>
|
|
|
|
***************************************************************************/
|
|
|
|
int FileSortCallback(const void *f1, const void *f2)
|
|
|
|
{
|
|
|
|
/* Special case for implicit directories */
|
2008-12-30 01:05:57 +01:00
|
|
|
if(((BROWSERENTRY *)f1)->filename[0] == '.' || ((BROWSERENTRY *)f2)->filename[0] == '.')
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
if(strcmp(((BROWSERENTRY *)f1)->filename, ".") == 0) { return -1; }
|
|
|
|
if(strcmp(((BROWSERENTRY *)f2)->filename, ".") == 0) { return 1; }
|
|
|
|
if(strcmp(((BROWSERENTRY *)f1)->filename, "..") == 0) { return -1; }
|
|
|
|
if(strcmp(((BROWSERENTRY *)f2)->filename, "..") == 0) { return 1; }
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If one is a file and one is a directory the directory is first. */
|
2008-12-30 01:05:57 +01:00
|
|
|
if(((BROWSERENTRY *)f1)->isdir && !(((BROWSERENTRY *)f2)->isdir)) return -1;
|
|
|
|
if(!(((BROWSERENTRY *)f1)->isdir) && ((BROWSERENTRY *)f2)->isdir) return 1;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
return stricmp(((BROWSERENTRY *)f1)->filename, ((BROWSERENTRY *)f2)->filename);
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
2008-10-05 23:34:06 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* IsValidROM
|
|
|
|
*
|
|
|
|
* Checks if the specified file is a valid ROM
|
|
|
|
* For now we will just check the file extension and file size
|
|
|
|
* If the file is a zip, we will check the file extension / file size of the
|
|
|
|
* first file inside
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
bool IsValidROM(int method)
|
|
|
|
{
|
2009-01-25 08:38:30 +01:00
|
|
|
// file size should be between 8K and 3MB
|
|
|
|
if(browserList[browser.selIndex].length < (1024*8) ||
|
2008-12-30 01:05:57 +01:00
|
|
|
browserList[browser.selIndex].length > (1024*1024*3))
|
2008-10-05 23:34:06 +02:00
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Invalid file size!");
|
2008-10-05 23:34:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
if (strlen(browserList[browser.selIndex].filename) > 4)
|
2008-10-05 23:34:06 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
char * p = strrchr(browserList[browser.selIndex].filename, '.');
|
2008-10-05 23:34:06 +02:00
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
{
|
2008-10-13 20:15:03 +02:00
|
|
|
if(stricmp(p, ".zip") == 0 && !inSz)
|
2008-10-05 23:34:06 +02:00
|
|
|
{
|
|
|
|
// we need to check the file extension of the first file in the archive
|
|
|
|
char * zippedFilename = GetFirstZipFilename (method);
|
|
|
|
|
2008-10-13 20:15:03 +02:00
|
|
|
if(zippedFilename == NULL) // we don't want to run strlen on NULL
|
|
|
|
p = NULL;
|
|
|
|
else if(strlen(zippedFilename) > 4)
|
2008-10-05 23:34:06 +02:00
|
|
|
p = strrchr(zippedFilename, '.');
|
|
|
|
else
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(p != NULL)
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
stricmp(p, ".nes") == 0 ||
|
|
|
|
stricmp(p, ".fds") == 0 ||
|
|
|
|
stricmp(p, ".nsf") == 0 ||
|
|
|
|
stricmp(p, ".unf") == 0 ||
|
|
|
|
stricmp(p, ".nez") == 0 ||
|
|
|
|
stricmp(p, ".unif") == 0
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Unknown file type!");
|
2008-10-05 23:34:06 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-13 20:15:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* IsSz
|
|
|
|
*
|
|
|
|
* Checks if the specified file is a 7z
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
bool IsSz()
|
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
if (strlen(browserList[browser.selIndex].filename) > 4)
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
char * p = strrchr(browserList[browser.selIndex].filename, '.');
|
2008-10-13 20:15:03 +02:00
|
|
|
|
|
|
|
if (p != NULL)
|
|
|
|
if(stricmp(p, ".7z") == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* StripExt
|
|
|
|
*
|
|
|
|
* Strips an extension from a filename
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void StripExt(char* returnstring, char * inputstring)
|
|
|
|
{
|
|
|
|
char* loc_dot;
|
|
|
|
|
|
|
|
strcpy (returnstring, inputstring);
|
|
|
|
loc_dot = strrchr(returnstring,'.');
|
|
|
|
if (loc_dot != NULL)
|
|
|
|
*loc_dot = '\0'; // strip file extension
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* FileSelector
|
|
|
|
*
|
|
|
|
* Let user select a file from the listing
|
|
|
|
****************************************************************************/
|
|
|
|
int FileSelector (int method)
|
|
|
|
{
|
|
|
|
u32 p = 0;
|
|
|
|
u32 wp = 0;
|
|
|
|
u32 ph = 0;
|
|
|
|
u32 wh = 0;
|
|
|
|
signed char gc_ay = 0;
|
|
|
|
signed char gc_sx = 0;
|
|
|
|
signed char wm_ay = 0;
|
|
|
|
signed char wm_sx = 0;
|
|
|
|
|
|
|
|
int haverom = 0;
|
|
|
|
int redraw = 1;
|
|
|
|
int selectit = 0;
|
|
|
|
|
|
|
|
int scroll_delay = 0;
|
|
|
|
bool move_selection = 0;
|
|
|
|
#define SCROLL_INITIAL_DELAY 15
|
|
|
|
#define SCROLL_LOOP_DELAY 2
|
|
|
|
|
|
|
|
while (haverom == 0)
|
|
|
|
{
|
|
|
|
if (redraw)
|
2008-12-30 01:05:57 +01:00
|
|
|
ShowFiles (browserList, browser.numEntries, browser.pageIndex, browser.selIndex);
|
2008-09-02 03:57:21 +02:00
|
|
|
redraw = 0;
|
|
|
|
|
|
|
|
VIDEO_WaitVSync(); // slow things down a bit so we don't overread the pads
|
|
|
|
|
|
|
|
gc_ay = PAD_StickY (0);
|
|
|
|
gc_sx = PAD_SubStickX (0);
|
|
|
|
|
|
|
|
p = PAD_ButtonsDown (0);
|
|
|
|
ph = PAD_ButtonsHeld (0);
|
|
|
|
#ifdef HW_RVL
|
|
|
|
wm_ay = WPAD_StickY (0, 0);
|
|
|
|
wm_sx = WPAD_StickX (0, 1);
|
|
|
|
|
|
|
|
wp = WPAD_ButtonsDown (0);
|
|
|
|
wh = WPAD_ButtonsHeld (0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*** Check for exit combo ***/
|
|
|
|
if ( (gc_sx < -70) || (wm_sx < -70) || (wp & WPAD_BUTTON_HOME) || (wp & WPAD_CLASSIC_BUTTON_HOME) )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*** Check buttons, perform actions ***/
|
|
|
|
if ( (p & PAD_BUTTON_A) || selectit || (wp & (WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A)) )
|
|
|
|
{
|
|
|
|
if ( selectit )
|
|
|
|
selectit = 0;
|
2008-10-13 20:15:03 +02:00
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
if (browserList[browser.selIndex].isdir) // This is directory
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
/* update current directory and set new entry list if directory has changed */
|
2008-10-13 20:15:03 +02:00
|
|
|
|
|
|
|
int status;
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
if(inSz && browser.selIndex == 0) // inside a 7z, requesting to leave
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
|
|
|
if(method == METHOD_DVD)
|
2008-12-30 01:05:57 +01:00
|
|
|
SetDVDdirectory(browserList[0].offset, browserList[0].length);
|
2008-10-13 20:15:03 +02:00
|
|
|
inSz = false;
|
|
|
|
status = 1;
|
|
|
|
SzClose();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = UpdateDirName(method);
|
|
|
|
}
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
if (status == 1) // ok, open directory
|
|
|
|
{
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case METHOD_DVD:
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.numEntries = ParseDVDdirectory();
|
2008-12-19 23:04:55 +01:00
|
|
|
break;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
default:
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.numEntries = ParseDirectory();
|
2008-12-19 23:04:55 +01:00
|
|
|
break;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
if (!browser.numEntries)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt ("Error reading directory!");
|
2008-09-02 03:57:21 +02:00
|
|
|
haverom = 1; // quit menu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (status == -1) // directory name too long
|
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
return 0; // quit menu
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
}
|
2008-10-13 20:15:03 +02:00
|
|
|
else // this is a file
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-10-13 20:15:03 +02:00
|
|
|
// 7z file - let's open it up to select a file inside
|
|
|
|
if(IsSz())
|
|
|
|
{
|
|
|
|
// we'll store the 7z filepath for extraction later
|
2008-11-12 09:40:09 +01:00
|
|
|
if(!MakeFilePath(szpath, FILE_ROM, method))
|
2008-10-28 07:50:07 +01:00
|
|
|
return 0;
|
2008-11-12 09:40:09 +01:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
// add device to filepath
|
|
|
|
char fullpath[1024];
|
|
|
|
sprintf(fullpath, "%s%s", rootdir, szpath);
|
|
|
|
strcpy(szpath, fullpath);
|
|
|
|
|
2008-10-15 01:27:48 +02:00
|
|
|
int szfiles = SzParse(szpath, method);
|
|
|
|
if(szfiles)
|
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.numEntries = szfiles;
|
2008-10-13 20:15:03 +02:00
|
|
|
inSz = true;
|
2008-10-15 01:27:48 +02:00
|
|
|
}
|
|
|
|
else
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Error opening archive!");
|
2008-10-13 20:15:03 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// check that this is a valid ROM
|
|
|
|
if(!IsValidROM(method))
|
|
|
|
return 0;
|
2008-10-06 00:46:15 +02:00
|
|
|
|
2008-10-13 20:15:03 +02:00
|
|
|
// store the filename (w/o ext) - used for state saving
|
2008-12-30 01:05:57 +01:00
|
|
|
StripExt(romFilename, browserList[browser.selIndex].filename);
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
ShowAction ("Loading...");
|
2008-10-02 07:28:01 +02:00
|
|
|
|
2008-10-13 20:15:03 +02:00
|
|
|
int size = 0;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
if(!inSz)
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
char filepath[1024];
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
if(!MakeFilePath(filepath, FILE_ROM, method))
|
|
|
|
return 0;
|
2008-10-13 20:15:03 +02:00
|
|
|
|
2009-01-25 08:09:11 +01:00
|
|
|
size = LoadFile((char *)nesrom, filepath, browserList[browser.selIndex].length, method, NOTSILENT);
|
2008-11-12 09:40:09 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (method)
|
|
|
|
{
|
|
|
|
case METHOD_DVD:
|
2008-12-30 01:05:57 +01:00
|
|
|
size = SzExtractFile(browserList[browser.selIndex].offset, nesrom);
|
2008-11-12 09:40:09 +01:00
|
|
|
break;
|
2008-12-19 23:04:55 +01:00
|
|
|
default:
|
|
|
|
size = LoadSzFile(szpath, nesrom);
|
2008-11-12 09:40:09 +01:00
|
|
|
break;
|
|
|
|
}
|
2008-10-13 20:15:03 +02:00
|
|
|
}
|
2008-11-12 09:40:09 +01:00
|
|
|
|
2008-10-13 20:15:03 +02:00
|
|
|
inSz = false;
|
|
|
|
|
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
if(GCMemROM(method, size) > 0)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2008-10-02 01:10:30 +02:00
|
|
|
else
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt("Error loading ROM!");
|
2008-10-02 01:10:30 +02:00
|
|
|
return 0;
|
2008-10-13 20:15:03 +02:00
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
redraw = 1;
|
|
|
|
} // End of A
|
2008-12-30 01:05:57 +01:00
|
|
|
if ((p & PAD_BUTTON_B)
|
|
|
|
|| (wp & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B)))
|
|
|
|
{
|
|
|
|
while ((PAD_ButtonsDown(0) & PAD_BUTTON_B)
|
2008-09-02 03:57:21 +02:00
|
|
|
#ifdef HW_RVL
|
2008-12-30 01:05:57 +01:00
|
|
|
|| (WPAD_ButtonsDown(0) & (WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B))
|
2008-09-02 03:57:21 +02:00
|
|
|
#endif
|
2008-12-30 01:05:57 +01:00
|
|
|
)
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
if (strcmp(browserList[0].filename, "..") == 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.selIndex = 0;
|
2008-09-02 03:57:21 +02:00
|
|
|
selectit = 1;
|
|
|
|
}
|
2008-12-30 01:05:57 +01:00
|
|
|
else if (strcmp(browserList[1].filename, "..") == 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.selIndex = selectit = 1;
|
|
|
|
}
|
|
|
|
else
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
return 0;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2008-12-30 01:05:57 +01:00
|
|
|
} // End of B
|
|
|
|
if (((p | ph) & PAD_BUTTON_DOWN) || ((wp | wh) & (WPAD_BUTTON_DOWN
|
|
|
|
| WPAD_CLASSIC_BUTTON_DOWN)) || (gc_ay < -PADCAL) || (wm_ay
|
|
|
|
< -PADCAL))
|
|
|
|
{
|
|
|
|
if ((p & PAD_BUTTON_DOWN) || (wp & (WPAD_BUTTON_DOWN
|
|
|
|
| WPAD_CLASSIC_BUTTON_DOWN)))
|
|
|
|
{ /*** Button just pressed ***/
|
|
|
|
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
move_selection = 1; //continue (move selection)
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2008-12-30 01:05:57 +01:00
|
|
|
else if (scroll_delay == 0)
|
|
|
|
{ /*** Button is held ***/
|
2008-09-02 03:57:21 +02:00
|
|
|
scroll_delay = SCROLL_LOOP_DELAY;
|
2008-12-30 01:05:57 +01:00
|
|
|
move_selection = 1; //continue (move selection)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scroll_delay--; // wait
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (move_selection)
|
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.selIndex++;
|
|
|
|
if (browser.selIndex == browser.numEntries)
|
|
|
|
browser.selIndex = browser.pageIndex = 0;
|
|
|
|
if ((browser.selIndex - browser.pageIndex) >= PAGESIZE)
|
|
|
|
browser.pageIndex += PAGESIZE;
|
|
|
|
redraw = 1;
|
2008-09-02 03:57:21 +02:00
|
|
|
move_selection = 0;
|
|
|
|
}
|
2008-12-30 01:05:57 +01:00
|
|
|
} // End of down
|
|
|
|
if (((p | ph) & PAD_BUTTON_UP) || ((wp | wh) & (WPAD_BUTTON_UP
|
|
|
|
| WPAD_CLASSIC_BUTTON_UP)) || (gc_ay > PADCAL) || (wm_ay
|
|
|
|
> PADCAL))
|
|
|
|
{
|
|
|
|
if ((p & PAD_BUTTON_UP) || (wp & (WPAD_BUTTON_UP
|
|
|
|
| WPAD_CLASSIC_BUTTON_UP)))
|
|
|
|
{ /*** Button just pressed***/
|
|
|
|
scroll_delay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
move_selection = 1; //continue (move selection)
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
2008-12-30 01:05:57 +01:00
|
|
|
else if (scroll_delay == 0)
|
|
|
|
{ /*** Button is held ***/
|
2008-09-02 03:57:21 +02:00
|
|
|
scroll_delay = SCROLL_LOOP_DELAY;
|
2008-12-30 01:05:57 +01:00
|
|
|
move_selection = 1; //continue (move selection)
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scroll_delay--; // wait
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (move_selection)
|
|
|
|
{
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.selIndex--;
|
|
|
|
if (browser.selIndex < 0)
|
|
|
|
{
|
|
|
|
browser.selIndex = browser.numEntries - 1;
|
|
|
|
browser.pageIndex = browser.selIndex - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (browser.selIndex < browser.pageIndex)
|
|
|
|
browser.pageIndex -= PAGESIZE;
|
|
|
|
if (browser.pageIndex < 0)
|
|
|
|
browser.pageIndex = 0;
|
|
|
|
redraw = 1;
|
2008-09-02 03:57:21 +02:00
|
|
|
move_selection = 0;
|
|
|
|
}
|
2008-12-30 01:05:57 +01:00
|
|
|
} // End of Up
|
|
|
|
if ((p & PAD_BUTTON_LEFT) || (wp & (WPAD_BUTTON_LEFT
|
|
|
|
| WPAD_CLASSIC_BUTTON_LEFT)))
|
|
|
|
{
|
|
|
|
/*** Go back a page ***/
|
|
|
|
browser.selIndex -= PAGESIZE;
|
|
|
|
if (browser.selIndex < 0)
|
|
|
|
{
|
|
|
|
browser.selIndex = browser.numEntries - 1;
|
|
|
|
browser.pageIndex = browser.selIndex - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (browser.selIndex < browser.pageIndex)
|
|
|
|
browser.pageIndex -= PAGESIZE;
|
|
|
|
if (browser.pageIndex < 0)
|
|
|
|
browser.pageIndex = 0;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
if ((p & PAD_BUTTON_RIGHT) || (wp & (WPAD_BUTTON_RIGHT
|
|
|
|
| WPAD_CLASSIC_BUTTON_RIGHT)))
|
|
|
|
{
|
|
|
|
/*** Go forward a page ***/
|
|
|
|
browser.selIndex += PAGESIZE;
|
|
|
|
if (browser.selIndex > browser.numEntries - 1)
|
|
|
|
browser.selIndex = browser.pageIndex = 0;
|
|
|
|
if ((browser.selIndex - browser.pageIndex) >= PAGESIZE)
|
|
|
|
browser.pageIndex += PAGESIZE;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2008-12-19 23:04:55 +01:00
|
|
|
* OpenROM
|
|
|
|
* Opens device specified by method, displays a list of ROMS
|
|
|
|
***************************************************************************/
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
int
|
2008-12-19 23:04:55 +01:00
|
|
|
OpenROM (int method)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
if(method == METHOD_AUTO)
|
|
|
|
method = autoLoadMethod();
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
if(ChangeInterface(method, NOTSILENT))
|
|
|
|
{
|
|
|
|
// change current dir to roms directory
|
|
|
|
switch(method)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2008-12-19 23:04:55 +01:00
|
|
|
case METHOD_DVD:
|
2008-12-30 01:05:57 +01:00
|
|
|
browser.dir[0] = 0;
|
|
|
|
browser.numEntries = ParseDVDdirectory(); // Parse root directory
|
2008-12-19 23:04:55 +01:00
|
|
|
SwitchDVDFolder(GCSettings.LoadFolder); // switch to ROM folder
|
|
|
|
break;
|
|
|
|
default:
|
2008-12-30 01:05:57 +01:00
|
|
|
sprintf(browser.dir, "/%s", GCSettings.LoadFolder);
|
|
|
|
browser.numEntries = ParseDirectory(); // Parse root directory
|
2008-12-19 23:04:55 +01:00
|
|
|
break;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
2008-12-30 01:05:57 +01:00
|
|
|
if (browser.numEntries > 0)
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
// Select an entry
|
|
|
|
return FileSelector (method);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no entries found
|
2008-12-19 23:04:55 +01:00
|
|
|
WaitPrompt ("No Files Found!");
|
2008-09-02 03:57:21 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|