Beispiel #1
0
        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");
            }
        }
Beispiel #2
0
        private static void SetCFBundleURLSchemes(
            PListDict plistDict,
            string appID,
            string urlSuffix,
            ICollection <string> appLinkSchemes)
        {
            IList <object> currentSchemas;

            if (ContainsKeyWithValueType(plistDict, PListParser.CFBundleURLTypesKey, typeof(IList <object>)))
            {
                currentSchemas = (IList <object>)plistDict[PListParser.CFBundleURLTypesKey];
            }
            else
            {
                // Didn't find any CFBundleURLTypes, let's create one
                currentSchemas = new List <object>();
                plistDict[PListParser.CFBundleURLTypesKey] = currentSchemas;
            }

            PListDict facebookBundleUrlSchemes = PListParser.GetFacebookUrlSchemes(currentSchemas);

            // Clear and set the CFBundleURLSchemes for the facebook schemes
            var facebookUrlSchemes = new List <object>();

            facebookBundleUrlSchemes[PListParser.CFBundleURLSchemesKey] = facebookUrlSchemes;
            AddAppID(facebookUrlSchemes, appID, urlSuffix);
            AddAppLinkSchemes(facebookUrlSchemes, appLinkSchemes);
        }
Beispiel #3
0
        private static void WhilelistFacebookServersForNetworkRequests(PListDict plistDict)
        {
            if (!ContainsKeyWithValueType(plistDict, PListParser.NSAppTransportSecurityKey, typeof(PListDict)))
            {
                // We don't have a NSAppTransportSecurity entry. We can easily add one
                plistDict[PListParser.NSAppTransportSecurityKey] = PListParser.FacebookNSAppTransportSecurity;
                return;
            }

            var appTransportSecurityDict = (PListDict)plistDict[PListParser.NSAppTransportSecurityKey];

            if (!ContainsKeyWithValueType(appTransportSecurityDict, PListParser.NSExceptionDomainsKey, typeof(PListDict)))
            {
                appTransportSecurityDict[PListParser.NSExceptionDomainsKey] = PListParser.FacebookNSExceptionDomainsEntry;
                return;
            }

            var exceptionDomains = (PListDict)appTransportSecurityDict[PListParser.NSExceptionDomainsKey];

            foreach (var key in PListParser.FacebookNSExceptionDomainsEntry.Keys)
            {
                // Instead of just updating overwrite values to keep things up to date
                exceptionDomains[key] = FacebookNSExceptionDomainsEntry[key];
            }
        }
Beispiel #4
0
 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);
     }
 }
Beispiel #5
0
        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);
        }
        public void UpdateFBSettings(string appID, string urlSuffix)
        {
            xmlDict["FacebookAppID"] = appID;

            if (xmlDict.ContainsKey("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"];
                            string firstAppID          = (string)appIdsFromPListDict[0];
                            if (firstAppID.Contains("fb"))
                            {
                                // this is FB component
                                // clear old FB schemas, add current (editor properties) schemas
                                appIdsFromPListDict.Clear();
                                AddAppID(appIdsFromPListDict, appID, urlSuffix);
                                return;
                            }
                        }
                    }
                }

                // Didn't find FB schema, let's add FB schema to the list of schemas already present
                var appIds = new List <object>();
                AddAppID(appIds, appID, urlSuffix);
                var schemaEntry = new PListDict();
                schemaEntry.Add("CFBundleURLSchemes", appIds);
                currentSchemas.Add(schemaEntry);
                return;
            }
            else
            {
                // Didn't find any CFBundleURLTypes, let's create one
                var appIds = new List <object>();
                AddAppID(appIds, appID, urlSuffix);
                var schemaEntry = new PListDict();
                schemaEntry.Add("CFBundleURLSchemes", appIds);

                var currentSchemas = new List <object>();
                currentSchemas.Add(schemaEntry);
                xmlDict.Add("CFBundleURLTypes", currentSchemas);
            }
        }
Beispiel #7
0
        public FBPListParser(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();
        }
Beispiel #8
0
        private static void WhitelistFacebookApps(PListDict plistDict)
        {
            if (!ContainsKeyWithValueType(plistDict, PListParser.LSApplicationQueriesSchemesKey, typeof(IList <object>)))
            {
                // We don't have a LSApplicationQueriesSchemes entry. We can easily add one
                plistDict[PListParser.LSApplicationQueriesSchemesKey] = PListParser.FacebookLSApplicationQueriesSchemes;
                return;
            }

            var applicationQueriesSchemes = (IList <object>)plistDict[PListParser.LSApplicationQueriesSchemesKey];

            foreach (var scheme in PListParser.FacebookLSApplicationQueriesSchemes)
            {
                if (!applicationQueriesSchemes.Contains(scheme))
                {
                    applicationQueriesSchemes.Add(scheme);
                }
            }
        }
Beispiel #9
0
        private static PListDict GetFacebookUrlSchemes(ICollection <object> plistSchemes)
        {
            foreach (var plistScheme in plistSchemes)
            {
                var bundleTypeNode = plistScheme as PListDict;
                if (bundleTypeNode != null)
                {
                    // Check to see if the url scheme name is facebook
                    string bundleURLName;
                    if (bundleTypeNode.TryGetValue <string>(PListParser.CFBundleURLName, out bundleURLName) &&
                        bundleURLName == PListParser.FacebookCFBundleURLName)
                    {
                        return(bundleTypeNode);
                    }
                }
            }

            // We didn't find a facebook scheme so lets create one
            PListDict facebookUrlSchemes = new PListDict(PListParser.FacebookUrlSchemes);

            plistSchemes.Add(facebookUrlSchemes);
            return(facebookUrlSchemes);
        }
Beispiel #10
0
 public PListDict(PListDict dict) : base(dict)
 {
 }