aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotaz2013-01-06 00:28:01 +0200
committernotaz2013-01-06 00:28:01 +0200
commit1f84e117ae9b49f6ed72c7243fd514dd1a9e581b (patch)
tree3711d2031f58152135a5fe472f7ff6037f9a545a
parente3d0c51433f54bd9a85c88c7612582e50b6d0b1d (diff)
downloadpcsx_rearmed-1f84e117ae9b49f6ed72c7243fd514dd1a9e581b.tar.gz
pcsx_rearmed-1f84e117ae9b49f6ed72c7243fd514dd1a9e581b.tar.bz2
pcsx_rearmed-1f84e117ae9b49f6ed72c7243fd514dd1a9e581b.zip
frontend: filter more unneeded files in browser
-rw-r--r--Makefile1
m---------frontend/libpicofe0
-rw-r--r--frontend/menu.c165
3 files changed, 143 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index 0d72dea..0ef7364 100644
--- a/Makefile
+++ b/Makefile
@@ -154,6 +154,7 @@ OBJS += frontend/libpicofe/linux/fbdev.o frontend/libpicofe/linux/xenv.o
OBJS += frontend/libpicofe/linux/in_evdev.o
OBJS += frontend/plat_pandora.o frontend/plat_omap.o
frontend/main.o frontend/menu.o: CFLAGS += -include frontend/pandora/ui_feat.h
+frontend/menu.o: CFLAGS += -D_FILE_OFFSET_BITS=64
USE_PLUGIN_LIB = 1
USE_FRONTEND = 1
endif
diff --git a/frontend/libpicofe b/frontend/libpicofe
-Subproject 0d645bc539fdc073f20c4dea9f4a4e218cebec0
+Subproject 8a0998fb31e440f7f7566510128049142bc3ad7
diff --git a/frontend/menu.c b/frontend/menu.c
index 7bec49a..8e182bf 100644
--- a/frontend/menu.c
+++ b/frontend/menu.c
@@ -1,5 +1,5 @@
/*
- * (C) Gražvydas "notaz" Ignotas, 2010-2011
+ * (C) Gražvydas "notaz" Ignotas, 2010-2013
*
* This work is licensed under the terms of any of these licenses
* (at your option):
@@ -8,6 +8,7 @@
* See the COPYING file in the top-level directory.
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -16,6 +17,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <dirent.h>
#include "main.h"
#include "menu.h"
@@ -84,7 +86,6 @@ typedef enum
static int last_vout_w, last_vout_h, last_vout_bpp;
static int cpu_clock, cpu_clock_st, volume_boost, frameskip;
-static char rom_fname_reload[MAXPATHLEN];
static char last_selected_fname[MAXPATHLEN];
static int config_save_counter, region, in_type_sel1, in_type_sel2;
static int psx_clock;
@@ -187,6 +188,107 @@ static int emu_save_load_game(int load, int unused)
return ret;
}
+static void rm_namelist_entry(struct dirent **namelist,
+ int count, const char *name)
+{
+ int i;
+
+ for (i = 1; i < count; i++) {
+ if (namelist[i] == NULL || namelist[i]->d_type == DT_DIR)
+ continue;
+
+ if (strcmp(name, namelist[i]->d_name) == 0) {
+ free(namelist[i]);
+ namelist[i] = NULL;
+ break;
+ }
+ }
+}
+
+static int optional_cdimg_filter(struct dirent **namelist, int count,
+ const char *basedir)
+{
+ const char *ext, *p;
+ char buf[256], buf2[256];
+ int i, d, ret, good_cue;
+ struct stat statf;
+ FILE *f;
+
+ for (i = 1; i < count; i++) {
+ if (namelist[i] == NULL || namelist[i]->d_type == DT_DIR)
+ continue;
+
+ ext = strrchr(namelist[i]->d_name, '.');
+ if (ext == NULL) {
+ // should not happen but whatever
+ free(namelist[i]);
+ namelist[i] = NULL;
+ continue;
+ }
+ ext++;
+
+ // first find .cue files and remove files they reference
+ if (strcasecmp(ext, "cue") == 0)
+ {
+ snprintf(buf, sizeof(buf), "%s/%s", basedir,
+ namelist[i]->d_name);
+
+ f = fopen(buf, "r");
+ if (f == NULL) {
+ free(namelist[i]);
+ namelist[i] = NULL;
+ continue;
+ }
+
+ good_cue = 0;
+ while (fgets(buf, sizeof(buf), f)) {
+ ret = sscanf(buf, " FILE \"%256[^\"]\"", buf2);
+ if (ret != 1)
+ ret = sscanf(buf, " FILE %256s", buf2);
+ if (ret != 1)
+ continue;
+
+ p = strrchr(buf2, '/');
+ if (p == NULL)
+ p = strrchr(buf2, '\\');
+ if (p == NULL)
+ p = buf2;
+
+ snprintf(buf, sizeof(buf), "%s/%s", basedir, p);
+ ret = stat(buf, &statf);
+ if (ret == 0) {
+ rm_namelist_entry(namelist, count, p);
+ good_cue = 1;
+ }
+ }
+ fclose(f);
+
+ if (!good_cue) {
+ free(namelist[i]);
+ namelist[i] = NULL;
+ }
+ continue;
+ }
+
+ p = strcasestr(namelist[i]->d_name, "track");
+ if (p != NULL) {
+ ret = strtoul(p + 5, NULL, 10);
+ if (ret > 1) {
+ free(namelist[i]);
+ namelist[i] = NULL;
+ continue;
+ }
+ }
+ }
+
+ // compact namelist
+ for (i = d = 1; i < count; i++)
+ if (namelist[i] != NULL)
+ namelist[d++] = namelist[i];
+
+ return d;
+}
+
// propagate menu settings to the emu vars
static void menu_sync_config(void)
{
@@ -406,14 +508,18 @@ static int menu_write_config(int is_game)
static int menu_do_last_cd_img(int is_get)
{
+ static const char *defaults[] = { "/media", "/mnt/sd", "/mnt" };
char path[256];
+ struct stat st;
FILE *f;
- int ret;
+ int i, ret = -1;
snprintf(path, sizeof(path), "." PCSX_DOT_DIR "lastcdimg.txt");
f = fopen(path, is_get ? "r" : "w");
- if (f == NULL)
- return -1;
+ if (f == NULL) {
+ ret = -1;
+ goto out;
+ }
if (is_get) {
ret = fread(last_selected_fname, 1, sizeof(last_selected_fname) - 1, f);
@@ -424,6 +530,17 @@ static int menu_do_last_cd_img(int is_get)
fprintf(f, "%s\n", last_selected_fname);
fclose(f);
+out:
+ if (is_get) {
+ for (i = 0; last_selected_fname[0] == 0
+ || stat(last_selected_fname, &st) != 0; i++)
+ {
+ if (i >= ARRAY_SIZE(defaults))
+ break;
+ strcpy(last_selected_fname, defaults[i]);
+ }
+ }
+
return 0;
}
@@ -547,20 +664,25 @@ fail:
return ret;
}
+static const char *filter_exts[] = {
+ "bin", "img", "mdf", "iso", "cue", "z",
+ "bz", "znx", "pbp", "cbn"
+};
+
// rrrr rggg gggb bbbb
static unsigned short fname2color(const char *fname)
{
- static const char *cdimg_exts[] = { ".bin", ".img", ".mdf", ".iso", ".cue", ".z",
- ".bz", ".znx", ".pbp", ".cbn" };
- static const char *other_exts[] = { ".ccd", ".toc", ".mds", ".sub",
- ".table", ".index", ".sbi" };
+ static const char *other_exts[] = {
+ "ccd", "toc", "mds", "sub", "table", "index", "sbi"
+ };
const char *ext = strrchr(fname, '.');
int i;
if (ext == NULL)
return 0xffff;
- for (i = 0; i < array_size(cdimg_exts); i++)
- if (strcasecmp(ext, cdimg_exts[i]) == 0)
+ ext++;
+ for (i = 0; i < array_size(filter_exts); i++)
+ if (strcasecmp(ext, filter_exts[i]) == 0)
return 0x7bff;
for (i = 0; i < array_size(other_exts); i++)
if (strcasecmp(ext, other_exts[i]) == 0)
@@ -570,10 +692,6 @@ static unsigned short fname2color(const char *fname)
static void draw_savestate_bg(int slot);
-static const char *filter_exts[] = {
- ".mp3", ".MP3", ".txt", ".htm", "html", ".jpg", ".pnd"
-};
-
#define MENU_ALIGN_LEFT
#ifdef __ARM_ARCH_7A__ // assume hires device
#define MENU_X2 1
@@ -1820,7 +1938,8 @@ static int run_exe(void)
{
const char *fname;
- fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
+ fname = menu_loop_romsel(last_selected_fname,
+ sizeof(last_selected_fname), NULL);
if (fname == NULL)
return -1;
@@ -1874,7 +1993,8 @@ static int romsel_run(void)
int prev_gpu, prev_spu;
const char *fname;
- fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
+ fname = menu_loop_romsel(last_selected_fname,
+ sizeof(last_selected_fname), optional_cdimg_filter);
if (fname == NULL)
return -1;
@@ -1898,7 +2018,7 @@ static int romsel_run(void)
return -1;
}
- strcpy(last_selected_fname, rom_fname_reload);
+ strcpy(last_selected_fname, fname);
menu_do_last_cd_img(0);
return 0;
}
@@ -1907,7 +2027,8 @@ static int swap_cd_image(void)
{
char *fname;
- fname = menu_loop_romsel(last_selected_fname, sizeof(last_selected_fname));
+ fname = menu_loop_romsel(last_selected_fname,
+ sizeof(last_selected_fname), optional_cdimg_filter);
if (fname == NULL)
return -1;
@@ -1929,7 +2050,7 @@ static int swap_cd_image(void)
SetCdOpenCaseTime(time(NULL) + 2);
LidInterrupt();
- strcpy(last_selected_fname, rom_fname_reload);
+ strcpy(last_selected_fname, fname);
return 0;
}
@@ -1957,7 +2078,7 @@ static void load_pcsx_cht(void)
char *fname;
path[0] = 0;
- fname = menu_loop_romsel(path, sizeof(path));
+ fname = menu_loop_romsel(path, sizeof(path), NULL);
if (fname == NULL)
return;
@@ -2278,8 +2399,6 @@ void menu_init(void)
char buff[MAXPATHLEN];
int i;
- strcpy(last_selected_fname, "/media");
-
cpu_clock_st = cpu_clock = plat_target_cpu_clock_get();
scan_bios_plugins();