src/newgrf_config.cpp
changeset 8133 3ab8eaf85ca0
parent 8131 160939e24ed3
child 8213 7bdd7593eb9b
equal deleted inserted replaced
8132:f4c7a8e4f25a 8133:3ab8eaf85ca0
    30 
    30 
    31 /* Calculate the MD5 Sum for a GRF */
    31 /* Calculate the MD5 Sum for a GRF */
    32 static bool CalcGRFMD5Sum(GRFConfig *config)
    32 static bool CalcGRFMD5Sum(GRFConfig *config)
    33 {
    33 {
    34 	FILE *f;
    34 	FILE *f;
    35 	md5_state_t md5state;
    35 	Md5 checksum;
    36 	md5_byte_t buffer[1024];
    36 	uint8 buffer[1024];
    37 	size_t len, size;
    37 	size_t len, size;
    38 
    38 
    39 	/* open the file */
    39 	/* open the file */
    40 	f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size);
    40 	f = FioFOpenFile(config->filename, "rb", DATA_DIR, &size);
    41 	if (f == NULL) return false;
    41 	if (f == NULL) return false;
    42 
    42 
    43 	/* calculate md5sum */
    43 	/* calculate md5sum */
    44 	md5_init(&md5state);
       
    45 	while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
    44 	while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
    46 		size -= len;
    45 		size -= len;
    47 		md5_append(&md5state, buffer, len);
    46 		checksum.Append(buffer, len);
    48 	}
    47 	}
    49 	md5_finish(&md5state, config->md5sum);
    48 	checksum.Finish(config->md5sum);
    50 
    49 
    51 	FioFCloseFile(f);
    50 	FioFCloseFile(f);
    52 
    51 
    53 	return true;
    52 	return true;
    54 }
    53 }