22 #define fetch_metadata(name) \ 23 item = metadata->GetItem(name, false); \ 24 if (item == nullptr || StrEmpty(item->value)) { \ 25 DEBUG(grf, 0, "Base " SET_TYPE "set detail loading: %s field missing.", name); \ 26 DEBUG(grf, 0, " Is %s readable for the user running OpenTTD?", full_filename); \ 38 template <
class T,
size_t Tnum_files,
bool Tsearch_in_tars>
51 for (
const IniItem *item = metadata->
item; item !=
nullptr; item = item->
next) {
52 if (strncmp(
"description.", item->
name, 12) != 0)
continue;
58 for (uint i = 0; item->
value[i] !=
'\0' && i < 4; i++) {
59 this->shortname |= ((uint8)item->
value[i]) << (i * 8);
63 this->version = atoi(item->
value);
65 item = metadata->
GetItem(
"fallback",
false);
66 this->fallback = (item !=
nullptr && strcmp(item->
value,
"0") != 0 && strcmp(item->
value,
"false") != 0);
72 for (uint i = 0; i < Tnum_files; i++) {
73 MD5File *file = &this->files[i];
76 if (item ==
nullptr || (item->
value ==
nullptr && !allow_empty_filename)) {
81 const char *filename = item->
value;
82 if (filename ==
nullptr) {
93 item = md5s->
GetItem(filename,
false);
94 if (item ==
nullptr || item->
value ==
nullptr) {
95 DEBUG(grf, 0,
"No MD5 checksum specified for: %s (in %s)", filename, full_filename);
98 char *c = item->
value;
99 for (uint i = 0; i <
sizeof(file->
hash) * 2; i++, c++) {
101 if (
'0' <= *c && *c <=
'9') {
103 }
else if (
'a' <= *c && *c <=
'f') {
105 }
else if (
'A' <= *c && *c <=
'F') {
108 DEBUG(grf, 0,
"Malformed MD5 checksum specified for: %s (in %s)", filename, full_filename);
112 file->
hash[i / 2] = j << 4;
114 file->
hash[i / 2] |= j;
119 item = origin->
GetItem(filename,
false);
120 if (item ==
nullptr) item = origin->
GetItem(
"default",
false);
121 if (item ==
nullptr) {
122 DEBUG(grf, 1,
"No origin warning message specified for: %s", filename);
139 DEBUG(grf, 1,
"MD5 checksum mismatch for: %s (in %s)", filename, full_filename);
144 DEBUG(grf, 1,
"The file %s specified in %s is missing", filename, full_filename);
152 template <
class Tbase_set>
156 DEBUG(grf, 1,
"Checking %s for base " SET_TYPE " set", filename);
158 Tbase_set *
set =
new Tbase_set();
160 char *path =
stredup(filename + basepath_length);
163 char *psep = strrchr(path, PATHSEPCHAR);
164 if (psep !=
nullptr) {
170 if (set->FillSetDetails(ini, path, filename)) {
171 Tbase_set *duplicate =
nullptr;
173 if (strcmp(c->name, set->name) == 0 || c->shortname ==
set->shortname) {
178 if (duplicate !=
nullptr) {
180 if ((duplicate->valid_files == set->valid_files && duplicate->version >= set->version) ||
181 duplicate->valid_files >
set->valid_files) {
182 DEBUG(grf, 1,
"Not adding %s (%i) as base " SET_TYPE " set (duplicate, %s)", set->name, set->version,
183 duplicate->valid_files > set->valid_files ?
"less valid files" :
"lower version");
188 while (*prev != duplicate) prev = &(*prev)->next;
191 set->next = duplicate->next;
198 DEBUG(grf, 1,
"Removing %s (%i) as base " SET_TYPE " set (duplicate, %s)", duplicate->name, duplicate->version,
199 duplicate->valid_files < set->valid_files ?
"less valid files" :
"lower version");
206 while (*last !=
nullptr) last = &(*last)->next;
212 DEBUG(grf, 1,
"Adding %s (%i) as base " SET_TYPE " set", set->name, set->version);
228 template <
class Tbase_set>
240 if (strcmp(name, s->name) == 0) {
255 template <
class Tbase_set>
260 p +=
seprintf(p, last,
"%18s: %s", s->name, s->GetDescription());
261 int invalid = s->GetNumInvalid();
263 int missing = s->GetNumMissing();
265 p +=
seprintf(p, last,
" (%i corrupt file%s)\n", invalid, invalid == 1 ?
"" :
"s");
267 p +=
seprintf(p, last,
" (unusable: %i missing file%s)\n", missing, missing == 1 ?
"" :
"s");
282 for (; s !=
nullptr; s = s->next) {
283 if (s->GetNumMissing() != 0)
continue;
285 if (s->shortname != ci->
unique_id)
continue;
286 if (!md5sum)
return s->files[0].filename;
289 memset(md5, 0,
sizeof(md5));
290 for (uint i = 0; i < Tbase_set::NUM_FILES; i++) {
291 for (uint j = 0; j <
sizeof(md5); j++) {
292 md5[j] ^= s->files[i].hash[j];
295 if (memcmp(md5, ci->
md5sum,
sizeof(md5)) == 0)
return s->files[0].filename;
300 template <
class Tbase_set>
311 template <
class Tbase_set>
326 template <
class Tbase_set>
332 if (s->GetNumMissing() != 0)
continue;
342 template <
class Tbase_set>
347 if (index == 0)
return s;
350 error(
"Base" SET_TYPE "::GetSet(): index %d out of range", index);
357 template <
class Tbase_set>
367 template <
class Tbase_set>
378 #define INSTANTIATE_BASE_MEDIA_METHODS(repl_type, set_type) \ 379 template const char *repl_type::ini_set; \ 380 template const char *repl_type::GetExtension(); \ 381 template bool repl_type::AddFile(const char *filename, size_t pathlength, const char *tar_filename); \ 382 template bool repl_type::HasSet(const struct ContentInfo *ci, bool md5sum); \ 383 template bool repl_type::SetSet(const char *name); \ 384 template char *repl_type::GetSetsList(char *p, const char *last); \ 385 template int repl_type::GetNumSets(); \ 386 template int repl_type::GetIndexOfUsedSet(); \ 387 template const set_type *repl_type::GetSet(int index); \ 388 template const set_type *repl_type::GetUsedSet(); \ 389 template bool repl_type::DetermineBestSet(); \ 390 template set_type *repl_type::GetAvailableSets(); \ 391 template const char *TryGetBaseSetFile(const ContentInfo *ci, bool md5sum, const set_type *s); A group within an ini file.
char *CDECL str_fmt(const char *str,...)
Format, "printf", into a newly allocated string.
uint32 unique_id
Unique ID; either GRF ID or shortname.
ChecksumResult check_result
cached result of md5 check
int CDECL seprintf(char *str, const char *last, const char *format,...)
Safer implementation of snprintf; same as snprintf except:
Structure holding filename and MD5 information about a single file.
Functions related to debugging.
IniItem * item
the first item in the group
#define SET_TYPE
The type of set we're replacing.
void CheckExternalFiles()
Checks whether the MD5 checksums of the files are correct.
IniGroup * GetGroup(const char *name, size_t len=0, bool create_new=true)
Get the group with the given name.
Subdirectory for all base data (base sets, intro game)
IniItem * next
The next item in this group.
The file did exist, just the md5 checksum did not match.
A single "line" in an ini file.
const char * missing_warning
warning when this file is missing
Functions related to low-level strings.
const char * filename
filename
void LoadFromDisk(const char *filename, Subdirectory subdir)
Load the Ini file's data from the disk.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
char * value
The value of this item.
Part of the network protocol handling content distribution.
Types related to reading/writing '*.ini' files.
byte md5sum[16]
The MD5 checksum.
#define DEBUG(name, level,...)
Output a line of debugging information.
Ini file that supports both loading and saving.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
The file did exist and the md5 checksum did match.
char * name
The name of this item.
bool FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename=true)
Read the set information from a loaded ini.
void CDECL error(const char *s,...)
Error handling for fatal non-user errors.
IniItem * GetItem(const char *name, bool create)
Get the item with the given name, and if it doesn't exist and create is true it creates a new item...
Information about a single base set.
The file has not been checked yet.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Container for all important information about a piece of content.
uint8 hash[16]
md5 sum of the file