2017-02-26 19:23:31 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Windows.Forms;
|
2020-04-23 08:16:16 +00:00
|
|
|
|
using HeliosPlus.Shared;
|
|
|
|
|
using HeliosPlus.ShellExtension.Resources;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
using SharpShell.Attributes;
|
|
|
|
|
using SharpShell.SharpContextMenu;
|
|
|
|
|
|
2020-04-23 08:16:16 +00:00
|
|
|
|
namespace HeliosPlus.ShellExtension
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
[ComVisible(true)]
|
|
|
|
|
[COMServerAssociation(AssociationType.ClassOfExtension, @".exe")]
|
2019-01-17 17:15:43 +00:00
|
|
|
|
[Guid("48B49131-2258-4694-879F-A3F96310A220")]
|
2017-02-26 19:23:31 +00:00
|
|
|
|
internal class HeliosExecutableMenuExtension : SharpContextMenu
|
|
|
|
|
{
|
|
|
|
|
protected override bool CanShowMenu()
|
|
|
|
|
{
|
2017-08-10 14:21:45 +00:00
|
|
|
|
return Helios.IsInstalled &&
|
2018-10-20 00:27:25 +00:00
|
|
|
|
SelectedItemPaths.Count() == 1 &&
|
2020-06-07 08:48:45 +00:00
|
|
|
|
ProfileItem.LoadAllProfiles().Any() &&
|
2018-10-20 00:27:25 +00:00
|
|
|
|
Path.GetExtension(SelectedItemPaths.First())?.ToLower() == @".exe";
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override ContextMenuStrip CreateMenu()
|
|
|
|
|
{
|
|
|
|
|
var explorerMenu = new ContextMenuStrip();
|
|
|
|
|
var extensionMenu = new ToolStripMenuItem(Language.Open_under_Display_Profile,
|
2017-08-07 16:25:34 +00:00
|
|
|
|
Properties.Resources.Icon_x16);
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-06-07 08:48:45 +00:00
|
|
|
|
if (ProfileItem.LoadAllProfiles().Any())
|
2018-10-20 00:22:48 +00:00
|
|
|
|
{
|
2020-06-07 08:48:45 +00:00
|
|
|
|
ProfileItem.UpdateCurrentProfile();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-06-07 08:48:45 +00:00
|
|
|
|
foreach (var profile in ProfileItem.LoadAllProfiles())
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2018-10-20 00:22:48 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(CreateProfileMenu(profile));
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-20 00:22:48 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(new ToolStripSeparator());
|
|
|
|
|
}
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Manage_Profiles,
|
2017-08-07 16:25:34 +00:00
|
|
|
|
Properties.Resources.Icon_x16,
|
2018-10-20 00:27:25 +00:00
|
|
|
|
(sender, args) =>
|
|
|
|
|
{
|
2020-05-03 08:39:35 +00:00
|
|
|
|
HeliosPlus.Open();
|
2018-10-20 00:27:25 +00:00
|
|
|
|
}));
|
2017-02-26 19:23:31 +00:00
|
|
|
|
explorerMenu.Items.Add(extensionMenu);
|
|
|
|
|
explorerMenu.Items.Add(new ToolStripSeparator());
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return explorerMenu;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-07 08:48:45 +00:00
|
|
|
|
private ToolStripMenuItem CreateProfileMenu(ProfileItem profile)
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
var profileMenu = new ToolStripMenuItem(profile.Name, new ProfileIcon(profile).ToBitmap(16, 16));
|
2018-10-23 23:38:35 +00:00
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run, null,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
(sender, args) =>
|
2020-05-03 08:39:35 +00:00
|
|
|
|
HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
SelectedItemPaths.FirstOrDefault())));
|
2017-08-10 14:09:41 +00:00
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run_as_administrator, Shield.SmallIcon,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
(sender, args) =>
|
2020-05-03 08:39:35 +00:00
|
|
|
|
HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
SelectedItemPaths.FirstOrDefault(), true)));
|
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripSeparator());
|
2018-10-23 23:38:35 +00:00
|
|
|
|
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Create_Shortcut, null,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
(sender, args) =>
|
2020-05-03 08:39:35 +00:00
|
|
|
|
HeliosPlus.Open(HeliosStartupAction.CreateShortcut, profile,
|
2017-02-26 19:23:31 +00:00
|
|
|
|
SelectedItemPaths.FirstOrDefault())));
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2017-02-26 19:23:31 +00:00
|
|
|
|
return profileMenu;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|