Added utility function to strip out a base file name from a full path.
This commit is contained in:
parent
e8f1ffdf8d
commit
08feb4710b
|
@ -743,25 +743,10 @@ void GuiCheatsDialog_t::saveCheatFile(void)
|
|||
|
||||
if ( GameInfo )
|
||||
{
|
||||
char *_filename;
|
||||
if ((_filename = strrchr(GameInfo->filename, '\\')) || (_filename = strrchr(GameInfo->filename, '/')))
|
||||
{
|
||||
strcpy( dir, _filename + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy( dir, GameInfo->filename);
|
||||
}
|
||||
getFileBaseName( GameInfo->filename, dir );
|
||||
|
||||
strcat( dir, ".cht");
|
||||
|
||||
_filename = strrchr( dir, '.');
|
||||
if (_filename)
|
||||
{
|
||||
strcpy(_filename, ".cht");
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat( dir, ".cht");
|
||||
}
|
||||
dialog.selectFile( dir );
|
||||
}
|
||||
|
||||
|
|
|
@ -45,25 +45,41 @@ const char *getRomFile( void )
|
|||
return NULL;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// TODO Finish writing this func
|
||||
// Return file base name stripping out preceding path and trailing suffix.
|
||||
int getFileBaseName( const char *filepath, char *base )
|
||||
{
|
||||
int i,j=0, start=0;
|
||||
int i=0,j=0,end=0;
|
||||
if ( filepath == NULL )
|
||||
{
|
||||
base[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
i=0; j=0;
|
||||
while ( filepath[i] != 0 )
|
||||
{
|
||||
if ( filepath[i] == '/' )
|
||||
if ( (filepath[i] == '/') || (filepath[i] == '\\') )
|
||||
{
|
||||
j = i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
start = j;
|
||||
i = j;
|
||||
|
||||
return 0;
|
||||
j=0;
|
||||
while ( filepath[i] != 0 )
|
||||
{
|
||||
base[j] = filepath[i]; i++; j++;
|
||||
}
|
||||
base[j] = 0; end=j;
|
||||
|
||||
while ( j > 1 )
|
||||
{
|
||||
j--;
|
||||
if ( base[j] == '.' )
|
||||
{
|
||||
end=j; base[j] = 0; break;
|
||||
}
|
||||
}
|
||||
return end;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -3,3 +3,5 @@
|
|||
int getDirFromFile( const char *path, char *dir );
|
||||
|
||||
const char *getRomFile( void );
|
||||
|
||||
int getFileBaseName( const char *filepath, char *base );
|
||||
|
|
Loading…
Reference in New Issue