MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / validateChecksum

Method validateChecksum

src/OpenLoco/src/S5/SawyerStream.cpp:55–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55bool SawyerStreamReader::validateChecksum()
56{
57 auto valid = false;
58 auto backupPos = _stream.getPosition();
59 auto fileLength = static_cast<uint32_t>(_stream.getLength());
60 if (fileLength >= 4)
61 {
62 // Read checksum
63 uint32_t checksum;
64 _stream.setPosition(fileLength - 4);
65 _stream.read(&checksum, sizeof(checksum));
66
67 // Calculate checksum
68 uint32_t actualChecksum = 0;
69 _stream.setPosition(0);
70 uint8_t buffer[2048];
71 for (uint32_t i = 0; i < fileLength - 4; i += sizeof(buffer))
72 {
73 auto readLength = std::min<size_t>(sizeof(buffer), fileLength - 4 - i);
74 _stream.read(buffer, readLength);
75 for (size_t j = 0; j < readLength; j++)
76 {
77 actualChecksum += buffer[j];
78 }
79 }
80
81 valid = checksum == actualChecksum;
82 }
83
84 // Restore position
85 _stream.setPosition(backupPos);
86
87 return valid;
88}
89
90std::span<const std::byte> SawyerStreamReader::decode(SawyerEncoding encoding, std::span<const std::byte> data)
91{

Callers 4

uncompressFileFunction · 0.80
loadSaveFunction · 0.80
readSaveDetailsFunction · 0.80
readScenarioOptionsFunction · 0.80

Calls 4

getPositionMethod · 0.45
getLengthMethod · 0.45
setPositionMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected