Merge pull request #407 from Pan7/fixvfswad

Adjusting vfswad filename extraction
This commit is contained in:
Timothee "TTimo" Besset 2017-02-25 15:24:34 -06:00 committed by GitHub
commit 3248d4adc5

View file

@ -145,13 +145,36 @@ int vfsBuildShortPathName( const char* pPath, char* pBuffer, int nBufferLen ){
#endif #endif
} }
void ExtractFileName( const char *path, char *dest ){
const char *src;
src = path + strlen( path ) - 1;
//
// back up until a \ or the start
//
while ( src != path && *( src - 1 ) != '/'
&& *( src - 1 ) != '\\' )
src--;
while ( *src )
{
*dest++ = *src++;
}
*dest = 0;
}
static void vfsInitPakFile( const char *filename ){ static void vfsInitPakFile( const char *filename ){
wadFile_t *wf; wadFile_t *wf;
unsigned int i; unsigned int i;
int err; int err;
char *wadnameptr;
char wadname[NAME_MAX]; char wadname[NAME_MAX];
char *ext;
if ( !filename || strlen( filename ) <= 0 ) {
g_FuncTable.m_pfnSysFPrintf( SYS_WRN, " missing wad filename\n" );
return;
}
wf = wadOpen( filename ); wf = wadOpen( filename );
if ( wf == NULL ) { if ( wf == NULL ) {
g_FuncTable.m_pfnSysFPrintf( SYS_WRN, " failed to init wad file %s\n", filename ); g_FuncTable.m_pfnSysFPrintf( SYS_WRN, " failed to init wad file %s\n", filename );
@ -159,13 +182,14 @@ static void vfsInitPakFile( const char *filename ){
} }
g_FuncTable.m_pfnSysPrintf( " wad file: %s\n", filename ); g_FuncTable.m_pfnSysPrintf( " wad file: %s\n", filename );
for ( i = strlen( filename ) - 1 ; i >= 0 && filename[i] != '\\' && filename[i] != '/' ; i-- ) ExtractFileName( filename, wadname );
wadnameptr = (char *)filename + i;
strcpy( wadname,wadnameptr );
wadname[strlen( wadname ) - 4] = 0; // ditch the .wad so everthing looks nice!
strlwr( wadname ); strlwr( wadname );
ext = strrchr( wadname, '.' );
if ( ext && strcmp( ext, ".wad" ) == 0 ) {
*ext = 0; // ditch the .wad so everthing looks nice!
}
g_wadFiles = g_slist_append( g_wadFiles, wf ); // store the wadfile handle g_wadFiles = g_slist_append( g_wadFiles, wf ); // store the wadfile handle
wadGoToFirstFile( wf ); wadGoToFirstFile( wf );