Modified Qt GUI parseFilepath to output std::string types instead of char * buffers to remove file path length limitations.

This commit is contained in:
harry 2023-01-10 21:14:10 -05:00
parent 4dd8943724
commit e06d1cd506
8 changed files with 128 additions and 122 deletions

View File

@ -51,7 +51,7 @@ static int autoResumeCDL = false;
static bool autoSaveArmedCDL = false;
static char loadedcdfile[512] = {0};
static int getDefaultCDLFile(char *filepath);
static int getDefaultCDLFile(std::string &filepath);
static CodeDataLoggerDialog_t *cdlWin = NULL;
//----------------------------------------------------
@ -280,9 +280,9 @@ CodeDataLoggerDialog_t::CodeDataLoggerDialog_t(QWidget *parent)
if (autoLoadCDL)
{
char nameo[2048];
std::string nameo;
getDefaultCDLFile(nameo);
LoadCDLog(nameo);
LoadCDLog(nameo.c_str());
}
restoreGeometry(settings.value("cdLogger/geometry").toByteArray());
@ -444,15 +444,15 @@ void CodeDataLoggerDialog_t::saveCdlFileAs(void)
if (romFile != NULL)
{
char dir[512], base[256];
std::string dir, base;
parseFilepath(romFile, dir, base);
parseFilepath(romFile, &dir, &base);
strcat(base, ".cdl");
base.append(".cdl");
dialog.setDirectory(tr(dir));
dialog.setDirectory(tr(dir.c_str()));
dialog.selectFile(tr(base));
dialog.selectFile(tr(base.c_str()));
}
// Check config option to use native file dialog or not
@ -587,11 +587,11 @@ void CodeDataLoggerDialog_t::SaveStrippedROM(int invert)
if (romFile != NULL)
{
char dir[512], base[256];
std::string dir;
parseFilepath(romFile, dir, base);
parseFilepath(romFile, &dir);
dialog.setDirectory(tr(dir));
dialog.setDirectory(tr(dir.c_str()));
}
// Check config option to use native file dialog or not
@ -725,12 +725,12 @@ void CodeDataLoggerDialog_t::SaveUnusedROMClicked(void)
SaveStrippedROM(1);
}
//----------------------------------------------------
static int getDefaultCDLFile(char *filepath)
static int getDefaultCDLFile(std::string &filepath)
{
const char *romFile;
char dir[512], baseFile[256];
std::string dir, baseFile;
filepath[0] = 0;
filepath.clear();
romFile = getRomFile();
@ -739,15 +739,18 @@ static int getDefaultCDLFile(char *filepath)
return -1;
}
parseFilepath(romFile, dir, baseFile);
parseFilepath(romFile, &dir, &baseFile);
if (dir[0] == 0)
if (dir.size() == 0)
{
sprintf(filepath, "%s.cdl", baseFile);
filepath.assign(baseFile);
filepath.append(".cdl");
}
else
{
sprintf(filepath, "%s/%s.cdl", dir, baseFile);
filepath.assign(dir);
filepath.append(baseFile);
filepath.append(".cdl");
}
//printf("%s\n", filepath );
@ -938,11 +941,11 @@ void CDLoggerROMChanged(void)
return;
// try to load respective CDL file
char nameo[1024];
std::string nameo;
getDefaultCDLFile(nameo);
FILE *FP;
FP = fopen(nameo, "rb");
FP = fopen(nameo.c_str(), "rb");
if (FP != NULL)
{
// .cdl file with this ROM name exists
@ -951,7 +954,7 @@ void CDLoggerROMChanged(void)
//{
// DoCDLogger();
//}
if (LoadCDLog(nameo))
if (LoadCDLog(nameo.c_str()))
{
StartCDLogging();
}
@ -967,9 +970,9 @@ void SaveCDLogFile(void)
{
if (loadedcdfile[0] == 0)
{
char nameo[1024];
std::string nameo;
getDefaultCDLFile(nameo);
RenameCDLog(nameo);
RenameCDLog(nameo.c_str());
}
FILE *FP;

View File

@ -4335,7 +4335,7 @@ void updateAllDebuggerWindows( void )
}
}
//----------------------------------------------------------------------------
static int getGameDebugBreakpointFileName(char *filepath)
static int getGameDebugBreakpointFileName(std::string &filepath)
{
int i,j;
const char *romFile;
@ -4352,11 +4352,11 @@ static int getGameDebugBreakpointFileName(char *filepath)
if ( romFile[i] == '|' )
{
filepath[i] = '.';
filepath.push_back('.');
}
else
{
if ( romFile[i] == '/' )
if ( (romFile[i] == '/') || (romFile[i] == '\\') )
{
j = -1;
}
@ -4364,20 +4364,15 @@ static int getGameDebugBreakpointFileName(char *filepath)
{
j = i;
}
filepath[i] = romFile[i];
filepath.push_back(romFile[i]);
}
i++;
}
if ( j >= 0 )
if ( (j >= 0) && (j < filepath.size()) )
{
filepath[j] = 0; i=j;
filepath.erase(j);
}
filepath[i] = '.'; i++;
filepath[i] = 'f'; i++;
filepath[i] = 'd'; i++;
filepath[i] = 'b'; i++;
filepath[i] = 0;
filepath.append(".fdb");
return 0;
}
@ -4386,28 +4381,28 @@ void saveGameDebugBreakpoints( bool force )
{
int i;
FILE *fp;
char stmp[512];
char flags[8];
debuggerBookmark_t *bm;
std::string fileName;
// If no breakpoints are loaded, skip saving
if ( !force && (numWPs == 0) && (dbgBmMgr.size() == 0) )
{
return;
}
if ( getGameDebugBreakpointFileName( stmp ) )
if ( getGameDebugBreakpointFileName( fileName ) )
{
printf("Error: Failed to get save file name for debug\n");
return;
}
printf("Debug Save File: '%s' \n", stmp );
printf("Debug Save File: '%s' \n", fileName.c_str());
fp = fopen( stmp, "w");
fp = fopen( fileName.c_str(), "w");
if ( fp == NULL )
{
printf("Error: Failed to open file '%s' for writing\n", stmp );
printf("Error: Failed to open file '%s' for writing\n", fileName.c_str() );
return;
}
@ -4532,6 +4527,7 @@ void loadGameDebugBreakpoints(void)
FILE *fp;
char stmp[512];
char id[64], data[128];
std::string fileName;
// If no debug windows are open, skip loading breakpoints
if ( dbgWin == NULL )
@ -4539,19 +4535,19 @@ void loadGameDebugBreakpoints(void)
printf("No Debug Windows Open: Skipping loading of breakpoint data\n");
return;
}
if ( getGameDebugBreakpointFileName( stmp ) )
if ( getGameDebugBreakpointFileName( fileName ) )
{
printf("Error: Failed to get load file name for debug\n");
return;
}
//printf("Debug Load File: '%s' \n", stmp );
//printf("Debug Load File: '%s' \n", fileName.c_str() );
fp = fopen( stmp, "r");
fp = fopen( fileName.c_str(), "r");
if ( fp == NULL )
{
printf("Error: Failed to open file '%s' for writing\n", stmp );
printf("Error: Failed to open file '%s' for writing\n", fileName.c_str() );
return;
}

