void CSettings::ParseCommandLine(char * szCommandLine)
{
	// Loop until we reach the end of the command line string
	while(*szCommandLine)
	{
		// Is the current char not a space?
		if(!isspace(*szCommandLine))
		{
			// Is the current char a '-'?
			if(*szCommandLine == '-')
			{
				// Skip the '-'
				szCommandLine++;

				// Collect the setting string
				String strSetting;

				while(*szCommandLine && !isspace(*szCommandLine))
				{
					strSetting += *szCommandLine;
					szCommandLine++;
				}

				// If we have run out of command line to process break out of the loop
				if(!(*szCommandLine))
					break;

				// Skip the spaces between the option and the value
				while(*szCommandLine && isspace(*szCommandLine))
					szCommandLine++;

				// If we have run out of command line to process break out of the loop
				if(!(*szCommandLine))
					break;

				// Collect the value string
				String strValue;

				while(*szCommandLine && !isspace(*szCommandLine))
				{
					strValue += *szCommandLine;
					szCommandLine++;
				}

				// Set the setting and value
				if(!SetEx(strSetting, strValue))
					CLogFile::Printf("WARNING: Command line setting %s does not exist.", strSetting.Get());

				CLogFile::Printf("argv/argc command line: setting %s value %s", strSetting.Get(), strValue.Get());

				// If we have run out of command line to process break out of the loop
				if(!(*szCommandLine))
					break;
			}
		}

		// Increment the command line string pointer
		szCommandLine++;
	}
}
Beispiel #2
0
CommandReciever::CommandReciever()
{
	mRecieverList.push_back( this );
	static bool bDoOnce = false;
	if ( !bDoOnce )
	{
		SetEx( "help", "Displays a list of commands", this, &CommandReciever::cmdHelp );
		bDoOnce = true;
	}
}
void CSettings::ParseCommandLine(int argc, char ** argv)
{
	for(int i = 0; i < argc; i++)
	{
		// Is the current char a '-'?
		if(argv[i][0] == '-')
		{
			// Is there a value?
			if((i + 1) < argc)
			{
				// Get the setting and value pointers
				String strSetting = (argv[i] + 1);
				String strValue = argv[i + 1];

				// Set the setting and value
				if(!SetEx(strSetting, strValue))
					CLogFile::Printf("WARNING: Command line setting %s does not exist.", strSetting.Get());

				CLogFile::Printf("argv/argc command line: setting %s value %s", strSetting.Get(), strValue.Get());
			}
		}
	}
}
bool CSettings::Open(String strPath, bool bCreate, bool bSave)
{
	// Flag we are not allowed to save the file by default
	m_bSave = false;

	// Load the default settings
	LoadDefaults();

	// Does the settings file not exist?
	bool bExists = true;

	if(!SharedUtility::Exists(strPath.Get()))
	{
		if(!bCreate)
		{
			CLogFile::Printf("ERROR: Settings file %s does not exist.", strPath.Get());
			return false;
		}
		else
		{
			CLogFile::Printf("WARNING: Settings file %s does not exist, it will now be created.", strPath.Get());

			// Attempt to open the file for write
			FILE * fFile = fopen(strPath.Get(), "w");

			// Ensure the file was opened
			if(!fFile)
			{
				CLogFile::Printf("WARNING: Failed to create settings file %s, no settings will be loaded or saved.", strPath.Get());

				// Flag the settings file as does not exist
				bExists = false;
			}
			else
			{
				// Write the default contents to the file
				fprintf(fFile, "<settings />");

				// Close the file
				fclose(fFile);
			}
		}
	}

	// Load the settings file
	if(bExists)
	{
		// Attempt to load the XML file
		if(m_XMLDocument.LoadFile(strPath.Get()))
		{
			// Flag ourselves as open
			m_bOpen = true;

			// Loop through all XML nodes
			for(TiXmlNode * pNode = m_XMLDocument.RootElement()->FirstChildElement(); pNode; pNode = pNode->NextSibling())
			{
				// Is this not an element node?
				if(pNode->Type() != TiXmlNode::ELEMENT)
					continue;

				// Get the setting and value
				String strSetting = pNode->Value();
				String strValue = pNode->ToElement()->GetText();

				// Does the setting not exist?
				if(!Exists(strSetting))
					CLogFile::Printf("WARNING: Log file setting %s does not exist.", strSetting.Get());
				else
					SetEx(strSetting, strValue);
			}

			// Flag if we are allowed to save the file
			m_bSave = bSave;

			// Save the XML file
			Save();
		}
		else
		{
			if(bCreate)
			{
				CLogFile::Printf("ERROR: Failed to open settings file %s.", strPath.Get());
				return false;
			}
			else
				CLogFile::Printf("WARNING: Failed to open settings file %s, no settings will be loaded or saved.", strPath.Get());
		}
	}

	return true;
}
Beispiel #5
0
void TacticalManager::InitCommands()
{
	SetEx( "goal_save", "Saves the goals to their own file.", this, &TacticalManager::cmdSave );
	SetEx( "goal_load", "Loads the goals from their own file.", this, &TacticalManager::cmdLoad );
	SetEx( "show_tokens", "Print out info about all the active stimulus for a player.", this, &TacticalManager::cmdShowTokens );
}