From 7b9829eda920cc8f3bc069a0090608ea2785b541 Mon Sep 17 00:00:00 2001 From: harry Date: Sat, 17 Feb 2024 08:42:12 -0500 Subject: [PATCH] Changed JS log file save function so that it doesn't truncate the current temp file. --- src/drivers/Qt/QtScriptManager.cpp | 20 +++++++++++++++----- src/drivers/Qt/QtScriptManager.h | 20 +------------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/drivers/Qt/QtScriptManager.cpp b/src/drivers/Qt/QtScriptManager.cpp index 34533633..34a9d5bf 100644 --- a/src/drivers/Qt/QtScriptManager.cpp +++ b/src/drivers/Qt/QtScriptManager.cpp @@ -2561,11 +2561,21 @@ void QScriptDialog_t::saveLog(bool openFileBrowser) } printf("Saving Log File: %s\n", logSavePath.toLocal8Bit().data()); FCEU_WRAPPER_LOCK(); - flushLog(); - if ( logFile->copy( logSavePath ) ) { - // Log file needs to be reopened on a successful copy - logFile->reopen(); + char buffer[4096]; + flushLog(); + QFile saveFile( logSavePath ); + if (saveFile.open(QIODeviceBase::ReadWrite)) + { + logFile->seek(0); + qint64 bytesRead = logFile->read(buffer, sizeof(buffer)); + while (bytesRead > 0) + { + saveFile.write(buffer, bytesRead); + + bytesRead = logFile->read(buffer, sizeof(buffer)); + } + } } FCEU_WRAPPER_UNLOCK(); } @@ -2957,7 +2967,7 @@ void QScriptDialog_t::resetLog() delete logFile; logFile = nullptr; } - logFile = new QScriptLogFile(this); + logFile = new QTemporaryFile(this); logFile->setAutoRemove(true); logFile->setFileTemplate(QDir::tempPath() + QString("/fceux_js_XXXXXX.log")); logFile->open(); diff --git a/src/drivers/Qt/QtScriptManager.h b/src/drivers/Qt/QtScriptManager.h index f94e1bdf..66638bf1 100644 --- a/src/drivers/Qt/QtScriptManager.h +++ b/src/drivers/Qt/QtScriptManager.h @@ -726,24 +726,6 @@ public: QMap childMap; }; -class QScriptLogFile : public QTemporaryFile -{ - Q_OBJECT - -public: - QScriptLogFile(QObject* parent = nullptr) - : QTemporaryFile(parent) - { - } - - ~QScriptLogFile(void){} - - void reopen() - { - open(QIODeviceBase::Append | QIODeviceBase::ReadWrite); - } -}; - class QScriptDialog_t : public QDialog { Q_OBJECT @@ -764,7 +746,7 @@ protected: QMenuBar* buildMenuBar(); QMenuBar* menuBar; - QScriptLogFile *logFile = nullptr; + QTemporaryFile *logFile = nullptr; QTimer *periodicTimer; QLineEdit *scriptPath; QLineEdit *scriptArgs;