Porytiles
Loading...
Searching...
No Matches
artifact_checksum_provider.cpp
Go to the documentation of this file.
2
3#include <string>
4#include <unordered_map>
5#include <vector>
6
7namespace porytiles2 {
8
10 const std::string &tileset_name, const std::vector<ArtifactKey> &artifact_keys) const
11{
12 const auto checksums = compute_tileset_artifact_checksums(tileset_name);
13 const auto cached_checksums = load_cached_tileset_checksums(tileset_name);
14
15 std::vector<ArtifactKey> mismatched_keys;
16 for (const auto &key : artifact_keys) {
17 const auto checksum_for_key = checksums.contains(key) ? checksums.at(key) : "";
18 const auto cached_checksum_for_key = cached_checksums.contains(key) ? cached_checksums.at(key) : "";
19 // TODO: more specific error message if one of the above is actually empty?
20 if (checksum_for_key != cached_checksum_for_key) {
21 mismatched_keys.push_back(key);
22 }
23 }
24 return mismatched_keys;
25}
26
28 const std::string &tileset_name, const std::vector<ArtifactKey> &artifact_keys) const
29{
30 return find_unsynced_tileset_artifacts(tileset_name, artifact_keys).empty();
31}
32
33} // namespace porytiles2
virtual std::unordered_map< ArtifactKey, std::string > compute_tileset_artifact_checksums(const std::string &tileset_name) const =0
Computes checksums for the artifacts that belong to the given Tileset.
virtual std::vector< ArtifactKey > find_unsynced_tileset_artifacts(const std::string &tileset_name, const std::vector< ArtifactKey > &artifact_keys) const
Finds all artifacts for the given Tileset with unsynced changes compared to cached checksums.
virtual bool all_checksums_tileset_match(const std::string &tileset_name, const std::vector< ArtifactKey > &artifact_keys) const
Checks if all artifact checksums for the given Tileset match their cached values.
virtual std::unordered_map< ArtifactKey, std::string > load_cached_tileset_checksums(const std::string &tileset_name) const =0
Loads the cached checksums for the given Tileset.