Inheritance: PlistElement
Esempio n. 1
1
        public void ReadFromString(string text)
        {
            XDocument doc = ParseXmlNoDtd(text);
            version = (string) doc.Root.Attribute("version");
            XElement xml = doc.XPathSelectElement("plist/dict");

            var dict = ReadElement(xml);
            if (dict == null)
                throw new Exception("Error parsing plist file");
            root = dict as PlistElementDict;
            if (root == null)
                throw new Exception("Malformed plist file");
        }
    private static void AddElementInfoPlist(string pathToBuiltProject)
    {
#if UNITY_IOS
        // Get plist
        string plistPath = pathToBuiltProject + "/Info.plist";
        var    plist     = new UnityEditor.iOS.Xcode.PlistDocument();
        plist.ReadFromString(File.ReadAllText(plistPath));
        bool changed = false;

        // Get root
        UnityEditor.iOS.Xcode.PlistElementDict rootDict = plist.root;

        foreach (var p in InfoPlist)
        {
            if (!rootDict.values.ContainsKey(p.Key))
            {
                rootDict.CreateDict(p.Key);
            }
            rootDict.SetString(p.Key, p.Value);
            changed = true;
        }

        if (changed)
        {
            // Write to file
            File.WriteAllText(plistPath, plist.WriteToString());
        }
#endif
    }
Esempio n. 3
0
    public static void OnPostprocessBuild(string xcodePath, string configPath)
    {
        pluginPath = configPath.Replace("XcodeSetting.json", "");
        string     projPath = PBXProject.GetPBXProjectPath(xcodePath);
        PBXProject proj     = new PBXProject();

        proj.ReadFromString(File.ReadAllText(projPath));

        string        plistPath = xcodePath + "/Info.plist";
        PlistDocument plist     = new PlistDocument();

        plist.ReadFromString(File.ReadAllText(plistPath));
        PlistElementDict rootDict = plist.root;

        //string target = proj.TargetGuidByName(PBXProject.GetUnityTargetName());
        //string target = proj.TargetGuidByName("UnityFramework");
        //string productName = proj.GetBuildPropertyForAnyConfig(target, "PRODUCT_NAME");
        string entitlementFilePath          = Path.Combine(PBXProject.GetUnityTargetName(), "usdk.entitlements");
        ProjectCapabilityManager pcbManager = new ProjectCapabilityManager(proj, projPath, entitlementFilePath, PBXProject.GetUnityTargetName());

        //读取配置文件
        string    json  = File.ReadAllText(configPath);
        Hashtable table = json.hashtableFromJson();

        embedFrameworksTable = table.SGet <Hashtable>("embedframeworks");

        //plist
        SetPlist(proj, rootDict, table.SGet <Hashtable>("plist"));
        plist.WriteToFile(plistPath);

        //lib
        SetLibs(proj, table.SGet <Hashtable>("libs"));
        //framework
        SetFrameworks(proj, table.SGet <Hashtable>("frameworks"));
        //building setting
        SetBuildProperties(proj, table.SGet <Hashtable>("properties"));
        SetShellScriptBuildPhase(proj, table.SGet <Hashtable>("shellscript"));
        //复制文件
        CopyFiles(proj, xcodePath, table.SGet <Hashtable>("files"));
        //复制文件夹
        CopyFolders(proj, xcodePath, table.SGet <Hashtable>("folders"));
        //文件编译符号
        SetFilesCompileFlag(proj, table.SGet <Hashtable>("filesCompileFlag"));
        //加入能力
        SetCapabilitys(pcbManager, table.SGet <Hashtable>("capabilitys"));
        //写入
        File.WriteAllText(projPath, proj.WriteToString());

        Console.WriteLine("***Info.plist*****\n" + File.ReadAllText(plistPath));
    }
Esempio n. 4
0
        public void ReadFromString(string text)
        {
            XDocument doc = ParseXmlNoDtd(text);

            version = (string)doc.Root.Attribute("version");
            XElement xml = doc.XPathSelectElement("plist/dict");

            var dict = ReadElement(xml);

            if (dict == null)
            {
                throw new Exception("Error parsing plist file");
            }
            root = dict as PlistElementDict;
            if (root == null)
            {
                throw new Exception("Malformed plist file");
            }
        }
