Browse Source

Projucer: Changed the way the license information is stored and recalled in the Projucer's settings to not use XML text elements

tags/2021-05-28
ed 7 years ago
parent
commit
a447a1f434
2 changed files with 39 additions and 15 deletions
  1. +38
    -15
      extras/Projucer/Source/Licenses/jucer_LicenseController.cpp
  2. +1
    -0
      extras/Projucer/Source/Licenses/jucer_LicenseController.h

+ 38
- 15
extras/Projucer/Source/Licenses/jucer_LicenseController.cpp View File

@@ -261,21 +261,47 @@ void LicenseController::updateState (const LicenseState& newState)
listeners.call (&StateChangedCallback::licenseStateChanged, getState());
}
LicenseState LicenseController::licenseStateFromOldSettings (XmlElement* licenseXml)
{
LicenseState result;
result.type = getLicenseTypeFromValue (licenseXml->getChildElementAllSubText ("type", {}));
result.applicationUsageDataState = getApplicationUsageDataTypeFromValue (licenseXml->getChildElementAllSubText ("applicationUsageData", {}));
result.username = licenseXml->getChildElementAllSubText ("username", {});
result.email = licenseXml->getChildElementAllSubText ("email", {});
result.authToken = licenseXml->getChildElementAllSubText ("authToken", {});
MemoryOutputStream imageData;
Base64::convertFromBase64 (imageData, licenseXml->getChildElementAllSubText ("avatar", {}));
result.avatar = ImageFileFormat::loadFrom (imageData.getData(), imageData.getDataSize());
return result;
}
LicenseState LicenseController::licenseStateFromSettings (PropertiesFile& props)
{
ScopedPointer<XmlElement> licenseXml = props.getXmlValue ("license");
if (licenseXml != nullptr)
{
// this is here for backwards compatibility with old-style settings files using XML text elements
if (licenseXml->getChildElementAllSubText ("type", {}) != String())
{
auto stateFromOldSettings = licenseStateFromOldSettings (licenseXml);
licenseStateToSettings (stateFromOldSettings, props);
return stateFromOldSettings;
}
LicenseState result;
result.type = getLicenseTypeFromValue (licenseXml->getChildElementAllSubText ("type", {}));
result.applicationUsageDataState = getApplicationUsageDataTypeFromValue (licenseXml->getChildElementAllSubText ("applicationUsageData", {}));
result.username = licenseXml->getChildElementAllSubText ("username", {});
result.email = licenseXml->getChildElementAllSubText ("email", {});
result.authToken = licenseXml->getChildElementAllSubText ("authToken", {});
result.type = getLicenseTypeFromValue (licenseXml->getStringAttribute ("type", {}));
result.applicationUsageDataState = getApplicationUsageDataTypeFromValue (licenseXml->getStringAttribute ("applicationUsageData", {}));
result.username = licenseXml->getStringAttribute ("username", {});
result.email = licenseXml->getStringAttribute ("email", {});
result.authToken = licenseXml->getStringAttribute ("authToken", {});
MemoryOutputStream imageData;
Base64::convertFromBase64 (imageData, licenseXml->getChildElementAllSubText ("avatar", {}));
Base64::convertFromBase64 (imageData, licenseXml->getStringAttribute ("avatar", {}));
result.avatar = ImageFileFormat::loadFrom (imageData.getData(), imageData.getDataSize());
return result;
@@ -293,19 +319,16 @@ void LicenseController::licenseStateToSettings (const LicenseState& state, Prope
XmlElement licenseXml ("license");
if (auto* typeString = getLicenseStateValue (state.type))
licenseXml.createNewChildElement ("type")->addTextElement (typeString);
licenseXml.createNewChildElement ("applicationUsageData")->addTextElement (getApplicationUsageDataStateValue (state.applicationUsageDataState));
licenseXml.createNewChildElement ("username")->addTextElement (state.username);
licenseXml.createNewChildElement ("email") ->addTextElement (state.email);
licenseXml.setAttribute ("type", typeString);
// TODO: encrypt authToken
licenseXml.createNewChildElement ("authToken")->addTextElement (state.authToken);
licenseXml.setAttribute ("applicationUsageData", getApplicationUsageDataStateValue (state.applicationUsageDataState));
licenseXml.setAttribute ("username", state.username);
licenseXml.setAttribute ("email", state.email);
licenseXml.setAttribute ("authToken", state.authToken);
MemoryOutputStream imageData;
if (state.avatar.isValid() && PNGImageFormat().writeImageToStream (state.avatar, imageData))
licenseXml.createNewChildElement ("avatar")->addTextElement (Base64::toBase64 (imageData.getData(), imageData.getDataSize()));
licenseXml.setAttribute ("avatar", Base64::toBase64 (imageData.getData(), imageData.getDataSize()));
props.setValue ("license", &licenseXml);
}


+ 1
- 0
extras/Projucer/Source/Licenses/jucer_LicenseController.h View File

@@ -96,6 +96,7 @@ private:
//==============================================================================
void updateState (const LicenseState&);
static LicenseState licenseStateFromOldSettings (XmlElement*);
static LicenseState licenseStateFromSettings (PropertiesFile&);
static void licenseStateToSettings (const LicenseState&, PropertiesFile&);


Loading…
Cancel
Save