1
0
Fork 0

(svn r19674) -Fix [FS#3774]: crash when the music/graphics metadata files were unreadable

release/1.1
rubidium 2010-04-19 09:34:56 +00:00
parent 3442b8c345
commit 83e40b8ced
4 changed files with 17 additions and 15 deletions

View File

@ -108,10 +108,11 @@ struct BaseSet {
* Read the set information from a loaded ini. * Read the set information from a loaded ini.
* @param ini the ini to read from * @param ini the ini to read from
* @param path the path to this ini file (for filenames) * @param path the path to this ini file (for filenames)
* @param full_filename the full filename of the loaded file (for error reporting purposes)
* @param allow_empty_filename empty filenames are valid * @param allow_empty_filename empty filenames are valid
* @return true if loading was successful. * @return true if loading was successful.
*/ */
bool FillSetDetails(IniFile *ini, const char *path, bool allow_empty_filename = true); bool FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename = true);
/** /**
* Get the description for the given ISO code. * Get the description for the given ISO code.
@ -238,7 +239,7 @@ enum GraphicsFileType {
struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, DATA_DIR> { struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, DATA_DIR> {
PaletteType palette; ///< Palette of this graphics set PaletteType palette; ///< Palette of this graphics set
bool FillSetDetails(struct IniFile *ini, const char *path); bool FillSetDetails(struct IniFile *ini, const char *path, const char *full_filename);
}; };
/** All data/functions related with replacing the base graphics. */ /** All data/functions related with replacing the base graphics. */
@ -276,7 +277,7 @@ struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, GM_DIR> {
byte track_nr[NUM_SONGS_AVAILABLE]; byte track_nr[NUM_SONGS_AVAILABLE];
byte num_available; byte num_available;
bool FillSetDetails(struct IniFile *ini, const char *path); bool FillSetDetails(struct IniFile *ini, const char *path, const char *full_filename);
}; };
/** All data/functions related with replacing the base music */ /** All data/functions related with replacing the base music */

View File

@ -25,12 +25,13 @@ template <class Tbase_set> /* static */ Tbase_set *BaseMedia<Tbase_set>::availab
#define fetch_metadata(name) \ #define fetch_metadata(name) \
item = metadata->GetItem(name, false); \ item = metadata->GetItem(name, false); \
if (item == NULL || StrEmpty(item->value)) { \ if (item == NULL || StrEmpty(item->value)) { \
DEBUG(grf, 0, "Base " SET_TYPE "set detail loading: %s field missing", name); \ DEBUG(grf, 0, "Base " SET_TYPE "set detail loading: %s field missing.", name); \
DEBUG(grf, 0, " Is %s readable for the user running OpenTTD?", full_filename); \
return false; \ return false; \
} }
template <class T, size_t Tnum_files, Subdirectory Tsubdir> template <class T, size_t Tnum_files, Subdirectory Tsubdir>
bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *path, bool allow_empty_filename) bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename)
{ {
memset(this, 0, sizeof(*this)); memset(this, 0, sizeof(*this));
@ -70,7 +71,7 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
/* Find the filename first. */ /* Find the filename first. */
item = files->GetItem(BaseSet<T, Tnum_files, Tsubdir>::file_names[i], false); item = files->GetItem(BaseSet<T, Tnum_files, Tsubdir>::file_names[i], false);
if (item == NULL || (item->value == NULL && !allow_empty_filename)) { if (item == NULL || (item->value == NULL && !allow_empty_filename)) {
DEBUG(grf, 0, "No " SET_TYPE " file for: %s", BaseSet<T, Tnum_files, Tsubdir>::file_names[i]); DEBUG(grf, 0, "No " SET_TYPE " file for: %s (in %s)", BaseSet<T, Tnum_files, Tsubdir>::file_names[i], full_filename);
return false; return false;
} }
@ -88,7 +89,7 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
/* Then find the MD5 checksum */ /* Then find the MD5 checksum */
item = md5s->GetItem(filename, false); item = md5s->GetItem(filename, false);
if (item == NULL) { if (item == NULL) {
DEBUG(grf, 0, "No MD5 checksum specified for: %s", filename); DEBUG(grf, 0, "No MD5 checksum specified for: %s (in %s)", filename, full_filename);
return false; return false;
} }
char *c = item->value; char *c = item->value;
@ -101,7 +102,7 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
} else if ('A' <= *c && *c <= 'F') { } else if ('A' <= *c && *c <= 'F') {
j = *c - 'A' + 10; j = *c - 'A' + 10;
} else { } else {
DEBUG(grf, 0, "Malformed MD5 checksum specified for: %s", filename); DEBUG(grf, 0, "Malformed MD5 checksum specified for: %s (in %s)", filename, full_filename);
return false; return false;
} }
if (i % 2 == 0) { if (i % 2 == 0) {
@ -155,7 +156,7 @@ bool BaseMedia<Tbase_set>::AddFile(const char *filename, size_t basepath_length)
*path = '\0'; *path = '\0';
} }
if (set->FillSetDetails(ini, path)) { if (set->FillSetDetails(ini, path, filename)) {
Tbase_set *duplicate = NULL; Tbase_set *duplicate = NULL;
for (Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != NULL; c = c->next) { for (Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != NULL; c = c->next) {
if (strcmp(c->name, set->name) == 0 || c->shortname == set->shortname) { if (strcmp(c->name, set->name) == 0 || c->shortname == set->shortname) {

View File

@ -202,9 +202,9 @@ void GfxLoadSprites()
GfxInitPalettes(); GfxInitPalettes();
} }
bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path) bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
{ {
bool ret = this->BaseSet<GraphicsSet, MAX_GFT, DATA_DIR>::FillSetDetails(ini, path, false); bool ret = this->BaseSet<GraphicsSet, MAX_GFT, DATA_DIR>::FillSetDetails(ini, path, full_filename, false);
if (ret) { if (ret) {
IniGroup *metadata = ini->GetGroup("metadata"); IniGroup *metadata = ini->GetGroup("metadata");
IniItem *item; IniItem *item;
@ -212,7 +212,7 @@ bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path)
fetch_metadata("palette"); fetch_metadata("palette");
this->palette = (*item->value == 'D' || *item->value == 'd') ? PAL_DOS : PAL_WINDOWS; this->palette = (*item->value == 'D' || *item->value == 'd') ? PAL_DOS : PAL_WINDOWS;
} }
return true; return ret;
} }

View File

@ -57,9 +57,9 @@ template <class Tbase_set>
return BaseMedia<Tbase_set>::used_set != NULL; return BaseMedia<Tbase_set>::used_set != NULL;
} }
bool MusicSet::FillSetDetails(IniFile *ini, const char *path) bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
{ {
bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, GM_DIR>::FillSetDetails(ini, path); bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, GM_DIR>::FillSetDetails(ini, path, full_filename);
if (ret) { if (ret) {
this->num_available = 0; this->num_available = 0;
IniGroup *names = ini->GetGroup("names"); IniGroup *names = ini->GetGroup("names");
@ -93,5 +93,5 @@ bool MusicSet::FillSetDetails(IniFile *ini, const char *path)
this->num_available++; this->num_available++;
} }
} }
return true; return ret;
} }