|
@@ -273,79 +273,81 @@ void GRFParameterInfo::SetValue(struct G
|
|
|
*/
|
|
|
bool UpdateNewGRFConfigPalette(int32 p1)
|
|
|
{
|
|
|
for (GRFConfig *c = _grfconfig_newgame; c != NULL; c = c->next) c->SetSuitablePalette();
|
|
|
for (GRFConfig *c = _grfconfig_static; c != NULL; c = c->next) c->SetSuitablePalette();
|
|
|
for (GRFConfig *c = _all_grfs; c != NULL; c = c->next) c->SetSuitablePalette();
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Calculate the MD5 sum for a GRF, and store it in the config.
|
|
|
* @param config GRF to compute.
|
|
|
* @param subdir The subdirectory to look in.
|
|
|
* @return MD5 sum was successfully computed
|
|
|
*/
|
|
|
static bool CalcGRFMD5Sum(GRFConfig *config)
|
|
|
static bool CalcGRFMD5Sum(GRFConfig *config, Subdirectory subdir)
|
|
|
{
|
|
|
FILE *f;
|
|
|
Md5 checksum;
|
|
|
uint8 buffer[1024];
|
|
|
size_t len, size;
|
|
|
|
|
|
/* open the file */
|
|
|
f = FioFOpenFile(config->filename, "rb", NEWGRF_DIR, &size);
|
|
|
f = FioFOpenFile(config->filename, "rb", subdir, &size);
|
|
|
if (f == NULL) return false;
|
|
|
|
|
|
/* calculate md5sum */
|
|
|
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
|
|
|
size -= len;
|
|
|
checksum.Append(buffer, len);
|
|
|
}
|
|
|
checksum.Finish(config->ident.md5sum);
|
|
|
|
|
|
FioFCloseFile(f);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Find the GRFID of a given grf, and calculate its md5sum.
|
|
|
* @param config grf to fill.
|
|
|
* @param is_static grf is static.
|
|
|
* @param subdir the subdirectory to search in.
|
|
|
* @return Operation was successfully completed.
|
|
|
*/
|
|
|
bool FillGRFDetails(GRFConfig *config, bool is_static)
|
|
|
bool FillGRFDetails(GRFConfig *config, bool is_static, Subdirectory subdir)
|
|
|
{
|
|
|
if (!FioCheckFileExists(config->filename)) {
|
|
|
if (!FioCheckFileExists(config->filename, subdir)) {
|
|
|
config->status = GCS_NOT_FOUND;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
/* Find and load the Action 8 information */
|
|
|
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN);
|
|
|
LoadNewGRFFile(config, CONFIG_SLOT, GLS_FILESCAN, subdir);
|
|
|
config->SetSuitablePalette();
|
|
|
|
|
|
/* Skip if the grfid is 0 (not read) or 0xFFFFFFFF (ttdp system grf) */
|
|
|
if (config->ident.grfid == 0 || config->ident.grfid == 0xFFFFFFFF || config->IsOpenTTDBaseGRF()) return false;
|
|
|
|
|
|
if (is_static) {
|
|
|
/* Perform a 'safety scan' for static GRFs */
|
|
|
LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
|
|
|
LoadNewGRFFile(config, 62, GLS_SAFETYSCAN, subdir);
|
|
|
|
|
|
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
|
|
|
if (HasBit(config->flags, GCF_UNSAFE)) return false;
|
|
|
}
|
|
|
|
|
|
return CalcGRFMD5Sum(config);
|
|
|
return CalcGRFMD5Sum(config, subdir);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Clear a GRF Config list, freeing all nodes.
|
|
|
* @param config Start of the list.
|
|
|
* @post \a config is set to \c NULL.
|
|
|
*/
|
|
|
void ClearGRFConfigList(GRFConfig **config)
|
|
|
{
|
|
|
GRFConfig *c, *next;
|
|
|
for (c = *config; c != NULL; c = next) {
|