#pragma once #include "core/disk-node.h" #include #include #include #include #include struct ScanStats { quint64 fileCount = 0; quint64 dirCount = 0; quint64 totalBytes = 0; // Entries that could not be read; the scan continues past them. QStringList errors; }; // Walks a directory on its own thread so the window stays responsive while a // large tree is being analysed. Symlinks are skipped: following them can loop // and would count the same bytes twice. class DiskScanner : public QThread { Q_OBJECT public: explicit DiskScanner(QString rootPath, QObject *parent = nullptr); ~DiskScanner() override; // Safe to call from another thread; the run stops at the next entry and // leaves no tree behind. void cancel(); // Hands the scanned tree to the caller. Null when the scan was cancelled. std::shared_ptr takeTree(); ScanStats stats() const { return m_stats; } signals: void progress(const QString ¤tPath, quint64 bytes); protected: void run() override; private: void scanDirectory(DiskNode &directory); QString m_rootPath; std::shared_ptr m_tree; ScanStats m_stats; std::atomic_bool m_cancelled{false}; };