Esempio n. 5
0
 //设置plist
 private static void SetPlist(PBXProject proj, PlistElementDict node, Hashtable arg)
 {
     if (arg != null)
     {
         foreach (DictionaryEntry i in arg)
         {
             string key   = i.Key.ToString();
             object val   = i.Value;
             var    vType = i.Value.GetType();
             if (vType == typeof(string))
             {
                 node.SetString(key, (string)val);
             }
             else if (vType == typeof(bool))
             {
                 node.SetBoolean(key, (bool)val);
             }
             else if (vType == typeof(double))
             {
                 int v = int.Parse(val.ToString());
                 node.SetInteger(key, v);
             }
             else if (vType == typeof(ArrayList))
             {
                 var t     = node.CreateArray(key);
                 var array = val as ArrayList;
                 SetPlist(proj, t, array);
             }
             else if (vType == typeof(Hashtable))
             {
                 var t     = node.CreateDict(key);
                 var table = val as Hashtable;
                 SetPlist(proj, t, table);
             }
         }
     }
 }
Esempio n. 6
0
        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");
                    }
                    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 "true":
                return(new PlistElementBoolean(true));

            case "false":
                return(new PlistElementBoolean(false));

            default:
                return(null);
            }
        }
Esempio n. 7
0
 public PlistDocument()
 {
     root    = new PlistElementDict();
     version = "1.0";
 }
Esempio n. 8
0
        public void AddMaps(MapsOptions options)
        {
            PlistElementArray root1 = (this.GetOrCreateInfoDoc().root[MapsInfo.BundleKey] ?? (this.GetOrCreateInfoDoc().root[MapsInfo.BundleKey] = (PlistElement) new PlistElementArray())) as PlistElementArray;

            root1.values.Add((PlistElement) new PlistElementDict());
            PlistElementDict dictElementInArray = this.GetOrCreateUniqueDictElementInArray(root1);

            dictElementInArray[MapsInfo.BundleNameKey] = (PlistElement) new PlistElementString(MapsInfo.BundleNameValue);
            this.GetOrCreateStringElementInArray((dictElementInArray[MapsInfo.BundleTypeKey] ?? (dictElementInArray[MapsInfo.BundleTypeKey] = (PlistElement) new PlistElementArray())) as PlistElementArray, MapsInfo.BundleTypeValue);
            PlistElementArray root2 = (this.GetOrCreateInfoDoc().root[MapsInfo.ModeKey] ?? (this.GetOrCreateInfoDoc().root[MapsInfo.ModeKey] = (PlistElement) new PlistElementArray())) as PlistElementArray;

            if ((options & MapsOptions.Airplane) == MapsOptions.Airplane)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModePlaneValue);
            }
            if ((options & MapsOptions.Bike) == MapsOptions.Bike)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeBikeValue);
            }
            if ((options & MapsOptions.Bus) == MapsOptions.Bus)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeBusValue);
            }
            if ((options & MapsOptions.Car) == MapsOptions.Car)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeCarValue);
            }
            if ((options & MapsOptions.Ferry) == MapsOptions.Ferry)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeFerryValue);
            }
            if ((options & MapsOptions.Other) == MapsOptions.Other)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeOtherValue);
            }
            if ((options & MapsOptions.Pedestrian) == MapsOptions.Pedestrian)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModePedestrianValue);
            }
            if ((options & MapsOptions.RideSharing) == MapsOptions.RideSharing)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeRideShareValue);
            }
            if ((options & MapsOptions.StreetCar) == MapsOptions.StreetCar)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeStreetCarValue);
            }
            if ((options & MapsOptions.Subway) == MapsOptions.Subway)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeSubwayValue);
            }
            if ((options & MapsOptions.Taxi) == MapsOptions.Taxi)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeTaxiValue);
            }
            if ((options & MapsOptions.Train) == MapsOptions.Train)
            {
                this.GetOrCreateStringElementInArray(root2, MapsInfo.ModeTrainValue);
            }
            this.project.AddCapability(this.m_TargetGuid, PBXCapabilityType.Maps, (string)null, false);
        }
 public PlistElementDict AddDict()
 {
     PlistElementDict item = new PlistElementDict();
     this.values.Add(item);
     return item;
 }
