优化部分代码,添加"共享到Skype"

This commit is contained in:
蓝点lilac
2020-11-04 01:43:35 +08:00
parent d0e009ab72
commit 5f8929ea64
33 changed files with 226 additions and 80 deletions

View File

@@ -53,6 +53,7 @@ namespace ContextMenuManager
public static string OpenWith => GetValue("OpenWith");
public static string WinX => GetValue("WinX");
public static string LnkFile => GetValue("LnkFile");
public static string UwpLnk => GetValue("UwpLnk");
public static string ExeFile => GetValue("ExeFile");
public static string TextFile => GetValue("TextFile");
public static string ImageFile => GetValue("ImageFile");
@@ -90,6 +91,7 @@ namespace ContextMenuManager
public static string OpenWith => GetValue("OpenWith");
public static string WinX => GetValue("WinX");
public static string LnkFile => GetValue("LnkFile");
public static string UwpLnk => GetValue("UwpLnk");
public static string ExeFile => GetValue("ExeFile");
public static string TextFile => GetValue("TextFile");
public static string ImageFile => GetValue("ImageFile");

View File

@@ -132,6 +132,9 @@
<Compile Include="Controls\Interfaces\IBtnMoveUpDownItem.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\SpecialItems\SkypeShareItem.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\SubMenuModeForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using System;
using System.Windows.Forms;

View File

