Loading...
Searching...
No Matches
FileOperation.hpp
1#pragma once
2#include <Process/ExternalFiles.hpp>
3
4#include <score/tools/ProjectFiles.hpp>
5
6#include <QString>
7
8#include <score_lib_process_export.h>
9
10#include <functional>
11#include <vector>
12
13namespace score
14{
15struct DocumentContext;
16}
17
18namespace Process
19{
20
29enum class FileAction
30{
31 Unchanged,
32 Collect,
35 Relinked,
36 Trimmed,
37 Unused,
38 Removed,
39 Missing,
41 Skipped,
42 Failed
43};
44
45SCORE_LIB_PROCESS_EXPORT
46QString toString(FileAction) noexcept;
47
49{
51 QString storedPath;
53 QString sourcePath;
58
59 score::FileKind kind{};
60 FileUsage usage{};
63 QString owner;
64
66 qint64 size{};
68 qint64 newSize{};
71 bool copyNeeded{};
72
74 QString note;
75};
76
77struct SCORE_LIB_PROCESS_EXPORT FileReport
78{
79 QString projectFolder;
80 std::vector<FileEntry> entries;
81
82 bool empty() const noexcept { return entries.empty(); }
83 int count(FileAction) const noexcept;
84 std::vector<const FileEntry*> with(FileAction) const noexcept;
85
87 qint64 bytesToCopy() const noexcept;
90 qint64 bytesSaved() const noexcept;
91};
92
96{
97 Consolidate,
98 Reanchor,
99 Relink,
100 Trim
101};
102
109using FilePolicy = std::function<QString(const ExternalFileRef&, FileEntry&)>;
110
119SCORE_LIB_PROCESS_EXPORT
121 const score::DocumentContext& ctx, const FilePolicy& policy, bool dryRun,
122 FileOperationKind kind = FileOperationKind::Consolidate);
123}
Base classes and tools to implement processes and layers.
Definition JSONVisitor.hpp:1115
FileAction
What an operation decided about one file reference.
Definition FileOperation.hpp:30
@ Missing
Not found.
@ Relinked
Was missing, found elsewhere, repointed.
@ Unchanged
Seen, nothing to do.
@ Unused
Sitting in the project folder with nothing pointing at it.
@ Removed
Moved aside or deleted.
@ Unsupported
A folder, or something score has no way to relocate.
@ Failed
Attempted and did not work; note says why.
@ Skipped
In scope but declined; note says why.
@ Trimmed
Rewritten down to the part the document actually reads.
@ Collect
Copied into the project folder and repointed.
@ KeptInLibrary
Resolves through the user library and was left there.
@ AlreadyThere
Already inside the project; only the reference changed.
FileReport runFileOperation(const score::DocumentContext &ctx, const FilePolicy &policy, bool dryRun, FileOperationKind kind)
Run policy over every external file reference of a document.
Definition FileOperation.cpp:96
FileUsage
Whether the process reads the file or writes to it.
Definition ExternalFiles.hpp:28
FileOperationKind
Definition FileOperation.hpp:96
std::function< QString(const ExternalFileRef &, FileEntry &)> FilePolicy
Decides what happens to one reference.
Definition FileOperation.hpp:109
Base toolkit upon which the software is built.
Definition Application.cpp:116
FileKind
Definition ProjectFiles.hpp:15
One external file referenced by a document.
Definition ExternalFiles.hpp:35
Definition FileOperation.hpp:49
QString note
Why the operation skipped or failed, shown to the user as-is.
Definition FileOperation.hpp:74
QString newStoredPath
What the reference becomes in the document.
Definition FileOperation.hpp:57
qint64 newSize
Size of what was written, when it differs from the source (trimming).
Definition FileOperation.hpp:68
bool copyNeeded
Definition FileOperation.hpp:71
QString sourcePath
Absolute path it resolves to right now (empty when unresolved).
Definition FileOperation.hpp:53
QString destinationPath
Absolute path it was / will be written to (empty when nothing is written).
Definition FileOperation.hpp:55
QString storedPath
Reference exactly as the document stores it.
Definition FileOperation.hpp:51
qint64 size
Size of the source in bytes, 0 when unknown.
Definition FileOperation.hpp:66
QString owner
Human-readable name of the object holding the reference.
Definition FileOperation.hpp:63
Definition FileOperation.hpp:78
Definition DocumentContext.hpp:18