summaryrefslogtreecommitdiff
path: root/src/gfxinit.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2012-02-04 13:29:00 +0000
committermichi_cc <michi_cc@openttd.org>2012-02-04 13:29:00 +0000
commita9b6c5cd86f4f17155695890bfaf2e30404f5921 (patch)
tree54a16a5b71593df1f2b7d4869cfe5ab71c47e233 /src/gfxinit.cpp
parent02d07e68d8c6fc760021ec1c36086877f714152c (diff)
downloadopenttd-a9b6c5cd86f4f17155695890bfaf2e30404f5921.tar.xz
(svn r23886) -Codechange: Allow limiting the MD5 file hash to the first x bytes of the file.
Diffstat (limited to 'src/gfxinit.cpp')
-rw-r--r--src/gfxinit.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp
index 56d5aaf69..f98e7c670 100644
--- a/src/gfxinit.cpp
+++ b/src/gfxinit.cpp
@@ -119,7 +119,7 @@ void CheckExternalFiles()
/* Not all files were loaded successfully, see which ones */
add_pos += seprintf(add_pos, last, "Trying to load graphics set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of readme.txt.\n\nThe following files are corrupted or missing:\n", used_set->name);
for (uint i = 0; i < GraphicsSet::NUM_FILES; i++) {
- MD5File::ChecksumResult res = used_set->files[i].CheckMD5(BASESET_DIR);
+ MD5File::ChecksumResult res = GraphicsSet::CheckMD5(&used_set->files[i], BASESET_DIR);
if (res != MD5File::CR_MATCH) add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", used_set->files[i].filename, res == MD5File::CR_MISMATCH ? "corrupt" : "missing", used_set->files[i].missing_warning);
}
add_pos += seprintf(add_pos, last, "\n");
@@ -132,7 +132,7 @@ void CheckExternalFiles()
assert_compile(SoundsSet::NUM_FILES == 1);
/* No need to loop each file, as long as there is only a single
* sound file. */
- add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename, sounds_set->files->CheckMD5(BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
+ add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename, SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);
}
if (add_pos != error_msg) ShowInfoF("%s", error_msg);
@@ -266,18 +266,21 @@ bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *ful
/**
* Calculate and check the MD5 hash of the supplied filename.
* @param subdir The sub directory to get the files from
+ * @param max_size Only calculate the hash for this many bytes from the file start.
* @return
* - #CR_MATCH if the MD5 hash matches
* - #CR_MISMATCH if the MD5 does not match
* - #CR_NO_FILE if the file misses
*/
-MD5File::ChecksumResult MD5File::CheckMD5(Subdirectory subdir) const
+MD5File::ChecksumResult MD5File::CheckMD5(Subdirectory subdir, size_t max_size) const
{
size_t size;
FILE *f = FioFOpenFile(this->filename, "rb", subdir, &size);
if (f == NULL) return CR_NO_FILE;
+ size = min(size, max_size);
+
Md5 checksum;
uint8 buffer[1024];
uint8 digest[16];