Example #1
0
        public static void ApplyGlobal(TyGlobal global, TyModEdit edit)
        {
            int  count  = 0;
            bool addNew = true;

            if (edit.Attributes.Count > 0)
            {
                // Find with TyGlobal based on first attribute
                string key   = edit.Attributes.Keys.ElementAt(0).ToLower();
                string regex = edit.Attributes[key];

                foreach (TyGlobalItem item in global.Items)
                {
                    if (ApplyGlobal_Find(global, item, edit, key, regex, ref count) > 0)
                    {
                        addNew = false;
                    }
                }
            }

            if (!addNew)
            {
                return;
            }

            // Add new to TyGlobal
            for (int x = 0; x < edit.SubItems.Count; x++)
            {
                global.Items.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, (global.Items.Count == 0 ? null : global.Items[global.Items.Count - 1].Context), 0, false));
                ApplyGlobal_Add(global, global.Items[global.Items.Count - 1], edit.SubItems[x]);
            }
        }
Example #2
0
        private static void AddFromNode_Global_Recursive(TyModEdit modEdit, XmlNode node)
        {
            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.HasTextChild())
                {
                    modEdit.SubItems.Add(new TyModEditItem(childNode.Name, childNode.GetFirstTextChild()));
                }

                AddFromNode_Global_Recursive(modEdit, childNode);
            }
        }
Example #3
0
        public static void ApplyGlobal_Apply(TyGlobal global, TyGlobalItem item, TyModEdit edit)
        {
            TyGlobalItem newItem;

            // If we are directly setting the value
            if (edit.Value != null)
            {
                item.Value = edit.Value;
            }

            switch (edit.Type)
            {
            case TyModEdit.EditType.exclusive:
                item.SubItems.Clear();
                for (int x = 0; x < edit.SubItems.Count; x++)
                {
                    item.SubItems.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, item.Context, item.Indents + 4, ApplyGlobal_EqualSign(global, item, edit.SubItems[x])));
                }
                break;

            case TyModEdit.EditType.inclusive:

                for (int x = 0; x < edit.SubItems.Count; x++)
                {
                    newItem = item.SubItems.Find(s => s.Key == edit.SubItems[x].Key);
                    if (newItem != null)
                    {
                        newItem.Value = edit.SubItems[x].Value;
                    }
                    else
                    {
                        item.SubItems.Add(new TyGlobalItem(edit.SubItems[x].Key, edit.SubItems[x].Value, item.Context, item.Indents + 4, ApplyGlobal_EqualSign(global, item, edit.SubItems[x])));
                    }
                }
                break;

            case TyModEdit.EditType.replace:
                for (int x = 0; x < edit.SubItems.Count; x++)
                {
                    newItem = item.SubItems.Find(s => s.Key == edit.SubItems[x].Key);
                    if (newItem != null)
                    {
                        newItem.Value = edit.SubItems[x].Value;
                    }
                }
                break;
            }
        }
Example #4
0
        public static int ApplyGlobal_Find(TyGlobal global, TyGlobalItem item, TyModEdit edit, string key, string regex, ref int count)
        {
            if (item.Key != null && item.Key.ToLower() == key)
            {
                if (item.Value != null && Regex.IsMatch(item.Value, regex))
                {
                    if (edit.Context == null || (item.Context != null && Regex.IsMatch(item.Context, edit.Context, RegexOptions.Multiline)))
                    {
                        ApplyGlobal_Apply(global, item, edit);
                        count++;
                    }
                }
            }

            foreach (TyGlobalItem sub in item.SubItems)
            {
                ApplyGlobal_Find(global, sub, edit, key, regex, ref count);
            }

            return(count);
        }
Example #5
0
        private static void AddFromNode_Global(TyMod tymod, XmlNode node)
        {
            string source, type, context = null;

            TyModEdit.EditType editType = TyModEdit.EditType.inclusive;
            TyModEdit          modEdit;

            if (node.Attributes == null)
            {
                Program.Log(tymod.ToString(), "No attributes assigned to global \"" + node.OuterXml + "\"");
                return;
            }

            try { source = node.Attributes.GetNamedItem("source").Value; } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid source attribute for global \"" + node.OuterXml + "\"", e); return; }
            try { type = node.Attributes.GetNamedItem("type").Value; editType = (TyModEdit.EditType)Enum.Parse(typeof(TyModEdit.EditType), type); } catch (Exception) { }
            try { context = node.Attributes.GetNamedItem("context")?.Value?.ToLower(); } catch (Exception) { }

            modEdit = new TyModEdit(source, editType, context);

            foreach (XmlAttribute attr in node.Attributes)
            {
                if (attr.Name == "source" || attr.Name == "type" || attr.Name == "context")
                {
                    continue;
                }

                modEdit.Attributes.Add(attr.Name, attr.Value);
            }

            if (node.HasTextChild())
            {
                modEdit.Value = node.GetFirstTextChild();
            }

            AddFromNode_Global_Recursive(modEdit, node);

            tymod.Edits.Add(modEdit);
        }