Changeset - r15044:862b76e20a87
[Not reviewed]
master
0 4 0
rubidium - 14 years ago 2010-04-19 09:34:56
rubidium@openttd.org
(svn r19674) -Fix [FS#3774]: crash when the music/graphics metadata files were unreadable
4 files changed with 17 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/base_media_base.h
Show inline comments
 
@@ -108,10 +108,11 @@ struct BaseSet {
 
	 * 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 @@ enum GraphicsFileType {
 
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 @@ struct MusicSet : BaseSet<MusicSet, NUM_
 
	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 */
src/base_media_func.h
Show inline comments
 
@@ -25,12 +25,13 @@ template <class Tbase_set> /* static */ 
 
#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 @@ bool BaseSet<T, Tnum_files, Tsubdir>::Fi
 
		/* 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 @@ bool BaseSet<T, Tnum_files, Tsubdir>::Fi
 
		/* 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 @@ bool BaseSet<T, Tnum_files, Tsubdir>::Fi
 
			} 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 @@ bool BaseMedia<Tbase_set>::AddFile(const
 
		*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) {
src/gfxinit.cpp
Show inline comments
 
@@ -202,9 +202,9 @@ void GfxLoadSprites()
 
	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 @@ bool GraphicsSet::FillSetDetails(IniFile
 
		fetch_metadata("palette");
 
		this->palette = (*item->value == 'D' || *item->value == 'd') ? PAL_DOS : PAL_WINDOWS;
 
	}
 
	return true;
 
	return ret;
 
}
 

	
 

	
src/music.cpp
Show inline comments
 
@@ -57,9 +57,9 @@ template <class Tbase_set>
 
	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 @@ bool MusicSet::FillSetDetails(IniFile *i
 
			this->num_available++;
 
		}
 
	}
 
	return true;
 
	return ret;
 
}
0 comments (0 inline, 0 general)