Răsfoiți Sursa

Fixes #8 Fixes #7 - fixup 0e535fc58223a54e514f45b40ba993e7e6cc22ae Add missing files

isundil 7 luni în urmă
părinte
comite
c5c475aa03
2 a modificat fișierele cu 128 adăugiri și 0 ștergeri
  1. 88 0
      fakeRaid/deepScanThread.cpp
  2. 40 0
      fakeRaid/deepScanThread.h

+ 88 - 0
fakeRaid/deepScanThread.cpp

@@ -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();
+}

+ 40 - 0
fakeRaid/deepScanThread.h

@@ -0,0 +1,40 @@
+#pragma once
+
+#include <QThread>
+
+class QTimer;
+class QThread;
+
+namespace craftlab::fakeraid
+{
+	struct DiffResult;
+	class IEngine;
+	struct FileAndSumListByRepositoryIndex;
+
+	class DeepScanThread : public QThread
+	{
+	Q_OBJECT
+	protected:
+		void run();
+
+	public:
+		DeepScanThread(craftlab::fakeraid::IEngine* engine);
+		~DeepScanThread();
+
+		craftlab::fakeraid::DiffResult* GetResult();
+		void Terminate();
+
+	signals:
+		void FileCountComputed(size_t count);
+		void Ping(size_t fileCount, const std::string& lastFile);
+
+	private:
+		QThread* countFileThread;
+		QTimer* timer;
+
+		bool threadStopping;
+		craftlab::fakeraid::IEngine* engine;
+		std::unique_ptr<DiffResult> result;
+		FileAndSumListByRepositoryIndex* fileList{};
+	};
+}