Archivage des passages (non terminé)
This commit is contained in:
@@ -151,7 +151,7 @@ CDatabaseMgrPage::CDatabaseMgrPage(QGraphicsWidget *Parent, bool EngMode)
|
||||
Title->setPos(350,70);
|
||||
|
||||
QGraphicsRectItem *MaintenanceZoneFrame = new QGraphicsRectItem(this);
|
||||
MaintenanceZoneFrame->setRect(QRectF(0,0,260,240));
|
||||
MaintenanceZoneFrame->setRect(QRectF(0,0,320,240));
|
||||
MaintenanceZoneFrame->setPos(350,100);
|
||||
MaintenanceZoneFrame->setPen(RectPen);
|
||||
|
||||
@@ -175,17 +175,31 @@ CDatabaseMgrPage::CDatabaseMgrPage(QGraphicsWidget *Parent, bool EngMode)
|
||||
mRebuildDatabaseFile->setPos(360,200);
|
||||
connect(mRebuildDatabaseFile,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
||||
|
||||
mArchiveDatabase = new CTextButtonWidget("Archiver les passages");
|
||||
mArchiveDatabase->setParentItem(this);
|
||||
mArchiveDatabase->setPos(360,230);
|
||||
connect(mArchiveDatabase,SIGNAL(TxtButtonClicked(CTextButtonWidget*)),this,SLOT(ButtonClicked(CTextButtonWidget*)));
|
||||
|
||||
mArchiveKeepDays = new QSpinBox();
|
||||
WidgetProxy = new QGraphicsProxyWidget(this);
|
||||
WidgetProxy->setWidget(mArchiveKeepDays);
|
||||
WidgetProxy->setPos(525,230);
|
||||
mArchiveKeepDays->setMaximum(100);
|
||||
mArchiveKeepDays->setMinimum(0);
|
||||
mArchiveKeepDays->setValue(10);
|
||||
mArchiveKeepDays->setSuffix(" Jours conservés");
|
||||
mArchiveKeepDays->resize(140,30);
|
||||
|
||||
|
||||
mDBMaintenanceProgressBar = new QProgressBar();
|
||||
WidgetProxy = new QGraphicsProxyWidget(this);
|
||||
WidgetProxy->setWidget(mDBMaintenanceProgressBar);
|
||||
WidgetProxy->setPos(360,240);
|
||||
WidgetProxy->setPos(360,275);
|
||||
|
||||
font.setPointSize(8);
|
||||
mDBMaintenanceProgressStatusText = new QGraphicsTextItem(this);
|
||||
mDBMaintenanceProgressStatusText->setFont(font);
|
||||
mDBMaintenanceProgressStatusText->setPos(360,260);
|
||||
mDBMaintenanceProgressStatusText->setPos(360,305);
|
||||
mDBMaintenanceProgressStatusText->setPlainText("");
|
||||
|
||||
if(EngMode == false)
|
||||
@@ -249,6 +263,10 @@ void CDatabaseMgrPage::ButtonClicked(CTextButtonWidget *BtnPtr)
|
||||
{
|
||||
mProgramHandle->RebuildDatabaseFile();
|
||||
}
|
||||
else if(BtnPtr == mArchiveDatabase)
|
||||
{
|
||||
ArchiveDB();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -441,6 +459,160 @@ bool CDatabaseMgrPage::CleanSingleZTLogFiles()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDatabaseMgrPage::ArchiveDB()
|
||||
{
|
||||
QList<CLogElement*> *LogsList = mLogMgrHandle->GetLogsList();
|
||||
QDate FilterDate = QDate::currentDate();
|
||||
FilterDate = FilterDate.addDays(-1 * mArchiveKeepDays->value());
|
||||
|
||||
mDBMaintenanceProgressStatusText->setPlainText(QString().sprintf("Archivage de la base de données\n%d fichiers à analyser",LogsList->size()));
|
||||
mDBMaintenanceProgressBar->setRange(0,LogsList->size());
|
||||
|
||||
QDir ArchiveDir = mLogMgrHandle->GetBaseLogDataDir();
|
||||
ArchiveDir.cdUp();
|
||||
QString Path = QString("Archives/%1").arg(QDate::currentDate().toString("yyyy-MM-dd"));
|
||||
ArchiveDir.mkpath(Path);
|
||||
ArchiveDir.cd(Path);
|
||||
QDir CurDir;
|
||||
QFileInfo FileInfo;
|
||||
|
||||
if(LogsList->at(0)->mZTLogType == ZT1_LOG_TYPE)
|
||||
{
|
||||
CZT1LogElement *tmp = (CZT1LogElement*)LogsList->at(0);
|
||||
QFileInfo FilePath(tmp->mLogFileName);
|
||||
CurDir = ArchiveDir;
|
||||
QDir StationDir = FilePath.dir();
|
||||
StationDir.cdUp();
|
||||
CurDir.mkdir(StationDir.dirName());
|
||||
CurDir.cd(StationDir.dirName());
|
||||
CurDir.mkdir(FilePath.dir().dirName());
|
||||
CurDir.cd(FilePath.dir().dirName());
|
||||
FileInfo = FilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
CZT2LogElement *tmp =(CZT2LogElement*)LogsList->at(0);
|
||||
QFileInfo FilePath(tmp->mLogFileName);
|
||||
CurDir = ArchiveDir;
|
||||
QDir StationDir = FilePath.dir();
|
||||
StationDir.cdUp();
|
||||
CurDir.mkdir(StationDir.dirName());
|
||||
CurDir.cd(StationDir.dirName());
|
||||
CurDir.mkdir(FilePath.dir().dirName());
|
||||
CurDir.cd(FilePath.dir().dirName());
|
||||
FileInfo = FilePath;
|
||||
}
|
||||
|
||||
int IgnoredFiles = 0;
|
||||
|
||||
|
||||
for(int i = 0; i < LogsList->size(); i++)
|
||||
{
|
||||
if(LogsList->at(i)->mZTLogType == ZT1_LOG_TYPE)
|
||||
{
|
||||
CZT1LogElement *tmp = (CZT1LogElement*)LogsList->at(i);
|
||||
|
||||
//We are changing directory...
|
||||
if(CurDir.dirName() != QFileInfo(tmp->mLogFileName).dir().dirName())
|
||||
{
|
||||
//Copy the Log file into the archive
|
||||
QFile::copy(FileInfo.dir().absoluteFilePath("ZTLog.txt"),CurDir.absoluteFilePath("ZTLog.txt"));
|
||||
|
||||
QDir DatabaseDir = FileInfo.dir();
|
||||
DatabaseDir.setFilter(QDir::Files);
|
||||
QStringList filter;
|
||||
filter << "*.bin";
|
||||
DatabaseDir.setNameFilters(filter);
|
||||
//If no binary file is left in the database dir, delete it.
|
||||
if(DatabaseDir.count() == 0)
|
||||
{
|
||||
filter.clear();
|
||||
DatabaseDir.setNameFilters(filter);
|
||||
RemoveDir(DatabaseDir);
|
||||
}
|
||||
|
||||
//Create the new archive dir.
|
||||
QFileInfo FilePath(tmp->mLogFileName);
|
||||
CurDir = ArchiveDir;
|
||||
QDir StationDir = FilePath.dir();
|
||||
StationDir.cdUp();
|
||||
CurDir.mkdir(StationDir.dirName());
|
||||
CurDir.cd(StationDir.dirName());
|
||||
CurDir.mkdir(FilePath.dir().dirName());
|
||||
CurDir.cd(FilePath.dir().dirName());
|
||||
FileInfo = FilePath;
|
||||
|
||||
}
|
||||
|
||||
FileInfo = QFileInfo(tmp->mLogFileName);
|
||||
|
||||
//Copy the file into archive
|
||||
QFile::copy(FileInfo.filePath(),CurDir.absoluteFilePath(FileInfo.fileName()));
|
||||
|
||||
//Check if we have to delete the source file
|
||||
if((tmp->mZTDetections.size() == 0) && (tmp->mPassageDateTime.date() < FilterDate) && (tmp->mFileProtected == false))
|
||||
{
|
||||
//Remove file from database
|
||||
QFile::remove(FileInfo.filePath());
|
||||
}
|
||||
else
|
||||
{
|
||||
IgnoredFiles++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CZT2LogElement *tmp =(CZT2LogElement*)LogsList->at(i);
|
||||
if(CurDir.dirName() != QFileInfo(tmp->mLogFileName).dir().dirName())
|
||||
{
|
||||
//Copy the Log file into the archive
|
||||
QFile::copy(FileInfo.dir().absoluteFilePath("ZTLog.txt"),CurDir.absoluteFilePath("ZTLog.txt"));
|
||||
|
||||
QDir DatabaseDir = FileInfo.dir();
|
||||
DatabaseDir.setFilter(QDir::Files);
|
||||
DatabaseDir.setNameFilters(QStringList("*.bin"));
|
||||
//If no binary file is left in the database dir, delete it.
|
||||
if(DatabaseDir.count() == 0)
|
||||
{
|
||||
RemoveDir(DatabaseDir);
|
||||
}
|
||||
|
||||
//Create the new archive dir.
|
||||
QFileInfo FilePath(tmp->mLogFileName);
|
||||
CurDir = ArchiveDir;
|
||||
QDir StationDir = FilePath.dir();
|
||||
StationDir.cdUp();
|
||||
CurDir.mkdir(StationDir.dirName());
|
||||
CurDir.cd(StationDir.dirName());
|
||||
CurDir.mkdir(FilePath.dir().dirName());
|
||||
CurDir.cd(FilePath.dir().dirName());
|
||||
FileInfo = FilePath;
|
||||
|
||||
}
|
||||
|
||||
FileInfo = QFileInfo(tmp->mLogFileName);
|
||||
|
||||
//Copy the file into archive
|
||||
QFile::copy(FileInfo.filePath(),CurDir.absoluteFilePath(FileInfo.fileName()));
|
||||
|
||||
//Check if we have to delete the source file
|
||||
if((tmp->mZTDetections.size() == 0) && (tmp->mPassageDateTime.date() < FilterDate))
|
||||
{
|
||||
//Remove file from database
|
||||
QFile::remove(FileInfo.filePath());
|
||||
}
|
||||
else
|
||||
{
|
||||
IgnoredFiles++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
void CDatabaseMgrPage::DatabaseImportFinished(bool ret,QStringList* FilesList)
|
||||
{
|
||||
if(ret == false)
|
||||
@@ -478,6 +650,49 @@ bool CDatabaseMgrPage::DeleteFile(QString FilePath)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CDatabaseMgrPage::RemoveDir(QDir Dir)
|
||||
{
|
||||
if (!Dir.exists())
|
||||
return true;
|
||||
|
||||
QFileInfoList DirList = Dir.entryInfoList(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
|
||||
for(int i = 0; i < DirList.size(); i++)
|
||||
{
|
||||
// QFileInfo info(DirList.at(i));
|
||||
if (DirList.at(i).isDir())
|
||||
{
|
||||
if (!RemoveDir(QDir(DirList.at(i).filePath())))
|
||||
{
|
||||
qDebug("Cannot delete %s",DirList.at(i).absoluteFilePath().toUtf8().data());
|
||||
return false;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// if(Dir.rmdir(DirList.at(i).absoluteFilePath()) == false)
|
||||
// {
|
||||
// qDebug("Could not delete %s",DirList.at(i).filePath().toUtf8().data());
|
||||
// }
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Dir.remove(DirList.at(i).absoluteFilePath()) == false)
|
||||
{
|
||||
qDebug("Cannot delete %s",DirList.at(i).absoluteFilePath().toUtf8().data()); // return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(QDir().rmdir(Dir.absolutePath()) == false)
|
||||
{
|
||||
qDebug("Could not delete %s",Dir.absolutePath().toUtf8().data());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CDatabaseMgrPage::UpdateDBStats()
|
||||
{
|
||||
int NbTrains, NbZTLog;
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#include <QThread>
|
||||
#include <QReadWriteLock>
|
||||
#include "ZTLogFilesMgr.h"
|
||||
#include <QSpinBox>
|
||||
//#include "DatabaseArchiver.h"
|
||||
|
||||
class COutilZT;
|
||||
|
||||
@@ -121,10 +123,11 @@ private:
|
||||
QProgressBar *mProgressBar;
|
||||
QGraphicsTextItem *mProgressStatusText;
|
||||
|
||||
CTextButtonWidget *mDeleteDBDuplicatesBtn, *mDeleteNonErrorLogs, *mDeleteZTLogFiles, *mRebuildDatabaseFile;
|
||||
CTextButtonWidget *mDeleteDBDuplicatesBtn, *mDeleteNonErrorLogs, *mDeleteZTLogFiles, *mRebuildDatabaseFile, *mArchiveDatabase;
|
||||
QProgressBar *mDBMaintenanceProgressBar;
|
||||
QGraphicsTextItem *mDBMaintenanceProgressStatusText;
|
||||
QGraphicsTextItem *mDBFileCountText;
|
||||
QSpinBox *mArchiveKeepDays;
|
||||
|
||||
|
||||
CDatabaseImporterThread *mDatabaseImporterWorkerThread;
|
||||
@@ -135,6 +138,8 @@ private:
|
||||
bool CleanDBNormalPasses();
|
||||
bool CleanSingleZTLogFiles();
|
||||
bool DeleteFile(QString FilePath);
|
||||
bool ArchiveDB();
|
||||
bool RemoveDir(QDir Dir);
|
||||
|
||||
|
||||
// int ParseDir(QDir dir);
|
||||
|
||||
Reference in New Issue
Block a user