Changeset - r7574:bb4845f3b405
[Not reviewed]
master
0 4 0
truelight - 17 years ago 2007-09-13 18:46:29
truelight@openttd.org
(svn r11099) -Codechange: allow on opening of a file via FioFOpenFile to request the size of the file, so we can keep that in mind
4 files changed with 19 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -267,7 +267,7 @@ char *FioGetDirectory(char *buf, size_t 
 
	return buf;
 
}
 

	
 
FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir)
 
FILE *FioFOpenFileSp(const char *filename, const char *mode, Searchpath sp, Subdirectory subdir, size_t *filesize)
 
{
 
#if defined(WIN32) && defined(UNICODE)
 
	/* fopen is implemented as a define with ellipses for
 
@@ -293,11 +293,17 @@ FILE *FioFOpenFileSp(const char *filenam
 
		f = fopen(buf, mode);
 
	}
 
#endif
 
	if (f != NULL && filesize != NULL) {
 
		/* Find the size of the file */
 
		fseek(f, 0, SEEK_END);
 
		*filesize = ftell(f);
 
		fseek(f, 0, SEEK_SET);
 
	}
 
	return f;
 
}
 

	
 
/** Opens OpenTTD files somewhere in a personal or global directory */
 
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir)
 
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *size)
 
{
 
	FILE *f = NULL;
 
	Searchpath sp;
 
@@ -305,7 +311,7 @@ FILE *FioFOpenFile(const char *filename,
 
	assert(subdir < NUM_SUBDIRS || subdir == NO_DIRECTORY);
 

	
 
	FOR_ALL_SEARCHPATHS(sp) {
 
		f = FioFOpenFileSp(filename, mode, sp, subdir);
 
		f = FioFOpenFileSp(filename, mode, sp, subdir, size);
 
		if (f != NULL || subdir == NO_DIRECTORY) break;
 
	}
 

	
src/fileio.h
Show inline comments
 
@@ -73,7 +73,7 @@ static inline bool IsValidSearchPath(Sea
 
/** Iterator for all the search paths */
 
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
 

	
 
FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR);
 
FILE *FioFOpenFile(const char *filename, const char *mode = "rb", Subdirectory subdir = DATA_DIR, size_t *filesize = NULL);
 
bool FioCheckFileExists(const char *filename, Subdirectory subdir = DATA_DIR);
 
char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
 
char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
src/gfxinit.cpp
Show inline comments
 
@@ -114,7 +114,8 @@ static bool CheckMD5Digest(const MD5File
 
 * returns true if the checksum is correct */
 
static bool FileMD5(const MD5File file, bool warn)
 
{
 
	FILE *f = FioFOpenFile(file.filename);
 
	size_t size;
 
	FILE *f = FioFOpenFile(file.filename, "rb", DATA_DIR, &size);
 

	
 
	if (f != NULL) {
 
		md5_state_t filemd5state;
 
@@ -123,8 +124,10 @@ static bool FileMD5(const MD5File file, 
 
		size_t len;
 

	
 
		md5_init(&filemd5state);
 
		while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0)
 
		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);
 
		fclose(f);
src/newgrf_config.cpp
Show inline comments
 
@@ -37,15 +37,16 @@ static bool CalcGRFMD5Sum(GRFConfig *con
 
	FILE *f;
 
	md5_state_t md5state;
 
	md5_byte_t buffer[1024];
 
	size_t len;
 
	size_t len, size;
 

	
 
	/* open the file */
 
	f = FioFOpenFile(config->filename);
 
	f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size);
 
	if (f == NULL) return false;
 

	
 
	/* calculate md5sum */
 
	md5_init(&md5state);
 
	while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0) {
 
	while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
 
		size -= len;
 
		md5_append(&md5state, buffer, len);
 
	}
 
	md5_finish(&md5state, config->md5sum);
0 comments (0 inline, 0 general)