@@ -2,7 +2,7 @@
using BulePointLilac.Methods;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface IBtnDeleteItem
{

View File

@@ -1,6 +1,6 @@
using BulePointLilac.Controls;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface IBtnMoveUpDownItem
{

View File

@@ -1,7 +1,7 @@
using BulePointLilac.Controls;
using static BulePointLilac.Methods.ObjectPath;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface IBtnOpenPathItem
{

View File

@@ -1,7 +1,7 @@
using BulePointLilac.Controls;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface IBtnShowMenuItem
{

View File

@@ -1,7 +1,7 @@
using BulePointLilac.Controls;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface IChkVisibleItem
{

View File

@@ -3,7 +3,7 @@ using System.Drawing;
using System.Windows.Forms;
using static BulePointLilac.Methods.ObjectPath;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface IFoldGroupItem
{

View File

@@ -2,7 +2,7 @@
using BulePointLilac.Methods;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiCommandItem
{

View File

@@ -1,7 +1,7 @@
using BulePointLilac.Methods;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiDeleteItem
{

View File

@@ -3,7 +3,7 @@ using System.IO;
using System.Windows.Forms;
using static BulePointLilac.Methods.ObjectPath;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiFilePathItem
{

View File

@@ -3,7 +3,7 @@ using BulePointLilac.Methods;
using System.Drawing;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiIconItem
{

View File

@@ -2,7 +2,7 @@
using System.Windows.Forms;
using static BulePointLilac.Methods.ObjectPath;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiRegPathItem
{

View File

@@ -2,7 +2,7 @@
using BulePointLilac.Methods;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiTextItem
{

View File

@@ -1,7 +1,7 @@
using System.Diagnostics;
using System.Windows.Forms;
namespace ContextMenuManager.Controls
namespace ContextMenuManager.Controls.Interfaces
{
interface ITsiWebSearchItem
{

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System;
using System.Diagnostics;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System.Drawing;
using System.Windows.Forms;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System.Drawing;
using System.IO;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System;
using System.Collections.Generic;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System;
using System.Collections.Generic;

View File

@@ -25,6 +25,7 @@ namespace ContextMenuManager.Controls
public const string MENUPATH_EXEFILE = @"HKEY_CLASSES_ROOT\exefile";//可执行文件
public const string MENUPATH_SYSLNKFILE = @"HKEY_CLASSES_ROOT\SystemFileAssociations\.lnk";
public const string MENUPATH_SYSEXEFILE = @"HKEY_CLASSES_ROOT\SystemFileAssociations\.exe";
public const string MENUPATH_UWPLNK = @"HKEY_CLASSES_ROOT\Launcher.ImmersiveApplication";
public const string MENUPATH_UNKNOWN = @"HKEY_CLASSES_ROOT\Unknown";//未知格式
public const string MENUPATH_TEXT = @"HKEY_CLASSES_ROOT\SystemFileAssociations\text";//通用文本文件
public const string MENUPATH_IMAGE = @"HKEY_CLASSES_ROOT\SystemFileAssociations\image";//通用图像文件
@@ -32,25 +33,21 @@ namespace ContextMenuManager.Controls
public const string MENUPATH_AUDIO = @"HKEY_CLASSES_ROOT\SystemFileAssociations\audio";//通用音频文件
public const string MENUPATH_DIRECTORY_IMAGE = @"HKEY_CLASSES_ROOT\SystemFileAssociations\Directory.Image";//通用图像文件目录
public const string MENUPATH_DIRECTORY_VIDEO = @"HKEY_CLASSES_ROOT\SystemFileAssociations\Directory.Video";//通用视频文件目录
public const string MENUPATH_DIRECTORY_AUDIO = @"HKEY_CLASSES_ROOT\SystemFileAssociations\Directory.Video";//通用音频文件目录
public const string MENUPATH_DIRECTORY_AUDIO = @"HKEY_CLASSES_ROOT\SystemFileAssociations\Directory.Audio";//通用音频文件目录
public const string SYSFILEASSPATH = @"HKEY_CLASSES_ROOT\SystemFileAssociations";//系统扩展名注册表父项路径
public enum Scenes
{
File, Folder, Directory, Background, Desktop, Drive, AllObjects,
Computer, RecycleBin, Library, LnkFile, ExeFile, Text, Image, Video, Audio,
ImageDirectory, VideoDirectory, AudioDirectory, Unknown, CustomExtension
File, Folder, Directory, Background, Desktop, Drive, AllObjects, Computer, RecycleBin,
Library, LnkFile, UwpLnk, ExeFile, TextFile, ImageFile, VideoFile, AudioFile,
ImageDirectory, VideoDirectory, AudioDirectory, UnknownType, CustomType
}
private Scenes scene;
public Scenes Scene
{
get => scene;
set
{
scene = value;
LoadItems();
}
set { scene = value; LoadItems(); }
}
private static string GetShellPath(string scenePath) => $@"{scenePath}\shell";
@@ -58,7 +55,7 @@ namespace ContextMenuManager.Controls
public ShellList()
{
TypeItem.ExtensionChanged += (sender, e) => this.Scene = Scenes.CustomExtension;
TypeItem.ExtensionChanged += (sender, e) => this.Scene = Scenes.CustomType;
}
private void LoadItems()
@@ -89,15 +86,17 @@ namespace ContextMenuManager.Controls
scenePath = MENUPATH_LIBRARY; break;
case Scenes.LnkFile:
scenePath = MENUPATH_LNKFILE; break;
case Scenes.UwpLnk:
scenePath = MENUPATH_UWPLNK; break;
case Scenes.ExeFile:
scenePath = MENUPATH_EXEFILE; break;
case Scenes.Text:
case Scenes.TextFile:
scenePath = MENUPATH_TEXT; break;
case Scenes.Image:
case Scenes.ImageFile:
scenePath = MENUPATH_IMAGE; break;
case Scenes.Video:
case Scenes.VideoFile:
scenePath = MENUPATH_VIDEO; break;
case Scenes.Audio:
case Scenes.AudioFile:
scenePath = MENUPATH_AUDIO; break;
case Scenes.ImageDirectory:
scenePath = MENUPATH_DIRECTORY_IMAGE; break;
@@ -105,9 +104,9 @@ namespace ContextMenuManager.Controls
scenePath = MENUPATH_DIRECTORY_VIDEO; break;
case Scenes.AudioDirectory:
scenePath = MENUPATH_DIRECTORY_AUDIO; break;
case Scenes.Unknown:
case Scenes.UnknownType:
scenePath = MENUPATH_UNKNOWN; break;
case Scenes.CustomExtension:
case Scenes.CustomType:
scenePath = TypeItem.SysAssExtPath; break;
}
this.AddNewItem(scenePath);
@@ -115,6 +114,9 @@ namespace ContextMenuManager.Controls
switch(scene)
{
case Scenes.File:
this.AddItem(new SpecialItems.SkypeShareItem());
break;
case Scenes.Background:
this.AddItem(new RegRuleItem(RegRuleItem.CustomFolder) { MarginRight = RegRuleItem.SysMarginRignt });
break;
@@ -134,7 +136,7 @@ namespace ContextMenuManager.Controls
case Scenes.ExeFile:
this.AddItems(MENUPATH_SYSEXEFILE);
break;
case Scenes.CustomExtension:
case Scenes.CustomType:
this.InsertItem(new TypeItem(), 0);
this.AddItems(TypeItem.AssExtPath);
break;
@@ -143,7 +145,7 @@ namespace ContextMenuManager.Controls
private void AddItems(string scenePath)
{
if(this.Scene == Scenes.CustomExtension && TypeItem.Extension == null) return;
if(this.Scene == Scenes.CustomType && TypeItem.Extension == null) return;
this.AddShellItems(GetShellPath(scenePath));
this.AddShellExItems(GetShellExPath(scenePath));
}
@@ -189,7 +191,7 @@ namespace ContextMenuManager.Controls
AddCommonButton btnAddCommon = new AddCommonButton();
newItem.AddCtr(btnAddCommon);
this.AddItem(newItem);
if(this.Scene == Scenes.CustomExtension)
if(this.Scene == Scenes.CustomType)
{
newItem.Visible = TypeItem.Extension != null;
TypeItem.ExtensionChanged += (sender, e) => newItem.Visible = TypeItem.Extension != null;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System;
using System.Drawing;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using System;
using System.Collections.Generic;
using System.Drawing;

View File

@@ -0,0 +1,112 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace ContextMenuManager.Controls.SpecialItems
{
//所有文件的右键菜单项目共享到Skype
//目前仅发现这一个特殊例子,不符合所有通用规则
sealed class SkypeShareItem : MyListItem, IChkVisibleItem, ITsiFilePathItem, ITsiRegPathItem, ITsiWebSearchItem, IBtnShowMenuItem
{
const string DllPath = @"Skype\SkypeContext.dll";
const string GuidName = "{776DBC8D-7347-478C-8D71-791E12EF49D8}";
const string PackageRegPath = @"HKEY_CLASSES_ROOT\PackagedCom\Package";
const string AppxRegPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Appx";
public SkypeShareItem()
{
InitializeComponents();
string path = ItemFilePath;
if(File.Exists(path))
{
ChkVisible.Checked = this.ItemVisible;
this.Text = ResourceString.GetDirectString($"@{path},-101");
string exePath = $@"{Path.GetDirectoryName(path)}\Skype.exe";
this.Image = Icon.ExtractAssociatedIcon(exePath)?.ToBitmap();
}
else this.Visible = false;
}
public string ItemFilePath
{
get
{
string AppxDirPath = Registry.GetValue(AppxRegPath, "PackageRoot", null)?.ToString();
if(!Directory.Exists(AppxDirPath)) return null;
foreach(DirectoryInfo di in new DirectoryInfo(AppxDirPath).GetDirectories())
{
if(di.Name.StartsWith("Microsoft.SkypeApp", StringComparison.OrdinalIgnoreCase))
{
string value = $@"{di.FullName}\{DllPath}";
if(File.Exists(value)) return value;
}
}
return null;
}
}
private string PackageName
{
get
{
if(!File.Exists(ItemFilePath)) return null;
string[] strs = ItemFilePath.Split('\\');
return strs[strs.Length - 3];
}
}
public string RegPath
{
get
{
if(PackageName == null) return null;
return $@"{PackageRegPath}\{PackageName}\Class\{GuidName}";
}
set { }
}
public bool ItemVisible
{
get
{
using(RegistryKey key = RegistryEx.GetRegistryKey(RegPath))
{
if(key == null) return true;
string value = key.GetValue("DllPath")?.ToString();
return value.Equals(DllPath, StringComparison.OrdinalIgnoreCase);
}
}
set
{
Registry.SetValue(RegPath, "DllPath", value ? DllPath : string.Empty);
}
}
public string SearchText => Text;
public MenuButton BtnShowMenu { get; set; }
public VisibleCheckBox ChkVisible { get; set; }
public WebSearchMenuItem TsiSearch { get; set; }
public RegLocationMenuItem TsiRegLocation { get; set; }
public FileLocationMenuItem TsiFileLocation { get; set; }
public FilePropertiesMenuItem TsiFileProperties { get; set; }
private void InitializeComponents()
{
BtnShowMenu = new MenuButton(this);
ChkVisible = new VisibleCheckBox(this);
TsiSearch = new WebSearchMenuItem(this);
TsiFileLocation = new FileLocationMenuItem(this);
TsiFileProperties = new FilePropertiesMenuItem(this);
TsiRegLocation = new RegLocationMenuItem(this);
ContextMenuStrip.Items.AddRange(new ToolStripItem[] { TsiSearch,
new ToolStripSeparator(), TsiFileProperties, TsiFileLocation, TsiRegLocation });
}
}
}

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using Microsoft.Win32;
using System;
using System.IO;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

View File

@@ -1,5 +1,6 @@
using BulePointLilac.Controls;
using BulePointLilac.Methods;
using ContextMenuManager.Controls.Interfaces;
using System;
using System.Collections.Generic;
using System.IO;

View File

@@ -79,6 +79,7 @@ namespace ContextMenuManager
static readonly string[] TypeItems = {
AppString.SideBar.LnkFile,
AppString.SideBar.UwpLnk,
AppString.SideBar.ExeFile,
null,
AppString.SideBar.TextFile,
@@ -96,6 +97,7 @@ namespace ContextMenuManager
};
static readonly string[] TypeItemInfos = {
AppString.StatusBar.LnkFile,
AppString.StatusBar.UwpLnk,
AppString.StatusBar.ExeFile,
null,
AppString.StatusBar.TextFile,
@@ -128,6 +130,40 @@ namespace ContextMenuManager
AppString.SideBar.Donate
};
static readonly ShellList.Scenes[] GeneralShellScenes =
{
ShellList.Scenes.File,
ShellList.Scenes.Folder,
ShellList.Scenes.Directory,
ShellList.Scenes.Background,
ShellList.Scenes.Desktop,
ShellList.Scenes.Drive,
ShellList.Scenes.AllObjects,
ShellList.Scenes.Computer,
ShellList.Scenes.RecycleBin,
ShellList.Scenes.Library
};
static readonly ShellList.Scenes?[] TypeShellScenes =
{
ShellList.Scenes.LnkFile,
ShellList.Scenes.UwpLnk,
ShellList.Scenes.ExeFile,
null,
ShellList.Scenes.TextFile,
ShellList.Scenes.ImageFile,
ShellList.Scenes.VideoFile,
ShellList.Scenes.AudioFile,
null,
ShellList.Scenes.ImageDirectory,
ShellList.Scenes.VideoDirectory,
ShellList.Scenes.AudioDirectory,
null,
ShellList.Scenes.UnknownType,
null,
ShellList.Scenes.CustomType
};
private void HideAllParts()
{
shellList.Visible = shellNewList.Visible = sendToList.Visible = openWithList.Visible
@@ -190,26 +226,6 @@ namespace ContextMenuManager
{
switch(SideBar.SelectIndex)
{
case 0:
shellList.Scene = ShellList.Scenes.File; break;
case 1:
shellList.Scene = ShellList.Scenes.Folder; break;
case 2:
shellList.Scene = ShellList.Scenes.Directory; break;
case 3:
shellList.Scene = ShellList.Scenes.Background; break;
case 4:
shellList.Scene = ShellList.Scenes.Desktop; break;
case 5:
shellList.Scene = ShellList.Scenes.Drive; break;
case 6:
shellList.Scene = ShellList.Scenes.AllObjects; break;
case 7:
shellList.Scene = ShellList.Scenes.Computer; break;
case 8:
shellList.Scene = ShellList.Scenes.RecycleBin; break;
case 9:
shellList.Scene = ShellList.Scenes.Library; break;
case 11:
shellNewList.LoadItems(); shellNewList.Visible = true; break;
case 12:
@@ -218,37 +234,19 @@ namespace ContextMenuManager
openWithList.LoadItems(); openWithList.Visible = true; break;
case 15:
winXList.LoadItems(); winXList.Visible = true; break;
default:
if(SideBar.SelectIndex <= 9)
{
shellList.Scene = GeneralShellScenes[SideBar.SelectIndex];
shellList.Visible = true;
}
break;
}
shellList.Visible = SideBar.SelectIndex <= 9;
}
private void SwitchTypeItem()
{
switch(SideBar.SelectIndex)
{
case 0:
shellList.Scene = ShellList.Scenes.LnkFile; break;
case 1:
shellList.Scene = ShellList.Scenes.ExeFile; break;
case 3:
shellList.Scene = ShellList.Scenes.Text; break;
case 4:
shellList.Scene = ShellList.Scenes.Image; break;
case 5:
shellList.Scene = ShellList.Scenes.Video; break;
case 6:
shellList.Scene = ShellList.Scenes.Audio; break;
case 8:
shellList.Scene = ShellList.Scenes.ImageDirectory; break;
case 9:
shellList.Scene = ShellList.Scenes.VideoDirectory; break;
case 10:
shellList.Scene = ShellList.Scenes.AudioDirectory; break;
case 12:
shellList.Scene = ShellList.Scenes.Unknown; break;
case 14:
shellList.Scene = ShellList.Scenes.CustomExtension; break;
}
shellList.Scene = (ShellList.Scenes)TypeShellScenes[SideBar.SelectIndex];
shellList.Visible = true;
}

View File

@@ -33,9 +33,11 @@ namespace ContextMenuManager
DirectoryInfo di = new DirectoryInfo(LanguagesDir);
if(value.Equals(string.Empty) && di.Exists)
{
string sysLanguageName = new CultureInfo(GetUserDefaultUILanguage()).Name;
foreach(FileInfo fi in di.GetFiles())
{
if(Path.GetFileNameWithoutExtension(fi.Name).Equals(new CultureInfo(GetUserDefaultUILanguage()).Name, StringComparison.OrdinalIgnoreCase))
string fileName = Path.GetFileNameWithoutExtension(fi.Name);
if(fileName.Equals(sysLanguageName, StringComparison.OrdinalIgnoreCase))
{
value = fi.FullName; break;
}

View File

@@ -31,6 +31,7 @@ OpenWith = 打开方式
WinX = Win+X
LnkFile = lnk文件
UwpLnk = uwp lnk
ExeFile = exe文件
TextFile = 文本文件
ImageFile = 图像文件
@@ -67,6 +68,7 @@ OpenWith = 所有文件右键 "打开方式" 的菜单项目
WinX = Win10 "开始" 按钮的右键Win+X菜单项目
LnkFile = 所有快捷方式的右键菜单
UwpLnk = Win10 UWP应用快捷方式的右键菜单
ExeFile = 所有EXE可执行文件的右键菜单
TextFile = 通用文本格式(如.txt、.ini)文件的右键菜单
ImageFile = 通用图像格式(如.jpg、.png)文件的右键菜单

View File

@@ -255,4 +255,16 @@ Text=金山毒霸(32位)扫描 && 文件粉碎
Icon=.\kismain.exe,0
[8f556da3-987d-47b0-aa88-eb8d52fe1b9a]
Text=迅雷播放组件
Icon=..\Program\XMP\XMP.exe,0
Icon=..\Program\XMP\XMP.exe,0
[dde4beeb-dde6-48fd-8eb5-035c09923f83]
Text=Unlocker
Icon=.\Unlocker.exe,0
[9c5397bb-07be-4e38-98ba-395f94045091]
Text=福昕PDF编辑器
Icon=..\FoxitPhantom.exe,0
[eee949eb-c9ed-4967-98b0-ed4e543befa5]
Text=115网盘
Icon=..\115chrome.exe,0
[C49499AC-DC25-478B-B903-E005012B3DD1]
Text=使用智量扫描
Icon=.\WiseVector.exe,0

View File

@@ -31,6 +31,7 @@ OpenWith = 打开方式
WinX = Win+X
LnkFile = lnk文件
UwpLnk = uwp lnk
ExeFile = exe文件
TextFile = 文本文件
ImageFile = 图像文件
@@ -67,6 +68,7 @@ OpenWith = 所有文件右键 "打开方式" 的菜单项目
WinX = Win10 "开始" 按钮的右键Win+X菜单项目
LnkFile = 所有快捷方式的右键菜单
UwpLnk = Win10 UWP应用快捷方式的右键菜单
ExeFile = 所有EXE可执行文件的右键菜单
TextFile = 通用文本格式(如.txt、.ini)文件的右键菜单
ImageFile = 通用图像格式(如.jpg、.png)文件的右键菜单