diff --git a/src/drivers/Qt/CheatsConf.cpp b/src/drivers/Qt/CheatsConf.cpp index 339d18d0..8160cb73 100644 --- a/src/drivers/Qt/CheatsConf.cpp +++ b/src/drivers/Qt/CheatsConf.cpp @@ -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 ); } diff --git a/src/drivers/Qt/ConsoleUtilities.cpp b/src/drivers/Qt/ConsoleUtilities.cpp index 50da5de5..fcb9a23c 100644 --- a/src/drivers/Qt/ConsoleUtilities.cpp +++ b/src/drivers/Qt/ConsoleUtilities.cpp @@ -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; } //--------------------------------------------------------------------------- diff --git a/src/drivers/Qt/ConsoleUtilities.h b/src/drivers/Qt/ConsoleUtilities.h index 46496fc1..e55e0361 100644 --- a/src/drivers/Qt/ConsoleUtilities.h +++ b/src/drivers/Qt/ConsoleUtilities.h @@ -3,3 +3,5 @@ int getDirFromFile( const char *path, char *dir ); const char *getRomFile( void ); + +int getFileBaseName( const char *filepath, char *base );