25 #define fetch_metadata(name) \
26 item = metadata->GetItem(name); \
27 if (item == nullptr || !item->value.has_value() || item->value->empty()) { \
28 Debug(grf, 0, "Base " SET_TYPE "set detail loading: {} field missing.", name); \
29 Debug(grf, 0, " Is {} readable for the user running OpenTTD?", full_filename); \
41 template <
class T,
size_t Tnum_files,
bool Tsearch_in_tars>
45 if (metadata ==
nullptr) {
46 Debug(grf, 0,
"Base " SET_TYPE "set detail loading: metadata missing.");
47 Debug(grf, 0,
" Is {} readable for the user running OpenTTD?", full_filename);
53 this->name = *item->
value;
56 this->description[std::string{}] = *item->
value;
58 item = metadata->
GetItem(
"url");
59 if (item !=
nullptr) this->url = *item->
value;
63 if (titem.
name.compare(0, 12,
"description.") != 0)
continue;
65 this->description[titem.
name.substr(12)] = titem.
value.value_or(
"");
69 for (uint i = 0; (*item->
value)[i] !=
'\0' && i < 4; i++) {
70 this->shortname |= ((uint8_t)(*item->
value)[i]) << (i * 8);
74 this->version = atoi(item->
value->c_str());
76 item = metadata->
GetItem(
"fallback");
77 this->fallback = (item !=
nullptr && item->
value && *item->
value !=
"0" && *item->
value !=
"false");
83 for (uint i = 0; i < Tnum_files; i++) {
84 MD5File *file = &this->files[i];
87 if (item ==
nullptr || (!item->
value.has_value() && !allow_empty_filename)) {
92 if (!item->
value.has_value()) {
100 const std::string &filename = item->
value.value();
104 item = md5s !=
nullptr ? md5s->
GetItem(filename) :
nullptr;
105 if (item ==
nullptr || !item->
value.has_value()) {
106 Debug(grf, 0,
"No MD5 checksum specified for: {} (in {})", filename, full_filename);
109 const char *c = item->
value->c_str();
110 for (
size_t i = 0; i < file->
hash.size() * 2; i++, c++) {
112 if (
'0' <= *c && *c <=
'9') {
114 }
else if (
'a' <= *c && *c <=
'f') {
116 }
else if (
'A' <= *c && *c <=
'F') {
119 Debug(grf, 0,
"Malformed MD5 checksum specified for: {} (in {})", filename, full_filename);
123 file->
hash[i / 2] = j << 4;
125 file->
hash[i / 2] |= j;
130 item = origin !=
nullptr ? origin->
GetItem(filename) :
nullptr;
131 if (item ==
nullptr) item = origin !=
nullptr ? origin->
GetItem(
"default") :
nullptr;
132 if (item ==
nullptr || !item->
value.has_value()) {
133 Debug(grf, 1,
"No origin warning message specified for: {}", filename);
150 Debug(grf, 1,
"MD5 checksum mismatch for: {} (in {})", filename, full_filename);
155 Debug(grf, 1,
"The file {} specified in {} is missing", filename, full_filename);
163 template <
class Tbase_set>
167 Debug(grf, 1,
"Checking {} for base " SET_TYPE " set", filename);
169 Tbase_set *set =
new Tbase_set();
171 std::string path{ filename, basepath_length };
174 auto psep = path.rfind(PATHSEPCHAR);
175 if (psep != std::string::npos) {
176 path.erase(psep + 1);
181 if (set->FillSetDetails(ini, path, filename)) {
182 Tbase_set *duplicate =
nullptr;
184 if (c->name == set->name || c->shortname == set->shortname) {
189 if (duplicate !=
nullptr) {
191 if ((duplicate->valid_files == set->valid_files && duplicate->version >= set->version) ||
192 duplicate->valid_files > set->valid_files) {
193 Debug(grf, 1,
"Not adding {} ({}) as base " SET_TYPE " set (duplicate, {})", set->name, set->version,
194 duplicate->valid_files > set->valid_files ?
"less valid files" :
"lower version");
199 while (*prev != duplicate) prev = &(*prev)->next;
202 set->next = duplicate->next;
205 set->CopyCompatibleConfig(*duplicate);
212 Debug(grf, 1,
"Removing {} ({}) as base " SET_TYPE " set (duplicate, {})", duplicate->name, duplicate->version,
213 duplicate->valid_files < set->valid_files ?
"less valid files" :
"lower version");
220 while (*last !=
nullptr) last = &(*last)->next;
226 Debug(grf, 1,
"Adding {} ({}) as base " SET_TYPE " set", set->name, set->version);
240 template <
class Tbase_set>
243 if (set ==
nullptr) {
257 template <
class Tbase_set>
261 return SetSet(
nullptr);
265 if (name == s->name) {
277 template <
class Tbase_set>
280 if (shortname == 0) {
281 return SetSet(
nullptr);
285 if (shortname == s->shortname) {
296 template <
class Tbase_set>
299 fmt::format_to(output_iterator,
"List of " SET_TYPE " sets:\n");
301 fmt::format_to(output_iterator,
"{:>18}: {}", s->name, s->GetDescription({}));
302 int invalid = s->GetNumInvalid();
304 int missing = s->GetNumMissing();
306 fmt::format_to(output_iterator,
" ({} corrupt file{})\n", invalid, invalid == 1 ?
"" :
"s");
308 fmt::format_to(output_iterator,
" (unusable: {} missing file{})\n", missing, missing == 1 ?
"" :
"s");
311 fmt::format_to(output_iterator,
"\n");
314 fmt::format_to(output_iterator,
"\n");
321 for (; s !=
nullptr; s = s->next) {
322 if (s->GetNumMissing() != 0)
continue;
324 if (s->shortname != ci->
unique_id)
continue;
325 if (!md5sum)
return s->files[0].filename.c_str();
328 for (
const auto &file : s->files) {
331 if (md5 == ci->
md5sum)
return s->files[0].filename.c_str();
336 template <
class Tbase_set>
347 template <
class Tbase_set>
362 template <
class Tbase_set>
368 if (s->GetNumMissing() != 0)
continue;
378 template <
class Tbase_set>
383 if (index == 0)
return s;
386 FatalError(
"Base" SET_TYPE "::GetSet(): index {} out of range", index);
393 template <
class Tbase_set>
403 template <
class Tbase_set>
414 #define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \
415 template const char *repl_type::GetExtension(); \
416 template bool repl_type::AddFile(const std::string &filename, size_t pathlength, const std::string &tar_filename); \
417 template bool repl_type::HasSet(const struct ContentInfo *ci, bool md5sum); \
418 template bool repl_type::SetSet(const set_type *set); \
419 template bool repl_type::SetSetByName(const std::string &name); \
420 template bool repl_type::SetSetByShortname(uint32_t shortname); \
421 template void repl_type::GetSetsList(std::back_insert_iterator<std::string> &output_iterator); \
422 template int repl_type::GetNumSets(); \
423 template int repl_type::GetIndexOfUsedSet(); \
424 template const set_type *repl_type::GetSet(int index); \
425 template const set_type *repl_type::GetUsedSet(); \
426 template bool repl_type::DetermineBestSet(); \
427 template set_type *repl_type::GetAvailableSets(); \
428 template const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const set_type *s);
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut 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.
#define SET_TYPE
The type of set we're replacing.
Functions related to low-level strings.
Information about a single base 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.
std::string name
The name 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
@ 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.
ChecksumResult check_result
cached result of md5 check
MD5Hash hash
md5 sum of the file
std::string filename
filename
Basic types related to the content on the content server.