mirror of
https://github.com/BluePointLilac/ContextMenuManager.git
synced 2026-01-16 07:04:39 +08:00
将添加常用菜单模块移动到其他规则
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using BulePointLilac.Controls;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
{
|
||||
sealed class AddCommonButton : PictureButton
|
||||
{
|
||||
public AddCommonButton() : base(AppImage.AddCommon)
|
||||
{
|
||||
MyToolTip.SetToolTip(this, AppString.Tip.AddCommonItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
109
ContextMenuManager/Controls/EnhanceMenusItem.cs
Normal file
109
ContextMenuManager/Controls/EnhanceMenusItem.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using BulePointLilac.Controls;
|
||||
using BulePointLilac.Methods;
|
||||
using ContextMenuManager.Controls.Interfaces;
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
{
|
||||
sealed class EnhanceShellItem : MyListItem, IFoldSubItem, IChkVisibleItem
|
||||
{
|
||||
public string RegPath { get; set; }
|
||||
public XmlElement ItemXE { get; set; }
|
||||
public VisibleCheckBox ChkVisible { get; set; }
|
||||
public IFoldGroupItem FoldGroupItem { get; set; }
|
||||
public bool ItemVisible
|
||||
{
|
||||
get
|
||||
{
|
||||
using(RegistryKey key = RegistryEx.GetRegistryKey(RegPath))
|
||||
return key != null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if(value) WriteSubKeysValue(ItemXE, RegPath);
|
||||
else RegistryEx.DeleteKeyTree(RegPath);
|
||||
}
|
||||
}
|
||||
|
||||
public EnhanceShellItem()
|
||||
{
|
||||
ChkVisible = new VisibleCheckBox(this);
|
||||
}
|
||||
|
||||
private static void WriteAttributesValue(XmlNode valueXN, string regPath)
|
||||
{
|
||||
if(valueXN == null) return;
|
||||
XmlNode szXN = valueXN.SelectSingleNode("REG_SZ");
|
||||
XmlNode dwordXN = valueXN.SelectSingleNode("REG_DWORD");
|
||||
XmlNode expand_szXN = valueXN.SelectSingleNode("REG_EXPAND_SZ");
|
||||
if(szXN != null)
|
||||
foreach(XmlAttribute a in szXN.Attributes)
|
||||
Registry.SetValue(regPath, a.Name, a.Value, RegistryValueKind.String);
|
||||
if(expand_szXN != null)
|
||||
foreach(XmlAttribute a in expand_szXN.Attributes)
|
||||
Registry.SetValue(regPath, a.Name, a.Value, RegistryValueKind.ExpandString);
|
||||
if(dwordXN != null)
|
||||
foreach(XmlAttribute a in dwordXN.Attributes)
|
||||
{
|
||||
int value = a.Value.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
|
||||
? Convert.ToInt32(a.Value, 16) : Convert.ToInt32(a.Value);
|
||||
Registry.SetValue(regPath, a.Name, value, RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteSubKeysValue(XmlElement keyXE, string regPath)
|
||||
{
|
||||
if(keyXE == null) return;
|
||||
string defaultValue = keyXE.GetAttribute("Default");
|
||||
if(!defaultValue.IsNullOrWhiteSpace()) Registry.SetValue(regPath, "", defaultValue);
|
||||
WriteAttributesValue(keyXE.SelectSingleNode("Value"), regPath);
|
||||
|
||||
XmlNode subKeyXN = keyXE.SelectSingleNode("SubKey");
|
||||
if(subKeyXN != null)
|
||||
{
|
||||
foreach(XmlElement xe in subKeyXN.ChildNodes)
|
||||
WriteSubKeysValue(xe, $@"{regPath}\{xe.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class EnhanceShellExItem : MyListItem, IFoldSubItem, IChkVisibleItem
|
||||
{
|
||||
public string ShellExPath { get; set; }
|
||||
public string DefaultKeyName { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
public VisibleCheckBox ChkVisible { get; set; }
|
||||
public IFoldGroupItem FoldGroupItem { get; set; }
|
||||
public bool ItemVisible
|
||||
{
|
||||
get => ShellExItem.GetPathAndGuids(ShellExPath).Values.Contains(Guid);
|
||||
set
|
||||
{
|
||||
if(value)
|
||||
{
|
||||
string regPath = ObjectPath.GetNewPathWithIndex
|
||||
($@"{ShellExPath}\ContextMenuHandlers\{DefaultKeyName}", ObjectPath.PathType.Registry);
|
||||
Registry.SetValue(regPath, "", this.Guid.ToString("B"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, Guid> dic = ShellExItem.GetPathAndGuids(ShellExPath);
|
||||
foreach(string regPath in dic.Keys)
|
||||
{
|
||||
if(dic[regPath].Equals(this.Guid))
|
||||
RegistryEx.DeleteKeyTree(regPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EnhanceShellExItem()
|
||||
{
|
||||
ChkVisible = new VisibleCheckBox(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
197
ContextMenuManager/Controls/EnhanceMenusList.cs
Normal file
197
ContextMenuManager/Controls/EnhanceMenusList.cs
Normal file
@@ -0,0 +1,197 @@
|
||||
using BulePointLilac.Controls;
|
||||
using BulePointLilac.Methods;
|
||||
using ContextMenuManager.Controls.Interfaces;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
{
|
||||
sealed class EnhanceMenusList : MyList
|
||||
{
|
||||
public void LoadItems()
|
||||
{
|
||||
this.ClearItems();
|
||||
XmlDocument doc = ReadXml();
|
||||
foreach(XmlNode xn in doc.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
|
||||
{
|
||||
PathType = ObjectPath.PathType.Registry,
|
||||
TargetPath = path,
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private XmlDocument ReadXml()
|
||||
{
|
||||
XmlDocument doc1 = new XmlDocument();
|
||||
//如果没有网络下载的,则将程序内置的写入
|
||||
if(!File.Exists(Program.AppDataEnhanceMenusDicPath))
|
||||
{
|
||||
File.WriteAllText(Program.AppDataEnhanceMenusDicPath, Properties.Resources.EnhanceMenusDic, Encoding.UTF8);
|
||||
}
|
||||
doc1.Load(Program.AppDataEnhanceMenusDicPath);
|
||||
if(File.Exists(Program.EnhanceMenusDicPath))
|
||||
{
|
||||
XmlDocument doc2 = new XmlDocument();
|
||||
doc2.Load(Program.EnhanceMenusDicPath);
|
||||
foreach(XmlNode xn in doc2.DocumentElement.ChildNodes)
|
||||
{
|
||||
XmlNode node = doc1.ImportNode(xn, true);
|
||||
doc1.DocumentElement.AppendChild(node);
|
||||
}
|
||||
}
|
||||
return doc1;
|
||||
}
|
||||
|
||||
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 LoadShellExItems(XmlElement shellExXE, GroupPathItem groupItem)
|
||||
{
|
||||
foreach(XmlElement itemXE in shellExXE.GetElementsByTagName("Item"))
|
||||
{
|
||||
XmlElement verXE = (XmlElement)itemXE.SelectSingleNode("OSVersion");
|
||||
if(!JudgeOSVersion(verXE)) continue;
|
||||
if(!GuidInfo.TryGetGuid(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 static bool JudgeOSVersion(XmlElement osXE)
|
||||
{
|
||||
if(osXE == null) return true;
|
||||
Version ver = new Version(osXE.InnerText);
|
||||
Version osVer = Environment.OSVersion.Version;
|
||||
int compare = osVer.CompareTo(ver);
|
||||
string symbol = osXE.GetAttribute("Compare");
|
||||
switch(symbol)
|
||||
{
|
||||
case ">":
|
||||
return compare > 0;
|
||||
case "<":
|
||||
return compare < 0;
|
||||
case "=":
|
||||
return compare == 0;
|
||||
case ">=":
|
||||
return compare >= 0;
|
||||
case "<=":
|
||||
return compare <= 0;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
using BulePointLilac.Controls;
|
||||
using BulePointLilac.Methods;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
{
|
||||
class SelectItemsForm : Form
|
||||
{
|
||||
public SelectItemsForm()
|
||||
{
|
||||
this.AcceptButton = btnOk;
|
||||
this.CancelButton = btnCancel;
|
||||
this.Font = SystemFonts.MessageBoxFont;
|
||||
this.ShowIcon = this.ShowInTaskbar = false;
|
||||
this.StartPosition = FormStartPosition.CenterParent;
|
||||
this.MinimumSize = this.Size = new Size(652, 425).DpiZoom();
|
||||
list.Owner = listBox;
|
||||
InitializeComponents();
|
||||
}
|
||||
|
||||
protected MyList list = new MyList();
|
||||
protected MyListBox listBox = new MyListBox();
|
||||
protected Panel pnlBorder = new Panel
|
||||
{
|
||||
BackColor = Color.FromArgb(200, 200, 200)
|
||||
};
|
||||
protected Button btnOk = new Button
|
||||
{
|
||||
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
||||
DialogResult = DialogResult.OK,
|
||||
Text = AppString.Dialog.Ok,
|
||||
AutoSize = true
|
||||
};
|
||||
protected Button btnCancel = new Button
|
||||
{
|
||||
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
||||
DialogResult = DialogResult.Cancel,
|
||||
Text = AppString.Dialog.Cancel,
|
||||
AutoSize = true
|
||||
};
|
||||
|
||||
private void InitializeComponents()
|
||||
{
|
||||
this.Controls.AddRange(new Control[] { listBox, pnlBorder, btnOk, btnCancel });
|
||||
int a = 20.DpiZoom();
|
||||
listBox.Location = new Point(a, a);
|
||||
pnlBorder.Location = new Point(a - 1, a - 1);
|
||||
btnOk.Top = btnCancel.Top = this.ClientSize.Height - btnCancel.Height - a;
|
||||
btnCancel.Left = this.ClientSize.Width - btnCancel.Width - a;
|
||||
btnOk.Left = btnCancel.Left - btnOk.Width - a;
|
||||
this.OnResize(null);
|
||||
}
|
||||
|
||||
protected override void OnResize(EventArgs e)
|
||||
{
|
||||
base.OnResize(e);
|
||||
listBox.Width = ClientSize.Width - 2 * listBox.Left;
|
||||
listBox.Height = btnOk.Top - 2 * listBox.Top;
|
||||
pnlBorder.Width = listBox.Width + 2;
|
||||
pnlBorder.Height = listBox.Height + 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
using BulePointLilac.Controls;
|
||||
using BulePointLilac.Methods;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using static Microsoft.Win32.Registry;
|
||||
|
||||
namespace ContextMenuManager.Controls
|
||||
{
|
||||
sealed class ShellCommonDialog : CommonDialog
|
||||
{
|
||||
public List<string> SelectedShellPaths { get; private set; }
|
||||
public Dictionary<string, Guid> SelectedShellExPathAndGuids { get; private set; }
|
||||
public string ShellExPath { get; set; }
|
||||
public string ShellPath { get; set; }
|
||||
public string ScenePath { get; set; }
|
||||
public override void Reset() { }
|
||||
|
||||
protected override bool RunDialog(IntPtr hwndOwner)
|
||||
{
|
||||
using(ShellCommonForm frm = new ShellCommonForm(ScenePath, ShellPath, ShellExPath))
|
||||
{
|
||||
if(frm.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
this.SelectedShellPaths = frm.SelectedShellPaths;
|
||||
this.SelectedShellExPathAndGuids = frm.SelectedShellExPathAndGuids;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ShellCommonForm : SelectItemsForm
|
||||
{
|
||||
public ShellCommonForm(string scenePath, string shellPath, string shellExPath)
|
||||
{
|
||||
this.ScenePath = scenePath;
|
||||
this.ShellPath = shellPath;
|
||||
this.ShellExPath = shellExPath;
|
||||
this.Text = AppString.Dialog.CheckCommon;
|
||||
btnOk.Click += (sender, e) => GetSelectedItems();
|
||||
LoadItems();
|
||||
}
|
||||
|
||||
public List<string> SelectedShellPaths { get; private set; } = new List<string>();
|
||||
public Dictionary<string, Guid> SelectedShellExPathAndGuids { get; private set; } = new Dictionary<string, Guid>();
|
||||
public string ScenePath { get; set; }
|
||||
public string ShellPath { get; set; }
|
||||
public string ShellExPath { get; set; }
|
||||
private XmlElement shellXE;
|
||||
private XmlElement shellExXE;
|
||||
|
||||
public void LoadItems()
|
||||
{
|
||||
XmlDocument doc1 = new XmlDocument();
|
||||
if(!File.Exists(Program.AppDataShellCommonDicPath))
|
||||
{
|
||||
File.WriteAllText(Program.AppDataShellCommonDicPath, Properties.Resources.ShellCommonDic, Encoding.UTF8);
|
||||
}
|
||||
doc1.Load(Program.AppDataShellCommonDicPath);
|
||||
|
||||
if(File.Exists(Program.ShellCommonDicPath))
|
||||
{
|
||||
XmlDocument doc2 = new XmlDocument();
|
||||
doc2.Load(Program.ShellCommonDicPath);
|
||||
foreach(XmlNode xn in doc2.DocumentElement.ChildNodes)
|
||||
{
|
||||
XmlNode node = doc1.ImportNode(xn, true);
|
||||
doc1.DocumentElement.AppendChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(XmlElement groupXE in doc1.DocumentElement.ChildNodes)
|
||||
{
|
||||
string scenePath = groupXE.GetAttribute("RegPath");
|
||||
if(ScenePath.Equals(scenePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
shellXE = (XmlElement)groupXE.SelectSingleNode("Shell");
|
||||
shellExXE = (XmlElement)groupXE.SelectSingleNode("ShellEx");
|
||||
if(shellXE != null) LoadShellItems();
|
||||
if(ShellExPath != null && shellExXE != null) LoadShellExItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadShellItems()
|
||||
{
|
||||
foreach(XmlElement itemXE in shellXE.GetElementsByTagName("Item"))
|
||||
{
|
||||
XmlElement szXE = (XmlElement)itemXE.SelectSingleNode("Value/REG_SZ");
|
||||
string keyName = itemXE.GetAttribute("KeyName");
|
||||
if(keyName.IsNullOrWhiteSpace()) continue;
|
||||
ShellCommonItem item = new ShellCommonItem
|
||||
{
|
||||
DefaultKeyName = keyName,
|
||||
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 = item.DefaultKeyName;
|
||||
item.SetTip(itemXE.GetAttribute("Tip"));
|
||||
list.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadShellExItems()
|
||||
{
|
||||
foreach(XmlElement itemXE in shellExXE.GetElementsByTagName("Item"))
|
||||
{
|
||||
if(!GuidInfo.TryGetGuid(itemXE.GetAttribute("Guid"), out Guid guid)) continue;
|
||||
if(ShellExItem.GetPathAndGuids(ShellExPath).Values.Contains(guid)) continue;
|
||||
ShellExCommonItem item = new ShellExCommonItem
|
||||
{
|
||||
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.SetTip(itemXE.GetAttribute("Tip"));
|
||||
list.AddItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetSelectedItems()
|
||||
{
|
||||
foreach(Control ctr in list.Controls)
|
||||
{
|
||||
if(ctr.GetType() == typeof(ShellCommonItem)) CreateShellItem((ShellCommonItem)ctr);
|
||||
else if(ctr.GetType() == typeof(ShellExCommonItem)) CreateShellExItem((ShellExCommonItem)ctr);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateShellItem(ShellCommonItem item)
|
||||
{
|
||||
if(!item.IsSelected) return;
|
||||
string regPath = ObjectPath.GetNewPathWithIndex
|
||||
($@"{ShellPath}\{item.DefaultKeyName}", ObjectPath.PathType.Registry);
|
||||
ShellCommonItem.WriteSubKeysValue(item.ItemXE, regPath);
|
||||
SelectedShellPaths.Add(regPath);
|
||||
}
|
||||
|
||||
private void CreateShellExItem(ShellExCommonItem item)
|
||||
{
|
||||
if(!item.IsSelected) return;
|
||||
string regPath = ObjectPath.GetNewPathWithIndex
|
||||
($@"{ShellExPath}\ContextMenuHandlers\{item.DefaultKeyName}", ObjectPath.PathType.Registry);
|
||||
SetValue(regPath, "", item.Guid.ToString("B"));
|
||||
SelectedShellExPathAndGuids.Add(regPath, item.Guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CheckBoxItem : MyListItem
|
||||
{
|
||||
readonly CheckBox chkSelected = new CheckBox { AutoSize = true };
|
||||
public bool IsSelected => chkSelected.Checked;
|
||||
|
||||
public CheckBoxItem()
|
||||
{
|
||||
this.AddCtr(chkSelected);
|
||||
}
|
||||
|
||||
public void SetTip(string tip)
|
||||
{
|
||||
MyToolTip.SetToolTip(chkSelected, tip);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ShellCommonItem : CheckBoxItem
|
||||
{
|
||||
public string DefaultKeyName { get; set; }
|
||||
public XmlElement ItemXE { get; set; }
|
||||
|
||||
public static void WriteAttributesValue(XmlNode valueXN, string regPath)
|
||||
{
|
||||
if(valueXN == null) return;
|
||||
XmlNode szXN = valueXN.SelectSingleNode("REG_SZ");
|
||||
XmlNode dwordXN = valueXN.SelectSingleNode("REG_DWORD");
|
||||
XmlNode expand_szXN = valueXN.SelectSingleNode("REG_EXPAND_SZ");
|
||||
if(szXN != null)
|
||||
foreach(XmlAttribute a in szXN.Attributes)
|
||||
SetValue(regPath, a.Name, a.Value, Microsoft.Win32.RegistryValueKind.String);
|
||||
if(expand_szXN != null)
|
||||
foreach(XmlAttribute a in expand_szXN.Attributes)
|
||||
SetValue(regPath, a.Name, a.Value, Microsoft.Win32.RegistryValueKind.ExpandString);
|
||||
if(dwordXN != null)
|
||||
foreach(XmlAttribute a in dwordXN.Attributes)
|
||||
{
|
||||
int value = a.Value.StartsWith("0x", StringComparison.OrdinalIgnoreCase)
|
||||
? Convert.ToInt32(a.Value, 16) : Convert.ToInt32(a.Value);
|
||||
SetValue(regPath, a.Name, value, Microsoft.Win32.RegistryValueKind.DWord);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteSubKeysValue(XmlElement keyXE, string regPath)
|
||||
{
|
||||
if(keyXE == null) return;
|
||||
string defaultValue = keyXE.GetAttribute("Default");
|
||||
if(!defaultValue.IsNullOrWhiteSpace()) SetValue(regPath, "", defaultValue);
|
||||
WriteAttributesValue(keyXE.SelectSingleNode("Value"), regPath);
|
||||
|
||||
XmlNode subKeyXN = keyXE.SelectSingleNode("SubKey");
|
||||
if(subKeyXN != null)
|
||||
{
|
||||
foreach(XmlElement xe in subKeyXN.ChildNodes)
|
||||
WriteSubKeysValue(xe, $@"{regPath}\{xe.Name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ShellExCommonItem : CheckBoxItem
|
||||
{
|
||||
public string DefaultKeyName { get; set; }
|
||||
public Guid Guid { get; set; }
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
@@ -1,9 +1,9 @@
|
||||
<?xml version='1.0' encoding='utf-8' ?>
|
||||
<!--此文件为常用右键菜单字典,
|
||||
Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开始, 子元素Value表示该项的注册表键值,目前仅支持REG_SZ、REG_DWORD、REG_EXPAND_SZ的键值类型,
|
||||
,子元素SubKey的所有子元素是该项的子项,项名即为元素名; 每一Item项和SubKey的所有子元素的属性Default为该注册表项默认值,不放在Value\REG_SZ元素里面是为了防止与可能存在的键名为Default的键产生冲突-->
|
||||
子元素SubKey的所有子元素是该项的子项,项名即为元素名; 每一Item项和SubKey的所有子元素的属性Default为该注册表项默认值,不放在Value\REG_SZ元素里面是为了防止与可能存在的键名为Default的键产生冲突-->
|
||||
<Data>
|
||||
<Group RegPath='HKEY_CLASSES_ROOT\*'>
|
||||
<File>
|
||||
<Shell>
|
||||
<Item KeyName='CopyContent' Tip='不需打开文件直接复制文件文本内容
非UTF-16 LE(或带BOM)编码会乱码'>
|
||||
<Value>
|
||||
@@ -14,6 +14,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
</SubKey>
|
||||
</Item>
|
||||
<Item KeyName='TakeOwnerShip'>
|
||||
<OSVersion Compare=">=">6.2</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='获取所有者权限' HasLUAShield='' NoWorkingDirectory=''/>
|
||||
</Value>
|
||||
@@ -25,6 +26,7 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
</SubKey>
|
||||
</Item>
|
||||
<Item KeyName='GetHash'>
|
||||
<OSVersion Compare=">=">6.3</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='获取哈希值'/>
|
||||
</Value>
|
||||
@@ -33,11 +35,15 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
</SubKey>
|
||||
</Item>
|
||||
</Shell>
|
||||
</Group>
|
||||
|
||||
<Group RegPath='HKEY_CLASSES_ROOT\Directory'>
|
||||
</File>
|
||||
|
||||
<Folder>
|
||||
</Folder>
|
||||
|
||||
<Directory>
|
||||
<Shell>
|
||||
<Item KeyName="TakeOwnerShip">
|
||||
<OSVersion Compare=">=">6.2</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='获取所有者权限' HasLUAShield='' NoWorkingDirectory=''/>
|
||||
</Value>
|
||||
@@ -50,22 +56,25 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
</SubKey>
|
||||
</Item>
|
||||
</Shell>
|
||||
</Group>
|
||||
</Directory>
|
||||
|
||||
<Group RegPath='HKEY_CLASSES_ROOT\Directory\Background'>
|
||||
<Background>
|
||||
<Shell>
|
||||
<Item KeyName='Windows.ShowHiddenFiles'>
|
||||
<OSVersion Compare=">=">6.2</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='显示/隐藏 隐藏文件' Icon='imageres.dll,-5314' Position='bottom' CommandStateSync='' ExplorerCommandHandler='{f7300245-1f4b-41ba-8948-6fd392064494}'/>
|
||||
</Value>
|
||||
</Item>
|
||||
<Item KeyName='Windows.ShowFileExtensions'>
|
||||
<Item KeyName='Windows.ShowFileExtensions'>
|
||||
<OSVersion Compare=">=">6.2</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='显示/隐藏 文件扩展名' Icon='imageres.dll,-5314' Position='bottom' CommandStateSync='' ExplorerCommandHandler='{4ac6c205-2853-4bf5-b47c-919a42a48a16}'/>
|
||||
</Value>
|
||||
</Item>
|
||||
<!--清空回收站-->
|
||||
<Item KeyName='Windows.RecycleBin.Empty'>
|
||||
<OSVersion Compare=">=">6.1</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='@shell32.dll,-10564' Icon='imageres.dll,-54' CommandStateHandler='{c9298eef-69dd-4cdd-b153-bdbc38486781}'/>
|
||||
</Value>
|
||||
@@ -89,29 +98,28 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
<ShellEx>
|
||||
<Item Text='窗口转换程序' Icon='imageres.dll,0' KeyName='Flip3D' Guid='{3080f90e-d7ad-11d9-bd98-0000947b0257}'/>
|
||||
</ShellEx>
|
||||
</Group>
|
||||
</Background>
|
||||
|
||||
<Group RegPath='HKEY_CLASSES_ROOT\DesktopBackground'>
|
||||
<Desktop>
|
||||
<Shell>
|
||||
<!--打开此电脑-->
|
||||
<Item KeyName='OpenThisPC'>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='@windows.storage.dll,-9216' Icon='imageres.dll,-109'/>
|
||||
<REG_SZ MUIVerb='打开此电脑' Icon='imageres.dll,-109'/>
|
||||
</Value>
|
||||
<SubKey>
|
||||
<Command Default='explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}'/>
|
||||
</SubKey>
|
||||
</Item>
|
||||
<!--打开控制面板-->
|
||||
<Item KeyName='OpenControlPanel'>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='@shell32.dll,-4161' Icon='imageres.dll,-27'/>
|
||||
<REG_SZ MUIVerb='打开控制面板' Icon='imageres.dll,-27'/>
|
||||
</Value>
|
||||
<SubKey>
|
||||
<Command Default='rundll32.exe shell32.dll,Control_RunDLL'/>
|
||||
</SubKey>
|
||||
</Item>
|
||||
<Item KeyName='RestartExplorer'>
|
||||
<OSVersion Compare=">=">6.1</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='重启资源管理器' Icon='explorer.exe,0'/>
|
||||
</Value>
|
||||
@@ -127,7 +135,8 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
<Command Default='regedit.exe -m'/>
|
||||
</SubKey>
|
||||
</Item>
|
||||
<Item KeyName='SnipToClipboard' Tip='仅适用于Win10操作系统
截屏后可直接Ctrl+V粘贴图片
适用位置:Word、QQ、PS等
快捷键:Win+Shift+S'>
|
||||
<Item KeyName='SnipToClipboard' Tip='截屏后可直接Ctrl+V粘贴图片
适用位置:Word、QQ、PS等
快捷键:Win+Shift+S'>
|
||||
<OSVersion Compare=">=">10.0</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='截屏到剪贴板' Icon='snippingTool.exe,0'/>
|
||||
</Value>
|
||||
@@ -135,10 +144,19 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
<Command Default='explorer ms-screenclip:'/>
|
||||
</SubKey>
|
||||
</Item>
|
||||
<Item KeyName='SlideToShutDown'>
|
||||
<!--OSVersion Compare=">=">10.0</OSVersion-->
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='滑动关机' Icon='shell32.dll,-28'/>
|
||||
</Value>
|
||||
<SubKey>
|
||||
<Command Default='SlideToShutDown.exe'/>
|
||||
</SubKey>
|
||||
</Item>
|
||||
</Shell>
|
||||
</Group>
|
||||
</Desktop>
|
||||
|
||||
<Group RegPath='HKEY_CLASSES_ROOT\Drive'>
|
||||
<Drive>
|
||||
<Shell>
|
||||
<!--优化驱动器-->
|
||||
<Item KeyName='OptimizeDrives'>
|
||||
@@ -157,18 +175,20 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
</Value>
|
||||
</Item>
|
||||
</Shell>
|
||||
</Group>
|
||||
</Drive>
|
||||
|
||||
<Group RegPath='HKEY_CLASSES_ROOT\AllFilesystemObjects'>
|
||||
<AllObjects>
|
||||
<Shell>
|
||||
<!--永久删除-->
|
||||
<Item KeyName='Windows.PermanentDelete' Tip='不能用于删除lnk快捷方式文件,
或通过快捷方式删除其目标对象'>
|
||||
<OSVersion Compare=">=">6.2</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='@shell32.dll,-37394' Icon='shell32.dll,-240' Position='bottom' CommandStateSync='' ExplorerCommandHandler='{E9571AB2-AD92-4ec6-8924-4E5AD33790F5}'/>
|
||||
</Value>
|
||||
</Item>
|
||||
<!--复制路径-->
|
||||
<Item KeyName='Windows.CopyAsPath' Tip='系统原生菜单项需按住Shift显示,
此项可以直接显示'>
|
||||
<OSVersion Compare=">=">6.2</OSVersion>
|
||||
<Value>
|
||||
<REG_SZ MUIVerb='@shell32.dll,-30329' Icon='imageres.dll,-5302' CommandStateHandler='{3B1599F9-E00A-4BBF-AD3E-B3F99FA87779}' CanonicalName='{707C7BC6-685A-4A4D-A275-3966A5A3EFAA}' CommandStateSync='' VerbHandler='{f3d06e7c-1e45-4a26-847e-f9fcdee59be0}' VerbName='copyaspath' Description='@shell32.dll,-30336'/>
|
||||
<REG_DWORD InvokeCommandOnSelection='1'/>
|
||||
@@ -181,5 +201,11 @@ Tip属性为鼠标悬浮在开关上时的提示信息,从每个Item节点开
|
||||
<!--移动到文件夹-->
|
||||
<Item Text='@shell32.dll,-30305' Icon='imageres.dll,-5303' KeyName='MoveTo' Guid='{c2fbb631-2971-11d1-a18c-00c04fd75d13}'/>
|
||||
</ShellEx>
|
||||
</Group>
|
||||
</AllObjects>
|
||||
|
||||
<Computer>
|
||||
</Computer>
|
||||
|
||||
<RecycleBin>
|
||||
</RecycleBin>
|
||||
</Data>
|
||||
Reference in New Issue
Block a user