Example #1
0
        /// <summary>
        /// 载入配置文件
        /// </summary>
        /// <param name="configPath">配置文件路径</param>
        public void Load(string configPath)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(configPath);

            if (doc != null)
            {
                XmlNode config = doc.SelectSingleNode("configuration");

                LoadNodes("ignoreitems", "item", config, out m_ignoreItems);
                IgnoreItems.Add("\\Upgrade.exe");
                IgnoreItems.Add("\\Upgrade.vshost.exe");
                IgnoreItems.Add("\\Upgrade.exe.lnk");

                for (int i = 0; i < IgnoreItems.Count; i++)
                {
                    if (!IgnoreItems[i].StartsWith("\\"))
                    {
                        IgnoreItems[i] = "\\" + IgnoreItems[i];
                    }
                }

                LoadNodes("runcmds", "cmd", config, out m_runCmds);
                LoadNodes("closeApps", "app", config, out m_closeApps);
            }
        }
Example #2
0
        public static void Load(XElement xml)
        {
            XElement[] elements = xml.Elements().ToArray();
            foreach (XElement element in elements)
            {
                string name  = element.Name.ToString();
                string value = element.Value;

                switch (name.ToLower())
                {
                case "autoequipitems":
                case "equipitems":
                    bool autoEquipItems;
                    if (!bool.TryParse(value, out autoEquipItems))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        autoEquipItems = true;
                    }

                    AutoEquipItems = autoEquipItems;
                    break;

                case "autoequipbags":
                case "equipbags":
                    bool autoEquipBags;
                    if (!bool.TryParse(value, out autoEquipBags))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        autoEquipBags = true;
                    }

                    AutoEquipBags = autoEquipBags;
                    break;

                case "equipepics":
                case "equipepic":
                case "equippurples":
                case "equippurple":
                    bool equipEpics;
                    if (!bool.TryParse(value, out equipEpics))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        equipEpics = false;
                    }

                    EquipPurples = equipEpics;
                    break;

                case "equiprares":
                case "equiprare":
                case "equipblues":
                case "equipblue":
                    bool equipRares;
                    if (!bool.TryParse(value, out equipRares))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        equipRares = false;
                    }

                    EquipBlues = equipRares;
                    break;

                case "equipuncommons":
                case "equipuncommon":
                case "equipgreens":
                case "equipgreen":
                    bool equipGreens;
                    if (!bool.TryParse(value, out equipGreens))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        equipGreens = false;
                    }

                    EquipGreens = equipGreens;
                    break;

                case "equipcommons":
                case "equipcommon":
                case "equipwhites":
                case "equipwhite":
                    bool equipWhites;
                    if (!bool.TryParse(value, out equipWhites))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        equipWhites = false;
                    }

                    EquipWhites = equipWhites;
                    break;

                case "equippoors":
                case "equippoor":
                case "equipgray":
                case "equipgrays":
                case "equipgrey":
                case "equipgreys":
                    bool equipGrays;
                    if (!bool.TryParse(value, out equipGrays))
                    {
                        Log(false, "Setting {0} has wrong value - boolean value expected, True/False. Value was: {1}", name, value);
                        equipGrays = false;
                    }

                    EquipGrays = equipGrays;
                    break;

                case "replaceboa":
                case "replaceboas":
                case "replaceheirloom":
                case "replaceheirlooms":
                    bool replaceHeirlooms;
                    if (!bool.TryParse(value, out replaceHeirlooms))
                    {
                        Log(false, "Setting ReplaceHeirlooms has wrong value - boolean value expected, True/False. Value was: {0}", value);
                        replaceHeirlooms = false;
                    }

                    ReplaceHeirlooms = replaceHeirlooms;
                    break;

                case "ignoretypes":
                case "dontequiptypes":
                    XElement[] ignoreTypes = element.Elements("Type").ToArray();
                    foreach (XElement ignoreType in ignoreTypes)
                    {
                        string ignoreTypeValue = ignoreType.Value;
                        if (string.IsNullOrEmpty(ignoreTypeValue))
                        {
                            continue;
                        }

                        InventoryType type;
                        try
                        {
                            type = (InventoryType)Enum.Parse(typeof(InventoryType), ignoreTypeValue, true);
                        }
                        catch (ArgumentException)
                        {
                            Log(false, "Ignore type \"{0}\" is unknown!", ignoreTypeValue);
                            continue;
                        }

                        if (!IgnoreTypes.Contains(type))
                        {
                            IgnoreTypes.Add(type);
                        }
                    }
                    break;

                case "protectedslots":
                case "protectslots":
                    XElement[] protectedSlots = element.Elements("Slot").ToArray();
                    foreach (XElement protectedSlot in protectedSlots)
                    {
                        string protectedSlotValue = protectedSlot.Value;
                        if (string.IsNullOrEmpty(protectedSlotValue))
                        {
                            continue;
                        }

                        InventorySlot slot;
                        try
                        {
                            slot = (InventorySlot)Enum.Parse(typeof(InventorySlot), protectedSlotValue, true);
                        }
                        catch (ArgumentException)
                        {
                            Log(false, "Protected slot \"{0}\" is unknown!", protectedSlotValue);
                            continue;
                        }

                        if (!ProtectedSlots.Contains(slot))
                        {
                            ProtectedSlots.Add(slot);
                        }
                    }
                    break;

                case "ignoreitems":
                case "protecteditems":
                    XElement[] ignoreItems = element.Elements("Item").ToArray();
                    foreach (XElement ignoreItem in ignoreItems)
                    {
                        uint   ignoreItemId   = 0;
                        string ignoreItemName = "";

                        XAttribute[] ignoreItemAttribs = ignoreItem.Attributes().ToArray();
                        foreach (XAttribute ignoreItemAttrib in ignoreItemAttribs)
                        {
                            string attribName  = ignoreItemAttrib.Name.ToString();
                            string attribValue = ignoreItemAttrib.Value;

                            switch (attribName.ToLower())
                            {
                            case "id":
                            case "entry":
                                if (!uint.TryParse(attribValue, out ignoreItemId))
                                {
                                    Log(false, "Setting {0} has wrong value - positive number expected, 0 or > 0. Value was: {1}", name, value);
                                }

                                break;

                            case "name":
                                ignoreItemName = attribValue;
                                break;
                            }
                        }

                        IgnoreItems.Add(new KeyValuePair <uint, string>(ignoreItemId, ignoreItemName));
                    }
                    break;
                }
            }
        }