public void LoadItems() { try { foreach (XmlNode xn in ReadXml().DocumentElement.ChildNodes) { GroupPathItem groupItem = GetGroupPathItem(xn); if (groupItem == null) { continue; } this.AddItem(groupItem); XmlElement shellXE = (XmlElement)xn.SelectSingleNode("Shell"); XmlElement shellExXE = (XmlElement)xn.SelectSingleNode("ShellEx"); if (shellXE != null) { LoadShellItems(shellXE, groupItem); } if (shellExXE != null) { LoadShellExItems(shellExXE, groupItem); } groupItem.IsFold = true; groupItem.HideWhenNoSubItem(); } } catch { } }
private void LoadShellExItems(XmlElement shellExXE, GroupPathItem groupItem) { foreach (XmlElement itemXE in shellExXE.SelectNodes("Item")) { if (!JudgeOSVersion(itemXE)) { continue; } if (!GuidEx.TryParse(itemXE.GetAttribute("Guid"), out Guid guid)) { continue; } EnhanceShellExItem item = new EnhanceShellExItem { FoldGroupItem = groupItem, ShellExPath = $@"{groupItem.TargetPath}\ShellEx", Image = ResourceIcon.GetIcon(itemXE.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.DllDefaultIcon, Text = ResourceString.GetDirectString(itemXE.GetAttribute("Text")), DefaultKeyName = itemXE.GetAttribute("KeyName"), Guid = guid }; if (item.Text.IsNullOrWhiteSpace()) { item.Text = GuidInfo.GetText(guid); } if (item.DefaultKeyName.IsNullOrWhiteSpace()) { item.DefaultKeyName = guid.ToString("B"); } item.ChkVisible.Checked = item.ItemVisible; MyToolTip.SetToolTip(item.ChkVisible, itemXE.GetAttribute("Tip")); this.AddItem(item); } }
public void LoadItems() { try { XmlDocument doc = AppDic.ReadXml(AppConfig.WebEnhanceMenusDic, AppConfig.UserEnhanceMenusDic, Properties.Resources.EnhanceMenusDic); foreach (XmlNode xn in doc.DocumentElement.ChildNodes) { GroupPathItem groupItem = GetGroupPathItem(xn); if (groupItem == null) { continue; } this.AddItem(groupItem); XmlElement shellXE = (XmlElement)xn.SelectSingleNode("Shell"); XmlElement shellExXE = (XmlElement)xn.SelectSingleNode("ShellEx"); if (shellXE != null) { LoadShellItems(shellXE, groupItem); } if (shellExXE != null) { LoadShellExItems(shellExXE, groupItem); } groupItem.IsFold = true; groupItem.HideWhenNoSubItem(); } } catch { } }
private void LoadShellItems(XmlElement shellXE, GroupPathItem groupItem) { foreach (XmlElement itemXE in shellXE.GetElementsByTagName("Item")) { XmlElement verXE = (XmlElement)itemXE.SelectSingleNode("OSVersion"); if (!JudgeOSVersion(verXE)) { continue; } XmlElement szXE = (XmlElement)itemXE.SelectSingleNode("Value/REG_SZ"); string keyName = itemXE.GetAttribute("KeyName"); if (keyName.IsNullOrWhiteSpace()) { continue; } string regPath = $@"{groupItem.TargetPath}\shell\{keyName}"; EnhanceShellItem item = new EnhanceShellItem() { RegPath = $@"{groupItem.TargetPath}\shell\{keyName}", FoldGroupItem = groupItem, ItemXE = itemXE }; if (szXE != null) { item.Text = ResourceString.GetDirectString(szXE.GetAttribute("MUIVerb")); if (szXE.HasAttribute("Icon")) { item.Image = ResourceIcon.GetIcon(szXE.GetAttribute("Icon"))?.ToBitmap(); } else if (szXE.HasAttribute("HasLUAShield")) { item.Image = AppImage.Shield; } } if (item.Image == null) { item.Image = AppImage.NotFound; } if (item.Text.IsNullOrWhiteSpace()) { item.Text = keyName; } item.ChkVisible.Checked = item.ItemVisible; MyToolTip.SetToolTip(item.ChkVisible, itemXE.GetAttribute("Tip")); this.AddItem(item); } }
private void LoadSubDirItems(DirectoryInfo di) { GroupPathItem groupItem = new GroupPathItem(di.FullName, ObjectPath.PathType.Directory) { Text = Path.GetFileNameWithoutExtension(di.FullName), Image = ResourceIcon.GetFolderIcon(di.FullName).ToBitmap() }; this.AddItem(groupItem); string iniPath = $@"{di.FullName}\desktop.ini"; DesktopIniReaders.Add(di.FullName, new IniReader(iniPath)); Array.ForEach(di.GetFiles(), fi => { if (fi.Extension.ToLower() == ".lnk") { this.AddItem(new WinXItem(fi.FullName, groupItem)); } }); }
public void LoadItems() { string webPath = AppConfig.WebEnhanceMenusDic; string userPath = AppConfig.UserEnhanceMenusDic; string contents = Properties.Resources.EnhanceMenusDic; if (!File.Exists(webPath)) { File.WriteAllText(webPath, contents, Encoding.Unicode); } GroupPathItem webGroupItem = new GroupPathItem(webPath, ObjectPath.PathType.File); GroupPathItem userGroupItem = new GroupPathItem(userPath, ObjectPath.PathType.File); webGroupItem.Text = AppString.SideBar.Dictionaries; userGroupItem.Text = AppString.Other.UserDictionaries; webGroupItem.Image = AppImage.App; userGroupItem.Image = AppImage.User; LoadDocItems(webPath, webGroupItem); LoadDocItems(userPath, userGroupItem); }
private void LoadShellExItems(string shellExPath) { List <string> names = new List <string>(); using (RegistryKey shellExKey = RegistryEx.GetRegistryKey(shellExPath)) { if (shellExKey == null) { return; } bool isDragDrop = Scene == Scenes.DragDrop; RegTrustedInstaller.TakeRegTreeOwnerShip(shellExKey.Name); Dictionary <string, Guid> dic = ShellExItem.GetPathAndGuids(shellExPath, isDragDrop); GroupPathItem groupItem = null; if (isDragDrop) { groupItem = GetDragDropGroupItem(shellExPath); this.AddItem(groupItem); } foreach (string path in dic.Keys) { string keyName = RegistryEx.GetKeyName(path); if (!names.Contains(keyName)) { ShellExItem item = new ShellExItem(dic[path], path); if (groupItem != null) { item.FoldGroupItem = groupItem; } this.AddItem(item); names.Add(keyName); } } if (groupItem != null) { groupItem.IsFold = true; } } }
private void LoadDocItems(string xmlPath, GroupPathItem groupItem) { if (!File.Exists(xmlPath)) { return; } this.AddItem(groupItem); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(File.ReadAllText(xmlPath, EncodingType.GetType(xmlPath)).Trim()); } catch (Exception e) { MessageBoxEx.Show(e.Message); return; } foreach (XmlNode xn in doc.DocumentElement.ChildNodes) { try { SubGroupItem subGroupItem = GetGroupPathItem(xn); if (subGroupItem == null) { continue; } this.AddItem(subGroupItem); XmlElement shellXE = (XmlElement)xn.SelectSingleNode("Shell"); XmlElement shellExXE = (XmlElement)xn.SelectSingleNode("ShellEx"); if (shellXE != null) { LoadShellItems(shellXE, subGroupItem); } if (shellExXE != null) { LoadShellExItems(shellExXE, subGroupItem); } subGroupItem.HideWhenNoSubItem(); subGroupItem.FoldGroupItem = groupItem; } catch { continue; } } groupItem.IsFold = true; groupItem.HideWhenNoSubItem(); }
public void LoadItems() { this.ClearItems(); XmlDocument doc1 = new XmlDocument(); if (!File.Exists(Program.AppDataThirdRulesDicPath)) { File.WriteAllText(Program.AppDataThirdRulesDicPath, Properties.Resources.ThirdRulesDic, Encoding.UTF8); } doc1.Load(Program.AppDataThirdRulesDicPath); if (File.Exists(Program.ThirdRulesDicPath)) { XmlDocument doc2 = new XmlDocument(); doc2.Load(Program.ThirdRulesDicPath); foreach (XmlNode xn in doc2.DocumentElement.ChildNodes) { XmlNode node = doc1.ImportNode(xn, true); doc1.DocumentElement.AppendChild(node); } } foreach (XmlElement groupXE in doc1.DocumentElement.ChildNodes) { if (!GuidInfo.TryGetGuid(groupXE.GetAttribute("Guid"), out Guid guid) && !groupXE.HasAttribute("Common")) { continue; } GroupPathItem groupItem = new GroupPathItem { Text = groupXE.GetAttribute("Text"), TargetPath = groupXE.GetAttribute("RegPath"), PathType = ObjectPath.PathType.Registry, Image = GuidInfo.GetImage(guid), }; if (string.IsNullOrWhiteSpace(groupItem.Text)) { groupItem.Text = GuidInfo.GetText(guid); } this.AddItem(groupItem); foreach (XmlElement itemXE in groupXE.ChildNodes) { RegRuleItem.ItemInfo itemInfo = new RegRuleItem.ItemInfo { Text = itemXE.GetAttribute("Text"), Tip = itemXE.GetAttribute("Tip"), RestartExplorer = itemXE.HasAttribute("RestartExplorer"), }; XmlNodeList ruleXNList = itemXE.GetElementsByTagName("Rule");//Rules RegRuleItem.RegRule[] rules = new RegRuleItem.RegRule[ruleXNList.Count]; for (int i = 0; i < ruleXNList.Count; i++) { XmlElement ruleXE = (XmlElement)ruleXNList[i]; rules[i] = new RegRuleItem.RegRule { RegPath = ruleXE.GetAttribute("RegPath"), ValueName = ruleXE.GetAttribute("ValueName"), TurnOnValue = ruleXE.GetAttribute("On"), TurnOffValue = ruleXE.GetAttribute("Off"), ValueKind = GetValueKind(ruleXE.GetAttribute("ValueKind")) }; if (string.IsNullOrEmpty(rules[i].RegPath)) { rules[i].RegPath = groupItem.TargetPath; } else if (rules[i].RegPath.StartsWith("\\")) { rules[i].RegPath = groupItem.TargetPath + rules[i].RegPath; } } this.AddItem(new RegRuleItem(rules, itemInfo) { FoldGroupItem = groupItem }); } groupItem.IsFold = true; } }
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.HasImage = false; ruleItem.FoldGroupItem = groupItem; } groupItem.IsFold = true; groupItem.HideWhenNoSubItem(); } } catch { } }
private GroupPathItem GetGroupPathItem(XmlNode xn) { string path; string text; Image image; switch (xn.Name) { case "File": path = ShellList.MENUPATH_FILE; text = AppString.SideBar.File; image = AppImage.File; break; case "Folder": path = ShellList.MENUPATH_FOLDER; text = AppString.SideBar.Folder; image = AppImage.Folder; break; case "Directory": path = ShellList.MENUPATH_FOLDER; text = AppString.SideBar.Directory; image = AppImage.Directory; break; case "Background": path = ShellList.MENUPATH_BACKGROUND; text = AppString.SideBar.Background; image = AppImage.Background; break; case "Desktop": path = ShellList.MENUPATH_DESKTOP; //Vista没有桌面右键菜单的独立注册表项 if (WindowsOsVersion.IsEqualVista) { path = ShellList.MENUPATH_BACKGROUND; } text = AppString.SideBar.Desktop; image = AppImage.Desktop; break; case "Drive": path = ShellList.MENUPATH_DRIVE; text = AppString.SideBar.Drive; image = AppImage.Drive; break; case "AllObjects": path = ShellList.MENUPATH_ALLOBJECTS; text = AppString.SideBar.AllObjects; image = AppImage.AllObjects; break; case "Computer": path = ShellList.MENUPATH_COMPUTER; text = AppString.SideBar.Computer; image = AppImage.Computer; break; case "RecycleBin": path = ShellList.MENUPATH_RECYCLEBIN; text = AppString.SideBar.RecycleBin; image = AppImage.RecycleBin; break; default: XmlElement xe = (XmlElement)xn; path = xe.GetAttribute("RegPath"); text = ResourceString.GetDirectString(xe.GetAttribute("Text")); if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(text)) { return(null); } image = ResourceIcon.GetIcon(xe.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.NotFound; break; } GroupPathItem groupItem = new GroupPathItem(path, ObjectPath.PathType.Registry) { Image = image, Text = text }; return(groupItem); }
private void LoadShellItems(XmlElement shellXE, GroupPathItem groupItem) { foreach (XmlElement itemXE in shellXE.SelectNodes("Item")) { if (!JudgeOSVersion(itemXE)) { continue; } if (!FileExists(itemXE)) { continue; } XmlElement szXE = (XmlElement)itemXE.SelectSingleNode("Value/REG_SZ"); string keyName = itemXE.GetAttribute("KeyName"); if (keyName.IsNullOrWhiteSpace()) { continue; } EnhanceShellItem item = new EnhanceShellItem() { RegPath = $@"{groupItem.TargetPath}\shell\{keyName}", FoldGroupItem = groupItem, ItemXE = itemXE }; if (szXE != null) { item.Text = ResourceString.GetDirectString(szXE.GetAttribute("MUIVerb")); if (szXE.HasAttribute("Icon")) { item.Image = ResourceIcon.GetIcon(szXE.GetAttribute("Icon"))?.ToBitmap(); } else if (szXE.HasAttribute("HasLUAShield")) { item.Image = AppImage.Shield; } else { XmlElement cmdXE = (XmlElement)itemXE.SelectSingleNode("SubKey/Command"); if (cmdXE != null) { Icon icon = null; if (cmdXE.HasAttribute("Default")) { string filePath = ObjectPath.ExtractFilePath(cmdXE.GetAttribute("Default")); icon = ResourceIcon.GetIcon(filePath); } item.Image = icon?.ToBitmap(); icon?.Dispose(); } } } if (item.Image == null) { item.Image = AppImage.NotFound; } if (item.Text.IsNullOrWhiteSpace()) { item.Text = keyName; } item.ChkVisible.Checked = item.ItemVisible; string tip = itemXE.GetAttribute("Tip"); if (itemXE.GetElementsByTagName("CreateFile").Count > 0) { if (!tip.IsNullOrWhiteSpace()) { tip += "\n"; } tip += AppString.Tip.CommandFiles; if (System.Diagnostics.Debugger.IsAttached) { item.ChkVisible.Checked = item.ItemVisible = true; } } MyToolTip.SetToolTip(item.ChkVisible, tip); this.AddItem(item); } }
public void LoadItems() { try { foreach (XmlNode xn in ReadXml().DocumentElement.ChildNodes) { string path = null; string text = null; Image image = null; switch (xn.Name) { case "File": path = ShellList.MENUPATH_FILE; text = AppString.SideBar.File; image = AppImage.File; break; case "Folder": path = ShellList.MENUPATH_FOLDER; text = AppString.SideBar.Folder; image = AppImage.Folder; break; case "Directory": path = ShellList.MENUPATH_FOLDER; text = AppString.SideBar.Directory; image = AppImage.Directory; break; case "Background": path = ShellList.MENUPATH_BACKGROUND; text = AppString.SideBar.Background; image = AppImage.Background; break; case "Desktop": path = ShellList.MENUPATH_DESKTOP; //Vista没有桌面右键菜单的独立注册表项 if (WindowsOsVersion.IsEqualVista) { path = ShellList.MENUPATH_BACKGROUND; } text = AppString.SideBar.Desktop; image = AppImage.Desktop; break; case "Drive": path = ShellList.MENUPATH_DRIVE; text = AppString.SideBar.Drive; image = AppImage.Drive; break; case "AllObjects": path = ShellList.MENUPATH_ALLOBJECTS; text = AppString.SideBar.AllObjects; image = AppImage.AllObjects; break; case "Computer": path = ShellList.MENUPATH_COMPUTER; text = AppString.SideBar.Computer; image = AppImage.Computer; break; case "RecycleBin": path = ShellList.MENUPATH_RECYCLEBIN; text = AppString.SideBar.RecycleBin; image = AppImage.RecycleBin; break; default: XmlElement xe = (XmlElement)xn; path = xe.GetAttribute("RegPath"); text = ResourceString.GetDirectString(xe.GetAttribute("Text")); image = ResourceIcon.GetIcon(xe.GetAttribute("Icon"))?.ToBitmap() ?? AppImage.NotFound; break; } if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(text)) { continue; } GroupPathItem groupItem = new GroupPathItem(path, ObjectPath.PathType.Registry) { Image = image, Text = text, }; this.AddItem(groupItem); XmlElement shellXE = (XmlElement)xn.SelectSingleNode("Shell"); XmlElement shellExXE = (XmlElement)xn.SelectSingleNode("ShellEx"); if (shellXE != null) { LoadShellItems(shellXE, groupItem); } if (shellExXE != null) { LoadShellExItems(shellExXE, groupItem); } groupItem.IsFold = true; } } catch { } }
public void LoadItems() { try { foreach (XmlElement groupXE in ReadXml().DocumentElement.ChildNodes) { Guid guid = Guid.Empty; if (groupXE.HasAttribute("Guid") && !GuidInfo.TryGetGuid(groupXE.GetAttribute("Guid"), out guid)) { continue; } GroupPathItem groupItem = new GroupPathItem(groupXE.GetAttribute("RegPath"), ObjectPath.PathType.Registry) { Text = groupXE.GetAttribute("Text"), Image = GuidInfo.GetImage(guid), }; if (groupItem.Text.IsNullOrWhiteSpace()) { groupItem.Text = GuidInfo.GetText(guid); } this.AddItem(groupItem); foreach (XmlElement itemXE in groupXE.ChildNodes) { XmlElement verXE = (XmlElement)itemXE.SelectSingleNode("OSVersion"); if (!EnhanceMenusList.JudgeOSVersion(verXE)) { continue; } RegRuleItem.ItemInfo itemInfo = new RegRuleItem.ItemInfo { Text = itemXE.GetAttribute("Text"), Tip = itemXE.GetAttribute("Tip"), RestartExplorer = itemXE.HasAttribute("RestartExplorer"), }; XmlNodeList ruleXNList = itemXE.GetElementsByTagName("Rule");//Rules RegRuleItem.RegRule[] rules = new RegRuleItem.RegRule[ruleXNList.Count]; for (int i = 0; i < ruleXNList.Count; i++) { XmlElement ruleXE = (XmlElement)ruleXNList[i]; rules[i] = new RegRuleItem.RegRule { RegPath = ruleXE.GetAttribute("RegPath"), ValueName = ruleXE.GetAttribute("ValueName"), TurnOnValue = ruleXE.GetAttribute("On"), TurnOffValue = ruleXE.GetAttribute("Off"), ValueKind = GetValueKind(ruleXE.GetAttribute("ValueKind")) }; if (string.IsNullOrEmpty(rules[i].RegPath)) { rules[i].RegPath = groupItem.TargetPath; } else if (rules[i].RegPath.StartsWith("\\")) { rules[i].RegPath = groupItem.TargetPath + rules[i].RegPath; } } this.AddItem(new RegRuleItem(rules, itemInfo) { FoldGroupItem = groupItem, HasImage = false }); } groupItem.IsFold = true; } } catch { } }
private void LoadDocItems(string xmlPath, GroupPathItem groupItem) { if (!File.Exists(xmlPath)) { return; } this.AddItem(groupItem); XmlDocument doc = new XmlDocument(); try { doc.LoadXml(File.ReadAllText(xmlPath, EncodingType.GetType(xmlPath)).Trim()); } catch (Exception e) { MessageBoxEx.Show(e.Message); return; } foreach (XmlElement groupXE in doc.DocumentElement.ChildNodes) { try { 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; } } SubGroupItem subGroupItem; bool isIniGroup = groupXE.HasAttribute("IsIniGroup"); string attribute = isIniGroup ? "FilePath" : "RegPath"; ObjectPath.PathType pathType = isIniGroup ? ObjectPath.PathType.File : ObjectPath.PathType.Registry; subGroupItem = new SubGroupItem(groupXE.GetAttribute(attribute), pathType) { Text = groupXE.GetAttribute("Text"), Image = GuidInfo.GetImage(guid) }; if (subGroupItem.Text.IsNullOrWhiteSpace()) { subGroupItem.Text = GuidInfo.GetText(guid); } this.AddItem(subGroupItem); string GetRuleFullRegPath(string regPath) { if (string.IsNullOrEmpty(regPath)) { regPath = subGroupItem.TargetPath; } else if (regPath.StartsWith("\\")) { regPath = subGroupItem.TargetPath + regPath; } return(regPath); }; foreach (XmlElement itemXE in groupXE.ChildNodes) { try { 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 = subGroupItem.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")) }; string turnOn = ruleXE.HasAttribute("On") ? ruleXE.GetAttribute("On") : null; string turnOff = ruleXE.HasAttribute("Off") ? ruleXE.GetAttribute("Off") : null; switch (rules[i].ValueKind) { case RegistryValueKind.Binary: rules[i].TurnOnValue = turnOn != null?EnhanceMenusList.ConvertToBinary(turnOn) : null; rules[i].TurnOffValue = turnOff != null?EnhanceMenusList.ConvertToBinary(turnOff) : null; break; case RegistryValueKind.DWord: if (turnOn == null) { rules[i].TurnOnValue = null; } else { rules[i].TurnOnValue = Convert.ToInt32(turnOn); } if (turnOff == null) { rules[i].TurnOffValue = null; } else { rules[i].TurnOffValue = Convert.ToInt32(turnOff); } break; default: rules[i].TurnOnValue = turnOn; rules[i].TurnOffValue = turnOff; break; } } ruleItem = new VisibleRegRuleItem(rules, info); } } this.AddItem(ruleItem); ruleItem.FoldGroupItem = subGroupItem; } catch { continue; } } subGroupItem.HideWhenNoSubItem(); subGroupItem.FoldGroupItem = groupItem; } catch { continue; } } groupItem.IsFold = true; groupItem.HideWhenNoSubItem(); }