123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using BluePointLilac.Controls;
- using BluePointLilac.Methods;
- using ContextMenuManager.Controls.Interfaces;
- using Microsoft.Win32;
- using System;
- using System.IO;
- using System.Xml;
- namespace ContextMenuManager.Controls
- {
- sealed class ThirdRulesList : MyList
- {
- public void LoadItems()
- {
- try
- {
- XmlDocument doc = AppDic.ReadXml(AppConfig.WebThirdRulesDic,
- AppConfig.UserThirdRulesDic, Properties.Resources.ThirdRulesDic);
- foreach(XmlElement groupXE in doc.DocumentElement.ChildNodes)
- {
- Guid guid = Guid.Empty;
- if(groupXE.HasAttribute("Guid"))
- {
- if(GuidEx.TryParse(groupXE.GetAttribute("Guid"), out guid))
- {
- if(!File.Exists(GuidInfo.GetFilePath(guid))) continue;
- }
- else continue;
- }
- GroupPathItem groupItem;
- bool isIniGroup = groupXE.HasAttribute("IsIniGroup");
- string attribute = isIniGroup ? "FilePath" : "RegPath";
- ObjectPath.PathType pathType = isIniGroup ? ObjectPath.PathType.File : ObjectPath.PathType.Registry;
- groupItem = new GroupPathItem(groupXE.GetAttribute(attribute), pathType)
- {
- Text = groupXE.GetAttribute("Text"),
- Image = GuidInfo.GetImage(guid)
- };
- if(groupItem.Text.IsNullOrWhiteSpace()) groupItem.Text = GuidInfo.GetText(guid);
- this.AddItem(groupItem);
- string GetRuleFullRegPath(string regPath)
- {
- if(string.IsNullOrEmpty(regPath)) regPath = groupItem.TargetPath;
- else if(regPath.StartsWith("\\")) regPath = groupItem.TargetPath + regPath;
- return regPath;
- };
- foreach(XmlElement itemXE in groupXE.ChildNodes)
- {
- if(!EnhanceMenusList.JudgeOSVersion(itemXE)) continue;
- RuleItem ruleItem;
- ItemInfo info = new ItemInfo
- {
- Text = itemXE.GetAttribute("Text"),
- Tip = itemXE.GetAttribute("Tip"),
- RestartExplorer = itemXE.HasAttribute("RestartExplorer"),
- };
- int defaultValue = 0, maxValue = 0, minValue = 0;
- if(itemXE.HasAttribute("IsNumberItem"))
- {
- XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
- defaultValue = ruleXE.HasAttribute("Default") ? Convert.ToInt32(ruleXE.GetAttribute("Default")) : 0;
- maxValue = ruleXE.HasAttribute("Max") ? Convert.ToInt32(ruleXE.GetAttribute("Max")) : int.MaxValue;
- minValue = ruleXE.HasAttribute("Min") ? Convert.ToInt32(ruleXE.GetAttribute("Min")) : int.MinValue;
- }
- if(isIniGroup)
- {
- XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
- string iniPath = ruleXE.GetAttribute("FilePath");
- if(iniPath.IsNullOrWhiteSpace()) iniPath = groupItem.TargetPath;
- string section = ruleXE.GetAttribute("Section");
- string keyName = ruleXE.GetAttribute("KeyName");
- if(itemXE.HasAttribute("IsNumberItem"))
- {
- var rule = new NumberIniRuleItem.IniRule
- {
- IniPath = iniPath,
- Section = section,
- KeyName = keyName,
- DefaultValue = defaultValue,
- MaxValue = maxValue,
- MinValue = maxValue
- };
- ruleItem = new NumberIniRuleItem(rule, info);
- }
- else if(itemXE.HasAttribute("IsStringItem"))
- {
- var rule = new StringIniRuleItem.IniRule
- {
- IniPath = iniPath,
- Secation = section,
- KeyName = keyName
- };
- ruleItem = new StringIniRuleItem(rule, info);
- }
- else
- {
- var rule = new VisbleIniRuleItem.IniRule
- {
- IniPath = iniPath,
- Section = section,
- KeyName = keyName,
- TurnOnValue = ruleXE.HasAttribute("On") ? ruleXE.GetAttribute("On") : null,
- TurnOffValue = ruleXE.HasAttribute("Off") ? ruleXE.GetAttribute("Off") : null,
- };
- ruleItem = new VisbleIniRuleItem(rule, info);
- }
- }
- else
- {
- if(itemXE.HasAttribute("IsNumberItem"))
- {
- XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
- var rule = new NumberRegRuleItem.RegRule
- {
- RegPath = GetRuleFullRegPath(ruleXE.GetAttribute("RegPath")),
- ValueName = ruleXE.GetAttribute("ValueName"),
- ValueKind = GetValueKind(ruleXE.GetAttribute("ValueKind")),
- DefaultValue = defaultValue,
- MaxValue = maxValue,
- MinValue = minValue
- };
- ruleItem = new NumberRegRuleItem(rule, info);
- }
- else if(itemXE.HasAttribute("IsStringItem"))
- {
- XmlElement ruleXE = (XmlElement)itemXE.SelectSingleNode("Rule");
- var rule = new StringRegRuleItem.RegRule
- {
- RegPath = GetRuleFullRegPath(ruleXE.GetAttribute("RegPath")),
- ValueName = ruleXE.GetAttribute("ValueName"),
- };
- ruleItem = new StringRegRuleItem(rule, info);
- }
- else
- {
- XmlNodeList ruleXNList = itemXE.SelectNodes("Rule");
- var rules = new VisibleRegRuleItem.RegRule[ruleXNList.Count];
- for(int i = 0; i < ruleXNList.Count; i++)
- {
- XmlElement ruleXE = (XmlElement)ruleXNList[i];
- rules[i] = new VisibleRegRuleItem.RegRule
- {
- RegPath = GetRuleFullRegPath(ruleXE.GetAttribute("RegPath")),
- ValueName = ruleXE.GetAttribute("ValueName"),
- ValueKind = GetValueKind(ruleXE.GetAttribute("ValueKind")),
- TurnOnValue = ruleXE.HasAttribute("On") ? ruleXE.GetAttribute("On") : null,
- TurnOffValue = ruleXE.HasAttribute("Off") ? ruleXE.GetAttribute("Off") : null,
- };
- }
- ruleItem = new VisibleRegRuleItem(rules, info);
- }
- }
- this.AddItem(ruleItem);
- ruleItem.FoldGroupItem = groupItem;
- }
- groupItem.IsFold = true;
- groupItem.HideWhenNoSubItem();
- }
- }
- catch { }
- }
- private static RegistryValueKind GetValueKind(string data)
- {
- switch(data.ToUpper())
- {
- case "REG_SZ":
- return RegistryValueKind.String;
- case "REG_BINARY":
- return RegistryValueKind.Binary;
- case "REG_DWORD":
- return RegistryValueKind.DWord;
- case "REG_QWORD":
- return RegistryValueKind.QWord;
- case "REG_MULTI_SZ":
- return RegistryValueKind.MultiString;
- case "REG_EXPAND_SZ":
- return RegistryValueKind.ExpandString;
- default:
- return RegistryValueKind.DWord;
- }
- }
- }
- }
|