# HG changeset patch # User chainsaw # Date 1136067471 28800 # Node ID 4a9139a7b53e22d8be0d57652d78c49020aaa36b # Parent 98831d210c57f59925188baec3c8ac9f86978d68 [svn] Use file magic instead of extensions (Phase 2). diff -r 98831d210c57 -r 4a9139a7b53e Plugins/Input/console/Audacious_Driver.cpp --- a/Plugins/Input/console/Audacious_Driver.cpp Sat Dec 31 13:36:01 2005 -0800 +++ b/Plugins/Input/console/Audacious_Driver.cpp Sat Dec 31 14:17:51 2005 -0800 @@ -16,6 +16,7 @@ #include "libaudacious/configdb.h" #include "libaudacious/util.h" #include "libaudacious/titlestring.h" +#include "libaudacious/vfs.h" #include "audacious/input.h" #include "audacious/output.h" #include "libaudcore/playback.h" @@ -57,24 +58,36 @@ static int is_our_file(gchar *filename) { - gchar *ext; - - ext = strrchr(filename, '.'); - - if (ext) - { - if (!strcasecmp(ext, ".spc")) + VFSFile *file; + gchar magic[4]; + if (file = vfs_fopen(filename, "rb")) { + vfs_fread(magic, 1, 4, file); + if (!strncmp(magic, "SNES", 4)) { + vfs_fclose(file); return PLAY_TYPE_SPC; - if (!strcasecmp(ext, ".nsf")) + } + if (!strncmp(magic, "NESM", 4)) { + vfs_fclose(file); return PLAY_TYPE_NSF; - if (!strcasecmp(ext, ".gbs")) + } + if (!strncmp(magic, "GYMX", 4)) { + vfs_fclose(file); + return PLAY_TYPE_GYM; + } + vfs_fclose(file); + } + if (file = vfs_fopen(filename, "rb")) { + vfs_fread(magic, 1, 3, file); + if (!strncmp(magic, "GBS", 3)) { + vfs_fclose(file); return PLAY_TYPE_GBS; - if (!strcasecmp(ext, ".gym")) - return PLAY_TYPE_GYM; - if (!strcasecmp(ext, ".vgm")) + } + if (!strncmp(magic, "Vgm", 3)) { + vfs_fclose(file); return PLAY_TYPE_VGM; + } + vfs_fclose(file); } - return 0; }