Page 1 of 1

wxFileConfig reading problem

Posted: Wed Jun 20, 2012 5:40 pm
by Tapsa
Any ideas why my wxFileConfig works on writing but not on reading? It uses the default values. Elsewhere I have a working code which is technically the same, but the reading works.

Code: Select all

void AGE_Frame::OnUnitsExtract(wxCommandEvent& Event)
{
	ExtractUnit = new wxFileConfig("AdvancedGenieEditor", wxEmptyString, "a2eUnit.txt", wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
	ExtractUnit->Write("Version/Number", 1);
	for(short loop = 0;loop < GenieFile->Civs.size();loop++)
	{
		ExtractUnit->Write("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Type", GenieFile->Civs[loop].Units[UnitID].Type);
		ExtractUnit->Write("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Class", GenieFile->Civs[loop].Units[UnitID].Class);
		ExtractUnit->Write("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Name", GenieFile->Civs[loop].Units[UnitID].Name);
		ExtractUnit->Write("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Name2", GenieFile->Civs[loop].Units[UnitID].Name2);
	}
	delete ExtractUnit;
}

void AGE_Frame::OnUnitsImport(wxCommandEvent& Event)
{
	long Number;
	wxString Text;
	ExtractUnit = new wxFileConfig("AdvancedGenieEditor", wxEmptyString, "a2eUnit.ini", wxEmptyString, wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_RELATIVE_PATH);
	for(short loop = 0;loop < GenieFile->Civs.size();loop++)
	{
		ExtractUnit->Read("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Type", &Number, 10);
		GenieFile->Civs[loop].Units[UnitID].Type = (char)Number;
		ExtractUnit->Read("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Class", &Number, 0);
		GenieFile->Civs[loop].Units[UnitID].Class = (short)Number;
		ExtractUnit->Read("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Name", &Text, "Imported Unit");
		GenieFile->Civs[loop].Units[UnitID].Name = (string)Text;
		ExtractUnit->Read("Civ"+lexical_cast<string>(loop)+"_Unit_Common/Name2", &Text, "Imported Unit");
		GenieFile->Civs[loop].Units[UnitID].Name2 = (string)Text;
	}
	delete ExtractUnit;
}

Re: wxFileConfig reading problem

Posted: Wed Jun 20, 2012 6:03 pm
by doublemax
Is Civs.size() already set when reading? Usually you'd save the size in the config and then read it back before reading the actual data.

Re: wxFileConfig reading problem

Posted: Wed Jun 20, 2012 6:10 pm
by Tapsa
Yes, it's not the problem. The data from config thing gets to where I want it. But it does not want to read it from the file and instead uses the default values I have set. Are there some obvious errors I am not seeing?

Re: wxFileConfig reading problem

Posted: Wed Jun 20, 2012 6:30 pm
by PB
Isn't the issue that you're trying to read from a different file than you have written to? a2eUnit.TXT in OnUnitsExtract() vs a2eUnit.INI in OnUnitsExport()

Re: wxFileConfig reading problem

Posted: Wed Jun 20, 2012 6:32 pm
by Tapsa
Thanks :D that's the obvious error. It's fixed now.