Changeset - r22912:55c82c991a10
[Not reviewed]
master
0 3 0
Niels Martin Hansen - 6 years ago 2018-06-07 19:34:24
nielsm@indvikleren.dk
Fix: Don't complain if CAT music files are missing entirely

Just complain if an index into a CAT file that exists is invalid.
3 files changed with 7 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/base_media_base.h
Show inline comments
 
@@ -17,32 +17,34 @@
 
#include "gfx_type.h"
 
#include "textfile_type.h"
 
#include "textfile_gui.h"
 

	
 
/* Forward declare these; can't do 'struct X' in functions as older GCCs barf on that */
 
struct IniFile;
 
struct ContentInfo;
 

	
 
/** Structure holding filename and MD5 information about a single file */
 
struct MD5File {
 
	/** The result of a checksum check */
 
	enum ChecksumResult {
 
		CR_UNKNOWN,  ///< The file has not been checked yet
 
		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
 
	};
 

	
 
	const char *filename;        ///< filename
 
	uint8 hash[16];              ///< md5 sum of the file
 
	const char *missing_warning; ///< warning when this file is missing
 
	ChecksumResult check_result; ///< cached result of md5 check
 

	
 
	ChecksumResult CheckMD5(Subdirectory subdir, size_t max_size) const;
 
};
 

	
 
/**
 
 * Information about a single base set.
 
 * @tparam T the real class we're going to be
 
 * @tparam Tnum_files the number of files in the set
 
 * @tparam Tsearch_in_tars whether to search in the tars or not
 
 */
 
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
 
struct BaseSet {
src/base_media_func.h
Show inline comments
 
@@ -120,25 +120,26 @@ bool BaseSet<T, Tnum_files, Tsearch_in_t
 
		}
 

	
 
		/* Then find the warning message when the file's missing */
 
		item = origin->GetItem(filename, false);
 
		if (item == NULL) item = origin->GetItem("default", false);
 
		if (item == NULL) {
 
			DEBUG(grf, 1, "No origin warning message specified for: %s", filename);
 
			file->missing_warning = stredup("");
 
		} else {
 
			file->missing_warning = stredup(item->value);
 
		}
 

	
 
		switch (T::CheckMD5(file, BASESET_DIR)) {
 
		file->check_result = T::CheckMD5(file, BASESET_DIR);
 
		switch (file->check_result) {
 
			case MD5File::CR_MATCH:
 
				this->valid_files++;
 
				this->found_files++;
 
				break;
 

	
 
			case MD5File::CR_MISMATCH:
 
				DEBUG(grf, 1, "MD5 checksum mismatch for: %s (in %s)", filename, full_filename);
 
				this->found_files++;
 
				break;
 

	
 
			case MD5File::CR_NO_FILE:
 
				DEBUG(grf, 1, "The file %s specified in %s is missing", filename, full_filename);
src/music.cpp
Show inline comments
 
@@ -119,40 +119,41 @@ template <class Tbase_set>
 
}
 

	
 
bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
 
{
 
	bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false>::FillSetDetails(ini, path, full_filename);
 
	if (ret) {
 
		this->num_available = 0;
 
		IniGroup *names = ini->GetGroup("names");
 
		IniGroup *catindex = ini->GetGroup("catindex");
 
		IniGroup *timingtrim = ini->GetGroup("timingtrim");
 
		for (uint i = 0, j = 1; i < lengthof(this->songinfo); i++) {
 
			const char *filename = this->files[i].filename;
 
			if (names == NULL || StrEmpty(filename)) {
 
			if (names == NULL || StrEmpty(filename) || this->files[i].check_result == MD5File::CR_NO_FILE) {
 
				this->songinfo[i].songname[0] = '\0';
 
				continue;
 
			}
 

	
 
			this->songinfo[i].filename = filename; // non-owned pointer
 

	
 
			IniItem *item = catindex->GetItem(_music_file_names[i], false);
 
			if (item != NULL && !StrEmpty(item->value)) {
 
				/* Song has a CAT file index, assume it's MPS MIDI format */
 
				this->songinfo[i].filetype = MTT_MPSMIDI;
 
				this->songinfo[i].cat_index = atoi(item->value);
 
				char *songname = GetMusicCatEntryName(filename, this->songinfo[i].cat_index);
 
				if (songname == NULL) {
 
					DEBUG(grf, 0, "Base music set song missing from CAT file: %s/%d", filename, this->songinfo[i].cat_index);
 
					return false;
 
					this->songinfo[i].songname[0] = '\0';
 
					continue;
 
				}
 
				strecpy(this->songinfo[i].songname, songname, lastof(this->songinfo[i].songname));
 
				free(songname);
 
			} else {
 
				this->songinfo[i].filetype = MTT_STANDARDMIDI;
 
			}
 

	
 
			const char *trimmed_filename = filename;
 
			/* As we possibly add a path to the filename and we compare
 
			 * on the filename with the path as in the .obm, we need to
 
			 * keep stripping path elements until we find a match. */
 
			for (; trimmed_filename != NULL; trimmed_filename = strchr(trimmed_filename, PATHSEPCHAR)) {
0 comments (0 inline, 0 general)