Esempio n. 10
0
        private static PlistElement ReadElement(XElement xml)
        {
            string localName = xml.Name.LocalName;
            // ISSUE: reference to a compiler-generated method
            uint stringHash = PrivateImplementationDetails.ComputeStringHash(localName);

            if (stringHash <= 1303515621U)
            {
                if (stringHash <= 398550328U)
                {
                    if ((int)stringHash != 184981848)
                    {
                        if ((int)stringHash == 398550328 && localName == "string")
                        {
                            return((PlistElement) new PlistElementString(PlistDocument.GetText(xml)));
                        }
                    }
                    else if (localName == "false")
                    {
                        return((PlistElement) new PlistElementBoolean(false));
                    }
                }
                else if ((int)stringHash != 1278716217)
                {
                    if ((int)stringHash == 1303515621 && localName == "true")
                    {
                        return((PlistElement) new PlistElementBoolean(true));
                    }
                }
                else if (localName == "dict")
                {
                    List <XElement>  list             = Enumerable.ToList <XElement>(xml.Elements());
                    PlistElementDict plistElementDict = new PlistElementDict();
                    if (list.Count % 2 == 1)
                    {
                        throw new Exception("Malformed plist file");
                    }
                    for (int index1 = 0; index1 < list.Count - 1; ++index1)
                    {
                        if (list[index1].Name != (XName)"key")
                        {
                            throw new Exception("Malformed plist file. Found '" + (object)list[index1].Name + "' where 'key' was expected.");
                        }
                        string       index2       = PlistDocument.GetText(list[index1]).Trim();
                        PlistElement plistElement = PlistDocument.ReadElement(list[index1 + 1]);
                        if (plistElement != null)
                        {
                            ++index1;
                            plistElementDict[index2] = plistElement;
                        }
                    }
                    return((PlistElement)plistElementDict);
                }
            }
            else if (stringHash <= 3218261061U)
            {
                if ((int)stringHash != -1973899994)
                {
                    int result;
                    if ((int)stringHash == -1076706235 && localName == "integer" && int.TryParse(PlistDocument.GetText(xml), out result))
                    {
                        return((PlistElement) new PlistElementInteger(result));
                    }
                }
                else if (localName == "array")
                {
                    List <XElement>   list = Enumerable.ToList <XElement>(xml.Elements());
                    PlistElementArray plistElementArray = new PlistElementArray();
                    foreach (XElement xml1 in list)
                    {
                        PlistElement plistElement = PlistDocument.ReadElement(xml1);
                        if (plistElement != null)
                        {
                            plistElementArray.values.Add(plistElement);
                        }
                    }
                    return((PlistElement)plistElementArray);
                }
            }
            else if ((int)stringHash != -730669991)
            {
                float result;
                if ((int)stringHash == -689983395 && localName == "real" && float.TryParse(PlistDocument.GetText(xml), out result))
                {
                    return((PlistElement) new PlistElementReal(result));
                }
            }
            else
            {
                DateTime result;
                if (localName == "date" && DateTime.TryParse(PlistDocument.GetText(xml), out result))
                {
                    return((PlistElement) new PlistElementDate(result.ToUniversalTime()));
                }
            }
            return((PlistElement)null);
        }
Esempio n. 11
0
 public PlistElementDict AddDict()
 {
     var v = new PlistElementDict();
     values.Add(v);
     return v;
 }
Esempio n. 12
0
 public PlistDocument()
 {
     root = new PlistElementDict();
     version = "1.0";
 }
Esempio n. 13
0
        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");
                        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 "true":
                    return new PlistElementBoolean(true);
                case "false":
                    return new PlistElementBoolean(false);
                default:
                    return null;
            }
        }
Esempio n. 14
0
 public PlistDocument()
 {
     this.root    = new PlistElementDict();
     this.version = "1.0";
 }
