Changed JS log file save function so that it doesn't truncate the current temp file.

This commit is contained in:
harry 2024-02-17 08:42:12 -05:00
parent a929eda845
commit 7b9829eda9
2 changed files with 16 additions and 24 deletions

View File

@ -2561,11 +2561,21 @@ void QScriptDialog_t::saveLog(bool openFileBrowser)
} }
printf("Saving Log File: %s\n", logSavePath.toLocal8Bit().data()); printf("Saving Log File: %s\n", logSavePath.toLocal8Bit().data());
FCEU_WRAPPER_LOCK(); FCEU_WRAPPER_LOCK();
flushLog();
if ( logFile->copy( logSavePath ) )
{ {
// Log file needs to be reopened on a successful copy char buffer[4096];
logFile->reopen(); 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(); FCEU_WRAPPER_UNLOCK();
} }
@ -2957,7 +2967,7 @@ void QScriptDialog_t::resetLog()
delete logFile; delete logFile;
logFile = nullptr; logFile = nullptr;
} }
logFile = new QScriptLogFile(this); logFile = new QTemporaryFile(this);
logFile->setAutoRemove(true); logFile->setAutoRemove(true);
logFile->setFileTemplate(QDir::tempPath() + QString("/fceux_js_XXXXXX.log")); logFile->setFileTemplate(QDir::tempPath() + QString("/fceux_js_XXXXXX.log"));
logFile->open(); logFile->open();

View File

@ -726,24 +726,6 @@ public:
QMap<QString, JsPropertyItem*> childMap; QMap<QString, JsPropertyItem*> 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 class QScriptDialog_t : public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -764,7 +746,7 @@ protected:
QMenuBar* buildMenuBar(); QMenuBar* buildMenuBar();
QMenuBar* menuBar; QMenuBar* menuBar;
QScriptLogFile *logFile = nullptr; QTemporaryFile *logFile = nullptr;
QTimer *periodicTimer; QTimer *periodicTimer;
QLineEdit *scriptPath; QLineEdit *scriptPath;
QLineEdit *scriptArgs; QLineEdit *scriptArgs;