Beispiel #1
0
bool GRFFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
{
	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;
				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
				 *  just after the first with the same name. Avoids doubles in the list. */
				if (strcasecmp(c->GetName(), d->GetName()) <= 0) {
					stop = true;
				} else if (stop) {
					break;
				}
			}
			if (added) {
				c->next = d;
				*pd = c;
			}
		}
	} else {
		added = false;
	}

	this->num_scanned++;
	if (this->next_update <= _realtime_tick) {
		_modal_progress_work_mutex->EndCritical();
		_modal_progress_paint_mutex->BeginCritical();

		const char *name = NULL;
		if (c->name != NULL) name = GetGRFStringFromGRFText(c->name->text);
		if (name == NULL) name = c->filename;
		UpdateNewGRFScanStatus(this->num_scanned, name);

		_modal_progress_work_mutex->BeginCritical();
		_modal_progress_paint_mutex->EndCritical();

		this->next_update = _realtime_tick + 200;
	}

	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. */
		delete c;
	}

	return added;
}
/**
 * Get a C-string from a stringid set by a newgrf.
 */
const char *GetGRFStringPtr(uint16 stringid)
{
	assert(_grf_text[stringid].grfid != 0);

	/* Remember this grfid in case the string has included text */
	_last_grfid = _grf_text[stringid].grfid;

	const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder);
	if (str != NULL) return str;

	/* Use the default string ID if the fallback string isn't available */
	return GetStringPtr(_grf_text[stringid].def_string);
}
Beispiel #3
0
/**
 * Get the grf url.
 * @return A string with an url of this grf.
 */
const char *GRFConfig::GetURL() const
{
	return GetGRFStringFromGRFText(this->url->text);
}
Beispiel #4
0
/**
 * Get the grf info.
 * @return A string with a description of this grf.
 */
const char *GRFConfig::GetDescription() const
{
	return GetGRFStringFromGRFText(this->info->text);
}
Beispiel #5
0
/**
 * 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
{
	const char *name = GetGRFStringFromGRFText(this->name->text);
	return StrEmpty(name) ? this->filename : name;
}