View File

@ -76,7 +76,7 @@ int getDirFromFile( const char *path, std::string &dir )
//---------------------------------------------------------------------------
const char *getRomFile( void )
{
static char filePath[2048];
static std::string filePath;
if ( GameInfo )
{
@ -85,32 +85,32 @@ const char *getRomFile( void )
if ( GameInfo->archiveFilename != NULL )
{
char dir[1024], base[512], suffix[64];
std::string dir, base, suffix;
parseFilepath( GameInfo->archiveFilename, dir, base, suffix );
parseFilepath( GameInfo->archiveFilename, &dir, &base, &suffix );
filePath[0] = 0;
filePath.clear();
if ( dir[0] != 0 )
if ( dir.size() != 0 )
{
strcat( filePath, dir );
filePath.append( dir );
}
parseFilepath( GameInfo->filename, dir, base, suffix );
parseFilepath( GameInfo->filename, &dir, &base, &suffix );
strcat( filePath, base );
strcat( filePath, suffix );
filePath.append( base );
filePath.append( suffix );
//printf("ArchivePath: '%s' \n", filePath );
//printf("ArchivePath: '%s' \n", filePath.c_str() );
return filePath;
return filePath.c_str();
}
else
{
return GameInfo->filename;
}
}
return NULL;
return nullptr;
}
//---------------------------------------------------------------------------
// Return file base name stripping out preceding path and trailing suffix.
@ -160,19 +160,25 @@ int getFileBaseName( const char *filepath, char *base, char *suffix )
return end;
}
//---------------------------------------------------------------------------
int parseFilepath( const char *filepath, char *dir, char *base, char *suffix )
int parseFilepath( const char *filepath, std::string *dir, std::string *base, std::string *suffix )
{
int i=0,j=0,end=0;
if ( suffix != NULL )
if (dir)
{
suffix[0] = 0;
dir->clear();
}
if (base)
{
base->clear();
}
if (suffix)
{
suffix->clear();
}
size_t i=0,j=0;
if ( filepath == NULL )
{
if ( dir ) dir[0] = 0;
if ( base ) base[0] = 0;
if ( suffix) suffix[0] = 0;
return 0;
}
i=0; j=0;
@ -184,47 +190,46 @@ int parseFilepath( const char *filepath, char *dir, char *base, char *suffix )
}
if ( dir )
{
dir[i] = filepath[i];
dir->push_back(filepath[i]);
}
i++;
}
if ( dir )
if (dir)
{
dir[j] = 0;
if (j > 0)
{
dir->erase(j);
}
}
i = j;
if ( base == NULL )
{
return end;
}
j=0;
while ( filepath[i] != 0 )
{
base[j] = filepath[i]; i++; j++;
}
base[j] = 0; end=j;
if ( suffix )
{
suffix[0] = 0;
}
while ( j > 1 )
{
j--;
if ( base[j] == '.' )
if (filepath[i] == '.')
{
if ( suffix )
{
strcpy( suffix, &base[j] );
}
end=j; base[j] = 0;
break;
j = i;
}
if (base)
{
base->push_back(filepath[i]);
}
i++;
}
if (filepath[j] == '.')
{
if ( suffix )
{
suffix->assign( &filepath[j] );
}
i = base->find_last_of('.');
if ( i != std::string::npos )
{
base->erase(i);
}
}
return end;
return 0;
}
//---------------------------------------------------------------------------
// Returns the path of fceux.exe as a string.

