Cleanup large log file on startup

This commit is contained in:
BigBahss 2020-10-10 14:06:51 -04:00 committed by huderlem
parent 4f68f85c90
commit 1ea50d7955
3 changed files with 14 additions and 0 deletions

View file

@ -20,5 +20,6 @@ void logError(QString message);
void log(QString message, LogType type);
QString getLogPath();
QString getMostRecentError();
bool cleanupLargeLog();
#endif // LOG_H

View file

@ -86,3 +86,14 @@ QString getLogPath() {
QString getMostRecentError() {
return mostRecentError;
}
bool cleanupLargeLog() {
QFile logFile(getLogPath());
if (logFile.size() < 20000000)
return false;
bool removed = logFile.remove();
if (removed)
logWarn(QString("Previous log file %1 was cleared due to being over 20MB in size.").arg(getLogPath()));
return removed;
}

View file

@ -53,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent) :
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-2.ico"));
ui->setupUi(this);
cleanupLargeLog();
this->initWindow();
if (!this->openRecentProject()) {
// Re-initialize everything to a blank slate if opening the recent project failed.