version / print-version (push) Successful in 1s
The UI and the tests were written against these modules, but the sources were never tracked, so the package could not build. The scanner aggregates sizes and file counts, skips symlinks, reports unreadable entries, and the layout implements a squarified treemap so tile areas stay proportional to the sizes.
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "core/disk-node.h"
|
|
|
|
#include <QString>
|
|
#include <QStringList>
|
|
#include <QThread>
|
|
|
|
#include <atomic>
|
|
#include <memory>
|
|
|
|
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<DiskNode> 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<DiskNode> m_tree;
|
|
ScanStats m_stats;
|
|
std::atomic_bool m_cancelled{false};
|
|
};
|