Delete local reports older than 30 days.

--HG--
branch : develop
This commit is contained in:
dismine 2014-11-29 14:12:43 +02:00
parent eee931def0
commit 6ded3d1c2b
2 changed files with 35 additions and 0 deletions

View File

@ -49,6 +49,7 @@
#include <QMessageBox>
#include <QLoggingCategory>
#include <QLockFile>
#include <QtXmlPatterns>
Q_LOGGING_CATEGORY(vApp, "v.application")
@ -2089,6 +2090,9 @@ void VApplication::StartLogging()
CreateLogDir();
BeginLogging();
ClearOldLogs();
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
ClearOldReports();
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
}
//---------------------------------------------------------------------------------------------------------------------
@ -2098,6 +2102,34 @@ QTextStream *VApplication::LogFile()
}
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
//---------------------------------------------------------------------------------------------------------------------
void VApplication::ClearOldReports() const
{
const QString reportsDir = QString("%1/reports").arg(qApp->applicationDirPath());
QDir reports(reportsDir);
if (reports.exists())
{
QStringList filters{"*.log", "*.RPT"};
QDir logsDir(reportsDir);
logsDir.setNameFilters(filters);
logsDir.setCurrent(reportsDir);
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
if (allFiles.isEmpty() == false)
{
const QDateTime now = QDateTime::currentDateTime();
for (int i = 0; i < allFiles.size(); ++i)
{
QFileInfo info(allFiles.at(i));
if (info.created().daysTo(now) > 30)
{
QFile(allFiles.at(i)).remove();
}
}
}
}
}
//---------------------------------------------------------------------------------------------------------------------
// Catch exception and create report. Use if program build with Mingw compiler.
// See more about catcher https://github.com/jrfonseca/drmingw/blob/master/README.md

View File

@ -107,9 +107,11 @@ public:
static QStringList LabelLanguages();
QString STDescription(const QString &id)const;
static bool SafeCopy(const QString &source, const QString &destination, QString &error);
void StartLogging();
QTextStream *LogFile();
#if defined(Q_OS_WIN) && defined(Q_CC_GNU)
static void DrMingw();
void CollectReports() const;
@ -180,6 +182,7 @@ private:
void CollectReport(const QString &reportName) const;
void SendReport(const QString &reportName) const;
QString ReadFileForSending(QFile &file)const;
void ClearOldReports()const;
#endif // defined(Q_OS_WIN) && defined(Q_CC_GNU)
QString LogDirPath()const;