MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / VersioningDatabase

Method VersioningDatabase

source/game/StarVersioningDatabase.cpp:84–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84VersioningDatabase::VersioningDatabase() {
85 auto assets = Root::singleton().assets();
86
87 for (auto const& pair : assets->json("/versioning.config").iterateObject())
88 m_currentVersions[pair.first] = pair.second.toUInt();
89
90 for (auto const& scriptFile : assets->scan("/versioning/", ".lua")) {
91 try {
92 auto scriptParts = File::baseName(scriptFile).splitAny("_.");
93 if (scriptParts.size() != 4)
94 throw VersioningDatabaseException::format("Script file '{}' filename not of the form <identifier>_<fromversion>_<toversion>.lua", scriptFile);
95
96 String identifier = scriptParts.at(0);
97 VersionNumber fromVersion = lexicalCast<VersionNumber>(scriptParts.at(1));
98 VersionNumber toVersion = lexicalCast<VersionNumber>(scriptParts.at(2));
99
100 m_versionUpdateScripts[identifier.toLower()].append({scriptFile, fromVersion, toVersion});
101 } catch (StarException const&) {
102 throw VersioningDatabaseException::format("Error parsing version information from versioning script '{}'", scriptFile);
103 }
104 }
105
106 // Sort each set of update scripts first by fromVersion, and then in
107 // *reverse* order of toVersion. This way, the first matching script for a
108 // given fromVersion should take the json to the *furthest* toVersion.
109 for (auto& pair : m_versionUpdateScripts) {
110 pair.second.sort([](VersionUpdateScript const& lhs, VersionUpdateScript const& rhs) {
111 if (lhs.fromVersion != rhs.fromVersion)
112 return lhs.fromVersion < rhs.fromVersion;
113 else
114 return lhs.toVersion < rhs.toVersion;
115 });
116 }
117}
118
119VersionedJson VersioningDatabase::makeCurrentVersionedJson(String const& identifier, Json const& content) const {
120 RecursiveMutexLocker locker(m_mutex);

Callers

nothing calls this directly

Calls 13

singletonClass · 0.85
assetsMethod · 0.80
iterateObjectMethod · 0.80
jsonMethod · 0.80
toUIntMethod · 0.80
splitAnyMethod · 0.80
toLowerMethod · 0.80
formatFunction · 0.50
scanMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected