|
@@ -7,24 +7,25 @@
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
/** @file newgrf_config.cpp Finding NewGRFs and configuring them. */
|
|
|
|
|
|
#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 "newgrf_text.h"
|
|
|
|
|
|
#include "fileio_func.h"
|
|
|
#include "fios.h"
|
|
|
|
|
|
/**
|
|
|
* Create a new GRFConfig.
|
|
|
* @param filename Set the filename of this GRFConfig to filename. The argument
|
|
|
* is copied so the original string isn't needed after the constructor.
|
|
|
*/
|
|
|
GRFConfig::GRFConfig(const char *filename)
|
|
|
{
|
|
|
if (filename != NULL) this->filename = strdup(filename);
|
|
@@ -36,59 +37,59 @@ GRFConfig::GRFConfig(const char *filenam
|
|
|
*/
|
|
|
GRFConfig::GRFConfig(const GRFConfig &config) :
|
|
|
ident(config.ident),
|
|
|
flags(config.flags & ~GCF_COPY),
|
|
|
status(config.status),
|
|
|
grf_bugs(config.grf_bugs),
|
|
|
num_params(config.num_params),
|
|
|
windows_paletted(config.windows_paletted)
|
|
|
{
|
|
|
MemCpyT<uint8>(this->original_md5sum, config.original_md5sum, lengthof(this->original_md5sum));
|
|
|
MemCpyT<uint32>(this->param, config.param, lengthof(this->param));
|
|
|
if (config.filename != NULL) this->filename = strdup(config.filename);
|
|
|
if (config.name != NULL) this->name = strdup(config.name);
|
|
|
if (config.info != NULL) this->info = strdup(config.info);
|
|
|
this->name = DuplicateGRFText(config.name);
|
|
|
this->info = DuplicateGRFText(config.info);
|
|
|
if (config.error != NULL) this->error = new GRFError(*config.error);
|
|
|
}
|
|
|
|
|
|
/** Cleanup a GRFConfig object. */
|
|
|
GRFConfig::~GRFConfig()
|
|
|
{
|
|
|
/* GCF_COPY as in NOT strdupped/alloced the filename, name and info */
|
|
|
/* GCF_COPY as in NOT strdupped/alloced the filename and info */
|
|
|
if (!HasBit(this->flags, GCF_COPY)) {
|
|
|
free(this->filename);
|
|
|
free(this->name);
|
|
|
free(this->info);
|
|
|
CleanUpGRFText(this->info);
|
|
|
delete this->error;
|
|
|
}
|
|
|
CleanUpGRFText(this->name);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the name of this grf. In case the name isn't known
|
|
|
* the filename is returned.
|
|
|
* @return The name of filename of this grf.
|
|
|
*/
|
|
|
const char *GRFConfig::GetName() const
|
|
|
{
|
|
|
if (StrEmpty(this->name)) return this->filename;
|
|
|
return this->name;
|
|
|
const char *name = GetGRFStringFromGRFText(this->name);
|
|
|
return StrEmpty(name) ? this->filename : name;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Get the grf info.
|
|
|
* @return A string with a description of this grf.
|
|
|
*/
|
|
|
const char *GRFConfig::GetDescription() const
|
|
|
{
|
|
|
return this->info;
|
|
|
return GetGRFStringFromGRFText(this->info);
|
|
|
}
|
|
|
|
|
|
GRFConfig *_all_grfs;
|
|
|
GRFConfig *_grfconfig;
|
|
|
GRFConfig *_grfconfig_newgame;
|
|
|
GRFConfig *_grfconfig_static;
|
|
|
|
|
|
/**
|
|
|
* Construct a new GRFError.
|
|
|
* @param severity The severity of this error.
|
|
|
* @param message The actual error-string.
|
|
|
*/
|
|
@@ -340,26 +341,26 @@ GRFListCompatibility IsGoodGRFConfigList
|
|
|
} else {
|
|
|
compatible_grf:
|
|
|
DEBUG(grf, 1, "Loading GRF %08X from %s", BSWAP32(f->ident.grfid), f->filename);
|
|
|
/* The filename could be the filename as in the savegame. As we need
|
|
|
* to load the GRF here, we need the correct filename, so overwrite that
|
|
|
* in any case and set the name and info when it is not set already.
|
|
|
* When the GCF_COPY flag is set, it is certain that the filename is
|
|
|
* already a local one, so there is no need to replace it. */
|
|
|
if (!HasBit(c->flags, GCF_COPY)) {
|
|
|
free(c->filename);
|
|
|
c->filename = strdup(f->filename);
|
|
|
memcpy(c->ident.md5sum, f->ident.md5sum, sizeof(c->ident.md5sum));
|
|
|
if (c->name == NULL && f->name != NULL) c->name = strdup(f->name);
|
|
|
if (c->info == NULL && f->info != NULL) c->info = strdup(f->info);
|
|
|
if (c->name == NULL) c->name = DuplicateGRFText(f->name);
|
|
|
if (c->info == NULL) c->info = DuplicateGRFText(f->info);
|
|
|
c->error = NULL;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
}
|
|
|
|
|
|
/** Helper for scanning for files with GRF as extension */
|
|
|
class GRFFileScanner : FileScanner {
|
|
|
public:
|
|
|
/* virtual */ bool AddFile(const char *filename, size_t basepath_length);
|