Skip to content

Commit

Permalink
Fix serializing empty configuration
Browse files Browse the repository at this point in the history
This ensures that if the buttonmap currently has data, but then all
data is reset, then the newly-reset state is still written to the file.

As example of writing an empty configuration:

  <?xml version="1.0" ?>
  <buttonmap>
      <device name="Extended Gamepad" provider="GCController" buttoncount="16" axiscount="4">
          <configuration />
      </device>
  </buttonmap>
  • Loading branch information
garbear committed Jan 13, 2025
1 parent 432c145 commit 3ec8b2c
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions src/storage/xml/DeviceXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,29 @@ bool CDeviceXml::Deserialize(const TiXmlElement* pElement, CDevice& record)

bool CDeviceXml::SerializeConfig(const CDeviceConfiguration& config, TiXmlElement* pElement)
{
if (!config.IsEmpty())
{
TiXmlElement configurationElement(BUTTONMAP_XML_ELEM_CONFIGURATION);
TiXmlNode* configurationNode = pElement->InsertEndChild(configurationElement);
if (configurationNode == nullptr)
return false;
TiXmlElement configurationElement(BUTTONMAP_XML_ELEM_CONFIGURATION);
TiXmlNode* configurationNode = pElement->InsertEndChild(configurationElement);
if (configurationNode == nullptr)
return false;

TiXmlElement* configurationElem = configurationNode->ToElement();
if (configurationElem == nullptr)
return false;
TiXmlElement* configurationElem = configurationNode->ToElement();
if (configurationElem == nullptr)
return false;

const std::string controllerId = config.GetAppearance();
if (!SerializeAppearance(controllerId, configurationElem))
return false;
const std::string controllerId = config.GetAppearance();
if (!SerializeAppearance(controllerId, configurationElem))
return false;

for (const auto& axis : config.Axes())
{
if (!SerializeAxis(axis.first, axis.second, configurationElem))
return false;
}
for (const auto& axis : config.Axes())
{
if (!SerializeAxis(axis.first, axis.second, configurationElem))
return false;
}

for (const auto& button : config.Buttons())
{
if (!SerializeButton(button.first, button.second, configurationElem))
return false;
}
for (const auto& button : config.Buttons())
{
if (!SerializeButton(button.first, button.second, configurationElem))
return false;
}

return true;
Expand Down

0 comments on commit 3ec8b2c

Please sign in to comment.