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;
66 std::vector<QString> companions;
67
69 qint64 size{};
71 qint64 newSize{};
74 bool copyNeeded{};
75
77 QString note;
78};
79
80struct SCORE_LIB_PROCESS_EXPORT FileReport
81{
82 QString projectFolder;
83 std::vector<FileEntry> entries;
84
85 bool empty() const noexcept { return entries.empty(); }
86 int count(FileAction) const noexcept;
87 std::vector<const FileEntry*> with(FileAction) const noexcept;
88
90 qint64 bytesToCopy() const noexcept;
93 qint64 bytesSaved() const noexcept;
94};
95
99{
100 Consolidate,
101 Reanchor,
102 Relink,
103 Trim
104};
105
112using FilePolicy = std::function<QString(const ExternalFileRef&, FileEntry&)>;
113
122SCORE_LIB_PROCESS_EXPORT
124 const score::DocumentContext& ctx, const FilePolicy& policy, bool dryRun,
125 FileOperationKind kind = FileOperationKind::Consolidate);
126}
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:99
std::function< QString(const ExternalFileRef &, FileEntry &)> FilePolicy
Decides what happens to one reference.
Definition FileOperation.hpp:112
Base toolkit upon which the software is built.
Definition Application.cpp:83
FileKind
Definition ProjectFiles.hpp:17
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:77
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:71
bool copyNeeded
Definition FileOperation.hpp:74
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
std::vector< QString > companions
Definition FileOperation.hpp:66
qint64 size
Size of the source in bytes, companions included; 0 when unknown.
Definition FileOperation.hpp:69
QString owner
Human-readable name of the object holding the reference.
Definition FileOperation.hpp:63
Definition FileOperation.hpp:81
Definition DocumentContext.hpp:18