|
|
@@ -0,0 +1,88 @@
|
|
|
+#include <QTimer>
|
|
|
+#include "IEngine.h"
|
|
|
+#include "fileDiff.h"
|
|
|
+#include "deepScanThread.h"
|
|
|
+
|
|
|
+using namespace craftlab::fakeraid;
|
|
|
+
|
|
|
+class CountFileThread : public QThread
|
|
|
+{
|
|
|
+ public:
|
|
|
+ CountFileThread(IEngine* engine);
|
|
|
+ size_t FileCount() const;
|
|
|
+
|
|
|
+ protected:
|
|
|
+ void run();
|
|
|
+
|
|
|
+ size_t fileCount;
|
|
|
+ IEngine* engine;
|
|
|
+};
|
|
|
+
|
|
|
+CountFileThread::CountFileThread(IEngine* _engine): engine(_engine), fileCount(0)
|
|
|
+{
|
|
|
+ setTerminationEnabled(true);
|
|
|
+}
|
|
|
+
|
|
|
+size_t CountFileThread::FileCount() const
|
|
|
+{
|
|
|
+ return fileCount;
|
|
|
+}
|
|
|
+
|
|
|
+void CountFileThread::run()
|
|
|
+{
|
|
|
+ fileCount = engine->CountFilesRecur();
|
|
|
+}
|
|
|
+
|
|
|
+DeepScanThread::DeepScanThread(craftlab::fakeraid::IEngine* _engine): threadStopping(false), engine(_engine), timer(new QTimer(this)), fileList(new FileAndSumListByRepositoryIndex())
|
|
|
+{
|
|
|
+ CountFileThread* threadType = new CountFileThread(engine);
|
|
|
+
|
|
|
+ connect(threadType, &CountFileThread::finished, this, [this]() {
|
|
|
+ emit FileCountComputed(((CountFileThread*)countFileThread)->FileCount());
|
|
|
+ });
|
|
|
+ connect(timer, &QTimer::timeout, this, [this]() {
|
|
|
+ emit Ping(fileList->ExistingFileCount(), fileList->lastInsertedFilename);
|
|
|
+ });
|
|
|
+
|
|
|
+ timer->setInterval(500);
|
|
|
+ timer->start();
|
|
|
+ countFileThread = threadType;
|
|
|
+ countFileThread->start();
|
|
|
+}
|
|
|
+
|
|
|
+DeepScanThread::~DeepScanThread()
|
|
|
+{
|
|
|
+ delete fileList;
|
|
|
+ if (countFileThread->isRunning())
|
|
|
+ {
|
|
|
+ countFileThread->terminate();
|
|
|
+ countFileThread->wait();
|
|
|
+ }
|
|
|
+ countFileThread->deleteLater();
|
|
|
+ timer->deleteLater();
|
|
|
+}
|
|
|
+
|
|
|
+DiffResult* DeepScanThread::GetResult()
|
|
|
+{
|
|
|
+ return threadStopping ? nullptr : result.get();
|
|
|
+}
|
|
|
+
|
|
|
+void DeepScanThread::run()
|
|
|
+{
|
|
|
+ threadStopping = false;
|
|
|
+ engine->ListFilesRecur(fileList, &threadStopping);
|
|
|
+ emit FileCountComputed(0);
|
|
|
+ result = std::make_unique<DiffResult>(FileDiff().Process(*engine, *fileList));
|
|
|
+}
|
|
|
+
|
|
|
+void DeepScanThread::Terminate()
|
|
|
+{
|
|
|
+ if (countFileThread->isRunning())
|
|
|
+ {
|
|
|
+ countFileThread->terminate();
|
|
|
+ countFileThread->wait();
|
|
|
+ }
|
|
|
+ timer->stop();
|
|
|
+ threadStopping = true;
|
|
|
+ wait();
|
|
|
+}
|