Ejemplo n.º 1
0
        void Load(string fileName)
        {
            this.FileName = fileName;
            string fileText = File.ReadAllText(fileName);

            //find the raw plist within the .mobileprovision file
            int start = fileText.IndexOf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            int length;

            if (start < 0 || (length = (fileText.IndexOf("</plist>", start) - start)) < 1)
            {
                throw new Exception("Did not find XML plist in '" + fileName + "'");
            }

            length += "</plist>".Length;
            string rawPlist = fileText.Substring(start, length);


            var doc = new PlistDocument();

            doc.LoadFromXml(rawPlist);
            var rootDict = (PlistDictionary)doc.Root;

            var prefixes = rootDict["ApplicationIdentifierPrefix"] as PlistArray;

            if (prefixes != null)
            {
                this.ApplicationIdentifierPrefix = prefixes.OfType <PlistString> ().Select(x => x.Value).ToArray();
            }

            var creationDate = rootDict ["CreationDate"] as PlistDate;

            if (creationDate != null)
            {
                this.CreationDate = creationDate.Value;
            }

            var devCerts = rootDict ["DeveloperCertificates"] as PlistArray;

            if (devCerts != null)
            {
                this.DeveloperCertificates = devCerts.OfType <PlistData> ().Select(x => new X509Certificate2(x.Value)).ToArray();
            }

            var entl = rootDict ["Entitlements"] as PlistDictionary;

            if (entl != null)
            {
                this.Entitlements = entl;                 //string application-identifier, bool get-task-allow, string[] keychain-access-groups
            }
            var expirationDate = rootDict ["ExpirationDate"] as PlistDate;

            if (expirationDate != null)
            {
                this.ExpirationDate = expirationDate.Value;
            }

            var name = rootDict ["Name"] as PlistString;

            if (name != null)
            {
                this.Name = name.Value;
            }

            var provDevs = rootDict.TryGetValue("ProvisionedDevices") as PlistArray;

            if (provDevs != null)
            {
                this.ProvisionedDevices = provDevs.OfType <PlistString> ().Select(x => x.Value).ToArray();
            }

            var ttl = rootDict ["TimeToLive"] as PlistInteger;

            if (ttl != null)
            {
                this.TimeToLive = ttl.Value;
            }

            var uuid = rootDict ["UUID"] as PlistString;

            if (uuid != null)
            {
                this.Uuid = uuid.Value;
            }

            var version = rootDict ["Version"] as PlistInteger;

            if (version != null)
            {
                this.Version = version.Value;
            }
        }