From 45e2c32c3072c6a30751cbcfc6f8ffa15cd396f0 Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 6 Dec 2020 21:19:03 +1300 Subject: [PATCH] Updated shell ext to createprofile --- DisplayMagician.Setup/HeliosPlus.Setup.vdproj | 46 ++++---- .../DisplayMagicianStartupAction.cs | 1 + .../DisplayMagicianDesktopMenuExtension.cs | 100 ++++++++++-------- .../Properties/AssemblyInfo.cs | 2 +- DisplayMagician/Program.cs | 26 +++++ DisplayMagician/ShortcutRepository.cs | 4 - 6 files changed, 107 insertions(+), 72 deletions(-) diff --git a/DisplayMagician.Setup/HeliosPlus.Setup.vdproj b/DisplayMagician.Setup/HeliosPlus.Setup.vdproj index ae221f3..da5dfd3 100644 --- a/DisplayMagician.Setup/HeliosPlus.Setup.vdproj +++ b/DisplayMagician.Setup/HeliosPlus.Setup.vdproj @@ -226,13 +226,13 @@ "Entry" { "MsmKey" = "8:_7E279826AED3D503C2B7F7DB69F2C6E7" - "OwnerKey" = "8:_60AA7260CBB14B2DA5A5237FEBBA6E3B" + "OwnerKey" = "8:_3427114400C346E681DEA717B5D9A237" "MsmSig" = "8:_UNDEFINED" } "Entry" { "MsmKey" = "8:_7E279826AED3D503C2B7F7DB69F2C6E7" - "OwnerKey" = "8:_3427114400C346E681DEA717B5D9A237" + "OwnerKey" = "8:_60AA7260CBB14B2DA5A5237FEBBA6E3B" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -394,7 +394,13 @@ "Entry" { "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_3427114400C346E681DEA717B5D9A237" + "OwnerKey" = "8:_65F5D368273B99C7FE49B20D33031A7B" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_6F55062F4B8FDA7C720DAA94953D9E90" "MsmSig" = "8:_UNDEFINED" } "Entry" @@ -406,6 +412,12 @@ "Entry" { "MsmKey" = "8:_UNDEFINED" + "OwnerKey" = "8:_3427114400C346E681DEA717B5D9A237" + "MsmSig" = "8:_UNDEFINED" + } + "Entry" + { + "MsmKey" = "8:_UNDEFINED" "OwnerKey" = "8:_7E279826AED3D503C2B7F7DB69F2C6E7" "MsmSig" = "8:_UNDEFINED" } @@ -583,18 +595,6 @@ "OwnerKey" = "8:_90FC8214331F53FD9474FAE9E83D2C2C" "MsmSig" = "8:_UNDEFINED" } - "Entry" - { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_65F5D368273B99C7FE49B20D33031A7B" - "MsmSig" = "8:_UNDEFINED" - } - "Entry" - { - "MsmKey" = "8:_UNDEFINED" - "OwnerKey" = "8:_6F55062F4B8FDA7C720DAA94953D9E90" - "MsmSig" = "8:_UNDEFINED" - } } "Configurations" { @@ -678,7 +678,7 @@ "EntryPoint" = "8:" "Sequence" = "3:1" "Identifier" = "8:_703939FB_1800_4C54_9228_AE37F541938E" - "InstallerClass" = "11:TRUE" + "InstallerClass" = "11:FALSE" "CustomActionData" = "8:" "Run64Bit" = "11:TRUE" } @@ -693,7 +693,7 @@ "EntryPoint" = "8:" "Sequence" = "3:1" "Identifier" = "8:_4CB63466_63BE_413E_AFD3_98040D42F4F1" - "InstallerClass" = "11:TRUE" + "InstallerClass" = "11:FALSE" "CustomActionData" = "8:" "Run64Bit" = "11:TRUE" } @@ -1034,7 +1034,7 @@ { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:DisplayMagician.ShellExtension, Version=0.1.0.41963, Culture=neutral, PublicKeyToken=23a864d3136391eb, processorArchitecture=MSIL" + "AssemblyAsmDisplayName" = "8:DisplayMagician.ShellExtension, Version=0.1.0.37800, Culture=neutral, PublicKeyToken=23a864d3136391eb, processorArchitecture=MSIL" "ScatterAssemblies" { "_3427114400C346E681DEA717B5D9A237" @@ -1542,7 +1542,7 @@ "SharedLegacy" = "11:FALSE" "PackageAs" = "3:1" "Register" = "3:1" - "Exclude" = "11:TRUE" + "Exclude" = "11:FALSE" "IsDependency" = "11:TRUE" "IsolateTo" = "8:" } @@ -1581,7 +1581,7 @@ { "AssemblyRegister" = "3:1" "AssemblyIsInGAC" = "11:FALSE" - "AssemblyAsmDisplayName" = "8:DisplayMagician.Shared, Version=0.9.5.40335, Culture=neutral, processorArchitecture=MSIL" + "AssemblyAsmDisplayName" = "8:DisplayMagician.Shared, Version=0.9.5.36656, Culture=neutral, processorArchitecture=MSIL" "ScatterAssemblies" { "_CF2B5512697D3444DA5C7C187AE26988" @@ -1892,15 +1892,15 @@ { "Name" = "8:Microsoft Visual Studio" "ProductName" = "8:DisplayMagician" - "ProductCode" = "8:{78BBD2D7-BE5D-4C74-B612-091C756EF26B}" - "PackageCode" = "8:{2712909A-C2E7-4E3C-907A-CEF66D9B7438}" + "ProductCode" = "8:{65098CF0-9B4F-4078-9DCA-3EB25C8497B7}" + "PackageCode" = "8:{7C3CC1F3-8872-45A6-A688-90E6938B88DC}" "UpgradeCode" = "8:{48CB9401-ADED-4D62-B779-8317C7D069E1}" "AspNetVersion" = "8:2.0.50727.0" "RestartWWWService" = "11:FALSE" "RemovePreviousVersions" = "11:FALSE" "DetectNewerInstalledVersion" = "11:TRUE" "InstallAllUsers" = "11:TRUE" - "ProductVersion" = "8:0.9.0" + "ProductVersion" = "8:0.1.0" "Manufacturer" = "8:Terry MacDonald" "ARPHELPTELEPHONE" = "8:" "ARPHELPLINK" = "8:" diff --git a/DisplayMagician.Shared/DisplayMagicianStartupAction.cs b/DisplayMagician.Shared/DisplayMagicianStartupAction.cs index 9160c13..93c078a 100644 --- a/DisplayMagician.Shared/DisplayMagicianStartupAction.cs +++ b/DisplayMagician.Shared/DisplayMagicianStartupAction.cs @@ -4,6 +4,7 @@ { RunShortcut, ChangeProfile, + CreateProfile, StartUpNormally } } \ No newline at end of file diff --git a/DisplayMagician.ShellExtension/DisplayMagicianDesktopMenuExtension.cs b/DisplayMagician.ShellExtension/DisplayMagicianDesktopMenuExtension.cs index 7ca6cc9..c9ee54e 100644 --- a/DisplayMagician.ShellExtension/DisplayMagicianDesktopMenuExtension.cs +++ b/DisplayMagician.ShellExtension/DisplayMagicianDesktopMenuExtension.cs @@ -15,22 +15,23 @@ using Microsoft.Win32; namespace DisplayMagician.ShellExtension { [ComVisible(true)] + [Guid("de271cd7-fa82-439f-b128-202d473bb51e")] + [RegistrationName("DisplayMagician.ShellExtension")] [COMServerAssociation(AssociationType.DesktopBackground)] - [Guid("592dcbe6-3052-47bb-b962-101abb5e0ce8")] - public class HeliosDesktopMenuExtension : SharpContextMenu + public class DisplayMagicianDesktopMenuExtension : SharpContextMenu { // Other constants that are useful - internal static Version _version = new Version(1, 0, 0); + internal static Version _version = new Version(0, 1, 0); internal static string AlternateAppHomePath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "DisplayMagician"); internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); private static string AppProfileStoragePath = System.IO.Path.Combine(AppDataPath, $"Profiles"); - private static string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_{_version.ToString(2)}.json"); + private static string _profileStorageJsonFileName = System.IO.Path.Combine(AppProfileStoragePath, $"DisplayProfiles_1.0.json"); internal static string registryDisplayMagician = @"SOFTWARE\DisplayMagician"; string DisplayMagicianFullname = ""; string DisplayMagicianInstallDir = ""; Process DisplayMagicianProcess = null; - public HeliosDesktopMenuExtension() + public DisplayMagicianDesktopMenuExtension() { } protected override bool CanShowMenu() @@ -70,54 +71,65 @@ namespace DisplayMagician.ShellExtension //Logging.Log($"Starting CreateMenu"); var explorerMenuStrip = new ContextMenuStrip(); - if (File.Exists(DisplayMagicianFullname)) + Dictionary profiles = new Dictionary(); + + if (File.Exists(_profileStorageJsonFileName)) { + //Logging.Log($"{_profileStorageJsonFileName} file exists"); + MatchCollection mc; + string uuid = ""; + string profileName = ""; - var extensionMenu = new ToolStripMenuItem("DisplayMagician: Change display profiles...", Properties.Resources.DisplayMagicianMenuImage); - explorerMenuStrip.Items.Add(extensionMenu); - - Dictionary profiles = new Dictionary(); - - if (File.Exists(_profileStorageJsonFileName)) + foreach (string aLine in File.ReadLines(_profileStorageJsonFileName, Encoding.Unicode)) { - MatchCollection mc; - string uuid = ""; - string profileName = ""; - - foreach (string aLine in File.ReadLines(_profileStorageJsonFileName, Encoding.Unicode)) + //Logging.Log($"Processing line: {_profileStorageJsonFileName}"); + string lineToProcess = aLine; + if (lineToProcess.StartsWith(" \"UUID\"")) { - 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); - } - + //Logging.Log($"Line starts with 4 spaces and UUID"); + mc = Regex.Matches(lineToProcess, " \"UUID\": \"(.*)\""); + uuid = mc[0].Groups[1].ToString(); + } + else if (lineToProcess.StartsWith(" \"Name\"")) + { + //Logging.Log($"Line starts with 4 spaces and 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 pair in profiles.OrderBy(key => key.Key)) - { - extensionMenu.DropDownItems.Add(new ToolStripMenuItem(pair.Key, null, - (sender, args) => - { - Logging.Log(DisplayMagicianFullname + $" ChangeProfile \"{pair.Value}\""); - DisplayMagicianProcess = Process.Start(DisplayMagicianFullname,$"ChangeProfile \"{pair.Value}\""); - Logging.Log(DisplayMagicianProcess.ToString()); - } - )); - } + var extensionMenu = new ToolStripMenuItem("DisplayMagician: Change display profiles...", Properties.Resources.DisplayMagicianMenuImage); + explorerMenuStrip.Items.Add(extensionMenu); + + // Add the first menu to create a new Displaay Profile + extensionMenu.DropDownItems.Add(new ToolStripMenuItem("Create a new display profile", null, + (sender, args) => + { + //Logging.Log(DisplayMagicianFullname + $" CreateProfile"); + DisplayMagicianProcess = Process.Start(DisplayMagicianFullname, $"CreateProfile"); + //Logging.Log(DisplayMagicianProcess.ToString()); + } + )); + + if (profiles.Count > 0) + { + extensionMenu.DropDownItems.Add(new ToolStripSeparator()); + + foreach (KeyValuePair pair in profiles.OrderBy(key => key.Key)) + { + extensionMenu.DropDownItems.Add(new ToolStripMenuItem(pair.Key, null, + (sender, args) => + { + //Logging.Log(DisplayMagicianFullname + $" ChangeProfile \"{pair.Value}\""); + DisplayMagicianProcess = Process.Start(DisplayMagicianFullname,$"ChangeProfile \"{pair.Value}\""); + //Logging.Log(DisplayMagicianProcess.ToString()); + } + )); } } diff --git a/DisplayMagician.ShellExtension/Properties/AssemblyInfo.cs b/DisplayMagician.ShellExtension/Properties/AssemblyInfo.cs index f219696..86daed4 100644 --- a/DisplayMagician.ShellExtension/Properties/AssemblyInfo.cs +++ b/DisplayMagician.ShellExtension/Properties/AssemblyInfo.cs @@ -22,7 +22,7 @@ using System.Runtime.InteropServices; // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("592dcbe6-3052-47bb-b962-101abb5e0ce8")] +[assembly: Guid("592ecbe6-3052-47bb-b962-101abb5e0ce9")] // Version information for an assembly consists of the following four values: // diff --git a/DisplayMagician/Program.cs b/DisplayMagician/Program.cs index fc744d8..7166f47 100644 --- a/DisplayMagician/Program.cs +++ b/DisplayMagician/Program.cs @@ -129,6 +129,32 @@ namespace DisplayMagician { }); }); + // This is the CreateProfile command + app.Command(DisplayMagicianStartupAction.CreateProfile.ToString(), (createProfileCmd) => + { + var argumentProfile = runProfileCmd.Argument("\"Profile_UUID\"", "(required) The UUID of the profile to run from those stored in the profile file.").IsRequired(); + argumentProfile.Validators.Add(new ProfileMustExistValidator()); + + //description and help text of the command. + createProfileCmd.Description = "Use this command to go directly to the create display profile screen."; + + createProfileCmd.OnExecute(() => + { + try + { + // Lookup the profile + ProfileItem profileToUse = ProfileRepository.AllProfiles.Where(p => p.UUID.Equals(argumentProfile.Value)).First(); + + ApplyProfile(profileToUse); + return 0; + } + catch (Exception) + { + return 1; + } + }); + }); + app.OnExecute(() => { diff --git a/DisplayMagician/ShortcutRepository.cs b/DisplayMagician/ShortcutRepository.cs index 4b31ba9..f1f0966 100644 --- a/DisplayMagician/ShortcutRepository.cs +++ b/DisplayMagician/ShortcutRepository.cs @@ -1,16 +1,12 @@ using AudioSwitcher.AudioApi.CoreAudio; using DisplayMagician.GameLibraries; using DisplayMagician.InterProcess; -using DisplayMagician.Resources; using DisplayMagician.Shared; using Newtonsoft.Json; -using NvAPIWrapper.Mosaic; -using NvAPIWrapper.Native.Mosaic; using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; -using System.Drawing.IconLib; using System.IO; using System.Linq; using System.Text;