Added a few missing config parameters to Qt trace logger. Namely, save to file (flag and path) and automatic window update.

This commit is contained in:
mjbudd77 2021-08-10 21:49:44 -04:00
parent 8e798cbbb9
commit 88da722533
3 changed files with 42 additions and 10 deletions

View File

@ -121,7 +121,7 @@ static HANDLE logFile = INVALID_HANDLE_VALUE;
#else #else
static int logFile = -1; static int logFile = -1;
#endif #endif
static char logFilePath[512] = { 0 }; static std::string logFilePath;
//---------------------------------------------------- //----------------------------------------------------
static void initLogOption( const char *name, int bitmask ) static void initLogOption( const char *name, int bitmask )
{ {
@ -151,7 +151,7 @@ TraceLoggerDialog_t::TraceLoggerDialog_t(QWidget *parent)
QMenu *fileMenu; QMenu *fileMenu;
QAction *act; QAction *act;
QLabel *lbl; QLabel *lbl;
int useNativeMenuBar; int opt, useNativeMenuBar;
if (recBufMax == 0) if (recBufMax == 0)
{ {
@ -244,7 +244,15 @@ TraceLoggerDialog_t::TraceLoggerDialog_t(QWidget *parent)
autoUpdateCbox = new QCheckBox(tr("Automatically update this window while logging")); autoUpdateCbox = new QCheckBox(tr("Automatically update this window while logging"));
clearButton = new QPushButton(tr("Clear Log")); clearButton = new QPushButton(tr("Clear Log"));
autoUpdateCbox->setChecked(true); g_config->getOption("SDL.TraceLogSaveFilePath", &logFilePath);
g_config->getOption("SDL.TraceLogSaveToFile", &opt );
logFileCbox->setChecked( opt );
connect(logFileCbox, SIGNAL(stateChanged(int)), this, SLOT(logToFileStateChanged(int)));
g_config->getOption("SDL.TraceLogPeriodicWindowUpdate", &opt );
autoUpdateCbox->setChecked( opt );
connect(autoUpdateCbox, SIGNAL(stateChanged(int)), this, SLOT(autoUpdateStateChanged(int)));
if (logging) if (logging)
{ {
@ -512,7 +520,7 @@ void TraceLoggerDialog_t::toggleLoggingOnOff(void)
{ {
if (logFileCbox->isChecked()) if (logFileCbox->isChecked())
{ {
if ( logFilePath[0] == 0 ) if ( logFilePath.size() == 0 )
{ {
openLogFile(); openLogFile();
} }
@ -563,11 +571,18 @@ void TraceLoggerDialog_t::openLogFile(void)
if (romFile != NULL) if (romFile != NULL)
{ {
char dir[512]; char dir[1024];
getDirFromFile(romFile, dir); getDirFromFile(romFile, dir);
dialog.setDirectory(tr(dir)); dialog.setDirectory(tr(dir));
} }
if ( logFilePath.size() != 0 )
{
char dir[1024];
getDirFromFile(logFilePath.c_str(), dir);
dialog.setDirectory(tr(dir));
}
// Check config option to use native file dialog or not // Check config option to use native file dialog or not
g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal); g_config->getOption("SDL.UseNativeFileDialog", &useNativeFileDialogVal);
@ -592,7 +607,9 @@ void TraceLoggerDialog_t::openLogFile(void)
} }
//qDebug() << "selected file path : " << filename.toUtf8(); //qDebug() << "selected file path : " << filename.toUtf8();
strcpy( logFilePath, filename.toStdString().c_str() ); logFilePath = filename.toStdString();
g_config->setOption("SDL.TraceLogSaveFilePath", logFilePath);
return; return;
} }
@ -608,6 +625,16 @@ void TraceLoggerDialog_t::vbarChanged(int val)
traceView->update(); traceView->update();
} }
//---------------------------------------------------- //----------------------------------------------------
void TraceLoggerDialog_t::logToFileStateChanged(int state)
{
g_config->setOption("SDL.TraceLogSaveToFile", state != Qt::Unchecked );
}
//----------------------------------------------------
void TraceLoggerDialog_t::autoUpdateStateChanged(int state)
{
g_config->setOption("SDL.TraceLogPeriodicWindowUpdate", state != Qt::Unchecked );
}
//----------------------------------------------------
void TraceLoggerDialog_t::logRegStateChanged(int state) void TraceLoggerDialog_t::logRegStateChanged(int state)
{ {
if (state == Qt::Unchecked) if (state == Qt::Unchecked)
@ -2337,24 +2364,24 @@ void TraceLogDiskThread_t::run(void)
setPriority( QThread::HighestPriority ); setPriority( QThread::HighestPriority );
#ifdef WIN32 #ifdef WIN32
logFile = CreateFileA( logFilePath, GENERIC_WRITE, logFile = CreateFileA( logFilePath.c_str(), GENERIC_WRITE,
0, NULL, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL ); 0, NULL, OPEN_ALWAYS, FILE_FLAG_WRITE_THROUGH | FILE_FLAG_NO_BUFFERING, NULL );
if ( logFile == INVALID_HANDLE_VALUE ) if ( logFile == INVALID_HANDLE_VALUE )
{ {
char stmp[1024]; char stmp[1024];
sprintf( stmp, "Error: Failed to open log file for writing: %s", logFilePath ); sprintf( stmp, "Error: Failed to open log file for writing: %s", logFilePath.c_str() );
consoleWindow->QueueErrorMsgWindow(stmp); consoleWindow->QueueErrorMsgWindow(stmp);
return; return;
} }
#else #else
logFile = open( logFilePath, O_CREAT | O_WRONLY | O_TRUNC, logFile = open( logFilePath.c_str(), O_CREAT | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH ); S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH );
if ( logFile == -1 ) if ( logFile == -1 )
{ {
char stmp[1024]; char stmp[1024];
sprintf( stmp, "Error: Failed to open log file for writing: %s", logFilePath ); sprintf( stmp, "Error: Failed to open log file for writing: %s", logFilePath.c_str() );
consoleWindow->QueueErrorMsgWindow(stmp); consoleWindow->QueueErrorMsgWindow(stmp);
return; return;
} }

View File

@ -199,6 +199,8 @@ public slots:
private slots: private slots:
void updatePeriodic(void); void updatePeriodic(void);
void toggleLoggingOnOff(void); void toggleLoggingOnOff(void);
void autoUpdateStateChanged(int state);
void logToFileStateChanged(int state);
void logRegStateChanged(int state); void logRegStateChanged(int state);
void logFrameStateChanged(int state); void logFrameStateChanged(int state);
void logEmuMsgStateChanged(int state); void logEmuMsgStateChanged(int state);

View File

@ -639,6 +639,9 @@ InitConfig()
config->addOption("autoResumeCDL", "SDL.AutoResumeCDL", 0); config->addOption("autoResumeCDL", "SDL.AutoResumeCDL", 0);
// Trace Logger Options // Trace Logger Options
config->addOption("SDL.TraceLogSaveToFile", 0);
config->addOption("SDL.TraceLogSaveFilePath", "");
config->addOption("SDL.TraceLogPeriodicWindowUpdate", 1);
config->addOption("SDL.TraceLogRegisterState", 1); config->addOption("SDL.TraceLogRegisterState", 1);
config->addOption("SDL.TraceLogProcessorState", 1); config->addOption("SDL.TraceLogProcessorState", 1);
config->addOption("SDL.TraceLogNewInstructions", 0); config->addOption("SDL.TraceLogNewInstructions", 0);