void AddEnumValues(PListDictionary dic)
    {
        var valDic = new PListDictionary();

        foreach (var kvp in _enumValues)
        {
            if (string.IsNullOrEmpty(kvp.Key) || string.IsNullOrEmpty(kvp.Value))
            {
                Debug.LogWarning("Warning adding empty key or value for enum");
                //                continue;
            }

            valDic.Add(kvp.Key, kvp.Value);
        }

        if (valDic.Count > 0)
        {
            dic.Add(VALUE_KEY, valDic);
        }

        int defaultIndex = _enumValues.Keys.ToList().IndexOf(_defaultEnum);

        if (defaultIndex >= 0)
        {
            dic.Add(DEFAULT_INDEX, defaultIndex);
        }
    }
        public override PListDictionary Serialize()
        {
            var dic = new PListDictionary();

            dic.Add(NAME_KEY, FileName);
            dic.Add(LINK_TYPE_KEY, Link.ToString());
            return(dic);
        }
Exemple #3
0
        public override PListDictionary Serialize()
        {
            var dic = new PListDictionary();

            dic.Add(PATH_KEY, Path);
            dic.Add(TYPE_KEY, EntryType);
            dic.Add(ADD_METHOD_KEY, Add.ToString());
            return(dic);
        }
Exemple #4
0
        public override PListDictionary Serialize()
        {
            var dic = new PListDictionary();

            dic.Add(NAME_KEY, Name);
            dic.Add(SHELL_KEY, Shell);
            dic.Add(SCRIPT_KEY, Script);
            return(dic);
        }
    void AddArrayValue(PListDictionary dic)
    {
        dic.Add(INHERIT_KEY, _isInherit);

        if (_isPath)
        {
            dic.Add(PATH_KEY, _isPath);
        }
    }
    void AddStringValue(PListDictionary dic)
    {
        if (!string.IsNullOrEmpty(_stringDefaultValue))
        {
            dic.Add(VALUE_KEY, _stringDefaultValue);
        }

        if (_isPath)
        {
            dic.Add(PATH_KEY, _isPath);
        }
    }
    void AddEntry()
    {
        if (!CanAddEntry())
        {
            return;
        }

        var settings             = _plist.Root.ArrayValue(BUILD_SETTINGS_KEY);
        int existingSettingIndex = IndexOfSetting(_setting);
        var dic = new PListDictionary();

        dic.Add(SETTING_KEY, _setting);
        dic.Add(DISPLAY_NAME_KEY, _name);
        dic.Add(GROUP_KEY, _groups[_groupIndex]);
        dic.Add(TYPE_KEY, _entryType.ToString());

        switch (_entryType)
        {
        case SettingType.Bool:
            AddBoolValue(dic);
            break;

        case SettingType.Enum:
            AddEnumValues(dic);
            break;

        case SettingType.String:
            AddStringValue(dic);
            break;

        case SettingType.Array:
        case SettingType.StringList:
            AddArrayValue(dic);
            break;

        default:
            throw new System.Exception("Invalid Entry Type");
        }

        if (existingSettingIndex < 0)
        {
            settings.Add(dic);
        }
        else
        {
            settings.RemoveAt(existingSettingIndex);
            settings.Insert(existingSettingIndex, dic);
        }

        _plist.Save();
        ResetEntry();
    }
Exemple #8
0
        public void Copy()
        {
            _element.Add("A", new PListString("Foo"));
            _element.Add("B", new PListInteger(10));
            var copy = _element.Copy() as PListDictionary;

            Assert.AreNotSame(copy, _element);
            Assert.AreEqual(_element.Count, copy.Count);

            foreach (var kvp in _element)
            {
                Assert.AreNotSame(kvp.Value, copy[kvp.Key]);
            }
        }
Exemple #9
0
        /// <summary>
        /// Loads from XML node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns>The PList data constructed from the xml node.</returns>
        public static IPListElement LoadFromXmlNode(XmlNode node)
        {
            switch (node.Name.ToLower())
            {
                case "string":
                    return new PListString(node.InnerText);

                case "real":
                    return new PListReal(decimal.Parse(node.InnerText));

                case "integer":
                    return new PListInteger(int.Parse(node.InnerText));

                case "true":
                    return new PListBoolean(true);

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

                case "date":
                    return new PListDate(DateTime.Parse(node.InnerText));

                case "data":
                    return new PListData(Convert.FromBase64String(node.InnerText));

                case "array":
                    {
                        var array = new PListArray();

                        foreach (XmlNode child in node.ChildNodes)
                        {
                            array.Add(LoadFromXmlNode(child));
                        }

                        return array;
                    }

                case "dict":
                    {
                        var dict = new PListDictionary();

                        for (int i = 0; i < node.ChildNodes.Count; i += 2)
                        {
                            var keyNode = node.ChildNodes[i];
                            var key = keyNode.InnerText;

                            dict.Add(key, LoadFromXmlNode(node.ChildNodes[i + 1]));
                        }

                        return dict;
                    }

                default:
                    return null;
            }
        }
