diff --git a/extras/Projucer/Source/Licenses/jucer_LicenseController.cpp b/extras/Projucer/Source/Licenses/jucer_LicenseController.cpp index 61c2b21d46..3338977ff2 100644 --- a/extras/Projucer/Source/Licenses/jucer_LicenseController.cpp +++ b/extras/Projucer/Source/Licenses/jucer_LicenseController.cpp @@ -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 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); } diff --git a/extras/Projucer/Source/Licenses/jucer_LicenseController.h b/extras/Projucer/Source/Licenses/jucer_LicenseController.h index e430c2bd9d..17c522b617 100644 --- a/extras/Projucer/Source/Licenses/jucer_LicenseController.h +++ b/extras/Projucer/Source/Licenses/jucer_LicenseController.h @@ -96,6 +96,7 @@ private: //============================================================================== void updateState (const LicenseState&); + static LicenseState licenseStateFromOldSettings (XmlElement*); static LicenseState licenseStateFromSettings (PropertiesFile&); static void licenseStateToSettings (const LicenseState&, PropertiesFile&);