Added CDL File load/save logic.

This commit is contained in:
Matthew Budd 2020-09-28 21:51:14 -04:00
parent 445b17104a
commit 63933a1821
3 changed files with 138 additions and 3 deletions

View File

@ -1,6 +1,7 @@
// CodeDataLogger.cpp
//
#include <QDir>
#include <QFileDialog>
#include <QInputDialog>
#include <QMessageBox>
@ -133,12 +134,15 @@ CodeDataLoggerDialog_t::CodeDataLoggerDialog_t(QWidget *parent)
btn = new QPushButton( tr("Save") );
grid->addWidget( btn, 0, 2, Qt::AlignCenter );
connect( btn, SIGNAL(clicked(void)), this, SLOT(saveCdlFile(void)));
btn = new QPushButton( tr("Load") );
grid->addWidget( btn, 1, 0, Qt::AlignCenter );
connect( btn, SIGNAL(clicked(void)), this, SLOT(loadCdlFile(void)));
btn = new QPushButton( tr("Save As") );
grid->addWidget( btn, 1, 2, Qt::AlignCenter );
connect( btn, SIGNAL(clicked(void)), this, SLOT(saveCdlFileAs(void)));
hbox = new QHBoxLayout();
vbox1->addLayout( hbox );
@ -287,18 +291,142 @@ void CodeDataLoggerDialog_t::StartPauseCDLogClicked(void)
{
if ( FCEUI_GetLoggingCD() )
{
printf("CD Logging Paused\n");
//printf("CD Logging Paused\n");
PauseCDLogging();
startPauseButton->setText( tr("Start") );
}
else
{
printf("CD Logging Started\n");
//printf("CD Logging Started\n");
StartCDLogging();
startPauseButton->setText( tr("Pause") );
}
}
//----------------------------------------------------
void CodeDataLoggerDialog_t::saveCdlFile(void)
{
SaveCDLogFile();
}
//----------------------------------------------------
void CodeDataLoggerDialog_t::saveCdlFileAs(void)
{
int ret, useNativeFileDialogVal;
QString filename;
const char *romFile;
QFileDialog dialog(this, tr("Save CDL To File") );
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setNameFilter(tr("CDL Files (*.cdl *.CDL) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Save") );
dialog.setDefaultSuffix( tr(".cdl") );
romFile = getRomFile();
if ( romFile != NULL )
{
char dir[512], base[256];
parseFilepath( romFile, dir, base );
strcat( base, ".cdl");
dialog.setDirectory( tr(dir) );
dialog.selectFile( tr(base) );
}
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
dialog.show();
ret = dialog.exec();
if ( ret )
{
QStringList fileList;
fileList = dialog.selectedFiles();
if ( fileList.size() > 0 )
{
filename = fileList[0];
}
}
if ( filename.isNull() )
{
return;
}
//qDebug() << "selected file path : " << filename.toUtf8();
fceuWrapperLock();
strcpy( loadedcdfile, filename.toStdString().c_str() );
SaveCDLogFile();
fceuWrapperUnLock();
}
//----------------------------------------------------
void CodeDataLoggerDialog_t::loadCdlFile(void)
{
int ret, useNativeFileDialogVal;
QString filename;
char dir[512];
const char *romFile;
QFileDialog dialog(this, tr("Load CDL File") );
dialog.setFileMode(QFileDialog::ExistingFile);
dialog.setNameFilter(tr("CDL files (*.cdl *.CDL) ;; All files (*)"));
dialog.setViewMode(QFileDialog::List);
dialog.setFilter( QDir::AllEntries | QDir::Hidden );
dialog.setLabelText( QFileDialog::Accept, tr("Load") );
romFile = getRomFile();
if ( romFile )
{
getDirFromFile( romFile, dir );
dialog.setDirectory( tr(dir) );
}
// Check config option to use native file dialog or not
g_config->getOption ("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
dialog.setOption(QFileDialog::DontUseNativeDialog, !useNativeFileDialogVal);
dialog.show();
ret = dialog.exec();
if ( ret )
{
QStringList fileList;
fileList = dialog.selectedFiles();
if ( fileList.size() > 0 )
{
filename = fileList[0];
}
}
if ( filename.isNull() )
{
return;
}
//qDebug() << "selected file path : " << filename.toUtf8();
fceuWrapperLock();
LoadCDLog ( filename.toStdString().c_str() );
fceuWrapperUnLock();
return;
}
//----------------------------------------------------
static int getDefaultCDLFile( char *filepath )
{
const char *romFile;
@ -399,7 +527,9 @@ bool LoadCDLog(const char* nameo)
FP = fopen(nameo, "rb");
if (FP == NULL)
{
return false;
}
for(i = 0;i < (int)cdloggerdataSize;i++)
{

View File

@ -45,6 +45,9 @@ class CodeDataLoggerDialog_t : public QDialog
public slots:
void closeWindow(void);
private slots:
void loadCdlFile(void);
void saveCdlFile(void);
void saveCdlFileAs(void);
void updatePeriodic(void);
void ResetCDLogClicked(void);
void StartPauseCDLogClicked(void);

View File

@ -88,7 +88,9 @@ int parseFilepath( const char *filepath, char *dir, char *base, char *suffix )
int i=0,j=0,end=0;
if ( filepath == NULL )
{
base[0] = 0;
if ( dir ) dir[0] = 0;
if ( base ) base[0] = 0;
if ( suffix) suffix[0] = 0;
return 0;
}
i=0; j=0;