View File

@ -15,9 +15,9 @@ int getDirFromFile( const char *path, std::string &dir );
const char *getRomFile( void );
int getFileBaseName( const char *filepath, char *base, char *suffix = NULL );
int getFileBaseName( const char *filepath, char *base, char *suffix = nullptr );
int parseFilepath( const char *filepath, char *dir, char *base, char *suffix = NULL );
int parseFilepath( const char *filepath, std::string *dir, std::string *base = nullptr, std::string *suffix = nullptr );
const char *fceuExecutablePath(void);

View File

@ -753,15 +753,17 @@ void fceuStyle::polish(QApplication *app)
if ( rccFilePath.size() == 0 )
{
char dir[1024], rccBase[256], tmpFile[2048];
std::string dir, rccBase, tmpFile;
parseFilepath( s.c_str(), dir, rccBase, NULL );
parseFilepath( s.c_str(), &dir, &rccBase, nullptr );
sprintf( tmpFile, "%s%s.rcc", dir, rccBase );
tmpFile.assign(dir);
tmpFile.append(rccBase);
tmpFile.append(".rcc");
//printf("RCC: '%s%s'\n", dir, rccBase );
//printf("RCC: '%s%s'\n", dir.c_str(), rccBase.c_str() );
if ( QResource::registerResource( tmpFile ) )
if ( QResource::registerResource( tmpFile.c_str() ) )
{
//printf("Loaded RCC File: '%s'\n", tmpFile );
rccFilePath.assign( tmpFile );

View File

@ -528,13 +528,13 @@ void InputConfDialog_t::openSavePresetFile(void)
if (romFile != NULL)
{
char dirStr[256], base[256];
std::string base;
parseFilepath(romFile, dirStr, base);
parseFilepath(romFile, nullptr, &base);
strcat(base, ".pre");
base.append(".pre");
dialog.selectFile(tr(base));
dialog.selectFile(tr(base.c_str()));
}
dialog.setDirectory(tr(path.c_str()));

View File

@ -434,11 +434,11 @@ void MoviePlayDialog_t::doScan(void)
if (romFile != NULL)
{
char dir[512], base[256];
std::string dir;
parseFilepath(romFile, dir, base);
parseFilepath(romFile, &dir);
path = std::string(dir);
path = dir;
scanDirectory(path.c_str(), md5);
}

View File

@ -544,15 +544,15 @@ void RamWatchDialog_t::openListCB(void)
if ( romFile != NULL )
{
char dir[512], base[256];
std::string dir, base;
parseFilepath( romFile, dir, base );
parseFilepath( romFile, &dir, &base );
strcat( base, ".wch");
base.append(".wch");
dialog.setDirectory( tr(dir) );
dialog.setDirectory( tr(dir.c_str()) );
dialog.selectFile( tr(base) );
dialog.selectFile( tr(base.c_str()) );
}
// Check config option to use native file dialog or not
@ -604,15 +604,15 @@ void RamWatchDialog_t::appendListCB(void)
if ( romFile != NULL )
{
char dir[512], base[256];
std::string dir, base;
parseFilepath( romFile, dir, base );
parseFilepath( romFile, &dir, &base );
strcat( base, ".wch");
base.append(".wch");
dialog.setDirectory( tr(dir) );
dialog.setDirectory( tr(dir.c_str()) );
dialog.selectFile( tr(base) );
dialog.selectFile( tr(base.c_str()) );
}
// Check config option to use native file dialog or not
@ -687,15 +687,15 @@ void RamWatchDialog_t::saveListAs(void)
if ( romFile != NULL )
{
char dir[512], base[256];
std::string dir, base;
parseFilepath( romFile, dir, base );
parseFilepath( romFile, &dir, &base );
strcat( base, ".wch");
base.append(".wch");
dialog.setDirectory( tr(dir) );
dialog.setDirectory( tr(dir.c_str()) );
dialog.selectFile( tr(base) );
dialog.selectFile( tr(base.c_str()) );
}
// Check config option to use native file dialog or not