Mercurial > hg > openttd
changeset 15054:e4700adec3ee draft
(svn r19674) -Fix [FS#3774]: crash when the music/graphics metadata files were unreadable
author | rubidium <rubidium@openttd.org> |
---|---|
date | Mon, 19 Apr 2010 09:34:56 +0000 |
parents | 851a045406bc |
children | b44e510a2774 |
files | src/base_media_base.h src/base_media_func.h src/gfxinit.cpp src/music.cpp |
diffstat | 4 files changed, 17 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/base_media_base.h +++ b/src/base_media_base.h @@ -108,10 +108,11 @@ * Read the set information from a loaded ini. * @param ini the ini to read from * @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 * @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. @@ -238,7 +239,7 @@ struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, DATA_DIR> { 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. */ @@ -276,7 +277,7 @@ byte track_nr[NUM_SONGS_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 */
--- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -25,12 +25,13 @@ #define fetch_metadata(name) \ item = metadata->GetItem(name, false); \ 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; \ } 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)); @@ -70,7 +71,7 @@ /* Find the filename first. */ item = files->GetItem(BaseSet<T, Tnum_files, Tsubdir>::file_names[i], false); 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; } @@ -88,7 +89,7 @@ /* Then find the MD5 checksum */ item = md5s->GetItem(filename, false); 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; } char *c = item->value; @@ -101,7 +102,7 @@ } else if ('A' <= *c && *c <= 'F') { j = *c - 'A' + 10; } 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; } if (i % 2 == 0) { @@ -155,7 +156,7 @@ *path = '\0'; } - if (set->FillSetDetails(ini, path)) { + if (set->FillSetDetails(ini, path, filename)) { Tbase_set *duplicate = NULL; 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) {
--- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -202,9 +202,9 @@ 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) { IniGroup *metadata = ini->GetGroup("metadata"); IniItem *item; @@ -212,7 +212,7 @@ fetch_metadata("palette"); this->palette = (*item->value == 'D' || *item->value == 'd') ? PAL_DOS : PAL_WINDOWS; } - return true; + return ret; }
--- a/src/music.cpp +++ b/src/music.cpp @@ -57,9 +57,9 @@ 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) { this->num_available = 0; IniGroup *names = ini->GetGroup("names"); @@ -93,5 +93,5 @@ this->num_available++; } } - return true; + return ret; }