2017-02-26 19:23:31 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2020-11-22 07:49:37 +00:00
|
|
|
|
using System.Drawing;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
using System.Windows.Forms;
|
2020-11-22 07:49:37 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System;
|
2020-04-23 08:16:16 +00:00
|
|
|
|
using HeliosPlus.ShellExtension.Resources;
|
2020-11-22 07:49:37 +00:00
|
|
|
|
using HeliosPlus;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
using SharpShell.Attributes;
|
|
|
|
|
using SharpShell.SharpContextMenu;
|
2020-11-22 07:49:37 +00:00
|
|
|
|
using SharpShell.Diagnostics;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using Microsoft.Win32;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
|
2020-04-23 08:16:16 +00:00
|
|
|
|
namespace HeliosPlus.ShellExtension
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
|
|
|
|
[ComVisible(true)]
|
2020-11-22 07:49:37 +00:00
|
|
|
|
[COMServerAssociation(AssociationType.DesktopBackground)]
|
|
|
|
|
[Guid("346e3285-43ca-45bc-8b33-1d4cdfe32e00")]
|
|
|
|
|
public class HeliosDesktopMenuExtension : SharpContextMenu
|
2017-02-26 19:23:31 +00:00
|
|
|
|
{
|
2020-11-22 07:49:37 +00:00
|
|
|
|
// Other constants that are useful
|
|
|
|
|
internal static Version _version = new Version(1, 0, 0);
|
|
|
|
|
internal static string AlternateAppHomePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "HeliosPlus");
|
|
|
|
|
internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
|
|
|
|
|
private static string AppProfileStoragePath = System.IO.Path.Combine(AppDataPath, $"Profiles");
|
|
|
|
|
private static string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{_version.ToString(2)}.json");
|
|
|
|
|
internal static string registryHeliosPlus = @"SOFTWARE\HeliosPlus";
|
|
|
|
|
string heliosPlusFullname = "";
|
|
|
|
|
string heliosPlusInstallDir = "";
|
2020-11-22 08:40:10 +00:00
|
|
|
|
Process heliosPlusProcess = null;
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-11-22 07:49:37 +00:00
|
|
|
|
public HeliosDesktopMenuExtension()
|
|
|
|
|
{ }
|
2017-02-26 19:23:31 +00:00
|
|
|
|
|
|
|
|
|
protected override bool CanShowMenu()
|
|
|
|
|
{
|
2020-11-22 07:49:37 +00:00
|
|
|
|
// Only show this menu if HeliosPlus is installed
|
|
|
|
|
heliosPlusInstallDir = "";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
RegistryKey heliosPlusKey = Registry.LocalMachine.OpenSubKey(registryHeliosPlus, RegistryKeyPermissionCheck.ReadSubTree);
|
|
|
|
|
heliosPlusInstallDir = heliosPlusKey.GetValue("InstallDir", AlternateAppHomePath).ToString();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
heliosPlusInstallDir = AlternateAppHomePath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
heliosPlusFullname = Path.Combine(heliosPlusInstallDir, "HeliosPlus.exe");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (File.Exists(heliosPlusFullname))
|
|
|
|
|
return true;
|
|
|
|
|
else
|
|
|
|
|
return false;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override ContextMenuStrip CreateMenu()
|
|
|
|
|
{
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-11-22 07:49:37 +00:00
|
|
|
|
var explorerMenuStrip = new ContextMenuStrip();
|
|
|
|
|
|
|
|
|
|
if (File.Exists(heliosPlusFullname))
|
2017-08-10 14:05:43 +00:00
|
|
|
|
{
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-11-22 07:49:37 +00:00
|
|
|
|
var extensionMenu = new ToolStripMenuItem("HeliosPlus: Change display profiles...", Properties.Resources.HeliosPlusMenuImage);
|
|
|
|
|
explorerMenuStrip.Items.Add(extensionMenu);
|
|
|
|
|
|
|
|
|
|
Dictionary<string, string> profiles = new Dictionary<string, string>();
|
|
|
|
|
|
|
|
|
|
if (File.Exists(_profileStorageJsonFileName))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2020-11-22 07:49:37 +00:00
|
|
|
|
MatchCollection mc;
|
|
|
|
|
string uuid = "";
|
|
|
|
|
string profileName = "";
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-11-22 07:49:37 +00:00
|
|
|
|
foreach (string aLine in File.ReadLines(_profileStorageJsonFileName, Encoding.Unicode))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2020-11-22 07:49:37 +00:00
|
|
|
|
string lineToProcess = aLine;
|
|
|
|
|
if (lineToProcess.StartsWith(" \"UUID\""))
|
|
|
|
|
{
|
|
|
|
|
mc = Regex.Matches(lineToProcess, " \"UUID\": \"(.*)\"");
|
|
|
|
|
uuid = mc[0].Groups[1].ToString();
|
|
|
|
|
}
|
|
|
|
|
else if (lineToProcess.StartsWith(" \"Name\""))
|
|
|
|
|
{
|
|
|
|
|
mc = Regex.Matches(lineToProcess, " \"Name\": \"(.*)\"");
|
|
|
|
|
profileName = mc[0].Groups[1].ToString();
|
|
|
|
|
if (!uuid.Equals(""))
|
|
|
|
|
profiles.Add(profileName, uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (profiles.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, string> pair in profiles.OrderBy(key => key.Key))
|
2018-10-20 00:27:25 +00:00
|
|
|
|
{
|
2020-11-22 07:49:37 +00:00
|
|
|
|
extensionMenu.DropDownItems.Add(new ToolStripMenuItem(pair.Key, null,
|
|
|
|
|
(sender, args) =>
|
|
|
|
|
{
|
2020-11-22 08:40:10 +00:00
|
|
|
|
Logging.Log(heliosPlusFullname + $" ChangeProfile \"{pair.Value}\"");
|
|
|
|
|
heliosPlusProcess = Process.Start(heliosPlusFullname,$"ChangeProfile \"{pair.Value}\"");
|
|
|
|
|
Logging.Log(heliosPlusProcess.ToString());
|
2020-11-22 07:49:37 +00:00
|
|
|
|
}
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-10 14:05:43 +00:00
|
|
|
|
}
|
2018-10-20 00:27:25 +00:00
|
|
|
|
|
2020-11-22 07:49:37 +00:00
|
|
|
|
return explorerMenuStrip;
|
2017-02-26 19:23:31 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|