Example #1
0
//Load preferences from given open preferences file. Closes the file when done. 
//Return 1 if everything read okay, 0 if invalid parameters somewhere, although it
//tries to keep reading what it can. Caller should first call 
//CreateDefaultPreferences(false) to load defaults in case one or more fields are 
//missing. Obviously field names need to be same as in SavePreferences()
int CFSXGUI::LoadPreferences(CParser &File)
{
	char FieldName[512];
	int Value;
	bool bSomethingBad = false;
	do
	{
		if (!File.GetString(FieldName, 512, true))
		{
			File.CloseFile();
			if (bSomethingBad)
				return 0;
			return 1;
		}
		if (strcmp(FieldName, "PTTKEY") == 0)
		{
			File.GetInt(&Value);
			if (Value > 0)
				m_Prefs.PTTVKey = Value;
			else
				bSomethingBad = true;
		}
		else if (strcmp(FieldName, "PTTJOYBUTTON") == 0)
		{
			File.GetInt(&Value);
			if (Value > 0)
				m_Prefs.PTTJoyButton = Value;
			else
				bSomethingBad = true;
		}
	} while (true);
}
Example #2
0
//Save preferences to m_cPrefPathAndFilename
int CFSXGUI::SavePreferences()
{
	CParser File;

	if (!File.OpenFileForOutput(m_cPrefPathAndFilename))  
		return 0;
	
	File.WriteString(STR_PREF_HEADER);
	File.WriteString("\nPTTKey = ");
	File.WriteInt(m_Prefs.PTTVKey);

	File.WriteString("\nPTTJoyButton = ");
	File.WriteInt(m_Prefs.PTTJoyButton);

	File.CloseFile();

	return 1;
}