24#define fetch_metadata(name) \
25 item = metadata->GetItem(name); \
26 if (item == nullptr || !item->value.has_value() || item->value->empty()) { \
27 Debug(grf, 0, "Base {}set detail loading: {} field missing.", BaseSet::SET_TYPE, name); \
28 Debug(grf, 0, " Is {} readable for the user running OpenTTD?", full_filename); \
44 if (metadata ==
nullptr) {
46 Debug(grf, 0,
" Is {} readable for the user running OpenTTD?", full_filename);
52 this->name = *item->
value;
55 this->description[std::string{}] = *item->
value;
57 item = metadata->
GetItem(
"url");
58 if (item !=
nullptr) this->url = *item->
value;
62 if (titem.name.compare(0, 12,
"description.") != 0)
continue;
64 this->description[titem.name.substr(12)] = titem.value.value_or(
"");
68 for (uint i = 0; (*item->
value)[i] !=
'\0' && i < 4; i++) {
69 this->shortname |= ((uint8_t)(*item->
value)[i]) << (i * 8);
73 this->version = atoi(item->
value->c_str());
75 item = metadata->
GetItem(
"fallback");
76 this->fallback = (item !=
nullptr && item->
value && *item->
value !=
"0" && *item->
value !=
"false");
84 for (uint i = 0; i < BaseSet<T>::NUM_FILES; i++) {
85 MD5File *file = &this->files[i];
87 item = files !=
nullptr ? files->
GetItem(file_names[i]) :
nullptr;
88 if (item ==
nullptr || (!item->
value.has_value() && !allow_empty_filename)) {
93 if (!item->
value.has_value()) {
101 const std::string &filename = item->
value.value();
105 item = md5s !=
nullptr ? md5s->
GetItem(filename) :
nullptr;
106 if (item ==
nullptr || !item->
value.has_value()) {
107 Debug(grf, 0,
"No MD5 checksum specified for: {} (in {})", filename, full_filename);
110 const char *c = item->
value->c_str();
111 for (
size_t i = 0; i < file->
hash.size() * 2; i++, c++) {
113 if (
'0' <= *c && *c <=
'9') {
115 }
else if (
'a' <= *c && *c <=
'f') {
117 }
else if (
'A' <= *c && *c <=
'F') {
120 Debug(grf, 0,
"Malformed MD5 checksum specified for: {} (in {})", filename, full_filename);
124 file->
hash[i / 2] = j << 4;
126 file->
hash[i / 2] |= j;
131 item = origin !=
nullptr ? origin->
GetItem(filename) :
nullptr;
132 if (item ==
nullptr) item = origin !=
nullptr ? origin->
GetItem(
"default") :
nullptr;
133 if (item ==
nullptr || !item->
value.has_value()) {
134 Debug(grf, 1,
"No origin warning message specified for: {}", filename);
151 Debug(grf, 1,
"MD5 checksum mismatch for: {} (in {})", filename, full_filename);
156 Debug(grf, 1,
"The file {} specified in {} is missing", filename, full_filename);
164template <
class Tbase_set>
170 Tbase_set *set =
new Tbase_set();
172 std::string path{ filename, basepath_length };
175 auto psep = path.rfind(PATHSEPCHAR);
176 if (psep != std::string::npos) {
177 path.erase(psep + 1);
182 if (set->FillSetDetails(ini, path, filename)) {
183 Tbase_set *duplicate =
nullptr;
185 if (c->name == set->name || c->shortname == set->shortname) {
190 if (duplicate !=
nullptr) {
192 if ((duplicate->valid_files == set->valid_files && duplicate->version >= set->version) ||
193 duplicate->valid_files > set->valid_files) {
194 Debug(grf, 1,
"Not adding {} ({}) as base {} set (duplicate, {})", set->name, set->version,
196 duplicate->
valid_files > set->valid_files ?
"less valid files" :
"lower version");
201 while (*prev != duplicate) prev = &(*prev)->next;
204 set->next = duplicate->next;
207 set->CopyCompatibleConfig(*duplicate);
214 Debug(grf, 1,
"Removing {} ({}) as base {} set (duplicate, {})", duplicate->name, duplicate->version,
216 duplicate->
valid_files < set->valid_files ?
"less valid files" :
"lower version");
223 while (*last !=
nullptr) last = &(*last)->next;
243template <
class Tbase_set>
246 if (set ==
nullptr) {
260template <
class Tbase_set>
264 return SetSet(
nullptr);
268 if (name == s->name) {
280template <
class Tbase_set>
283 if (shortname == 0) {
284 return SetSet(
nullptr);
288 if (shortname == s->shortname) {
299template <
class Tbase_set>
304 fmt::format_to(output_iterator,
"{:>18}: {}", s->name, s->GetDescription({}));
305 int invalid = s->GetNumInvalid();
307 int missing = s->GetNumMissing();
309 fmt::format_to(output_iterator,
" ({} corrupt file{})\n", invalid, invalid == 1 ?
"" :
"s");
311 fmt::format_to(output_iterator,
" (unusable: {} missing file{})\n", missing, missing == 1 ?
"" :
"s");
314 fmt::format_to(output_iterator,
"\n");
317 fmt::format_to(output_iterator,
"\n");
324 for (; s !=
nullptr; s = s->next) {
325 if (s->GetNumMissing() != 0)
continue;
327 if (s->shortname != ci.
unique_id)
continue;
328 if (!md5sum)
return s->files[0].filename.c_str();
331 for (
const auto &file : s->files) {
334 if (md5 == ci.
md5sum)
return s->files[0].filename.c_str();
339template <
class Tbase_set>
350template <
class Tbase_set>
365template <
class Tbase_set>
371 if (s->GetNumMissing() != 0)
continue;
381template <
class Tbase_set>
386 if (index == 0)
return s;
396template <
class Tbase_set>
406template <
class Tbase_set>
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Error reporting related functions.
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Types related to reading/writing '*.ini' files.
Functions related to low-level strings.
Information about a single base set.
uint valid_files
Number of the files that could be found and are valid.
static std::span< const std::string_view > GetFilenames()
Get the internal names of the files in this set.
bool FillSetDetails(const IniFile &ini, const std::string &path, const std::string &full_filename, bool allow_empty_filename=true)
Read the set information from a loaded ini.
Container for all important information about a piece of content.
uint32_t unique_id
Unique ID; either GRF ID or shortname.
MD5Hash md5sum
The MD5 checksum.
Ini file that supports both loading and saving.
A group within an ini file.
const IniItem * GetItem(std::string_view name) const
Get the item with the given name.
std::list< IniItem > items
all items in the group
A single "line" in an ini file.
std::optional< std::string > value
The value of this item.
void LoadFromDisk(const std::string &filename, Subdirectory subdir)
Load the Ini file's data from the disk.
const IniGroup * GetGroup(std::string_view name) const
Get the group with the given name.
Structure holding filename and MD5 information about a single file.
std::string missing_warning
warning when this file is missing
ChecksumResult check_result
cached result of md5 check
@ CR_MATCH
The file did exist and the md5 checksum did match.
@ CR_MISMATCH
The file did exist, just the md5 checksum did not match.
@ CR_NO_FILE
The file did not exist.
@ CR_UNKNOWN
The file has not been checked yet.
MD5Hash hash
md5 sum of the file
std::string filename
filename
Basic types related to the content on the content server.