added USB storage support

This commit is contained in:
ekeeke31 2008-12-08 17:26:50 +00:00
parent 3b6375670a
commit 6a9974c865
5 changed files with 110 additions and 75 deletions

View File

@ -163,7 +163,7 @@ int UnZipDVD (unsigned char *outbuffer, u64 discoffset, int length)
return 0; return 0;
} }
int UnZipSDCARD (unsigned char *outbuffer, char *filename) int UnZipFAT (unsigned char *outbuffer, char *filename)
{ {
unzFile *fd = NULL; unzFile *fd = NULL;
unz_file_info info; unz_file_info info;

View File

@ -10,6 +10,6 @@
extern int IsZipFile (char *buffer); extern int IsZipFile (char *buffer);
int UnZipDVD (unsigned char *outbuffer, u64 discoffset, int length); int UnZipDVD (unsigned char *outbuffer, u64 discoffset, int length);
int UnZipSDCARD (unsigned char *outbuffer, char *filename); int UnZipFAT (unsigned char *outbuffer, char *filename);
#endif #endif

View File

@ -28,10 +28,10 @@ static int offset = 0;
static int selection = 0; static int selection = 0;
static int old_selection = 0; static int old_selection = 0;
static int old_offset = 0; static int old_offset = 0;
static char rootSDdir[256]; static char rootFATdir[256];
static u8 haveDVDdir = 0; static u8 haveDVDdir = 0;
static u8 haveSDdir = 0; static u8 haveFATdir = 0;
static u8 UseSDCARD = 0; static u8 UseFAT = 0;
static u8 UseHistory = 0; static u8 UseHistory = 0;
static int LoadFile (unsigned char *buffer); static int LoadFile (unsigned char *buffer);
@ -88,11 +88,11 @@ static void ShowFiles (int offset, int selection)
} }
/*************************************************************************** /***************************************************************************
* updateSDdirname * updateFATdirname
* *
* Update ROOT directory while browsing SDCARD * Update ROOT directory while browsing SDCARD
***************************************************************************/ ***************************************************************************/
static int updateSDdirname() static int updateFATdirname()
{ {
int size=0; int size=0;
char *test; char *test;
@ -105,7 +105,7 @@ static int updateSDdirname()
else if (strcmp(filelist[selection].filename,"..") == 0) else if (strcmp(filelist[selection].filename,"..") == 0)
{ {
/* determine last subdirectory namelength */ /* determine last subdirectory namelength */
sprintf(temp,"%s",rootSDdir); sprintf(temp,"%s",rootFATdir);
test= strtok(temp,"/"); test= strtok(temp,"/");
while (test != NULL) while (test != NULL)
{ {
@ -114,33 +114,33 @@ static int updateSDdirname()
} }
/* remove last subdirectory name */ /* remove last subdirectory name */
size = strlen(rootSDdir) - size; size = strlen(rootFATdir) - size;
rootSDdir[size-1] = 0; rootFATdir[size-1] = 0;
} }
else else
{ {
sprintf(rootSDdir, "%s%s/",rootSDdir, filelist[selection].filename); sprintf(rootFATdir, "%s%s/",rootFATdir, filelist[selection].filename);
} }
return 1; return 1;
} }
/*************************************************************************** /***************************************************************************
* parseSDdirectory * parseFATdirectory
* *
* List files into one SDCARD directory * List files into one SDCARD directory
***************************************************************************/ ***************************************************************************/
static int parseSDdirectory() static int parseFATdirectory()
{ {
int nbfiles = 0; int nbfiles = 0;
char filename[MAXPATHLEN]; char filename[MAXPATHLEN];
struct stat filestat; struct stat filestat;
/* open directory */ /* open directory */
DIR_ITER *dir = diropen (rootSDdir); DIR_ITER *dir = diropen (rootFATdir);
if (dir == NULL) if (dir == NULL)
{ {
sprintf(filename, "Error opening %s", rootSDdir); sprintf(filename, "Error opening %s", rootFATdir);
WaitPrompt (filename); WaitPrompt (filename);
return 0; return 0;
} }
@ -176,8 +176,8 @@ static int FileSelected()
if(UseHistory) if(UseHistory)
{ {
/* Get the parent folder for the file. */ /* Get the parent folder for the file. */
strncpy(rootSDdir, history.entries[selection].filepath, MAXJOLIET-1); strncpy(rootFATdir, history.entries[selection].filepath, MAXJOLIET-1);
rootSDdir[MAXJOLIET-1] = '\0'; rootFATdir[MAXJOLIET-1] = '\0';
/* Get the length of the file. This has to be done /* Get the length of the file. This has to be done
* before calling LoadFile(). */ * before calling LoadFile(). */
@ -192,7 +192,7 @@ static int FileSelected()
} }
/* Add/move the file to the top of the history. */ /* Add/move the file to the top of the history. */
if (UseSDCARD) history_add_file(rootSDdir, filelist[selection].filename); if (UseFAT) history_add_file(rootFATdir, filelist[selection].filename);
rootdir = filelist[selection].offset; rootdir = filelist[selection].offset;
rootdirlength = filelist[selection].length; rootdirlength = filelist[selection].length;
@ -302,7 +302,7 @@ static int FileSelector ()
if (p & PAD_BUTTON_B) if (p & PAD_BUTTON_B)
{ {
filelist[selection].filename_offset = 0; filelist[selection].filename_offset = 0;
if (UseSDCARD) if (UseFAT)
{ {
if (strcmp(filelist[0].filename,"..") != 0) return 0; if (strcmp(filelist[0].filename,"..") != 0) return 0;
} }
@ -328,17 +328,17 @@ static int FileSelector ()
{ {
/* select item #1 */ /* select item #1 */
go_up = 0; go_up = 0;
selection = UseSDCARD ? 0 : 1; selection = UseFAT ? 0 : 1;
} }
/*** This is directory ***/ /*** This is directory ***/
if (filelist[selection].flags) if (filelist[selection].flags)
{ {
/* SDCARD directory handler */ /* SDCARD directory handler */
if (UseSDCARD) if (UseFAT)
{ {
/* update current directory */ /* update current directory */
if (updateSDdirname()) if (updateFATdirname())
{ {
/* reinit selector (previous value is saved for one level) */ /* reinit selector (previous value is saved for one level) */
if (selection == 0) if (selection == 0)
@ -358,12 +358,12 @@ static int FileSelector ()
} }
/* set new entry list */ /* set new entry list */
maxfiles = parseSDdirectory(); maxfiles = parseFATdirectory();
if (!maxfiles) if (!maxfiles)
{ {
/* quit */ /* quit */
WaitPrompt ("No files found !"); WaitPrompt ("No files found !");
haveSDdir = 0; haveFATdir = 0;
return 0; return 0;
} }
} }
@ -415,9 +415,7 @@ static int FileSelector ()
****************************************************************************/ ****************************************************************************/
int OpenDVD () int OpenDVD ()
{ {
int ret = 0; UseFAT = 0;
UseSDCARD = 0;
UseHistory = 0; UseHistory = 0;
if (!getpvd()) if (!getpvd())
@ -458,36 +456,41 @@ int OpenDVD ()
if (haveDVDdir == 0) if (haveDVDdir == 0)
{ {
/* don't mess with SD entries */ /* don't mess with SD entries */
haveSDdir = 0; haveFATdir = 0;
/* reinit selector */ /* reinit selector */
rootdir = basedir; rootdir = basedir;
old_selection = selection = offset = old_offset = 0; old_selection = selection = offset = old_offset = 0;
if ((maxfiles = parseDVDdirectory ()))
{
ret = FileSelector ();
haveDVDdir = 1;
}
} }
else ret = FileSelector ();
/* Parse root directory and get entries list */
return ret; ShowAction("Reading Directory ...");
if ((maxfiles = parseDVDdirectory ()))
{
/* Select an entry */
haveDVDdir = 1;
return FileSelector ();
}
else
{
/* no entries found */
WaitPrompt ("no files found !");
haveDVDdir = 0;
return 0;
}
} }
/**************************************************************************** /****************************************************************************
* OpenSD * OpenFAT
* *
* Function to load a SDCARD directory and display to user. * Function to load a FAT directory and display to user.
****************************************************************************/ ****************************************************************************/
int OpenSD () int OpenFAT (char *name)
{ {
int ret = 0; UseFAT = 1;
UseSDCARD = 1;
UseHistory = 0; UseHistory = 0;
if (haveSDdir == 0) if (haveFATdir == 0)
{ {
/* don't mess with DVD entries */ /* don't mess with DVD entries */
haveDVDdir = 0; haveDVDdir = 0;
@ -496,33 +499,29 @@ int OpenSD ()
old_selection = selection = offset = old_offset = 0; old_selection = selection = offset = old_offset = 0;
/* Reset SDCARD root directory */ /* Reset SDCARD root directory */
sprintf (rootSDdir, "/genplus/roms/"); sprintf (rootFATdir, "%s/genplus/roms/", name);
/* if directory doesn't exist, use root */ /* if directory doesn't exist, use root */
DIR_ITER *dir = diropen(rootSDdir); DIR_ITER *dir = diropen(rootFATdir);
if (dir == NULL) sprintf (rootSDdir, "fat:/"); if (dir == NULL) sprintf (rootFATdir, "%s/", name);
else dirclose(dir); else dirclose(dir);
} }
/* Parse root directory and get entries list */ /* Parse root directory and get entries list */
ShowAction("Reading Directory ..."); ShowAction("Reading Directory ...");
if ((maxfiles = parseSDdirectory ())) if ((maxfiles = parseFATdirectory ()))
{ {
/* Select an entry */ /* Select an entry */
ret = FileSelector (); haveFATdir = 1;
return FileSelector ();
/* memorize last entries list, actual root directory and selection for next access */
haveSDdir = 1;
} }
else else
{ {
/* no entries found */ /* no entries found */
WaitPrompt ("no files found !"); WaitPrompt ("no files found !");
haveSDdir = 0; haveFATdir = 0;
return 0; return -1;
} }
return ret;
} }
/**************************************************************************** /****************************************************************************
@ -534,11 +533,11 @@ int OpenHistory()
{ {
int i; int i;
UseSDCARD = 1; UseFAT = 1;
UseHistory = 1; UseHistory = 1;
/* don't mess with other entries */ /* don't mess with other entries */
haveSDdir = 0; haveFATdir = 0;
haveDVDdir = 0; haveDVDdir = 0;
/* reinit selector */ /* reinit selector */
@ -598,23 +597,23 @@ static int LoadFile (unsigned char *buffer)
if (rootdirlength == 0) return 0; if (rootdirlength == 0) return 0;
/* SDCard access */ /* SDCard access */
if (UseSDCARD) if (UseFAT)
{ {
/* open file */ /* open file */
sprintf(fname, "%s%s",rootSDdir,filelist[selection].filename); sprintf(fname, "%s%s",rootFATdir,filelist[selection].filename);
sdfile = fopen(fname, "rb"); sdfile = fopen(fname, "rb");
if (sdfile == NULL) if (sdfile == NULL)
{ {
WaitPrompt ("Unable to open file!"); WaitPrompt ("Unable to open file!");
haveSDdir = 0; haveFATdir = 0;
return 0; return -1;
} }
} }
ShowAction ("Loading ... Wait"); ShowAction ("Loading ... Wait");
/* Read first data chunk */ /* Read first data chunk */
if (UseSDCARD) if (UseFAT)
{ {
fread(readbuffer, 1, 2048, sdfile); fread(readbuffer, 1, 2048, sdfile);
} }
@ -627,7 +626,7 @@ static int LoadFile (unsigned char *buffer)
/* determine file type */ /* determine file type */
if (!IsZipFile ((char *) readbuffer)) if (!IsZipFile ((char *) readbuffer))
{ {
if (UseSDCARD) if (UseFAT)
{ {
/* go back to file start and read file */ /* go back to file start and read file */
fseek(sdfile, 0, SEEK_SET); fseek(sdfile, 0, SEEK_SET);
@ -662,7 +661,7 @@ static int LoadFile (unsigned char *buffer)
else else
{ {
/* unzip file */ /* unzip file */
if (UseSDCARD) return UnZipSDCARD (buffer, fname); if (UseFAT) return UnZipFAT(buffer, fname);
else return UnZipDVD (buffer, discoffset, rootdirlength); else return UnZipDVD (buffer, discoffset, rootdirlength);
} }

View File

@ -896,13 +896,24 @@ int loadmenu ()
int prevmenu = menu; int prevmenu = menu;
int ret; int ret;
int quit = 0; int quit = 0;
int count = 3 + dvd_on; #ifdef HW_RVL
char item[4][25] = { int count = 4 + dvd_on;
char item[5][25] = {
{"Load Recent"}, {"Load Recent"},
{"Load from SDCARD"}, {"Load from SD"},
{"Load from USB"},
{"Load from DVD"}, {"Load from DVD"},
{"Stop DVD Motor"} {"Stop DVD Motor"}
}; };
#else
int count = 3 + dvd_on;
char item[4][25] = {
{"Load Recent"},
{"Load from SD"},
{"Load from DVD"},
{"Stop DVD Motor"}
};
#endif
menu = load_menu; menu = load_menu;
@ -912,21 +923,37 @@ int loadmenu ()
ret = domenu (&item[0], count, 0); ret = domenu (&item[0], count, 0);
switch (ret) switch (ret)
{ {
case -1: /*** Button B ***/ /*** Button B ***/
case -1:
quit = 1; quit = 1;
break; break;
case 0: /*** Load Recent ***/ /*** Load Recent ***/
case 0:
load_menu = menu; load_menu = menu;
if (OpenHistory()) return 1; if (OpenHistory()) return 1;
break; break;
case 1: /*** Load from SCDARD ***/ /*** Load from SD ***/
load_menu = menu; case 1:
if (OpenSD()) return 1; load_menu = menu;
if (OpenFAT("") > 0) return 1;
break; break;
#ifdef HW_RVL
/*** Load from USB ***/
case 2:
load_menu = menu;
if (OpenFAT("usb:") > 0) return 1;
break;
#endif
/*** Load from DVD ***/
#ifdef HW_RVL
case 3:
#else
case 2: case 2:
#endif
load_menu = menu; load_menu = menu;
if (OpenDVD()) if (OpenDVD())
{ {
@ -935,10 +962,19 @@ int loadmenu ()
} }
break; break;
case 3: /*** Stop DVD Disc ***/ /*** Stop DVD Disc ***/
#ifdef HW_RVL
case 4:
#else
case 3:
#endif
dvd_motor_off(); dvd_motor_off();
dvd_on = 0; dvd_on = 0;
#ifdef HW_RVL
count = 4 + dvd_on;
#else
count = 3 + dvd_on; count = 3 + dvd_on;
#endif
menu = load_menu; menu = load_menu;
break; break;
} }

View File

@ -35,7 +35,7 @@ extern void set_region();
extern int ManageSRAM(u8 direction, u8 device); extern int ManageSRAM(u8 direction, u8 device);
extern int ManageState(u8 direction, u8 device); extern int ManageState(u8 direction, u8 device);
extern int OpenDVD(); extern int OpenDVD();
extern int OpenSD(); extern int OpenFAT(char *name);
extern int OpenHistory(); extern int OpenHistory();
extern void memfile_autosave(); extern void memfile_autosave();
extern void memfile_autoload(); extern void memfile_autoload();