2008-12-11 18:38:29 +01:00
|
|
|
/*
|
|
|
|
* filesel.c
|
|
|
|
*
|
|
|
|
* File Selection menu
|
|
|
|
*
|
|
|
|
* code by Softdev (2006), Eke-Eke (2007,2008)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2008-08-07 14:26:07 +02:00
|
|
|
*
|
2008-12-11 18:38:29 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
#include "shared.h"
|
|
|
|
#include "font.h"
|
2008-12-11 18:38:29 +01:00
|
|
|
#include "file_dvd.h"
|
|
|
|
#include "file_fat.h"
|
2008-12-10 19:16:30 +01:00
|
|
|
#include "filesel.h"
|
|
|
|
|
|
|
|
/* Global Variables */
|
|
|
|
int maxfiles = 0;
|
|
|
|
int offset = 0;
|
|
|
|
int selection = 0;
|
|
|
|
int old_selection = 0;
|
|
|
|
int old_offset = 0;
|
|
|
|
int useFAT = 0;
|
|
|
|
int useHistory = 0;
|
|
|
|
int haveDVDdir = 0;
|
|
|
|
int haveFATdir = 0;
|
2008-12-08 12:24:04 +01:00
|
|
|
|
2008-12-11 18:38:29 +01:00
|
|
|
FILEENTRIES filelist[MAXFILES];
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/***************************************************************************
|
|
|
|
* ShowFiles
|
|
|
|
*
|
|
|
|
* Show filenames list in current directory
|
|
|
|
***************************************************************************/
|
|
|
|
static void ShowFiles (int offset, int selection)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
char text[MAXJOLIET+2];
|
|
|
|
|
2009-02-22 20:57:41 +01:00
|
|
|
ClearScreen ((GXColor)BLACK);
|
2008-08-07 14:26:07 +02:00
|
|
|
j = 0;
|
|
|
|
|
|
|
|
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
|
|
|
|
{
|
|
|
|
memset(text,0,MAXJOLIET+2);
|
|
|
|
if (filelist[i].flags) sprintf(text, "[%s]", filelist[i].filename + filelist[i].filename_offset);
|
|
|
|
else sprintf (text, "%s", filelist[i].filename + filelist[i].filename_offset);
|
2008-12-11 18:38:29 +01:00
|
|
|
if (j == (selection - offset)) WriteCentre_HL ((j * fheight) + PAGEOFFSET, text);
|
|
|
|
else WriteCentre ((j * fheight) + PAGEOFFSET, text);
|
2008-08-07 14:26:07 +02:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
SetScreen ();
|
|
|
|
}
|
|
|
|
|
2008-12-14 13:38:52 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* FileSortCallback (Marty Disibio)
|
|
|
|
*
|
|
|
|
* 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 */
|
|
|
|
if(((FILEENTRIES *)f1)->filename[0] == '.' || ((FILEENTRIES *)f2)->filename[0] == '.')
|
|
|
|
{
|
|
|
|
if(strcmp(((FILEENTRIES *)f1)->filename, ".") == 0) { return -1; }
|
|
|
|
if(strcmp(((FILEENTRIES *)f2)->filename, ".") == 0) { return 1; }
|
|
|
|
if(strcmp(((FILEENTRIES *)f1)->filename, "..") == 0) { return -1; }
|
|
|
|
if(strcmp(((FILEENTRIES *)f2)->filename, "..") == 0) { return 1; }
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If one is a file and one is a directory the directory is first. */
|
|
|
|
if(((FILEENTRIES *)f1)->flags == 1 && ((FILEENTRIES *)f2)->flags == 0) return -1;
|
|
|
|
if(((FILEENTRIES *)f1)->flags == 0 && ((FILEENTRIES *)f2)->flags == 1) return 1;
|
|
|
|
|
|
|
|
return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename);
|
|
|
|
}
|
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* FileSelector
|
|
|
|
*
|
|
|
|
* Let user select a file from the File listing
|
2008-12-11 18:38:29 +01:00
|
|
|
.* ROM file buffer is provided as input
|
|
|
|
* ROM size is returned
|
|
|
|
*
|
2008-08-07 14:26:07 +02:00
|
|
|
****************************************************************************/
|
2009-03-30 09:05:34 +02:00
|
|
|
extern s16 ogc_input__getMenuButtons(u32 cnt);
|
2008-12-11 18:38:29 +01:00
|
|
|
int FileSelector(unsigned char *buffer)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
short p;
|
|
|
|
int redraw = 1;
|
|
|
|
int go_up = 0;
|
2008-12-10 19:16:30 +01:00
|
|
|
int ret;
|
2008-08-07 14:26:07 +02:00
|
|
|
int i,size;
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-11-13 08:24:30 +01:00
|
|
|
while (1)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
if (redraw) ShowFiles (offset, selection);
|
|
|
|
redraw = 0;
|
2009-03-29 20:56:36 +02:00
|
|
|
p = ogc_input__getMenuButtons(0);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
|
|
|
/* scroll displayed filename */
|
|
|
|
if (p & PAD_BUTTON_LEFT)
|
|
|
|
{
|
|
|
|
if (filelist[selection].filename_offset > 0)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset --;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (p & PAD_BUTTON_RIGHT)
|
|
|
|
{
|
|
|
|
size = 0;
|
|
|
|
for (i=filelist[selection].filename_offset; i<strlen(filelist[selection].filename); i++)
|
|
|
|
size += font_size[(int)filelist[selection].filename[i]];
|
|
|
|
|
|
|
|
if (size > back_framewidth)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset ++;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* highlight next item */
|
|
|
|
else if (p & PAD_BUTTON_DOWN)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset = 0;
|
|
|
|
selection++;
|
|
|
|
if (selection == maxfiles) selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE) offset += PAGESIZE;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* highlight previous item */
|
|
|
|
else if (p & PAD_BUTTON_UP)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset = 0;
|
|
|
|
selection--;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (selection < offset) offset -= PAGESIZE;
|
|
|
|
if (offset < 0) offset = 0;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* go back one page */
|
|
|
|
else if (p & PAD_TRIGGER_L)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset = 0;
|
|
|
|
selection -= PAGESIZE;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
|
|
|
if (selection < offset) offset -= PAGESIZE;
|
|
|
|
if (offset < 0) offset = 0;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* go forward one page */
|
|
|
|
else if (p & PAD_TRIGGER_R)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset = 0;
|
|
|
|
selection += PAGESIZE;
|
|
|
|
if (selection > maxfiles - 1) selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE) offset += PAGESIZE;
|
|
|
|
redraw = 1;
|
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* quit */
|
|
|
|
if (p & PAD_TRIGGER_Z)
|
|
|
|
{
|
|
|
|
filelist[selection].filename_offset = 0;
|
2008-11-13 08:24:30 +01:00
|
|
|
return 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/* open selected file or directory */
|
2008-12-10 19:16:30 +01:00
|
|
|
if ((p & PAD_BUTTON_A) || (p & PAD_BUTTON_B))
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
|
|
|
filelist[selection].filename_offset = 0;
|
2008-12-10 19:16:30 +01:00
|
|
|
go_up = 0;
|
|
|
|
|
|
|
|
if (p & PAD_BUTTON_B)
|
2008-08-07 14:26:07 +02:00
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
/* go up one directory or quit */
|
|
|
|
go_up = 1;
|
|
|
|
selection = useFAT ? 0 : 1;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
2008-12-12 14:27:38 +01:00
|
|
|
|
2008-08-07 14:26:07 +02:00
|
|
|
/*** This is directory ***/
|
|
|
|
if (filelist[selection].flags)
|
|
|
|
{
|
2008-12-10 19:16:30 +01:00
|
|
|
/* get new directory */
|
2008-12-11 18:38:29 +01:00
|
|
|
if (useFAT) ret =FAT_UpdateDir(go_up);
|
|
|
|
else ret = DVD_UpdateDir(go_up);
|
2008-08-07 14:26:07 +02:00
|
|
|
|
2008-12-10 19:16:30 +01:00
|
|
|
/* get new entry list or quit */
|
2008-12-11 18:38:29 +01:00
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
if (useFAT) maxfiles = FAT_ParseDirectory();
|
|
|
|
else maxfiles = DVD_ParseDirectory();
|
|
|
|
}
|
2008-12-10 19:16:30 +01:00
|
|
|
else return 0;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
|
2008-12-10 19:16:30 +01:00
|
|
|
/*** This is a file ***/
|
|
|
|
else
|
2008-08-17 22:17:49 +02:00
|
|
|
{
|
2008-12-12 14:27:38 +01:00
|
|
|
/* root directory ? */
|
|
|
|
if (go_up) return 0;
|
|
|
|
|
2008-12-10 19:16:30 +01:00
|
|
|
/* Load file */
|
2008-12-14 13:38:52 +01:00
|
|
|
if (useFAT) return FAT_LoadFile(buffer);
|
|
|
|
else return DVD_LoadFile(buffer);
|
2008-08-17 22:17:49 +02:00
|
|
|
}
|
2008-12-10 19:16:30 +01:00
|
|
|
redraw = 1;
|
2008-08-07 14:26:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|