#include "filebackup.h" #include #include FileBackup::FileBackup() { } FileBackup::~FileBackup() { this->requestInterruption(); QTime xTime; xTime.start(); while((xTime.elapsed()<200)&&(mbComplete == false)) { } } void FileBackup::SetOpenDrive(OpenDrive &xxodr) { mMutex.lock(); mxodr = xxodr; mMutex.unlock(); mbUpdate = true; mwc.wakeAll(); } void FileBackup::Activate(QString strpath) { mMutex.lock(); mstrpath = strpath+".bak"; mMutex.unlock(); mbactive = true; } void FileBackup::run() { QString strpath; while(!QThread::isInterruptionRequested()) { if(mbactive) { mWaitMutex.lock(); mwc.wait(&mWaitMutex,50); mWaitMutex.unlock(); if(mbUpdate) { mMutex.lock(); OpenDrive xxodr = mxodr; strpath = mstrpath; mMutex.unlock(); mbUpdate = false; //Save bak file OpenDriveXmlWriter x(&xxodr); x.WriteFile(strpath.toStdString()); } } else { msleep(50); } } if(mbactive) { QFile fileBack(mstrpath); fileBack.remove(); //Delete bak file } mbComplete = true; }