2009-04-15 17:33:51 +02:00
|
|
|
/*
|
|
|
|
* filesel.c
|
|
|
|
*
|
|
|
|
* File Selection menu
|
|
|
|
*
|
2009-05-13 16:26:55 +02:00
|
|
|
* Softdev (2006)
|
|
|
|
* Eke-Eke (2007,2008,2009)
|
2009-04-15 17:33:51 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
#include "shared.h"
|
2010-05-06 14:59:43 +02:00
|
|
|
#include "filesel.h"
|
|
|
|
#include "menu.h"
|
2009-04-15 17:33:51 +02:00
|
|
|
#include "font.h"
|
2009-05-13 16:26:55 +02:00
|
|
|
#include "gui.h"
|
2009-04-15 17:33:51 +02:00
|
|
|
#include "file_dvd.h"
|
|
|
|
#include "file_fat.h"
|
2010-05-06 14:59:43 +02:00
|
|
|
#include "file_slot.h"
|
2009-04-15 17:33:51 +02:00
|
|
|
|
|
|
|
#ifdef HW_RVL
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#endif
|
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
#define PAGESIZE 11
|
|
|
|
#define PAGEOFFSET 120
|
2009-04-15 17:33:51 +02:00
|
|
|
|
|
|
|
FILEENTRIES filelist[MAXFILES];
|
|
|
|
|
2009-05-25 19:07:34 +02:00
|
|
|
static int offset = 0;
|
|
|
|
static int selection = 0;
|
|
|
|
static int old_selection = 0;
|
|
|
|
static int old_offset = 0;
|
|
|
|
static int maxfiles = 0;
|
2010-05-06 14:59:43 +02:00
|
|
|
static int string_offset = 0;
|
|
|
|
static void selector_cb(void);
|
2009-05-25 19:07:34 +02:00
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* GUI Buttons data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
static butn_data arrow_up_data =
|
|
|
|
{
|
|
|
|
{NULL,NULL},
|
|
|
|
{Button_up_png,Button_up_over_png}
|
|
|
|
};
|
|
|
|
|
|
|
|
static butn_data arrow_down_data =
|
|
|
|
{
|
|
|
|
{NULL,NULL},
|
|
|
|
{Button_down_png,Button_down_over_png}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2009-04-20 19:41:54 +02:00
|
|
|
/* GUI Arrows button */
|
2009-04-20 00:31:08 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
2010-05-06 14:59:43 +02:00
|
|
|
static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,76,360,32};
|
|
|
|
static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,368,360,32};
|
2009-04-20 00:31:08 +02:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* GUI helpers */
|
|
|
|
/*****************************************************************************/
|
|
|
|
static gui_item action_cancel =
|
|
|
|
{
|
2009-05-19 18:14:43 +02:00
|
|
|
NULL,Key_B_png,"","Previous Directory",10,422,28,28
|
2009-04-20 00:31:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static gui_item action_select =
|
|
|
|
{
|
2009-05-19 18:14:43 +02:00
|
|
|
NULL,Key_A_png,"","Load ROM file",602,422,28,28
|
2009-04-20 00:31:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* GUI Background images */
|
|
|
|
/*****************************************************************************/
|
2009-05-01 14:56:48 +02:00
|
|
|
static gui_image bg_filesel[10] =
|
2009-04-20 00:31:08 +02:00
|
|
|
{
|
2010-03-22 15:07:25 +01:00
|
|
|
{NULL,Bg_main_png,IMAGE_VISIBLE,374,140,284,288,255},
|
2009-05-04 23:43:16 +02:00
|
|
|
{NULL,Bg_overlay_png,IMAGE_VISIBLE|IMAGE_REPEAT,0,0,640,480,255},
|
|
|
|
{NULL,Banner_top_png,IMAGE_VISIBLE,0,0,640,108,255},
|
|
|
|
{NULL,Banner_bottom_png,IMAGE_VISIBLE,0,380,640,100,255},
|
|
|
|
{NULL,Main_logo_png,IMAGE_VISIBLE,466,40,152,44,255},
|
2010-03-22 15:07:25 +01:00
|
|
|
{NULL,Frame_s1_png,IMAGE_VISIBLE,8,70,372,336,200},
|
2009-05-04 23:43:16 +02:00
|
|
|
{NULL,Frame_s2_png,0,384,264,248,140,200},
|
|
|
|
{NULL,Snap_empty_png,IMAGE_VISIBLE,422,114,164,116,255},
|
|
|
|
{NULL,NULL,0,424,116,160,112,255},
|
|
|
|
{NULL,Snap_frame_png,IMAGE_VISIBLE,388,112,236,148,255}
|
2009-04-20 00:31:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
/* GUI Descriptor */
|
|
|
|
/*****************************************************************************/
|
|
|
|
static gui_menu menu_browser =
|
|
|
|
{
|
2009-05-01 14:56:48 +02:00
|
|
|
"Game Selection",
|
2009-04-24 01:24:40 +02:00
|
|
|
-1,-1,
|
2009-12-30 16:31:50 +01:00
|
|
|
0,0,10,0,
|
2009-04-20 00:31:08 +02:00
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
bg_filesel,
|
|
|
|
{&action_cancel, &action_select},
|
2010-05-06 14:59:43 +02:00
|
|
|
{&arrow_up,&arrow_down},
|
|
|
|
selector_cb
|
2009-04-20 00:31:08 +02:00
|
|
|
};
|
|
|
|
|
2009-04-15 17:33:51 +02: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* FileSelector
|
|
|
|
*
|
|
|
|
* Let user select a file from the File listing
|
|
|
|
..* ROM file buffer is provided as input
|
|
|
|
* ROM size is returned
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2010-05-06 14:59:43 +02:00
|
|
|
static void selector_cb(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char text[MAXPATHLEN];
|
|
|
|
int yoffset = PAGEOFFSET;
|
|
|
|
|
|
|
|
/* Initialize directory icon */
|
|
|
|
gui_image dir_icon;
|
|
|
|
dir_icon.texture = gxTextureOpenPNG(Browser_dir_png,0);
|
|
|
|
dir_icon.w = dir_icon.texture->width;
|
|
|
|
dir_icon.h = dir_icon.texture->height;
|
|
|
|
dir_icon.x = 26;
|
|
|
|
dir_icon.y = PAGEOFFSET;
|
|
|
|
|
|
|
|
/* Initialize selection bar */
|
|
|
|
gui_image bar_over;
|
|
|
|
bar_over.texture = gxTextureOpenPNG(Overlay_bar_png,0);
|
|
|
|
bar_over.w = bar_over.texture->width;
|
|
|
|
bar_over.h = bar_over.texture->height;
|
|
|
|
bar_over.x = 22;
|
|
|
|
bar_over.y = -(bar_over.h - dir_icon.h)/2;
|
|
|
|
|
|
|
|
/* Draw Files list */
|
|
|
|
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
|
|
|
|
{
|
|
|
|
if (i == selection)
|
|
|
|
{
|
|
|
|
/* selection bar */
|
|
|
|
gxDrawTexture(bar_over.texture,bar_over.x,yoffset+bar_over.y,bar_over.w,bar_over.h,255);
|
|
|
|
|
|
|
|
/* scrolling text */
|
|
|
|
if ((string_offset/10) >= strlen(filelist[i].filename))
|
|
|
|
string_offset = 0;
|
|
|
|
sprintf(text, "%s ",filelist[i].filename + string_offset/10);
|
|
|
|
strncat(text, filelist[i].filename, string_offset/10);
|
|
|
|
if (filelist[i].flags)
|
|
|
|
{
|
|
|
|
/* directory icon */
|
|
|
|
gxDrawTexture(dir_icon.texture,dir_icon.x-1,yoffset-1,dir_icon.w+2,dir_icon.h+2,255);
|
|
|
|
if (FONT_write(text,18,dir_icon.x+dir_icon.w+6,yoffset+16,bar_over.w-dir_icon.w-14,(GXColor)WHITE))
|
|
|
|
{
|
|
|
|
/* string is too large -> scroll text */
|
|
|
|
string_offset ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (FONT_write(text,18,dir_icon.x,yoffset+16,bar_over.w-8,(GXColor)WHITE))
|
|
|
|
{
|
|
|
|
/* text scrolling */
|
|
|
|
string_offset ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (filelist[i].flags)
|
|
|
|
{
|
|
|
|
/* directory icon */
|
|
|
|
gxDrawTexture(dir_icon.texture,dir_icon.x,yoffset,dir_icon.w,dir_icon.h,255);
|
|
|
|
FONT_write(filelist[i].filename,16,dir_icon.x+dir_icon.w+6,yoffset+16,bar_over.w-dir_icon.w-14,(GXColor)WHITE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FONT_write(filelist[i].filename,16,dir_icon.x,yoffset+16,bar_over.w-8,(GXColor)WHITE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
yoffset += 22;
|
|
|
|
}
|
|
|
|
|
|
|
|
gxTextureClose(&bar_over.texture);
|
|
|
|
gxTextureClose(&dir_icon.texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-25 19:07:34 +02:00
|
|
|
int FileSelector(unsigned char *buffer, bool useFAT)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
|
|
|
short p;
|
2010-05-06 14:59:43 +02:00
|
|
|
int ret;
|
2009-05-25 19:07:34 +02:00
|
|
|
int size = 0;
|
|
|
|
int go_up = 0;
|
2009-05-01 14:56:48 +02:00
|
|
|
int old = -1;
|
2009-04-20 00:31:08 +02:00
|
|
|
char fname[MAXPATHLEN];
|
2010-05-06 14:59:43 +02:00
|
|
|
char text[MAXPATHLEN];
|
2009-04-20 00:31:08 +02:00
|
|
|
FILE *xml,*snap;
|
|
|
|
|
2009-04-21 17:20:15 +02:00
|
|
|
#ifdef HW_RVL
|
2010-05-06 14:59:43 +02:00
|
|
|
int x,y,i,yoffset;
|
2009-04-21 17:20:15 +02:00
|
|
|
gui_butn *button;
|
|
|
|
#endif
|
|
|
|
|
2010-03-22 15:07:25 +01:00
|
|
|
/* Background Settings */
|
2010-04-15 14:01:14 +02:00
|
|
|
if (config.bg_color == 0)
|
2010-03-22 15:07:25 +01:00
|
|
|
bg_filesel[0].data = Bg_main_2_png;
|
|
|
|
else
|
|
|
|
bg_filesel[0].data = Bg_main_png;
|
|
|
|
if (config.bg_overlay)
|
|
|
|
bg_filesel[1].state |= IMAGE_VISIBLE;
|
|
|
|
else
|
|
|
|
bg_filesel[1].state &= ~IMAGE_VISIBLE;
|
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
/* Initialize Menu */
|
|
|
|
gui_menu *m = &menu_browser;
|
|
|
|
GUI_InitMenu(m);
|
2010-05-06 14:59:43 +02:00
|
|
|
string_offset = 0;
|
2009-04-20 00:31:08 +02:00
|
|
|
|
2009-05-19 18:14:43 +02:00
|
|
|
while (1)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-05-14 14:32:20 +02:00
|
|
|
/* ROM file snapshot/database */
|
|
|
|
if (old != selection)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-05-14 14:32:20 +02:00
|
|
|
old = selection;
|
2009-05-25 19:07:34 +02:00
|
|
|
string_offset = 0;
|
|
|
|
|
2009-05-14 14:32:20 +02:00
|
|
|
/* delete previous texture if any */
|
|
|
|
gxTextureClose(&bg_filesel[8].texture);
|
|
|
|
bg_filesel[8].state &= ~IMAGE_VISIBLE;
|
|
|
|
bg_filesel[6].state &= ~IMAGE_VISIBLE;
|
2009-05-01 14:56:48 +02:00
|
|
|
|
2009-05-14 14:32:20 +02:00
|
|
|
if (!filelist[selection].flags)
|
2009-05-01 14:56:48 +02:00
|
|
|
{
|
2009-05-14 14:32:20 +02:00
|
|
|
/* get ROM filename without extension */
|
|
|
|
sprintf (text, "%s", filelist[selection].filename);
|
2010-05-06 14:59:43 +02:00
|
|
|
if (strlen(text) >= 4)
|
|
|
|
text[strlen(text) - 4] = 0;
|
2009-05-06 12:03:33 +02:00
|
|
|
|
2009-05-14 14:32:20 +02:00
|
|
|
/* ROM database informations */
|
|
|
|
sprintf (fname, "%s/db/%s.xml", DEFAULT_PATH, text);
|
|
|
|
xml = fopen(fname, "rb");
|
|
|
|
if (xml)
|
|
|
|
{
|
|
|
|
bg_filesel[6].state |= IMAGE_VISIBLE;
|
|
|
|
fclose(xml); /* TODO */
|
|
|
|
}
|
2009-05-06 12:03:33 +02:00
|
|
|
|
|
|
|
/* open screenshot file */
|
|
|
|
sprintf (fname, "%s/snaps/%s.png", DEFAULT_PATH, text);
|
|
|
|
snap = fopen(fname, "rb");
|
|
|
|
if (snap)
|
|
|
|
{
|
|
|
|
bg_filesel[8].texture = gxTextureOpenPNG(0,snap);
|
2010-05-06 14:59:43 +02:00
|
|
|
if (bg_filesel[8].texture)
|
|
|
|
bg_filesel[8].state |= IMAGE_VISIBLE;
|
2009-05-14 14:32:20 +02:00
|
|
|
fclose(snap);
|
2009-05-06 12:03:33 +02:00
|
|
|
}
|
2009-05-01 14:56:48 +02:00
|
|
|
}
|
2009-05-06 16:47:22 +02:00
|
|
|
}
|
2009-04-15 17:33:51 +02:00
|
|
|
|
2009-05-25 19:07:34 +02:00
|
|
|
/* update helper */
|
2009-05-20 17:11:06 +02:00
|
|
|
if (m->selected != -1)
|
2009-05-25 19:07:34 +02:00
|
|
|
{
|
|
|
|
/* out of focus */
|
2009-05-20 17:11:06 +02:00
|
|
|
strcpy(action_select.comment,"");
|
2009-05-25 19:07:34 +02:00
|
|
|
}
|
|
|
|
else if (!filelist[selection].flags)
|
|
|
|
{
|
|
|
|
/* this is a file */
|
|
|
|
strcpy(action_select.comment,"Load ROM File");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* this is a directory */
|
|
|
|
if (!strcmp(filelist[selection].filename,".."))
|
|
|
|
strcpy(action_select.comment,"Previous Directory");
|
|
|
|
else
|
|
|
|
strcpy(action_select.comment,"Open Directory");
|
|
|
|
}
|
2009-05-20 17:11:06 +02:00
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
/* Draw menu*/
|
|
|
|
GUI_DrawMenu(m);
|
2009-04-16 14:19:12 +02:00
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
if (Shutdown)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
gxTextureClose(&w_pointer);
|
|
|
|
GUI_DeleteMenu(m);
|
2009-05-04 23:43:16 +02:00
|
|
|
GUI_FadeOut();
|
2009-04-20 00:31:08 +02:00
|
|
|
shutdown();
|
|
|
|
SYS_ResetSystem(SYS_POWEROFF, 0, 0);
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
2009-04-20 00:31:08 +02:00
|
|
|
else if (m_input.ir.valid)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
/* get cursor position */
|
|
|
|
x = m_input.ir.x;
|
|
|
|
y = m_input.ir.y;
|
|
|
|
|
|
|
|
/* draw wiimote pointer */
|
2009-05-23 19:29:53 +02:00
|
|
|
gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255);
|
2009-04-20 00:31:08 +02:00
|
|
|
|
|
|
|
/* find selected item */
|
2009-05-23 19:29:53 +02:00
|
|
|
yoffset = PAGEOFFSET - 4;
|
2009-04-20 00:31:08 +02:00
|
|
|
m->selected = m->max_buttons + 2;
|
|
|
|
for (i = offset; i < (offset + PAGESIZE) && (i < maxfiles); i++)
|
|
|
|
{
|
2009-05-26 15:14:33 +02:00
|
|
|
if ((x<=380)&&(y>=yoffset)&&(y<(yoffset+24)))
|
2009-04-20 00:31:08 +02:00
|
|
|
{
|
|
|
|
selection = i;
|
|
|
|
m->selected = -1;
|
|
|
|
break;
|
|
|
|
}
|
2009-05-26 15:14:33 +02:00
|
|
|
yoffset += 24;
|
2009-04-20 00:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find selected button */
|
|
|
|
for (i=0; i<2; i++)
|
2009-04-21 03:05:56 +02:00
|
|
|
{
|
2009-05-01 14:56:48 +02:00
|
|
|
button = m->arrows[i];
|
|
|
|
if (button)
|
2009-04-20 00:31:08 +02:00
|
|
|
{
|
2009-05-01 14:56:48 +02:00
|
|
|
if (button->state & BUTTON_VISIBLE)
|
2009-04-21 03:05:56 +02:00
|
|
|
{
|
2009-05-01 14:56:48 +02:00
|
|
|
if ((x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
|
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
m->selected = m->max_buttons + i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-20 00:31:08 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* reset indicator */
|
|
|
|
m->selected = -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* copy EFB to XFB */
|
2009-05-19 18:14:43 +02:00
|
|
|
gxSetScreen();
|
2009-04-20 00:31:08 +02:00
|
|
|
|
|
|
|
p = m_input.keys;
|
2009-04-15 17:33:51 +02:00
|
|
|
|
|
|
|
/* highlight next item */
|
2009-04-20 00:31:08 +02:00
|
|
|
if (p & PAD_BUTTON_DOWN)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
|
|
|
selection++;
|
2010-05-06 14:59:43 +02:00
|
|
|
if (selection == maxfiles)
|
|
|
|
selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE)
|
|
|
|
offset += PAGESIZE;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* highlight previous item */
|
|
|
|
else if (p & PAD_BUTTON_UP)
|
|
|
|
{
|
|
|
|
selection--;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
2010-05-06 14:59:43 +02:00
|
|
|
if (selection < offset)
|
|
|
|
offset -= PAGESIZE;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* go back one page */
|
|
|
|
else if (p & PAD_TRIGGER_L)
|
|
|
|
{
|
|
|
|
selection -= PAGESIZE;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
2010-05-06 14:59:43 +02:00
|
|
|
if (selection < offset)
|
|
|
|
offset -= PAGESIZE;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* go forward one page */
|
|
|
|
else if (p & PAD_TRIGGER_R)
|
|
|
|
{
|
|
|
|
selection += PAGESIZE;
|
2010-05-06 14:59:43 +02:00
|
|
|
if (selection > maxfiles - 1)
|
|
|
|
selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE)
|
|
|
|
offset += PAGESIZE;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* quit */
|
2009-04-20 00:31:08 +02:00
|
|
|
else if (p & PAD_TRIGGER_Z)
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-05-19 18:14:43 +02:00
|
|
|
GUI_DeleteMenu(m);
|
|
|
|
return 0;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* open selected file or directory */
|
2009-04-20 00:31:08 +02:00
|
|
|
else if ((p & PAD_BUTTON_A) || (p & PAD_BUTTON_B))
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-05-25 19:07:34 +02:00
|
|
|
string_offset = 0;
|
2009-04-15 17:33:51 +02:00
|
|
|
go_up = 0;
|
2009-04-20 00:31:08 +02:00
|
|
|
|
2009-04-15 17:33:51 +02:00
|
|
|
if (p & PAD_BUTTON_B)
|
|
|
|
{
|
|
|
|
/* go up one directory or quit */
|
|
|
|
go_up = 1;
|
2009-05-06 16:47:22 +02:00
|
|
|
selection = 0;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
2009-04-20 00:31:08 +02:00
|
|
|
#ifdef HW_RVL
|
|
|
|
else
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
/* arrow buttons selected */
|
|
|
|
if (m->selected == m->max_buttons) /* up arrow */
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
selection--;
|
|
|
|
if (selection < 0)
|
|
|
|
{
|
|
|
|
selection = maxfiles - 1;
|
|
|
|
offset = selection - PAGESIZE + 1;
|
|
|
|
}
|
2010-05-06 14:59:43 +02:00
|
|
|
if (selection < offset)
|
|
|
|
offset -= PAGESIZE;
|
|
|
|
if (offset < 0)
|
|
|
|
offset = 0;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
2009-04-20 00:31:08 +02:00
|
|
|
else if (m->selected == (m->max_buttons+1)) /* down arrow */
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
selection++;
|
2010-05-06 14:59:43 +02:00
|
|
|
if (selection == maxfiles)
|
|
|
|
selection = offset = 0;
|
|
|
|
if ((selection - offset) >= PAGESIZE)
|
|
|
|
offset += PAGESIZE;
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
}
|
2009-04-20 00:31:08 +02:00
|
|
|
#endif
|
2009-04-21 03:05:56 +02:00
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
/* ensure we are in focus area */
|
2009-04-21 03:05:56 +02:00
|
|
|
if (go_up || (m->selected < m->max_buttons))
|
2009-04-15 17:33:51 +02:00
|
|
|
{
|
2009-04-20 00:31:08 +02:00
|
|
|
/*** This is directory ***/
|
|
|
|
if (filelist[selection].flags)
|
|
|
|
{
|
2009-05-25 19:07:34 +02:00
|
|
|
/* force going up */
|
|
|
|
go_up = (selection == 0);
|
|
|
|
|
2009-04-20 00:31:08 +02:00
|
|
|
/* get new directory */
|
2009-05-25 19:07:34 +02:00
|
|
|
if (useFAT)
|
2009-05-26 15:14:33 +02:00
|
|
|
ret = FAT_UpdateDirectory(go_up,filelist[selection].filename);
|
2009-05-25 19:07:34 +02:00
|
|
|
else
|
2009-05-26 15:14:33 +02:00
|
|
|
ret = DVD_UpdateDirectory(go_up,filelist[selection].offset,filelist[selection].length);
|
2009-04-20 00:31:08 +02:00
|
|
|
|
|
|
|
/* get new entry list or quit */
|
|
|
|
if (ret)
|
|
|
|
{
|
2009-05-25 19:07:34 +02:00
|
|
|
/* reinit selector (previous value is saved for one level) */
|
|
|
|
if (selection == 0)
|
|
|
|
{
|
|
|
|
selection = old_selection;
|
|
|
|
offset = old_offset;
|
|
|
|
old_selection = 0;
|
|
|
|
old_offset = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* save current selector value */
|
|
|
|
old_selection = selection;
|
|
|
|
old_offset = offset;
|
|
|
|
selection = 0;
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get directory entries */
|
|
|
|
if (useFAT)
|
|
|
|
maxfiles = FAT_ParseDirectory();
|
|
|
|
else
|
|
|
|
maxfiles = DVD_ParseDirectory();
|
2009-04-20 00:31:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-19 18:14:43 +02:00
|
|
|
GUI_DeleteMenu(m);
|
|
|
|
return 0;
|
2009-04-20 00:31:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*** This is a file ***/
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* root directory ? */
|
2009-05-19 18:14:43 +02:00
|
|
|
if (go_up)
|
|
|
|
{
|
|
|
|
GUI_DeleteMenu(m);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-07 20:25:27 +02:00
|
|
|
/* Load ROM file from device */
|
|
|
|
if (useFAT)
|
|
|
|
size = FAT_LoadFile(buffer,selection);
|
|
|
|
else
|
|
|
|
size = DVD_LoadFile(buffer,selection);
|
|
|
|
|
|
|
|
/* Reload emulation */
|
|
|
|
if (size)
|
2009-05-20 17:11:06 +02:00
|
|
|
{
|
2010-05-07 20:25:27 +02:00
|
|
|
if (config.s_auto & 2)
|
|
|
|
slot_autosave(config.s_default,config.s_device);
|
|
|
|
reloadrom(size,filelist[selection].filename);
|
|
|
|
if (config.s_auto & 1)
|
|
|
|
slot_autoload(0,config.s_device);
|
|
|
|
if (config.s_auto & 2)
|
|
|
|
slot_autoload(config.s_default,config.s_device);
|
2009-05-20 17:11:06 +02:00
|
|
|
}
|
2009-05-25 19:07:34 +02:00
|
|
|
|
2010-05-07 20:25:27 +02:00
|
|
|
/* Exit */
|
2009-05-20 17:11:06 +02:00
|
|
|
GUI_MsgBoxClose();
|
2010-05-07 20:25:27 +02:00
|
|
|
GUI_DeleteMenu(m);
|
|
|
|
return size;
|
2009-05-19 18:14:43 +02:00
|
|
|
}
|
2009-04-20 00:31:08 +02:00
|
|
|
}
|
2009-04-15 17:33:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-05-25 19:07:34 +02:00
|
|
|
|
2009-05-26 15:14:33 +02:00
|
|
|
void ClearSelector(u32 max)
|
2009-05-25 19:07:34 +02:00
|
|
|
{
|
|
|
|
maxfiles = max;
|
|
|
|
offset = 0;
|
|
|
|
selection = 0;
|
|
|
|
old_offset = 0;
|
|
|
|
old_selection = 0;
|
|
|
|
}
|