Loading...
Searching...
No Matches
MissingFiles.hpp
1#pragma once
2#include <Process/FileOperation.hpp>
3
4#include <QHash>
5#include <QMultiHash>
6#include <QString>
7
8#include <score_lib_process_export.h>
9
10#include <atomic>
11#include <functional>
12#include <memory>
13#include <mutex>
14#include <vector>
15
16class QObject;
17
18namespace score
19{
20struct DocumentContext;
21}
22
23namespace Process
24{
25
34SCORE_LIB_PROCESS_EXPORT
35FileReport scanMissingFiles(const score::DocumentContext& ctx);
36
45class FileScan;
46
47class SCORE_LIB_PROCESS_EXPORT FileIndex
48{
49public:
52 void scan(const QString& folder, FileScan* progress = nullptr);
53
56 std::vector<QString> candidates(const QString& missingPath, qint64 size = -1) const;
57
58 int fileCount() const noexcept { return int(m_byName.size()); }
59 const QString& root() const noexcept { return m_root; }
60
61private:
62 QString m_root;
64 QMultiHash<QString, QString> m_byName;
65};
66
74class SCORE_LIB_PROCESS_EXPORT FileScan
75{
76public:
78 using OnFinished = std::function<void(FileIndex, bool cancelled)>;
79
80 explicit FileScan(QString folder);
81
84 static std::shared_ptr<FileScan>
85 start(const QString& folder, QObject* context, OnFinished onFinished);
86
87 void cancel() noexcept { m_cancelled.store(true, std::memory_order_relaxed); }
88 bool cancelled() const noexcept
89 {
90 return m_cancelled.load(std::memory_order_relaxed);
91 }
92
93 int filesSeen() const noexcept { return m_filesSeen.load(std::memory_order_relaxed); }
95 QString currentFolder() const;
96
97 const QString& root() const noexcept { return m_root; }
98
99private:
100 friend class FileIndex;
101 void fileSeen() noexcept { m_filesSeen.fetch_add(1, std::memory_order_relaxed); }
102 void setCurrentFolder(const QString& folder);
103
104 QString m_root;
105 mutable std::mutex m_mutex;
106 QString m_currentFolder;
107 std::atomic_int m_filesSeen{};
108 std::atomic_bool m_cancelled{};
109};
110
122SCORE_LIB_PROCESS_EXPORT
123FileReport relinkFiles(
124 const score::DocumentContext& ctx, const QHash<QString, QString>& chosen);
125}
Definition MissingFiles.hpp:48
A folder walk running on the task pool, and the handle to it.
Definition MissingFiles.hpp:75
std::function< void(FileIndex, bool cancelled)> OnFinished
Called on context's thread when the walk ends, cancelled or not.
Definition MissingFiles.hpp:78
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
FileReport relinkFiles(const score::DocumentContext &ctx, const QHash< QString, QString > &chosen)
Repoint references at the files they were found at.
Definition MissingFiles.cpp:165
FileReport scanMissingFiles(const score::DocumentContext &ctx)
Everything the document references and cannot find right now.
Definition MissingFiles.cpp:19
Base toolkit upon which the software is built.
Definition Application.cpp:83
Definition DocumentContext.hpp:18