MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / addOrigin

Method addOrigin

src/shared/fileentry.cpp:18–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16{}
17
18void FileEntry::addOrigin(OriginID origin, FILETIME fileTime, std::wstring_view archive,
19 int order)
20{
21 std::scoped_lock lock(m_OriginsMutex);
22
23 if (m_Parent != nullptr) {
24 m_Parent->propagateOrigin(origin);
25 }
26
27 if (m_Origin == -1) {
28 // If this file has no previous origin, this mod is now the origin with no
29 // alternatives
30 m_Origin = origin;
31 m_FileTime = fileTime;
32 m_Archive = DataArchiveOrigin(std::wstring(archive.begin(), archive.end()), order);
33 } else if ((m_Parent != nullptr) &&
34 ((m_Parent->getOriginByID(origin).getPriority() >
35 m_Parent->getOriginByID(m_Origin).getPriority()) ||
36 (archive.size() == 0 && m_Archive.isValid()))) {
37 // If this mod has a higher priority than the origin mod OR
38 // this mod has a loose file and the origin mod has an archived file,
39 // this mod is now the origin and the previous origin is the first alternative
40
41 auto itor =
42 std::find_if(m_Alternatives.begin(), m_Alternatives.end(), [&](auto&& i) {
43 return i.originID() == m_Origin;
44 });
45
46 if (itor == m_Alternatives.end()) {
47 m_Alternatives.push_back({m_Origin, m_Archive});
48 }
49
50 m_Origin = origin;
51 m_FileTime = fileTime;
52 m_Archive = DataArchiveOrigin(std::wstring(archive.begin(), archive.end()), order);
53 } else {
54 // This mod is just an alternative
55 bool found = false;
56
57 if (m_Origin == origin) {
58 // already an origin
59 return;
60 }
61
62 for (auto iter = m_Alternatives.begin(); iter != m_Alternatives.end(); ++iter) {
63 if (iter->originID() == origin) {
64 // already an origin
65 return;
66 }
67
68 if ((m_Parent != nullptr) &&
69 (m_Parent->getOriginByID(iter->originID()).getPriority() <
70 m_Parent->getOriginByID(origin).getPriority())) {
71 m_Alternatives.insert(
72 iter, {origin, {std::wstring(archive.begin(), archive.end()), order}});
73 found = true;
74 break;
75 }

Callers 3

fileMovedMethod · 0.80
insertMethod · 0.80

Calls 9

DataArchiveOriginClass · 0.85
propagateOriginMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
getPriorityMethod · 0.45
sizeMethod · 0.45
isValidMethod · 0.45
originIDMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected