MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / AddFile

Method AddFile

src/script/script_scanner.cpp:154–177  ·  view source on GitHub ↗

Add the file and calculate the md5 sum. */

Source from the content-addressed store, hash-verified

152
153 /* Add the file and calculate the md5 sum. */
154 bool AddFile(const std::string &filename, size_t, const std::string &) override
155 {
156 Md5 checksum;
157 uint8_t buffer[1024];
158 size_t len, size;
159
160 /* Open the file ... */
161 auto f = FioFOpenFile(filename, "rb", this->dir, &size);
162 if (!f.has_value()) return false;
163
164 /* ... calculate md5sum... */
165 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
166 size -= len;
167 checksum.Append(buffer, len);
168 }
169
170 MD5Hash tmp_md5sum;
171 checksum.Finish(tmp_md5sum);
172
173 /* ... and xor it to the overall md5sum. */
174 this->md5sum ^= tmp_md5sum;
175
176 return true;
177 }
178};
179
180/**

Callers

nothing calls this directly

Calls 3

FioFOpenFileFunction · 0.85
AppendMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected