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

Method AddFile

src/fios.cpp:623–652  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

621 }
622
623 bool AddFile(const std::string &filename, size_t, const std::string &) override
624 {
625 auto f = FioFOpenFile(filename, "r", SCENARIO_DIR);
626 if (!f.has_value()) return false;
627
628 ScenarioIdentifier id;
629 int fret = fscanf(*f, "%u", &id.scenid);
630 if (fret != 1) return false;
631 id.filename = filename;
632
633 Md5 checksum;
634 uint8_t buffer[1024];
635 size_t len, size;
636
637 /* open the scenario file, but first get the name.
638 * This is safe as we check on extension which
639 * must always exist. */
640 f = FioFOpenFile(filename.substr(0, filename.rfind('.')), "rb", SCENARIO_DIR, &size);
641 if (!f.has_value()) return false;
642
643 /* calculate md5sum */
644 while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, *f)) != 0 && size != 0) {
645 size -= len;
646 checksum.Append(buffer, len);
647 }
648 checksum.Finish(id.md5sum);
649
650 include(*this, id);
651 return true;
652 }
653};
654
655/** Scanner for scenarios */

Callers

nothing calls this directly

Calls 5

FioFOpenFileFunction · 0.85
includeFunction · 0.85
substrMethod · 0.80
AppendMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected