-
Автор темы
- #1
Как фиксануть сохранение CFG в Ayyware
Код:
void CGUI::SaveWindowState(CWindow* window, std::string Filename)
{
// Create a whole new document and we'll just save over top of the old one
tinyxml2::XMLDocument Doc;
// Root Element is called "PASTA"
tinyxml2::XMLElement *Root = Doc.NewElement("PASTA");
Doc.LinkEndChild(Root);
Utilities::Log("Saving Window %s", window->Title.c_str());
// If the window has some tabs..
if (Root && window->Tabs.size() > 0)
{
for (auto Tab : window->Tabs)
{
// Add a new section for this tab
tinyxml2::XMLElement *TabElement = Doc.NewElement(Tab->Title.c_str());
Root->LinkEndChild(TabElement);
Utilities::Log("Saving Tab %s", Tab->Title.c_str());
// Now we itterate the controls this tab contains
if (TabElement && Tab->Controls.size() > 0)
{
for (auto Control : Tab->Controls)
{
// If the control is ok to be saved
if (Control && Control->Flag(UIFlags::UI_SaveFile) && Control->FileIdentifier.length() > 1 && Control->FileControlType && Control->FileIdentifier.c_str() != "Settings")
{
// Create an element for the control
tinyxml2::XMLElement *ControlElement = Doc.NewElement(Control->FileIdentifier.c_str());
TabElement->LinkEndChild(ControlElement);
Utilities::Log("Saving control %s", Control->FileIdentifier.c_str());
if (!ControlElement)
{
Utilities::Log("Error saving ControlElement");
return;
}
CCheckBox* cbx = nullptr;
CComboBox* cbo = nullptr;
CKeyBind* key = nullptr;
CSlider* sld = nullptr;
// Figure out what kind of control and data this is
switch (Control->FileControlType)
{
case UIControlTypes::UIC_CheckBox:
cbx = (CCheckBox*)Control;
ControlElement->SetText(cbx->GetState());
break;
case UIControlTypes::UIC_ComboBox:
cbo = (CComboBox*)Control;
ControlElement->SetText(cbo->GetIndex());
break;
case UIControlTypes::UIC_KeyBind:
key = (CKeyBind*)Control;
ControlElement->SetText(key->GetKey());
break;
case UIControlTypes::UIC_Slider:
sld = (CSlider*)Control;
ControlElement->SetText(sld->GetValue());
break;
}
}
}
}
}
}
//Save the file
if (Doc.SaveFile(Filename.c_str()) != tinyxml2::XML_NO_ERROR)
{
MessageBox(NULL, "Failed To Save Config File!", "PASTA", MB_OK);
}
}