|
@@ -17,12 +17,27 @@
|
|
|
#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;
|
|
|
|
|
@@ -102,46 +117,32 @@ bool FillGRFDetails(GRFConfig *config, b
|
|
|
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) {
|
|
@@ -200,13 +201,13 @@ static void RemoveDuplicatesFromGRFConfi
|
|
|
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);
|
|
|
}
|
|
|
|
|
@@ -317,14 +318,13 @@ public:
|
|
|
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 {
|
|
@@ -352,13 +352,13 @@ bool GRFFileScanner::AddFile(const char
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/**
|