Changeset - r7841:0e193e9f1f5b
[Not reviewed]
master
1 2 0
rubidium - 17 years ago 2007-11-07 23:29:43
rubidium@openttd.org
(svn r11391) -Change: print all error messages related to missing/corrupted files in one message including the location where they can get said missing/corrupted files.
3 files changed with 83 insertions and 59 deletions:
0 comments (0 inline, 0 general)
bin/data/dosdummy.grf
Show inline comments
 
deleted file
 
binary diff not shown
src/gfxinit.cpp
Show inline comments
 
@@ -22,13 +22,13 @@
 
struct MD5File {
 
	const char * filename;     ///< filename
 
	md5_byte_t hash[16];       ///< md5 sum of the file
 
};
 

	
 
struct FileList {
 
	MD5File basic[4];          ///< grf files that always have to be loaded
 
	MD5File basic[2];          ///< grf files that always have to be loaded
 
	MD5File landscape[3];      ///< landscape specific grf files
 
};
 

	
 
#include "table/files.h"
 
#include "table/landscape_sprite.h"
 

	
 
@@ -50,13 +50,13 @@ static const SpriteID * const _halftile_
 
	_halftile_foundation_spriteindexes_1,
 
	_halftile_foundation_spriteindexes_2,
 
	_halftile_foundation_spriteindexes_3,
 
};
 

	
 

	
 
static uint LoadGrfFile(const char* filename, uint load_index, int file_index)
 
static uint LoadGrfFile(const char *filename, uint load_index, int file_index)
 
