Add get_realname() to streamfile, so that we can get the plain name of the file even if the file names handled by the streamfile are encoded somehow. Needed for nwa.

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@306 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2008-07-11 08:29:04 +00:00
parent 804c36b01e
commit b058236064
4 changed files with 30 additions and 7 deletions

View File

@ -45,20 +45,25 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) {
{
char ininame[260];
char * ini_lastslash;
char namebase_array[260];
char *namebase;
STREAMFILE *inistreamfile;
/* here we assume that the "special encoding" does not affect
* the directory separator */
strncpy(ininame,filename,sizeof(ininame));
ininame[sizeof(ininame)-1]='\0'; /* a pox on the stdlib! */
streamFile->get_realname(streamFile,namebase_array,sizeof(namebase_array));
ini_lastslash = strrchr(ininame,DIRSEP);
if (!ini_lastslash) {
strncpy(ininame,"NWAINFO.INI",sizeof(ininame));
namebase = filename;
namebase = namebase_array;
} else {
strncpy(ini_lastslash+1,"NWAINFO.INI",
sizeof(ininame)-(ini_lastslash+1-ininame));
namebase = ini_lastslash+1-ininame+filename;
namebase = strrchr(namebase_array,DIRSEP)+1;
}
ininame[sizeof(ininame)-1]='\0'; /* curse you, strncpy! */
@ -117,20 +122,23 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) {
{
char ininame[260];
char * ini_lastslash;
char namebase_array[260];
char * namebase;
STREAMFILE *inistreamfile;
strncpy(ininame,filename,sizeof(ininame));
ininame[sizeof(ininame)-1]='\0'; /* a pox on the stdlib! */
streamFile->get_realname(streamFile,namebase_array,sizeof(namebase_array));
ini_lastslash = strrchr(ininame,DIRSEP);
if (!ini_lastslash) {
strncpy(ininame,"Gameexe.ini",sizeof(ininame));
namebase = filename;
namebase = namebase_array;
} else {
strncpy(ini_lastslash+1,"Gameexe.ini",
sizeof(ininame)-(ini_lastslash+1-ininame));
namebase = ini_lastslash+1-ininame+filename;
namebase = strrchr(namebase_array,DIRSEP)+1;
}
ininame[sizeof(ininame)-1]='\0'; /* curse you, strncpy! */
@ -183,8 +191,6 @@ VGMSTREAM * init_vgmstream_nwa(STREAMFILE *streamFile) {
char loopstring[9]={0};
int start_ok = 0, end_ok = 0;
printf("found!\n");
if (read_streamfile((uint8_t*)loopstring,found_off,8,
inistreamfile)==8 &&
memcmp("99999999",loopstring,8))

View File

@ -171,6 +171,7 @@ static STREAMFILE * open_stdio_streamfile_buffer_by_FILE(FILE *infile,const char
streamfile->sf.get_size = (void*)get_size_stdio;
streamfile->sf.get_offset = (void*)get_offset_stdio;
streamfile->sf.get_name = (void*)get_name_stdio;
streamfile->sf.get_realname = (void*)get_name_stdio;
streamfile->sf.open = (void*)open_stdio;
streamfile->sf.close = (void*)close_stdio;
#ifdef PROFILE_STREAMFILE

View File

@ -36,6 +36,9 @@ typedef struct _STREAMFILE {
off_t (*get_offset)(struct _STREAMFILE *);
// for dual-file support
void (*get_name)(struct _STREAMFILE *,char *name,size_t length);
// for when the "name" is encoded specially, this is the actual user
// visible name
void (*get_realname)(struct _STREAMFILE *,char *name,size_t length);
struct _STREAMFILE * (*open)(struct _STREAMFILE *,const char * const filename,size_t buffersize);
void (*close)(struct _STREAMFILE *);

View File

@ -4,6 +4,7 @@
#include <audacious/output.h>
#include <audacious/i18n.h>
#include <audacious/strings.h>
#include <glib.h>
#include <unistd.h>
#include <pthread.h>
@ -25,6 +26,7 @@ typedef struct _VFSSTREAMFILE
VFSFile *vfsFile;
off_t offset;
char name[260];
char realname[260];
} VFSSTREAMFILE;
static size_t read_vfs(VFSSTREAMFILE *streamfile,uint8_t *dest,off_t offset,size_t length)
@ -67,6 +69,11 @@ static void get_name_vfs(VFSSTREAMFILE *streamfile,char *buffer,size_t length)
strcpy(buffer,streamfile->name);
}
static void get_realname_vfs(VFSSTREAMFILE *streamfile,char *buffer,size_t length)
{
strcpy(buffer,streamfile->realname);
}
static STREAMFILE *open_vfs_by_VFSFILE(VFSFile *file,const char *path);
static STREAMFILE *open_vfs_impl(VFSSTREAMFILE *streamfile,const char * const filename,size_t buffersize)
@ -107,12 +114,18 @@ static STREAMFILE *open_vfs_by_VFSFILE(VFSFile *file,const char *path)
streamfile->sf.get_size = (void*)get_size_vfs;
streamfile->sf.get_offset = (void*)get_offset_vfs;
streamfile->sf.get_name = (void*)get_name_vfs;
streamfile->sf.get_realname = (void*)get_realname_vfs;
streamfile->sf.open = (void*)open_vfs_impl;
streamfile->sf.close = (void*)close_vfs;
streamfile->vfsFile = file;
streamfile->offset = 0;
strcpy(streamfile->name,path);
{
gchar* realname = g_filename_from_uri(path,NULL,NULL);
strcpy(streamfile->realname,realname);
g_free(realname);
}
return &streamfile->sf;
}