Esempio n. 1
0
/**
**	@brief	Process data provided by a configuration file
**
**	@param	config_data	The configuration data
*/
void CWorld::ProcessConfigData(const CConfigData *config_data)
{
	for (size_t i = 0; i < config_data->Properties.size(); ++i) {
		std::string key = config_data->Properties[i].first;
		std::string value = config_data->Properties[i].second;
		
		if (key == "name") {
			this->Name = value;
		} else if (key == "description") {
			this->Description = value;
		} else if (key == "background") {
			this->Background = value;
		} else if (key == "quote") {
			this->Quote = value;
		} else if (key == "plane") {
			value = FindAndReplaceString(value, "_", "-");
			this->Plane = CPlane::GetPlane(value);
		} else if (key == "time_of_day_schedule") {
			value = FindAndReplaceString(value, "_", "-");
			this->TimeOfDaySchedule = CTimeOfDaySchedule::GetTimeOfDaySchedule(value);
		} else if (key == "season_schedule") {
			value = FindAndReplaceString(value, "_", "-");
			this->SeasonSchedule = CSeasonSchedule::GetSeasonSchedule(value);
		} else {
			fprintf(stderr, "Invalid world property: \"%s\".\n", key.c_str());
		}
	}
}
Esempio n. 2
0
void CTriggerDependency::ProcessConfigDataProperty(const std::pair<std::string, std::string> &property)
{
	const std::string &key = property.first;
	std::string value = property.second;
	if (key == "trigger") {
		value = FindAndReplaceString(value, "_", "-");
		this->Trigger = CTrigger::GetTrigger(value);
	} else {
		fprintf(stderr, "Invalid trigger dependency property: \"%s\".\n", key.c_str());
	}
}
Esempio n. 3
0
void CSeasonDependency::ProcessConfigDataProperty(const std::pair<std::string, std::string> &property)
{
	const std::string &key = property.first;
	std::string value = property.second;
	if (key == "season") {
		value = FindAndReplaceString(value, "_", "-");
		this->Season = CSeason::GetSeason(value);
	} else {
		fprintf(stderr, "Invalid season dependency property: \"%s\".\n", key.c_str());
	}
}
Esempio n. 4
0
/**
**	@brief	Process data provided by a configuration file
**
**	@param	config_data	The configuration data
*/
void CUpgradeModifier::ProcessConfigData(const CConfigData *config_data)
{
	for (size_t i = 0; i < config_data->Properties.size(); ++i) {
		std::string key = config_data->Properties[i].first;
		std::string value = config_data->Properties[i].second;
		
		if (key == "apply_to") {
			value = FindAndReplaceString(value, "_", "-");
			const int unit_type_id = UnitTypeIdByIdent(value.c_str());
			if (unit_type_id != -1) {
				this->ApplyTo[unit_type_id] = 'X';
			} else {
				fprintf(stderr, "Invalid unit type: \"%s\".\n", value.c_str());
			}
		} else if (key == "remove_upgrade") {
			value = FindAndReplaceString(value, "_", "-");
			CUpgrade *removed_upgrade = CUpgrade::Get(value);
			if (removed_upgrade) {
				this->RemoveUpgrades.push_back(removed_upgrade);
			} else {
				fprintf(stderr, "Invalid upgrade: \"%s\".\n", value.c_str());
			}
		} else {
			key = SnakeCaseToPascalCase(key);
			
			int index = UnitTypeVar.VariableNameLookup[key.c_str()]; // variable index
			if (index != -1) { // valid index
				if (IsStringNumber(value)) {
					this->Modifier.Variables[index].Enable = 1;
					this->Modifier.Variables[index].Value = std::stoi(value);
					this->Modifier.Variables[index].Max = std::stoi(value);
				} else { // error
					fprintf(stderr, "Invalid value (\"%s\") for variable \"%s\" when defining modifier for upgrade \"%s\".\n", value.c_str(), key.c_str(), AllUpgrades[this->UpgradeId]->Ident.c_str());
				}
			} else {
				fprintf(stderr, "Invalid upgrade modifier property: \"%s\".\n", key.c_str());
			}
		}
	}
}
Esempio n. 5
0
void CUpgradeDependency::ProcessConfigDataProperty(const std::pair<std::string, std::string> &property)
{
	const std::string &key = property.first;
	std::string value = property.second;
	if (key == "upgrade") {
		value = FindAndReplaceString(value, "_", "-");
		this->Upgrade = CUpgrade::Get(value);
		if (!this->Upgrade) {
			fprintf(stderr, "Invalid upgrade: \"%s\".\n", value.c_str());
		}
	} else {
		fprintf(stderr, "Invalid upgrade dependency property: \"%s\".\n", key.c_str());
	}
}
Esempio n. 6
0
void CUnitTypeDependency::ProcessConfigDataProperty(const std::pair<std::string, std::string> &property)
{
	const std::string &key = property.first;
	std::string value = property.second;
	if (key == "unit_type") {
		value = FindAndReplaceString(value, "_", "-");
		this->UnitType = UnitTypeByIdent(value);
		if (!this->UnitType) {
			fprintf(stderr, "Invalid unit type: \"%s\".\n", value.c_str());
		}
	} else if (key == "count") {
		this->Count = std::stoi(value);
	} else {
		fprintf(stderr, "Invalid unit type dependency property: \"%s\".\n", key.c_str());
	}
}
Esempio n. 7
0
/** 
Function to extract individual or a subset of file.

@internalComponent
@released

@param aData - ROM/ROFS image buffer pointer.
*/
void ImageReader::ExtractFileSet(char* aData)
{
	FILEINFOMAP fileInfoMap;
	string dirSep(DIR_SEPARATOR), backSlash("\\"), Pattern;
	TUint extfileCount = 0, noWcardFlag = 0, pos;

	//Get the filelist map
	GetFileInfo(fileInfoMap);

	//Check for wildcards
	pos = iPattern.rfind("\\");
	if(pos == string::npos)
	{
		pos = iPattern.rfind("/");
		if(pos == string::npos)
			pos = 0;
	}
	pos = iPattern.find_first_of("*?", pos);
	if(pos == string::npos)
	{
		noWcardFlag = 1;
	}

	//Process the map
	if(fileInfoMap.size() > 0)
	{
		FILEINFOMAP::iterator begin = fileInfoMap.begin();
		FILEINFOMAP::iterator end = fileInfoMap.end();

		// Replace all backslashes with forward slashes
		Pattern = iPattern;
		FindAndReplaceString(Pattern, backSlash, dirSep);

		// Insert root directory at the beginning if it is not there
		pos = Pattern.find_first_not_of(" ", 0);
		if(pos != string::npos)
		{
			if(Pattern.at(pos) != *DIR_SEPARATOR)
				Pattern.insert(pos, dirSep);
		}

		// Assign CWD for destination path if it is empty
		if(ImageReader::iZdrivePath.empty())
			ImageReader::iZdrivePath.assign(".");

		while(begin != end)
		{
			int status = 0;
			PFILEINFO pInfo = 0;
			string fileName = (*begin).first;
			pInfo = (*begin).second;

			// First match
			status = FileNameMatch(Pattern, fileName, (iDisplayOptions & RECURSIVE_FLAG));

			// If no match
			if((!status) && noWcardFlag)
			{
				string newPattern(Pattern);

				// Add * at the end
				if(newPattern.at(Pattern.length()-1) != *DIR_SEPARATOR)
				{
					newPattern.append(DIR_SEPARATOR);
				}
				newPattern += "*";
				status = FileNameMatch(newPattern, fileName, (iDisplayOptions & RECURSIVE_FLAG));

				// If it matches update the pattern and reset wildcard flag
				if(status)
				{
					Pattern = newPattern;
					noWcardFlag = 0;
				}
			}

			if(status)
			{
				// Extract the file

				// Separarate the path and file name
				string fullPath = fileName.substr(0, fileName.rfind(DIR_SEPARATOR));
				string file = fileName.substr(fileName.rfind(DIR_SEPARATOR)+1, fileName.length());
				FindAndReplaceString(fullPath, dirSep, backSlash);

				// Extract only those files exists in the image
				if(pInfo->iSize && pInfo->iOffset)
				{
					ExtractFile(pInfo->iOffset, pInfo->iSize, file.c_str(), fullPath.c_str() , 
						&ImageReader::iZdrivePath[0], aData);

					extfileCount++;
				}
			}

			if(pInfo)
				delete pInfo;
			++begin;
		}
		fileInfoMap.clear();
	}

	// Throw error if the extracted file count is zero
	if(!extfileCount)
	{
		throw ImageReaderException((char*)ImageReader::iImgFileName.c_str(), "No matching files found for the given pattern");
	}
}