comparison Plugins/Input/console/Audacious_Driver.cpp @ 366:4a9139a7b53e trunk

[svn] Use file magic instead of extensions (Phase 2).
author chainsaw
date Sat, 31 Dec 2005 14:17:51 -0800
parents 98831d210c57
children e296500f595a
comparison
equal deleted inserted replaced
365:98831d210c57 366:4a9139a7b53e
14 #include <glib/gi18n.h> 14 #include <glib/gi18n.h>
15 #include <gtk/gtk.h> 15 #include <gtk/gtk.h>
16 #include "libaudacious/configdb.h" 16 #include "libaudacious/configdb.h"
17 #include "libaudacious/util.h" 17 #include "libaudacious/util.h"
18 #include "libaudacious/titlestring.h" 18 #include "libaudacious/titlestring.h"
19 #include "libaudacious/vfs.h"
19 #include "audacious/input.h" 20 #include "audacious/input.h"
20 #include "audacious/output.h" 21 #include "audacious/output.h"
21 #include "libaudcore/playback.h" 22 #include "libaudcore/playback.h"
22 23
23 }; 24 };
55 extern InputPlugin console_ip; 56 extern InputPlugin console_ip;
56 static int playing_type; 57 static int playing_type;
57 58
58 static int is_our_file(gchar *filename) 59 static int is_our_file(gchar *filename)
59 { 60 {
60 gchar *ext; 61 VFSFile *file;
61 62 gchar magic[4];
62 ext = strrchr(filename, '.'); 63 if (file = vfs_fopen(filename, "rb")) {
63 64 vfs_fread(magic, 1, 4, file);
64 if (ext) 65 if (!strncmp(magic, "SNES", 4)) {
65 { 66 vfs_fclose(file);
66 if (!strcasecmp(ext, ".spc"))
67 return PLAY_TYPE_SPC; 67 return PLAY_TYPE_SPC;
68 if (!strcasecmp(ext, ".nsf")) 68 }
69 if (!strncmp(magic, "NESM", 4)) {
70 vfs_fclose(file);
69 return PLAY_TYPE_NSF; 71 return PLAY_TYPE_NSF;
70 if (!strcasecmp(ext, ".gbs")) 72 }
73 if (!strncmp(magic, "GYMX", 4)) {
74 vfs_fclose(file);
75 return PLAY_TYPE_GYM;
76 }
77 vfs_fclose(file);
78 }
79 if (file = vfs_fopen(filename, "rb")) {
80 vfs_fread(magic, 1, 3, file);
81 if (!strncmp(magic, "GBS", 3)) {
82 vfs_fclose(file);
71 return PLAY_TYPE_GBS; 83 return PLAY_TYPE_GBS;
72 if (!strcasecmp(ext, ".gym")) 84 }
73 return PLAY_TYPE_GYM; 85 if (!strncmp(magic, "Vgm", 3)) {
74 if (!strcasecmp(ext, ".vgm")) 86 vfs_fclose(file);
75 return PLAY_TYPE_VGM; 87 return PLAY_TYPE_VGM;
76 } 88 }
77 89 vfs_fclose(file);
90 }
78 return 0; 91 return 0;
79 } 92 }
80 93
81 static gchar *get_title_spc(gchar *filename) 94 static gchar *get_title_spc(gchar *filename)
82 { 95 {