Esempio n. 15
0
        private static PlistElement ReadElement(XElement xml)
        {
            string localName = xml.Name.LocalName;

            if (localName != null)
            {
                Dictionary <string, int> types = new Dictionary <string, int>(8)
                {
                    {
                        "dict",
                        0
                    },
                    {
                        "array",
                        1
                    },
                    {
                        "string",
                        2
                    },
                    {
                        "integer",
                        3
                    },
                    {
                        "real",
                        4
                    },
                    {
                        "date",
                        5
                    },
                    {
                        "true",
                        6
                    },
                    {
                        "false",
                        7
                    }
                };

                int num = 0;
                if (types.TryGetValue(localName, out num))
                {
                    switch (num)
                    {
                    case 0:
                        List <XElement>  list1            = Enumerable.ToList <XElement>(xml.Elements());
                        PlistElementDict plistElementDict = new PlistElementDict();
                        if (list1.Count % 2 == 1)
                        {
                            throw new Exception("Malformed plist file");
                        }
                        for (int index1 = 0; index1 < list1.Count - 1; ++index1)
                        {
                            if (list1[index1].Name != (XName)"key")
                            {
                                throw new Exception("Malformed plist file. Found '" + (object)list1[index1].Name + "' where 'key' was expected.");
                            }
                            string       index2       = PlistDocument.GetText(list1[index1]).Trim();
                            PlistElement plistElement = PlistDocument.ReadElement(list1[index1 + 1]);
                            if (plistElement != null)
                            {
                                ++index1;
                                plistElementDict[index2] = plistElement;
                            }
                        }
                        return((PlistElement)plistElementDict);

                    case 1:
                        List <XElement>   list2             = Enumerable.ToList <XElement>(xml.Elements());
                        PlistElementArray plistElementArray = new PlistElementArray();
                        foreach (XElement xml1 in list2)
                        {
                            PlistElement plistElement = PlistDocument.ReadElement(xml1);
                            if (plistElement != null)
                            {
                                plistElementArray.values.Add(plistElement);
                            }
                        }
                        return((PlistElement)plistElementArray);

                    case 2:
                        return((PlistElement) new PlistElementString(PlistDocument.GetText(xml)));

                    case 3:
                        int result1;
                        if (int.TryParse(PlistDocument.GetText(xml), out result1))
                        {
                            return((PlistElement) new PlistElementInteger(result1));
                        }
                        return((PlistElement)null);

                    case 4:
                        float result2;
                        if (float.TryParse(PlistDocument.GetText(xml), out result2))
                        {
                            return((PlistElement) new PlistElementReal(result2));
                        }
                        return((PlistElement)null);

                    case 5:
                        DateTime result3;
                        if (DateTime.TryParse(PlistDocument.GetText(xml), out result3))
                        {
                            return((PlistElement) new PlistElementDate(result3.ToUniversalTime()));
                        }
                        return((PlistElement)null);

                    case 6:
                        return((PlistElement) new PlistElementBoolean(true));

                    case 7:
                        return((PlistElement) new PlistElementBoolean(false));
                    }
                }
            }
            return(null);
        }
Esempio n. 16
0
 public PlistElementDict CreateDict(string key)
 {
     var v = new PlistElementDict();
     values[key] = v;
     return v;
 }
Esempio n. 17
0
        // Add Maps capability to the project.
        public void AddMaps(MapsOptions options)
        {
            var bundleArr = (GetOrCreateInfoDoc().root[MapsInfo.BundleKey] ?? (GetOrCreateInfoDoc().root[MapsInfo.BundleKey] = new PlistElementArray())) as PlistElementArray;

            bundleArr.values.Add(new PlistElementDict());
            PlistElementDict bundleDic = GetOrCreateUniqueDictElementInArray(bundleArr);

            bundleDic[MapsInfo.BundleNameKey] = new PlistElementString(MapsInfo.BundleNameValue);
            var bundleTypeArr = (bundleDic[MapsInfo.BundleTypeKey] ?? (bundleDic[MapsInfo.BundleTypeKey] = new PlistElementArray())) as PlistElementArray;

            GetOrCreateStringElementInArray(bundleTypeArr, MapsInfo.BundleTypeValue);

            var optionArr = (GetOrCreateInfoDoc().root[MapsInfo.ModeKey] ??
                             (GetOrCreateInfoDoc().root[MapsInfo.ModeKey] = new PlistElementArray())) as PlistElementArray;

            if ((options & MapsOptions.Airplane) == MapsOptions.Airplane)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModePlaneValue);
            }
            if ((options & MapsOptions.Bike) == MapsOptions.Bike)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeBikeValue);
            }
            if ((options & MapsOptions.Bus) == MapsOptions.Bus)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeBusValue);
            }
            if ((options & MapsOptions.Car) == MapsOptions.Car)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeCarValue);
            }
            if ((options & MapsOptions.Ferry) == MapsOptions.Ferry)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeFerryValue);
            }
            if ((options & MapsOptions.Other) == MapsOptions.Other)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeOtherValue);
            }
            if ((options & MapsOptions.Pedestrian) == MapsOptions.Pedestrian)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModePedestrianValue);
            }
            if ((options & MapsOptions.RideSharing) == MapsOptions.RideSharing)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeRideShareValue);
            }
            if ((options & MapsOptions.StreetCar) == MapsOptions.StreetCar)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeStreetCarValue);
            }
            if ((options & MapsOptions.Subway) == MapsOptions.Subway)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeSubwayValue);
            }
            if ((options & MapsOptions.Taxi) == MapsOptions.Taxi)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeTaxiValue);
            }
            if ((options & MapsOptions.Train) == MapsOptions.Train)
            {
                GetOrCreateStringElementInArray(optionArr, MapsInfo.ModeTrainValue);
            }

            project.AddCapability(m_TargetGuid, PBXCapabilityType.Maps);
        }
 public PlistElementDict CreateDict(string key)
 {
     PlistElementDict dict = new PlistElementDict();
     this.values[key] = dict;
     return dict;
 }