Exemple #10
0
        public void Create()
        {
            PList p    = new PList();
            var   dict = p.Root;

            dict.Add("IntValue", new PListInteger(10));
            dict.Add("RealValue", new PListReal(3.14f));
            dict.Add("StringValue", new PListString("Foo"));
            dict.Add("BoolValueTrue", new PListBoolean(true));
            dict.Add("BoolValueFalse", new PListBoolean(false));
            dict.Add("DateValue", new PListDate("2014-03-07T13:28:45Z"));
            dict.Add("DataValue", new PListData("bXkgcGhvdG8="));
            var array = new PListArray();

            array.Add(new PListString("Array Element"));
            array.Add(new PListBoolean(true));
            array.Add(new PListInteger(20));
            array.Add(new PListReal(20.12f));
            array.Add(new PListDate("2014-03-08T13:31:13Z"));
            array.Add(new PListData("ASNFZw=="));
            dict.Add("ArrayValue", array);
            var d = new PListDictionary();

            d.Add("DicInt", new PListInteger(30));
            d.Add("DicReal", new PListReal(30.12f));
            d.Add("DicString", new PListString("Dictionary Element"));
            d.Add("DicBool", new PListBoolean(true));
            d.Add("DicData", new PListData("ASNFZ4mrze8="));
            d.Add("DicDate", new PListDate("2014-03-09T13:33:00Z"));
            dict.Add("DictionaryValue", d);;
            string path = Path.Combine(_sampleFilePath, "manual.plist");

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            Assert.IsFalse(File.Exists(path));
            bool ok = p.Save(path);

            Assert.IsTrue(ok);
            PList reload = new PList();

            ok = reload.Load(path);
            Assert.IsTrue(ok);
            Assert.AreEqual(_basicPlist.ToString(), reload.ToString());
            File.Delete(path);
        }
Exemple #11
0
        protected void UpdateDictionaryKey(PListDictionary dict, string oldKey, string newKey)
        {
            if (oldKey == newKey)
            {
                return;
            }

            if (string.IsNullOrEmpty(newKey))
            {
                return;
            }

            if (dict.ContainsKey(newKey))
            {
                return;
            }

            var element = dict[oldKey];

            dict.Remove(oldKey);
            dict.Add(newKey, element);
        }
Exemple #12
0
        protected override void DrawDictionaryCommon(PListDictionary dic)
        {
            _indentLevel++;
            string        entryToRemove    = "";
            string        keyToUpdate      = "";
            string        newKeyValue      = "";
            string        valueToUpdateKey = "";
            IPListElement valueToUpdate    = null;
            Color         original         = GUI.color;

            foreach (var kvp in dic)
            {
                Style.IndentedHorizontalLine(Styling.ROW_COLOR, _indentLevel * INDENT_AMOUNT);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(_indentLevel * INDENT_AMOUNT);
                bool open = DrawFoldout(kvp.Value);

                try
                {
                    //draw the key
                    EditorGUI.BeginChangeCheck();
                    string key = EditorGUILayout.TextField(kvp.Key, GUILayout.MinWidth(KEY_WIDTH), GUILayout.MaxWidth(KEY_WIDTH));

                    if (EditorGUI.EndChangeCheck())
                    {
                        keyToUpdate = kvp.Key;
                        newKeyValue = key;
                        IsDirty     = true;
                    }

                    //draw type selector
                    IPListElement value = TypeSelector(kvp.Value);

                    if (value != kvp.Value)
                    {
                        valueToUpdateKey = key;
                        valueToUpdate    = value;
                        IsDirty          = true;
                    }
                }
                catch
                {
                    Debug.LogError("EgoXproject: Failed to update key: " + kvp.Key);
                }

                //draw the value
                DrawElement(kvp.Value);

                if (RemoveElement(kvp.Key))
                {
                    entryToRemove = kvp.Key;
                    IsDirty       = true;
                }

                EditorGUILayout.EndHorizontal();

                if (!open)
                {
                    continue;
                }

                //if element is a dictionary or an array, draw its entries
                if (kvp.Value is PListDictionary)
                {
                    DrawDictionaryCommon(kvp.Value as PListDictionary);
                }
                else if (kvp.Value is PListArray)
                {
                    DrawArrayContent(kvp.Value as PListArray);
                }
            }

            GUI.color = original;

            //perform dictionary maintenance
            if (!string.IsNullOrEmpty(keyToUpdate))
            {
                UpdateDictionaryKey(dic, keyToUpdate, newKeyValue);
            }

            if (!string.IsNullOrEmpty(valueToUpdateKey))
            {
                RemoveFoldoutEntry(dic [valueToUpdateKey]);
                dic [valueToUpdateKey] = valueToUpdate;
            }

            if (!string.IsNullOrEmpty(entryToRemove))
            {
                RemoveFoldoutEntry(dic [entryToRemove]);
                dic.Remove(entryToRemove);
            }

            if (AddElement())
            {
                string newKeyName = "New Key";
                int    count      = 1;

                while (dic.ContainsKey(newKeyName))
                {
                    newKeyName = "New Key " + count;
                    count++;
                }

                dic.Add(newKeyName, new PListString());
                IsDirty = true;
            }

            _indentLevel--;
        }
 void AddBoolValue(PListDictionary dic)
 {
     dic.Add(VALUE_KEY, _boolDefaultValue);
 }