2008-09-02 03:57:21 +02:00
|
|
|
/****************************************************************************
|
2009-07-22 04:05:49 +02:00
|
|
|
* FCE Ultra
|
2008-09-02 03:57:21 +02:00
|
|
|
* Nintendo Wii/Gamecube Port
|
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* Tantric 2008-2009
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* filebrowser.cpp
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
2009-07-17 19:27:04 +02:00
|
|
|
#include "fceusupport.h"
|
2008-11-17 01:09:31 +01:00
|
|
|
#include "fceugx.h"
|
2009-03-28 18:23:08 +01:00
|
|
|
#include "menu.h"
|
|
|
|
#include "filebrowser.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"
|
2009-03-28 18:23:08 +01:00
|
|
|
#include "fceuram.h"
|
|
|
|
#include "fceustate.h"
|
2009-07-23 07:39:43 +02:00
|
|
|
#include "patch.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
|
|
|
|
|
|
|
|
static char szpath[MAXPATHLEN];
|
|
|
|
static bool inSz = false;
|
|
|
|
|
2009-03-30 10:22:55 +02:00
|
|
|
char romFilename[256];
|
2008-09-02 03:57:21 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* autoLoadMethod()
|
2009-10-02 00:21:25 +02:00
|
|
|
* Auto-determines and sets the load device
|
|
|
|
* Returns device set
|
2008-09-02 03:57:21 +02:00
|
|
|
****************************************************************************/
|
|
|
|
int autoLoadMethod()
|
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
ShowAction ("Attempting to determine load device...");
|
|
|
|
|
|
|
|
int device = DEVICE_AUTO;
|
|
|
|
|
|
|
|
if(ChangeInterface(DEVICE_SD, SILENT))
|
|
|
|
device = DEVICE_SD;
|
|
|
|
else if(ChangeInterface(DEVICE_USB, SILENT))
|
|
|
|
device = DEVICE_USB;
|
|
|
|
else if(ChangeInterface(DEVICE_DVD, SILENT))
|
|
|
|
device = DEVICE_DVD;
|
|
|
|
else if(ChangeInterface(DEVICE_SMB, SILENT))
|
|
|
|
device = DEVICE_SMB;
|
2008-09-02 03:57:21 +02:00
|
|
|
else
|
2009-10-02 00:21:25 +02:00
|
|
|
ErrorPrompt("Unable to locate a load device!");
|
2008-12-22 09:38:49 +01:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
if(GCSettings.LoadMethod == DEVICE_AUTO)
|
|
|
|
GCSettings.LoadMethod = device; // save device found for later use
|
2009-03-28 18:23:08 +01:00
|
|
|
CancelAction();
|
2009-10-02 00:21:25 +02:00
|
|
|
return device;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* autoSaveMethod()
|
2009-10-02 00:21:25 +02:00
|
|
|
* Auto-determines and sets the save device
|
|
|
|
* Returns device set
|
2008-09-02 03:57:21 +02:00
|
|
|
****************************************************************************/
|
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)
|
2009-10-02 00:21:25 +02:00
|
|
|
ShowAction ("Attempting to determine save device...");
|
|
|
|
|
|
|
|
int device = DEVICE_AUTO;
|
|
|
|
|
|
|
|
if(ChangeInterface(DEVICE_SD, SILENT))
|
|
|
|
device = DEVICE_SD;
|
|
|
|
else if(ChangeInterface(DEVICE_USB, SILENT))
|
|
|
|
device = DEVICE_USB;
|
|
|
|
else if(ChangeInterface(DEVICE_MC_SLOTA, SILENT))
|
|
|
|
device = DEVICE_MC_SLOTA;
|
|
|
|
else if(ChangeInterface(DEVICE_MC_SLOTB, SILENT))
|
|
|
|
device = DEVICE_MC_SLOTB;
|
|
|
|
else if(ChangeInterface(DEVICE_SMB, SILENT))
|
|
|
|
device = DEVICE_SMB;
|
2008-12-22 09:38:49 +01:00
|
|
|
else if(!silent)
|
2009-10-02 00:21:25 +02:00
|
|
|
ErrorPrompt("Unable to locate a save device!");
|
2008-12-22 09:38:49 +01:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
if(GCSettings.SaveMethod == DEVICE_AUTO)
|
|
|
|
GCSettings.SaveMethod = device; // save device found for later use
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
CancelAction();
|
2009-10-02 00:21:25 +02:00
|
|
|
return device;
|
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()
|
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
browser.numEntries = 0;
|
|
|
|
browser.selIndex = 0;
|
|
|
|
browser.pageIndex = 0;
|
2008-12-30 01:05:57 +01:00
|
|
|
|
|
|
|
// 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));
|
2009-10-02 00:21:25 +02:00
|
|
|
browser.size = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AddBrowserEntry()
|
|
|
|
{
|
|
|
|
BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (browser.size+1) * sizeof(BROWSERENTRY));
|
|
|
|
|
|
|
|
if(!newBrowserList) // failed to allocate required memory
|
|
|
|
{
|
|
|
|
ResetBrowser();
|
|
|
|
ErrorPrompt("Out of memory: too many files!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
browserList = newBrowserList;
|
|
|
|
}
|
|
|
|
memset(&(browserList[browser.size]), 0, sizeof(BROWSERENTRY)); // clear the new entry
|
|
|
|
browser.size++;
|
|
|
|
return true;
|
2008-12-30 01:05:57 +01:00
|
|
|
}
|
|
|
|
|
2009-06-12 09:48:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* CleanupPath()
|
|
|
|
* Cleans up the filepath, removing double // and replacing \ with /
|
|
|
|
***************************************************************************/
|
|
|
|
static void CleanupPath(char * path)
|
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
if(!path || path[0] == 0)
|
|
|
|
return;
|
|
|
|
|
2009-06-12 09:48:27 +02:00
|
|
|
int pathlen = strlen(path);
|
|
|
|
int j = 0;
|
|
|
|
for(int i=0; i < pathlen && i < MAXPATHLEN; i++)
|
|
|
|
{
|
|
|
|
if(path[i] == '\\')
|
|
|
|
path[i] = '/';
|
|
|
|
|
|
|
|
if(j == 0 || !(path[j-1] == '/' && path[i] == '/'))
|
|
|
|
path[j++] = path[i];
|
|
|
|
}
|
|
|
|
path[j] = 0;
|
2009-10-02 00:21:25 +02:00
|
|
|
}
|
2009-06-12 09:48:27 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
bool IsDeviceRoot(char * path)
|
|
|
|
{
|
|
|
|
if(path == NULL || path[0] == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(strcmp(path, "sd:/") == 0 ||
|
|
|
|
strcmp(path, "usb:/") == 0 ||
|
|
|
|
strcmp(path, "dvd:/") == 0 ||
|
|
|
|
strcmp(path, "smb:/") == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2009-06-12 09:48:27 +02:00
|
|
|
}
|
|
|
|
|
2008-12-19 23:04:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* UpdateDirName()
|
|
|
|
* Update curent directory name for file browser
|
2008-09-02 03:57:21 +02:00
|
|
|
***************************************************************************/
|
2009-10-02 00:21:25 +02:00
|
|
|
int UpdateDirName()
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
|
|
|
int size=0;
|
2008-11-12 09:40:09 +01:00
|
|
|
char * test;
|
2008-09-02 03:57:21 +02:00
|
|
|
char temp[1024];
|
2009-10-02 00:21:25 +02:00
|
|
|
int device = 0;
|
|
|
|
|
|
|
|
if(browser.numEntries == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
FindDevice(browser.dir, &device);
|
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
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
// already at the top level
|
|
|
|
if(IsDeviceRoot(browser.dir))
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
browser.dir[0] = 0; // remove device - we are going to the device listing screen
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* determine last subdirectory namelength */
|
|
|
|
sprintf(temp,"%s",browser.dir);
|
|
|
|
test = strtok(temp,"/");
|
|
|
|
while (test != NULL)
|
|
|
|
{
|
|
|
|
size = strlen(test);
|
|
|
|
test = strtok(NULL,"/");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove last subdirectory name */
|
|
|
|
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 */
|
2009-06-12 09:48:27 +02:00
|
|
|
sprintf(browser.dir, "%s%s/",browser.dir, browserList[browser.selIndex].filename);
|
2008-09-02 03:57:21 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
ErrorPrompt("Directory name is too long!");
|
2008-09-02 03:57:21 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
bool MakeFilePath(char filepath[], int type, char * filename, int filenum)
|
2008-10-13 20:15:03 +02:00
|
|
|
{
|
2008-11-12 09:40:09 +01:00
|
|
|
char file[512];
|
|
|
|
char folder[1024];
|
2009-03-28 18:23:08 +01:00
|
|
|
char ext[4];
|
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
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
ErrorPrompt("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
|
|
|
{
|
2009-06-12 09:48:27 +02: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
|
|
|
|
{
|
2009-10-04 01:08:40 +02:00
|
|
|
if(GCSettings.SaveMethod == DEVICE_AUTO)
|
|
|
|
GCSettings.SaveMethod = autoSaveMethod(SILENT);
|
|
|
|
|
|
|
|
if(GCSettings.SaveMethod == DEVICE_AUTO)
|
|
|
|
return false;
|
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case FILE_RAM:
|
|
|
|
case FILE_STATE:
|
|
|
|
sprintf(folder, GCSettings.SaveFolder);
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
if(type == FILE_RAM) sprintf(ext, "sav");
|
|
|
|
else sprintf(ext, "fcs");
|
|
|
|
|
2009-04-09 09:49:28 +02:00
|
|
|
if(filenum >= -1)
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
if(GCSettings.SaveMethod == DEVICE_MC_SLOTA || GCSettings.SaveMethod == DEVICE_MC_SLOTB)
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
2009-04-09 09:49:28 +02:00
|
|
|
if(filenum > 9)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(filenum == -1)
|
|
|
|
{
|
|
|
|
filename[27] = 0; // truncate filename
|
|
|
|
sprintf(file, "%s.%s", filename, ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename[26] = 0; // truncate filename
|
|
|
|
sprintf(file, "%s%i.%s", filename, filenum, ext);
|
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-04-09 09:49:28 +02:00
|
|
|
if(filenum == -1)
|
|
|
|
sprintf(file, "%s.%s", filename, ext);
|
|
|
|
else if(filenum == 0)
|
2009-03-28 18:23:08 +01:00
|
|
|
sprintf(file, "%s Auto.%s", filename, ext);
|
|
|
|
else
|
|
|
|
sprintf(file, "%s %i.%s", filename, filenum, ext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf(file, "%s", filename);
|
|
|
|
}
|
2008-11-12 09:40:09 +01:00
|
|
|
break;
|
2009-03-28 18:23:08 +01:00
|
|
|
|
2008-11-12 09:40:09 +01:00
|
|
|
case FILE_FDSBIOS:
|
2009-07-29 08:33:17 +02:00
|
|
|
sprintf(folder, "fceugx");
|
2008-11-12 09:40:09 +01:00
|
|
|
sprintf(file, "disksys.rom");
|
|
|
|
break;
|
2009-10-02 00:21:25 +02:00
|
|
|
|
2009-07-29 08:33:17 +02:00
|
|
|
case FILE_GGROM:
|
|
|
|
sprintf(folder, "fceugx");
|
|
|
|
sprintf(file, "gg.rom");
|
|
|
|
break;
|
2009-10-02 00:21:25 +02:00
|
|
|
|
2009-07-22 03:58:45 +02:00
|
|
|
case FILE_CHEAT:
|
|
|
|
sprintf(folder, GCSettings.CheatFolder);
|
|
|
|
sprintf(file, "%s.cht", romFilename);
|
|
|
|
break;
|
2008-11-12 09:40:09 +01:00
|
|
|
}
|
2009-10-02 00:21:25 +02:00
|
|
|
switch(GCSettings.SaveMethod)
|
2008-11-12 09:40:09 +01:00
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
case DEVICE_MC_SLOTA:
|
|
|
|
case DEVICE_MC_SLOTB:
|
|
|
|
sprintf (temppath, "%s%s", pathPrefix[GCSettings.SaveMethod], file);
|
2008-11-12 09:40:09 +01:00
|
|
|
temppath[31] = 0; // truncate filename
|
|
|
|
break;
|
2008-12-19 23:04:55 +01:00
|
|
|
default:
|
2009-10-02 00:21:25 +02:00
|
|
|
sprintf (temppath, "%s%s/%s", pathPrefix[GCSettings.SaveMethod], folder, file);
|
2008-12-19 23:04:55 +01:00
|
|
|
break;
|
2008-11-12 09:40:09 +01:00
|
|
|
}
|
|
|
|
}
|
2009-06-12 09:48:27 +02:00
|
|
|
CleanupPath(temppath); // cleanup path
|
2009-03-28 18:23:08 +01:00
|
|
|
strncpy(filepath, temppath, MAXPATHLEN);
|
2008-11-12 09:40:09 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
/****************************************************************************
|
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
|
|
|
|
***************************************************************************/
|
2009-10-02 00:21:25 +02:00
|
|
|
static bool IsValidROM()
|
2008-10-05 23:34:06 +02:00
|
|
|
{
|
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
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
ErrorPrompt("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
|
2009-10-02 00:21:25 +02:00
|
|
|
char * zippedFilename = GetFirstZipFilename ();
|
2008-10-05 23:34:06 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
ErrorPrompt("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
|
2009-03-28 18:23:08 +01:00
|
|
|
***************************************************************************/
|
2008-09-02 03:57:21 +02:00
|
|
|
void StripExt(char* returnstring, char * inputstring)
|
|
|
|
{
|
|
|
|
char* loc_dot;
|
|
|
|
|
2009-06-27 21:12:47 +02:00
|
|
|
strncpy (returnstring, inputstring, MAXJOLIET);
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
if(inputstring == NULL || strlen(inputstring) < 4)
|
|
|
|
return;
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
loc_dot = strrchr(returnstring,'.');
|
|
|
|
if (loc_dot != NULL)
|
2009-03-28 18:23:08 +01:00
|
|
|
*loc_dot = 0; // strip file extension
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2009-03-28 18:23:08 +01:00
|
|
|
* BrowserLoadSz
|
2008-09-02 03:57:21 +02:00
|
|
|
*
|
2009-03-28 18:23:08 +01:00
|
|
|
* Opens the selected 7z file, and parses a listing of the files within
|
|
|
|
***************************************************************************/
|
2009-10-02 00:21:25 +02:00
|
|
|
int BrowserLoadSz()
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-03-28 18:23:08 +01:00
|
|
|
char filepath[MAXPATHLEN];
|
|
|
|
memset(filepath, 0, MAXPATHLEN);
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
// we'll store the 7z filepath for extraction later
|
2009-10-02 00:21:25 +02:00
|
|
|
if(!MakeFilePath(szpath, FILE_ROM))
|
2009-03-28 18:23:08 +01:00
|
|
|
return 0;
|
2008-10-13 20:15:03 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
int szfiles = SzParse(szpath);
|
2009-03-28 18:23:08 +01:00
|
|
|
if(szfiles)
|
|
|
|
{
|
|
|
|
browser.numEntries = szfiles;
|
|
|
|
inSz = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ErrorPrompt("Error opening archive!");
|
2008-10-13 20:15:03 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
return szfiles;
|
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* BrowserLoadFile
|
|
|
|
*
|
|
|
|
* Loads the selected ROM
|
|
|
|
***************************************************************************/
|
2009-10-02 00:21:25 +02:00
|
|
|
int BrowserLoadFile()
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
|
|
|
char filepath[1024];
|
2009-10-03 21:10:34 +02:00
|
|
|
size_t filesize = 0;
|
2009-03-28 18:23:08 +01:00
|
|
|
romLoaded = false;
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
int device;
|
|
|
|
|
|
|
|
if(!FindDevice(browser.dir, &device))
|
|
|
|
return 0;
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
// check that this is a valid ROM
|
2009-10-02 00:21:25 +02:00
|
|
|
if(!IsValidROM())
|
2009-03-28 18:23:08 +01:00
|
|
|
goto done;
|
2008-11-12 09:40:09 +01:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
// store the filename (w/o ext) - used for ram/state naming
|
|
|
|
StripExt(romFilename, browserList[browser.selIndex].filename);
|
2008-12-19 23:04:55 +01:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(!inSz)
|
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
if(!MakeFilePath(filepath, FILE_ROM))
|
2009-03-28 18:23:08 +01:00
|
|
|
goto done;
|
2008-10-06 00:46:15 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
filesize = LoadFile ((char *)nesrom, filepath, browserList[browser.selIndex].length, NOTSILENT);
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-03 19:04:33 +02:00
|
|
|
filesize = LoadSzFile(szpath, nesrom);
|
|
|
|
|
2009-07-09 23:49:26 +02:00
|
|
|
if(filesize <= 0)
|
|
|
|
{
|
|
|
|
browser.selIndex = 0;
|
2009-10-02 00:21:25 +02:00
|
|
|
BrowserChangeFolder();
|
2009-07-09 23:49:26 +02:00
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if (filesize <= 0)
|
|
|
|
{
|
|
|
|
ErrorPrompt("Error loading ROM!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-07-23 07:39:43 +02:00
|
|
|
// load UPS/IPS/PPF patch
|
2009-10-02 00:21:25 +02:00
|
|
|
filesize = LoadPatch(filesize);
|
2009-07-23 07:39:43 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
if(GCMemROM(filesize) > 0)
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
|
|
|
romLoaded = true;
|
2008-10-02 07:28:01 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
// load RAM or state
|
|
|
|
if (GCSettings.AutoLoad == 1)
|
2009-10-02 00:21:25 +02:00
|
|
|
LoadRAMAuto(SILENT);
|
2009-03-28 18:23:08 +01:00
|
|
|
else if (GCSettings.AutoLoad == 2)
|
2009-10-02 00:21:25 +02:00
|
|
|
LoadStateAuto(SILENT);
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
ResetNES();
|
|
|
|
ResetBrowser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
CancelAction();
|
|
|
|
return romLoaded;
|
|
|
|
}
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* BrowserChangeFolder
|
|
|
|
*
|
|
|
|
* Update current directory and set new entry list if directory has changed
|
|
|
|
***************************************************************************/
|
2009-10-02 00:21:25 +02:00
|
|
|
int BrowserChangeFolder()
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
int device = 0;
|
|
|
|
FindDevice(browser.dir, &device);
|
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
if(inSz && browser.selIndex == 0) // inside a 7z, requesting to leave
|
|
|
|
{
|
|
|
|
inSz = false;
|
|
|
|
SzClose();
|
|
|
|
}
|
2008-11-12 09:40:09 +01:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
if(!UpdateDirName())
|
2009-03-28 18:23:08 +01:00
|
|
|
return -1;
|
2008-10-13 20:15:03 +02:00
|
|
|
|
2009-06-12 09:48:27 +02:00
|
|
|
CleanupPath(browser.dir);
|
2009-10-02 00:21:25 +02:00
|
|
|
HaltParseThread(); // halt parsing
|
|
|
|
ResetBrowser(); // reset browser
|
2009-06-12 09:48:27 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
if(browser.dir[0] != 0)
|
2009-10-03 19:04:33 +02:00
|
|
|
ParseDirectory();
|
|
|
|
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-10-02 00:21:25 +02:00
|
|
|
if(browser.numEntries == 0)
|
|
|
|
{
|
|
|
|
browser.dir[0] = 0;
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
AddBrowserEntry();
|
|
|
|
sprintf(browserList[i].filename, "sd:/");
|
|
|
|
sprintf(browserList[i].displayname, "SD Card");
|
|
|
|
browserList[i].length = 0;
|
|
|
|
browserList[i].mtime = 0;
|
|
|
|
browserList[i].isdir = 1;
|
|
|
|
browserList[i].icon = ICON_SD;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
AddBrowserEntry();
|
|
|
|
sprintf(browserList[i].filename, "usb:/");
|
|
|
|
sprintf(browserList[i].displayname, "USB Mass Storage");
|
|
|
|
browserList[i].length = 0;
|
|
|
|
browserList[i].mtime = 0;
|
|
|
|
browserList[i].isdir = 1;
|
|
|
|
browserList[i].icon = ICON_USB;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
AddBrowserEntry();
|
|
|
|
sprintf(browserList[i].filename, "smb:/");
|
|
|
|
sprintf(browserList[i].displayname, "Network Share");
|
|
|
|
browserList[i].length = 0;
|
|
|
|
browserList[i].mtime = 0;
|
|
|
|
browserList[i].isdir = 1;
|
|
|
|
browserList[i].icon = ICON_SMB;
|
|
|
|
i++;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
AddBrowserEntry();
|
|
|
|
sprintf(browserList[i].filename, "dvd:/");
|
|
|
|
sprintf(browserList[i].displayname, "Data DVD");
|
|
|
|
browserList[i].length = 0;
|
|
|
|
browserList[i].mtime = 0;
|
|
|
|
browserList[i].isdir = 1;
|
|
|
|
browserList[i].icon = ICON_DVD;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
browser.numEntries += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(browser.dir[0] == 0)
|
|
|
|
{
|
|
|
|
GCSettings.LoadFolder[0] = 0;
|
|
|
|
GCSettings.LoadMethod = 0;
|
|
|
|
}
|
|
|
|
else
|
2009-03-28 18:23:08 +01:00
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
char * path = StripDevice(browser.dir);
|
|
|
|
if(path != NULL)
|
|
|
|
strcpy(GCSettings.LoadFolder, path);
|
|
|
|
FindDevice(browser.dir, &GCSettings.LoadMethod);
|
2008-12-30 01:05:57 +01:00
|
|
|
}
|
2009-03-28 18:23:08 +01:00
|
|
|
|
|
|
|
return browser.numEntries;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2008-12-19 23:04:55 +01:00
|
|
|
* OpenROM
|
2009-03-28 18:23:08 +01:00
|
|
|
* Displays a list of ROMS on load device
|
2008-12-19 23:04:55 +01:00
|
|
|
***************************************************************************/
|
2008-09-02 03:57:21 +02:00
|
|
|
int
|
2009-03-28 18:23:08 +01:00
|
|
|
OpenGameList ()
|
2008-09-02 03:57:21 +02:00
|
|
|
{
|
2009-10-02 00:21:25 +02:00
|
|
|
int device = GCSettings.LoadMethod;
|
2009-03-28 18:23:08 +01:00
|
|
|
|
2009-10-06 08:38:32 +02:00
|
|
|
if(device == DEVICE_AUTO && strlen(GCSettings.LoadFolder) > 0)
|
2009-10-02 00:21:25 +02:00
|
|
|
device = autoLoadMethod();
|
2008-09-02 03:57:21 +02:00
|
|
|
|
2009-03-28 18:23:08 +01:00
|
|
|
// change current dir to roms directory
|
2009-10-02 00:21:25 +02:00
|
|
|
if(device > 0)
|
2009-10-02 05:14:04 +02:00
|
|
|
sprintf(browser.dir, "%s%s/", pathPrefix[device], GCSettings.LoadFolder);
|
2009-10-02 00:21:25 +02:00
|
|
|
else
|
|
|
|
browser.dir[0] = 0;
|
|
|
|
|
|
|
|
BrowserChangeFolder();
|
2009-03-28 18:23:08 +01:00
|
|
|
return browser.numEntries;
|
2008-09-02 03:57:21 +02:00
|
|
|
}
|