wxFileConfig reading problem Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

wxFileConfig reading problem

Post 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;
}
User avatar
doublemax
Moderator
Moderator
Posts: 19151
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxFileConfig reading problem

Post 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.
Use the source, Luke!
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: wxFileConfig reading problem

Post 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?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4199
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxFileConfig reading problem

Post 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()
Last edited by PB on Wed Jun 20, 2012 6:36 pm, edited 1 time in total.
Tapsa
Earned some good credits
Earned some good credits
Posts: 147
Joined: Tue Dec 06, 2011 5:52 pm
Location: Helsinki

Re: wxFileConfig reading problem

Post by Tapsa »

Thanks :D that's the obvious error. It's fixed now.
Post Reply