private PlistElementDict GetOrCreateUniqueDictElementInArray(PlistElementArray root) { PlistElementDict r; if (root.values.Count == 0) { r = root.values[0] as PlistElementDict; } else { r = new PlistElementDict(); root.values.Add(r); } return(r); }
private PlistElementString GetOrCreateStringElementInArray(PlistElementArray root, string value) { PlistElementString r = null; var c = root.values.Count; var exist = false; for (var i = 0; i < c; i++) { if (root.values[i] is PlistElementString && (root.values[i] as PlistElementString).value == value) { r = root.values[i] as PlistElementString; exist = true; } } if (!exist) { r = new PlistElementString(value); root.values.Add(r); } return(r); }
private static PlistElement ReadElement(XElement xml) { switch (xml.Name.LocalName) { case "dict": { List <XElement> children = xml.Elements().ToList(); var el = new PlistElementDict(); if (children.Count % 2 == 1) { throw new Exception("Malformed plist file"); } for (int i = 0; i < children.Count - 1; i++) { if (children[i].Name != "key") { throw new Exception("Malformed plist file. Found '" + children[i].Name + "' where 'key' was expected."); } string key = GetText(children[i]).Trim(); var newChild = ReadElement(children[i + 1]); if (newChild != null) { i++; el[key] = newChild; } } return(el); } case "array": { List <XElement> children = xml.Elements().ToList(); var el = new PlistElementArray(); foreach (var childXml in children) { var newChild = ReadElement(childXml); if (newChild != null) { el.values.Add(newChild); } } return(el); } case "string": return(new PlistElementString(GetText(xml))); case "integer": { int r; if (int.TryParse(GetText(xml), out r)) { return(new PlistElementInteger(r)); } return(null); } case "real": { float f; if (float.TryParse(GetText(xml), out f)) { return(new PlistElementReal(f)); } return(null); } case "date": { DateTime date; if (DateTime.TryParse(GetText(xml), out date)) { return(new PlistElementDate(date.ToUniversalTime())); } return(null); } case "true": return(new PlistElementBoolean(true)); case "false": return(new PlistElementBoolean(false)); default: return(null); } }
public void AddiCloud(bool enableKeyValueStorage, bool enableiCloudDocument, bool enablecloudKit, bool addDefaultContainers, string[] customContainers) { var ent = GetOrCreateEntitlementDoc(); var val = (ent.root[ICloudEntitlements.ContainerIdKey] = new PlistElementArray()) as PlistElementArray; // Cloud document storage and CloudKit require specifying services. PlistElementArray ser = null; if (enableiCloudDocument || enablecloudKit) { ser = (ent.root[ICloudEntitlements.ServicesKey] = new PlistElementArray()) as PlistElementArray; } if (enableiCloudDocument) { val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue)); ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesDocValue)); var ubiquity = (ent.root[ICloudEntitlements.UbiquityContainerIdKey] = new PlistElementArray()) as PlistElementArray; if (addDefaultContainers) { ubiquity.values.Add(new PlistElementString(ICloudEntitlements.UbiquityContainerIdValue)); } if (customContainers != null && customContainers.Length > 0) { // For cloud document, custom containers go in the ubiquity values. for (var i = 0; i < customContainers.Length; i++) { ubiquity.values.Add(new PlistElementString(customContainers[i])); } } } if (enablecloudKit) { if (addDefaultContainers && !enableiCloudDocument) { val.values.Add(new PlistElementString(ICloudEntitlements.ContainerIdValue)); } if (customContainers != null && customContainers.Length > 0) { // For CloudKit, custom containers also go in the container id values. for (var i = 0; i < customContainers.Length; i++) { val.values.Add(new PlistElementString(customContainers[i])); } } ser.values.Add(new PlistElementString(ICloudEntitlements.ServicesKitValue)); } if (enableKeyValueStorage) { ent.root[ICloudEntitlements.KeyValueStoreKey] = new PlistElementString(ICloudEntitlements.KeyValueStoreValue); } project.AddCapability(m_TargetGuid, PBXCapabilityType.iCloud, m_EntitlementFilePath, enablecloudKit); }