Browse Source

Ensure custom data restore is exactly how it was saved

Fixes #1521

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.4.2
falkTX 3 years ago
parent
commit
4fa1d2ba6b
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 41 additions and 6 deletions
  1. +41
    -6
      source/utils/CarlaStateUtils.cpp

+ 41
- 6
source/utils/CarlaStateUtils.cpp View File

@@ -486,23 +486,58 @@ bool CarlaStateSave::fillFromXmlElement(const XmlElement* const xmlElement)
{
CustomData* const stateCustomData(new CustomData());

// find type first
for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
{
const String& cTag(xmlSubData->getTagName());
const String cText(xmlSubData->getAllSubText().trim());

/**/ if (cTag == "Type")
stateCustomData->type = xmlSafeStringCharDup(cText, false);
else if (cTag == "Key")
stateCustomData->key = xmlSafeStringCharDup(cText, false);
if (cTag != "Type")
continue;

stateCustomData->type = xmlSafeStringCharDup(xmlSubData->getAllSubText().trim(), false);
break;
}

if (stateCustomData->type == nullptr || stateCustomData->type[0] == '\0')
{
carla_stderr("Reading CustomData type failed");
delete stateCustomData;
continue;
}

// now fill in key and value, knowing what the type is
for (XmlElement* xmlSubData = xmlData->getFirstChildElement(); xmlSubData != nullptr; xmlSubData = xmlSubData->getNextElement())
{
const String& cTag(xmlSubData->getTagName());
String cText(xmlSubData->getAllSubText());

/**/ if (cTag == "Key")
{
stateCustomData->key = xmlSafeStringCharDup(cText.trim(), false);
}
else if (cTag == "Value")
stateCustomData->value = carla_strdup(cText.toRawUTF8()); //xmlSafeStringCharDup(cText, false);
{
// save operation adds a newline and newline+space around the string in some cases
const int len = cText.length();
if (std::strcmp(stateCustomData->type, CUSTOM_DATA_TYPE_CHUNK) == 0 || len >= 128+6)
{
CARLA_SAFE_ASSERT_CONTINUE(len >= 6);
cText = cText.substring(1, len - 6);
}

stateCustomData->value = xmlSafeStringCharDup(cText, false);
}
}

if (stateCustomData->isValid())
{
customData.append(stateCustomData);
}
else
{
carla_stderr("Reading CustomData property failed, missing data");
delete stateCustomData;
}
}

// -------------------------------------------------------


Loading…
Cancel
Save