{
 
	uint load_index_org = load_index;
 
	uint sprite_id = 0;
 

	
 
	FioOpenFile(file_index, filename);
 

	
 
@@ -107,23 +107,18 @@ static void LoadGrfIndexed(const char* f
 
	DEBUG(sprite, 2, "Reading indexed grf-file '%s'", filename);
 

	
 
	LoadSpritesIndexed(file_index, &sprite_id, index_tbl);
 
}
 

	
 

	
 
/* Check that the supplied MD5 hash matches that stored for the supplied filename */
 
static bool CheckMD5Digest(const MD5File file, md5_byte_t *digest, bool warn)
 
{
 
	if (memcmp(file.hash, digest, sizeof(file.hash)) == 0) return true;
 
	if (warn) fprintf(stderr, "MD5 of %s is ****INCORRECT**** - File Corrupt.\n", file.filename);
 
	return false;
 
}
 

	
 
/* Calculate and check the MD5 hash of the supplied filename.
 
 * returns true if the checksum is correct */
 
static bool FileMD5(const MD5File file, bool warn)
 
/**
 
 * Calculate and check the MD5 hash of the supplied filename.
 
 * @param file filename and expected MD5 hash for the given filename.
 
 * @return true if the checksum is correct.
 
 */
 
static bool FileMD5(const MD5File file)
 
{
 
	size_t size;
 
	FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
 

	
 
	if (f != NULL) {
 
		md5_state_t filemd5state;
 
@@ -134,67 +129,92 @@ static bool FileMD5(const MD5File file, 
 
		md5_init(&filemd5state);
 
		while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
 
			size -= len;
 
			md5_append(&filemd5state, buffer, len);
 
		}
 

	
 
		if (ferror(f) && warn) ShowInfoF("Error Reading from %s \n", file.filename);
 
		FioFCloseFile(f);
 

	
 
		md5_finish(&filemd5state, digest);
 
		return CheckMD5Digest(file, digest, warn);
 
		return memcmp(file.hash, digest, sizeof(file.hash)) == 0;
 
	} else { // file not found
 
		return false;
 
	}
 
}
 

	
 
/* Checks, if either the Windows files exist (TRG1R.GRF) or the DOS files (TRG1.GRF)
 
 * by comparing the MD5 checksums of the files. _use_dos_palette is set accordingly.
 
 * If neither are found, Windows palette is assumed.
 
 *
 
 * (Note: Also checks sample.cat for corruption) */
 
void CheckExternalFiles()
 
/**
 
 * Determine the palette that has to be used.
 
 *  - forced DOS palette via command line -> leave it that way
 
 *  - all Windows files present -> Windows palette
 
 *  - all DOS files present -> DOS palette
 
 *  - no Windows files present and any DOS file present -> DOS palette
 
 *  - otherwise -> Windows palette
 
 */
 
static void DeterminePalette()
 
{
 
	uint i;
 
	/* count of files from this version */
 
	if (_use_dos_palette) return;
 

	
 
	/* Count of files from the different versions. */
 
	uint dos = 0;
 
	uint win = 0;
 

	
 
	for (i = 0; i < 2; i++) if (FileMD5(files_dos.basic[i], true)) dos++;
 
	for (i = 0; i < 3; i++) if (FileMD5(files_dos.landscape[i], true)) dos++;
 

	
 
	for (i = 0; i < 2; i++) if (FileMD5(files_win.basic[i], true)) win++;
 
	for (i = 0; i < 3; i++) if (FileMD5(files_win.landscape[i], true)) win++;
 

	
 
	if (!FileMD5(sample_cat_win, false) && !FileMD5(sample_cat_dos, false))
 
		ShowInfo("Your 'sample.cat' file is corrupted or missing!");
 
	for (uint i = 0; i < lengthof(files_dos.basic); i++) if (FioCheckFileExists(files_dos.basic[i].filename)) dos++;
 
	for (uint i = 0; i < lengthof(files_dos.landscape); i++) if (FioCheckFileExists(files_dos.landscape[i].filename)) dos++;
 

	
 
	for (i = 0; i < lengthof(files_openttd); i++) {
 
		if (!FileMD5(files_openttd[i], false)) {
 
			ShowInfoF("Your '%s' file is corrupted or missing!", files_openttd[i].filename);
 
		}
 
	}
 
	for (uint i = 0; i < lengthof(files_win.basic); i++) if (FioCheckFileExists(files_win.basic[i].filename)) win++;
 
	for (uint i = 0; i < lengthof(files_win.landscape); i++) if (FioCheckFileExists(files_win.landscape[i].filename)) win++;
 

	
 
	/*
 
	 * forced DOS palette via command line -> leave it that way
 
	 * all Windows files present -> Windows palette
 
	 * all DOS files present -> DOS palette
 
	 * no Windows files present and any DOS file present -> DOS palette
 
	 * otherwise -> Windows palette
 
	 */
 
	if (_use_dos_palette) {
 
		return;
 
	} else if (win == 5) {
 
	if (win == 5) {
 
		_use_dos_palette = false;
 
	} else if (dos == 5 || (win == 0 && dos > 0)) {
 
		_use_dos_palette = true;
 
	} else {
 
		_use_dos_palette = false;
 
	}
 
}
 

	
 
/**
 
 * Checks whether the MD5 checksums of the files are correct.
 
 *
 
 * @note Also checks sample.cat and other required non-NewGRF GRFs for corruption.
 
 */
 
void CheckExternalFiles()
 
{
 
	DeterminePalette();
 

	
 
	static const size_t ERROR_MESSAGE_LENGTH = 128;
 
	const FileList *files = _use_dos_palette ? &files_dos : &files_win;
 
	char error_msg[ERROR_MESSAGE_LENGTH * (lengthof(files->basic) + lengthof(files->landscape) + lengthof(files_openttd) + 1)];
 
	error_msg[0] = '\0';
 
	char *add_pos = error_msg;
 

	
 
	for (uint i = 0; i < lengthof(files->basic); i++) {
 
		if (!FileMD5(files->basic[i])) {
 
			add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! You can find '%s' on your Transport Tycoon Deluxe CD-ROM.\n", files->basic[i].filename, files->basic[i].filename);
 
		}
 
	}
 

	
 
	for (uint i = 0; i < lengthof(files->landscape); i++) {
 
		if (!FileMD5(files->landscape[i])) {
 
			add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! You can find '%s' on your Transport Tycoon Deluxe CD-ROM.\n", files->landscape[i].filename, files->landscape[i].filename);
 
		}
 
	}
 

	
 
	if (!FileMD5(sample_cat_win) && !FileMD5(sample_cat_dos)) {
 
		add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your 'sample.cat' file is corrupted or missing! You can find 'sample.cat' on your Transport Tycoon Deluxe CD-ROM.\n");
 
	}
 

	
 
	for (uint i = 0; i < lengthof(files_openttd); i++) {
 
		if (!FileMD5(files_openttd[i])) {
 
			add_pos += snprintf(add_pos, ERROR_MESSAGE_LENGTH, "Your '%s' file is corrupted or missing! The file was part of your installation.\n", files_openttd[i].filename);
 
		}
 
	}
 

	
 
	if (add_pos != error_msg) ShowInfoF(error_msg);
 
}
 

	
 

	
 
static const SpriteID trg1idx[] = {
 
	   0,    1, ///< Mouse cursor, ZZZ
 
/* Medium font */
 
	   2,   92, ///< ' ' till 'z'
 
	SKIP,   36,
 
@@ -329,36 +349,44 @@ static const SpriteID _openttd_grf_index
 
	END
 
};
 

	
 

	
 
static void LoadSpriteTables()
 
{
 
	const FileList* files = _use_dos_palette ? &files_dos : &files_win;
 
	const FileList *files = _use_dos_palette ? &files_dos : &files_win;
 
	uint load_index;
 
	uint i = FIRST_GRF_SLOT;
 

	
 
	LoadGrfIndexed(files->basic[0].filename, trg1idx, i++);
 
	DupSprite(  2, 130); // non-breaking space medium
 
	DupSprite(226, 354); // non-breaking space tiny
 
	DupSprite(450, 578); // non-breaking space large
 
	load_index = 4793;
 

	
 
	for (uint j = 1; files->basic[j].filename != NULL; j++) {
 
		load_index += LoadGrfFile(files->basic[j].filename, load_index, i++);
 
	}
 
	/*
 
	 * The second basic file always starts at the given location and does
 
	 * contain a different amount of sprites depending on the "type"; DOS
 
	 * has a few sprites less. However, we do not care about those missing
 
	 * sprites as they are not shown anyway (logos in intro game).
 
	 */
 
	LoadGrfFile(files->basic[1].filename, 4793, i++);
 

	
 
	/* Load additional sprites for climates other than temperate */
 
	/*
 
	 * Load additional sprites for climates other than temperate.
 
	 * This overwrites some of the temperate sprites, such as foundations
 
	 * and the ground sprites.
 
	 */
 
	if (_opt.landscape != LT_TEMPERATE) {
 
		LoadGrfIndexed(
 
			files->landscape[_opt.landscape - 1].filename,
 
			_landscape_spriteindexes[_opt.landscape - 1],
 
			i++
 
		);
 
	}
 

	
 
	assert(load_index == SPR_SIGNALS_BASE);
 
	/* Start loading the extra, non-TTD, base GRFs for the given index. */
 
	load_index = SPR_SIGNALS_BASE;
 
	load_index += LoadGrfFile("nsignalsw.grf", load_index, i++);
 

	
 
	assert(load_index == SPR_CANALS_BASE);
 
	load_index += LoadGrfFile("canalsw.grf", load_index, i++);
 

	
 
	assert(load_index == SPR_SLOPES_BASE);
src/table/files.h
Show inline comments
 
@@ -23,28 +23,24 @@
 
*/
 

	
 

	
 
static FileList files_dos = {
 
	{
 
		{ "TRG1.GRF",      {0x93, 0x11, 0x67, 0x62, 0x80, 0xe5, 0xb1, 0x40, 0x77, 0xa8, 0xee, 0x41, 0xc1, 0xb4, 0x21, 0x92} }, //    0 - 4792 inclusive
 
		{ "TRGI.GRF",      {0xda, 0x6a, 0x6c, 0x9d, 0xcc, 0x45, 0x1e, 0xec, 0x88, 0xd7, 0x92, 0x11, 0x43, 0x7b, 0x76, 0xa8} }, // 4793 - 4889 inclusive
 
		{ "dosdummy.grf",  {0x07, 0x01, 0xe6, 0xc4, 0x07, 0x6a, 0x5b, 0xc3, 0xf4, 0x9f, 0x01, 0xad, 0x21, 0x6c, 0xa0, 0xc2} }, // 4890 - 4895 inclusive
 
		{ NULL, { 0 } }
 
		{ "TRGI.GRF",      {0xda, 0x6a, 0x6c, 0x9d, 0xcc, 0x45, 0x1e, 0xec, 0x88, 0xd7, 0x92, 0x11, 0x43, 0x7b, 0x76, 0xa8} }  // 4793 - 4889 inclusive
 
	}, {
 
		{ "TRGC.GRF",      {0xed, 0x44, 0x66, 0x37, 0xe0, 0x34, 0x10, 0x4c, 0x55, 0x59, 0xb3, 0x2c, 0x18, 0xaf, 0xe7, 0x8d} },
 
		{ "TRGH.GRF",      {0xee, 0x66, 0x16, 0xfb, 0x0e, 0x6e, 0xf6, 0xb2, 0x48, 0x92, 0xc5, 0x8c, 0x93, 0xd8, 0x6f, 0xc9} },
 
		{ "TRGT.GRF",      {0xfc, 0xde, 0x1d, 0x7e, 0x8a, 0x74, 0x19, 0x7d, 0x72, 0xa6, 0x26, 0x95, 0x88, 0x4b, 0x90, 0x9e} }
 
	}
 
};
 

	
 
static FileList files_win = {
 
	{
 
		{ "TRG1R.GRF",     {0xb0, 0x4c, 0xe5, 0x93, 0xd8, 0xc5, 0x01, 0x6e, 0x07, 0x47, 0x3a, 0x74, 0x3d, 0x7d, 0x33, 0x58} }, //    0 - 4792 inclusive
 
		{ "TRGIR.GRF",     {0x0c, 0x24, 0x84, 0xff, 0x6b, 0xe4, 0x9f, 0xc6, 0x3a, 0x83, 0xbe, 0x6a, 0xb5, 0xc3, 0x8f, 0x32} }, // 4793 - 4895 inclusive
 
		{ NULL, { 0 } },
 
		{ NULL, { 0 } }
 
		{ "TRGIR.GRF",     {0x0c, 0x24, 0x84, 0xff, 0x6b, 0xe4, 0x9f, 0xc6, 0x3a, 0x83, 0xbe, 0x6a, 0xb5, 0xc3, 0x8f, 0x32} }  // 4793 - 4895 inclusive
 
	}, {
 
		{ "TRGCR.GRF",     {0x36, 0x68, 0xf4, 0x10, 0xc7, 0x61, 0xa0, 0x50, 0xb5, 0xe7, 0x09, 0x5a, 0x2b, 0x14, 0x87, 0x9b} },
 
		{ "TRGHR.GRF",     {0x06, 0xbf, 0x2b, 0x7a, 0x31, 0x76, 0x6f, 0x04, 0x8b, 0xaa, 0xc2, 0xeb, 0xe4, 0x34, 0x57, 0xb1} },
 
		{ "TRGTR.GRF",     {0xde, 0x53, 0x65, 0x05, 0x17, 0xfe, 0x66, 0x1c, 0xea, 0xa3, 0x13, 0x8c, 0x6e, 0xdb, 0x0e, 0xb8} }
 
	}
 
};
0 comments (0 inline, 0 general)