|
@@ -11,24 +11,39 @@
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
#include "debug.h"
|
|
|
#include "3rdparty/md5/md5.h"
|
|
|
#include "newgrf.h"
|
|
|
#include "gamelog.h"
|
|
|
#include "network/network_func.h"
|
|
|
#include "gfx_func.h"
|
|
|
|
|
|
#include "fileio_func.h"
|
|
|
#include "fios.h"
|
|
|
|
|
|
GRFConfig::GRFConfig(const char *filename)
|
|
|
{
|
|
|
if (filename != NULL) this->filename = strdup(filename);
|
|
|
}
|
|
|
|
|
|
GRFConfig::~GRFConfig()
|
|
|
{
|
|
|
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
|
|
|
if (!HasBit(this->flags, GCF_COPY)) {
|
|
|
free(this->filename);
|
|
|
free(this->name);
|
|
|
free(this->info);
|
|
|
delete this->error;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
GRFConfig *_all_grfs;
|
|
|
GRFConfig *_grfconfig;
|
|
|
GRFConfig *_grfconfig_newgame;
|
|
|
GRFConfig *_grfconfig_static;
|
|
|
|
|
|
GRFError::GRFError(StringID severity, StringID message) :
|
|
|
message(message),
|
|
|
severity(severity)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -96,58 +111,44 @@ bool FillGRFDetails(GRFConfig *config, b
|
|
|
LoadNewGRFFile(config, 62, GLS_SAFETYSCAN);
|
|
|
|
|
|
/* GCF_UNSAFE is set if GLS_SAFETYSCAN finds unsafe actions */
|
|
|
if (HasBit(config->flags, GCF_UNSAFE)) return false;
|
|
|
}
|
|
|
|
|
|
config->windows_paletted = (_use_palette == PAL_WINDOWS);
|
|
|
|
|
|
return CalcGRFMD5Sum(config);
|
|
|
}
|
|
|
|
|
|
|
|
|
void ClearGRFConfig(GRFConfig **config)
|
|
|
{
|
|
|
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
|
|
|
if (!HasBit((*config)->flags, GCF_COPY)) {
|
|
|
free((*config)->filename);
|
|
|
free((*config)->name);
|
|
|
free((*config)->info);
|
|
|
delete (*config)->error;
|
|
|
}
|
|
|
free(*config);
|
|
|
*config = NULL;
|
|
|
}
|
|
|
|
|
|
|
|
|
/* Clear a GRF Config list */
|
|
|
void ClearGRFConfigList(GRFConfig **config)
|
|
|
{
|
|
|
GRFConfig *c, *next;
|
|
|
for (c = *config; c != NULL; c = next) {
|
|
|
next = c->next;
|
|
|
ClearGRFConfig(&c);
|
|
|
delete c;
|
|
|
}
|
|
|
*config = NULL;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* Make a deep copy of a GRFConfig.
|
|
|
* @param c the grfconfig to copy
|
|
|
* @return A pointer to a new grfconfig that's a copy of the original
|
|
|
*/
|
|
|
GRFConfig *DuplicateGRFConfig(const GRFConfig *c)
|
|
|
{
|
|
|
GRFConfig *config = MallocT<GRFConfig>(1);
|
|
|
GRFConfig *config = new GRFConfig();
|
|
|
*config = *c;
|
|
|
|
|
|
if (c->filename != NULL) config->filename = strdup(c->filename);
|
|
|
if (c->name != NULL) config->name = strdup(c->name);
|
|
|
if (c->info != NULL) config->info = strdup(c->info);
|
|
|
if (c->error != NULL) {
|
|
|
config->error = new GRFError(c->error->severity, c->error->message);
|
|
|
config->error->num_params = c->error->num_params;
|
|
|
memcpy(config->error->param_value, c->error->param_value, sizeof(config->error->param_value));
|
|
|
if (c->error->data != NULL) config->error->data = strdup(c->error->data);
|
|
|
if (c->error->custom_message != NULL) config->error->custom_message = strdup(c->error->custom_message);
|
|
|
}
|
|
@@ -194,25 +195,25 @@ GRFConfig **CopyGRFConfigList(GRFConfig
|
|
|
*/
|
|
|
static void RemoveDuplicatesFromGRFConfigList(GRFConfig *list)
|
|
|
{
|
|
|
GRFConfig *prev;
|
|
|
GRFConfig *cur;
|
|
|
|
|
|
if (list == NULL) return;
|
|
|
|
|
|
for (prev = list, cur = list->next; cur != NULL; prev = cur, cur = cur->next) {
|
|
|
if (cur->ident.grfid != list->ident.grfid) continue;
|
|
|
|
|
|
prev->next = cur->next;
|
|
|
ClearGRFConfig(&cur);
|
|
|
delete cur;
|
|
|
cur = prev; // Just go back one so it continues as normal later on
|
|
|
}
|
|
|
|
|
|
RemoveDuplicatesFromGRFConfigList(list->next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Appends the static GRFs to a list of GRFs
|
|
|
* @param dst the head of the list to add to
|
|
|
*/
|
|
|
void AppendStaticGRFConfigs(GRFConfig **dst)
|
|
|
{
|
|
@@ -311,26 +312,25 @@ public:
|
|
|
/* virtual */ bool AddFile(const char *filename, size_t basepath_length);
|
|
|
|
|
|
/** Do the scan for GRFs. */
|
|
|
static uint DoScan()
|
|
|
{
|
|
|
GRFFileScanner fs;
|
|
|
return fs.Scan(".grf", DATA_DIR);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length)
|
|
|
{
|
|
|
GRFConfig *c = CallocT<GRFConfig>(1);
|
|
|
c->filename = strdup(filename + basepath_length);
|
|
|
GRFConfig *c = new GRFConfig(filename + basepath_length);
|
|
|
|
|
|
bool added = true;
|
|
|
if (FillGRFDetails(c, false)) {
|
|
|
if (_all_grfs == NULL) {
|
|
|
_all_grfs = c;
|
|
|
} else {
|
|
|
/* Insert file into list at a position determined by its
|
|
|
* name, so the list is sorted as we go along */
|
|
|
GRFConfig **pd, *d;
|
|
|
bool stop = false;
|
|
|
for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
|
|
|
if (c->ident.grfid == d->ident.grfid && memcmp(c->ident.md5sum, d->ident.md5sum, sizeof(c->ident.md5sum)) == 0) added = false;
|
|
@@ -346,25 +346,25 @@ bool GRFFileScanner::AddFile(const char
|
|
|
if (added) {
|
|
|
c->next = d;
|
|
|
*pd = c;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
added = false;
|
|
|
}
|
|
|
|
|
|
if (!added) {
|
|
|
/* File couldn't be opened, or is either not a NewGRF or is a
|
|
|
* 'system' NewGRF or it's already known, so forget about it. */
|
|
|
ClearGRFConfig(&c);
|
|
|
delete c;
|
|
|
}
|
|
|
|
|
|
return added;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Simple sorter for GRFS
|
|
|
* @param p1 the first GRFConfig *
|
|
|
* @param p2 the second GRFConfig *
|
|
|
* @return the same strcmp would return for the name of the NewGRF.
|
|
|
*/
|
|
|
static int CDECL GRFSorter(GRFConfig * const *p1, GRFConfig * const *p2)
|