private object ParseValueForLoad(XElement val)
        {
            switch (val.Name.ToString())
            {
            case "string":
                return(val.Value);

            case "integer":
                return(int.Parse(val.Value));

            case "real":
                return(float.Parse(val.Value));

            case "true":
                return(true);

            case "false":
                return(false);

            case "dict":
                PListDict plist = new PListDict();
                ParseDictForLoad(plist, val.Elements());
                return(plist);

            case "array":
                return(ParseArrayForLoad(val.Elements()));

            default:
                throw new ArgumentException("Format unsupported, Parser update needed");
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates the schemes settings.
        /// </summary>
        /// <param name="urlSchemes">URL schemes.</param>
        public void UpdateSchemesSettings(string[] urlSchemes)
        {
            if (xmlDict.ContainsKey("CFBundleURLTypes"))
            {
                //Debug.Log ("Find CFBundleURLTypes");
                var currentSchemas = (List <object>)xmlDict ["CFBundleURLTypes"];
                for (int i = 0; i < currentSchemas.Count; i++)
                {
                    // if it's not a dictionary, go to next index
                    if (currentSchemas [i].GetType() == typeof(PListDict))
                    {
                        var bundleTypeNode = (PListDict)currentSchemas [i];
                        if (bundleTypeNode.ContainsKey("CFBundleURLSchemes") && bundleTypeNode ["CFBundleURLSchemes"].GetType() == typeof(List <object>))
                        {
                            var appIdsFromPListDict = (List <object>)bundleTypeNode ["CFBundleURLSchemes"];
                            appIdsFromPListDict.Clear();
                            for (int j = 0; j < urlSchemes.Length; j++)
                            {
                                string modifiedID = urlSchemes [j];
                                appIdsFromPListDict.Add((object)modifiedID);
                            }
                            return;
                        }
                    }
                }

                // Didn't find schema, let's add schema to the list of schemas already present
                var appIds = new List <object> ();
                for (int j = 0; j < urlSchemes.Length; j++)
                {
                    string modifiedID = urlSchemes [j];
                    appIds.Add((object)modifiedID);
                }
                var schemaEntry = new PListDict();
                schemaEntry.Add("CFBundleURLSchemes", appIds);
                currentSchemas.Add(schemaEntry);
                return;
            }
            else
            {
                //Debug.Log ("Didn't find any CFBundleURLTypes");
                var appIds = new List <object> ();
                for (int j = 0; j < urlSchemes.Length; j++)
                {
                    Debug.Log("urlScheme : " + urlSchemes [j]);

                    string modifiedID = urlSchemes [j];
                    appIds.Add((object)modifiedID);
                }
                var schemaEntry = new PListDict();
                schemaEntry.Add("CFBundleURLSchemes", appIds);

                var currentSchemas = new List <object> ();
                currentSchemas.Add(schemaEntry);
                xmlDict.Add("CFBundleURLTypes", currentSchemas);
            }
        }
 private void ParseDictForLoad(PListDict dict, IEnumerable <XElement> elements)
 {
     for (int i = 0; i < elements.Count(); i += 2)
     {
         XElement key = elements.ElementAt(i);
         XElement val = elements.ElementAt(i + 1);
         dict[key.Value] = ParseValueForLoad(val);
     }
 }
        private XElement ParseDictForSave(PListDict dict)
        {
            XElement dictNode = new XElement("dict");

            foreach (string key in dict.Keys)
            {
                dictNode.Add(new XElement("key", key));
                dictNode.Add(ParseValueForSave(dict[key]));
            }
            return(dictNode);
        }
Exemple #5
0
        public PListParser(string fullPath)
        {
            filePath = fullPath;
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ProhibitDtd = false;
            XmlReader plistReader = XmlReader.Create(filePath, settings);

            XDocument doc   = XDocument.Load(plistReader);
            XElement  plist = doc.Element("plist");
            XElement  dict  = plist.Element("dict");

            xmlDict = new PListDict(dict);
            plistReader.Close();
        }
Exemple #6
0
        public void UpdateDomainSecuritySettings(string[] domains)
        {
            string currentKey = "NSAppTransportSecurity";

            if (xmlDict.ContainsKey(currentKey))
            {
                xmlDict.Remove(currentKey);
            }

            if (domains.Length == 0)
            {
                var    dictSecurity = new PListDict();
                object setVlaue     = "true";
                dictSecurity.Add("NSAllowsArbitraryLoads", setVlaue);
                xmlDict.Add(currentKey, dictSecurity);
            }
            else
            {
                var    dictSecurity = new PListDict();
                var    dictDomains  = new PListDict();
                var    settings     = new PListDict();
                object setVlaue;

                setVlaue = "true";
                settings.Add("NSExceptionAllowsInsecureHTTPLoads", setVlaue);
                setVlaue = "false";
                settings.Add("NSExceptionRequiresForwardSecrecy", setVlaue);
                setVlaue = "true";
                settings.Add("NSIncludesSubdomains", setVlaue);

                for (int j = 0; j < domains.Length; j++)
                {
                    string domain = domains [j];
                    dictDomains.Add(domain, settings);
                }

                dictSecurity.Add("NSExceptionDomains", dictDomains);
                xmlDict.Add(currentKey, dictSecurity);
            }
        }