From 5836f88ef0d17d71e88e30815a2299aa484448b7 Mon Sep 17 00:00:00 2001 From: Vincent Maas Date: Mon, 27 Jun 2022 19:07:33 +0200 Subject: [PATCH] restructured code (wip), add game launcher and quick access --- ColorControl.sln | 10 + ColorControl/ColorControl.csproj | 20 +- .../{ => Common}/ExceptionExtensions.cs | 2 +- ColorControl/Common/ProcessExtensions.cs | 54 ++ ColorControl/{ => Common}/Utils.cs | 459 ++-------- ColorControl/{ => Common}/WOL.cs | 2 +- ColorControl/Config.cs | 6 + ColorControl/Forms/FormUtils.cs | 466 ++++++++++ .../{ => Forms}/ListViewColumnSorter.cs | 0 ColorControl/{ => Forms}/MessageForms.cs | 48 +- ColorControl/{ => Forms}/TreeNodeBuilder.cs | 0 ColorControl/MainForm.Designer.cs | 542 ++++++++++- ColorControl/MainForm.cs | 842 ++++++++++++++---- ColorControl/MainForm.resx | 9 + ColorControl/{ => Native}/CCD.cs | 0 ColorControl/{ => Native}/PnpDev.cs | 0 ColorControl/{ => Native}/RestartDetector.cs | 0 .../{ => Native}/ScreenInterrogatory.cs | 0 ColorControl/{ => Native}/UserSessionInfo.cs | 0 ColorControl/Program.cs | 6 +- ColorControl/{ => Services/AMD}/ADL.cs | 0 ColorControl/{ => Services/AMD}/ADLWrapper.cs | 2 +- .../{ => Services/AMD}/AmdDisplayInfo.cs | 2 +- ColorControl/{ => Services/AMD}/AmdPreset.cs | 9 +- ColorControl/{ => Services/AMD}/AmdService.cs | 14 +- .../{ => Services/Common}/GraphicsService.cs | 11 +- .../{ => Services/Common}/PresetBase.cs | 14 +- .../Common/QuickAccessForm.Designer.cs | 124 +++ .../Services/Common/QuickAccessForm.cs | 237 +++++ .../Common/QuickAccessForm.resx} | 0 .../{ => Services/Common}/ServiceBase.cs | 35 +- .../Services/GameLauncher/GamePreset.cs | 61 ++ .../Services/GameLauncher/GameService.cs | 146 +++ ColorControl/{ => Services/LG}/LgDevice.cs | 42 +- .../{ => Services/LG}/LgGameBar.Designer.cs | 2 +- ColorControl/{ => Services/LG}/LgGameBar.cs | 12 +- ColorControl/Services/LG/LgGameBar.resx | 63 ++ ColorControl/{ => Services/LG}/LgPreset.cs | 5 +- ColorControl/{ => Services/LG}/LgService.cs | 38 +- .../{ => Services/LG}/LgServiceConfig.cs | 2 +- .../LG}/RemoteControlForm.Designer.cs | 2 +- .../{ => Services/LG}/RemoteControlForm.cs | 2 +- .../{ => Services/LG}/RemoteControlForm.resx | 0 .../LG}/RemoteControlPanel.Designer.cs | 2 +- .../{ => Services/LG}/RemoteControlPanel.cs | 5 +- .../{ => Services/LG}/RemoteControlPanel.resx | 0 .../NVIDIA}/ColorDataConverter.cs | 2 +- .../{ => Services/NVIDIA}/NvDisplayInfo.cs | 2 +- .../{ => Services/NVIDIA}/NvPreset.cs | 13 +- .../{ => Services/NVIDIA}/NvService.cs | 26 +- ColorControl/lgtv/ClientKeyStore.cs | 2 +- ColorControl/lgtv/LgTvApi.cs | 1 + ColorControl/lgtv/LgTvConnection.cs | 1 + .../Common/Cache/CachedSettingValue.cs | 0 .../Common/Cache/CachedSettings.cs | 0 .../Common/CustomSettings/CustomSetting.cs | 0 .../CustomSettings/CustomSettingNames.cs | 0 .../CustomSettings/CustomSettingValue.cs | 0 .../Common/DrsDecrypterService.cs | 5 +- .../Common/DrsImportService.cs | 9 +- .../Common/DrsScannerService.cs | 8 +- .../Common/DrsServiceLocator.cs | 7 +- .../Common/DrsSessionScope.cs | 0 .../Common/DrsSettingsMetaService.cs | 7 +- .../Common/DrsSettingsService.cs | 12 +- .../Common/DrsSettingsServiceBase.cs | 12 +- .../nspector => Nspector}/Common/DrsUtil.cs | 0 .../Common/Helper/AdminHelper.cs | 0 .../Helper/DropDownMenuScrollWheelHandler.cs | 0 .../Common/Helper/InputBox.cs | 0 .../Common/Helper/ListSort.cs | 0 .../Common/Helper/ListViewGroupSorter.cs | 0 .../Common/Helper/NoBorderRenderer.cs | 0 .../Common/Helper/ShortcutResolver.cs | 0 .../Common/Helper/SteamAppResolver.cs | 0 .../Common/Helper/TempFile.cs | 0 .../Common/Helper/UserSettings.cs | 0 .../Common/Helper/XMLHelper.cs | 0 .../Common/Import/ImportExportUitl.cs | 0 .../Common/Import/Profile.cs | 0 .../Common/Import/ProfileSetting.cs | 0 .../Common/Import/Profiles.cs | 0 .../Common/Import/SettingValueType.cs | 0 .../Common/Meta/ConstantSettingMetaService.cs | 0 .../Common/Meta/CustomSettingMetaService.cs | 0 .../Common/Meta/DriverSettingMetaService.cs | 0 .../Common/Meta/ISettingMetaService.cs | 6 +- .../Common/Meta/MetaServiceItem.cs | 0 .../Common/Meta/ScannedSettingMetaService.cs | 0 .../Common/Meta/SettingMeta.cs | 3 +- .../Common/Meta/SettingMetaSource.cs | 0 .../Common/Meta/SettingValue.cs | 2 +- .../Common/NvapiException.cs | 0 .../Common/SettingItem.cs | 4 +- .../Common/SettingViewMode.cs | 0 .../nspector => Nspector}/Images/0_gear2.png | Bin .../Images/1_gear2_2.png | Bin .../Images/4_gear_nv2.png | Bin .../Images/6_gear_inherit.png | Bin .../Images/PortableDeviceStatus_3_16-011.png | Bin .../nspector => Nspector}/Images/apply.png | Bin .../nspector => Nspector}/Images/export1.png | Bin .../Images/filter_user.png | Bin .../Images/find_set2.png | Bin .../nspector => Nspector}/Images/home_sm.png | Bin .../Images/ieframe_1_18212.png | Bin .../Images/ieframe_1_31073-002.png | Bin .../nspector => Nspector}/Images/import1.png | Bin .../nspector => Nspector}/Images/n1-016.png | Bin .../nspector => Nspector}/Images/nv_btn.png | Bin .../nspector => Nspector}/Images/shield.png | Bin .../nspector => Nspector}/Images/shield16.ico | Bin .../Images/text_binary.png | Bin .../Images/transparent16.png | Bin .../Images/window_application_add.png | Bin .../Images/window_application_delete.png | Bin .../nspector => Nspector}/ListViewEx.cs | 0 .../Native/NVAPI/NvApiDriverSettings.cs | 0 .../Native/NVAPI/NvApiDriverSettings.h | 0 .../Native/NVAPI/NvApiDriverSettings.tt | 0 .../Native/NVAPI/NvapiDrsWrapper.cs | 49 +- .../Native/NativeArrayHelper.cs | 0 .../Native/WINAPI/DragAcceptNativeHelper.cs | 0 .../Native/WINAPI/MessageHelper.cs | 0 .../Native/WINAPI/SafeNativeMethods.cs | 0 .../Native/WINAPI/ShellLink.cs | 0 .../Native/WINAPI/TaskBarList3.cs | 0 Nspector/Nspector.csproj | 52 ++ .../Properties/Resources.Designer.cs | 0 .../Properties/Resources.resx | 4 +- .../nspector => Nspector}/app.manifest | 0 .../frmBitEditor.Designer.cs | 0 .../nspector => Nspector}/frmBitEditor.cs | 0 .../nspector => Nspector}/frmBitEditor.resx | 0 .../frmDrvSettings.Designer.cs | 0 .../nspector => Nspector}/frmDrvSettings.cs | 50 +- .../nspector => Nspector}/frmDrvSettings.resx | 0 .../frmExportProfiles.Designer.cs | 0 .../frmExportProfiles.cs | 0 .../frmExportProfiles.resx | 0 {ColorControl/nspector => Nspector}/n1.ico | Bin .../nspector/CustomSettingNames.xml | 0 .../nspector/Reference.xml | 0 .../nvidiaProfileInspector.csproj | 0 144 files changed, 2769 insertions(+), 804 deletions(-) rename ColorControl/{ => Common}/ExceptionExtensions.cs (98%) create mode 100644 ColorControl/Common/ProcessExtensions.cs rename ColorControl/{ => Common}/Utils.cs (64%) rename ColorControl/{ => Common}/WOL.cs (99%) create mode 100644 ColorControl/Forms/FormUtils.cs rename ColorControl/{ => Forms}/ListViewColumnSorter.cs (100%) rename ColorControl/{ => Forms}/MessageForms.cs (85%) rename ColorControl/{ => Forms}/TreeNodeBuilder.cs (100%) rename ColorControl/{ => Native}/CCD.cs (100%) rename ColorControl/{ => Native}/PnpDev.cs (100%) rename ColorControl/{ => Native}/RestartDetector.cs (100%) rename ColorControl/{ => Native}/ScreenInterrogatory.cs (100%) rename ColorControl/{ => Native}/UserSessionInfo.cs (100%) rename ColorControl/{ => Services/AMD}/ADL.cs (100%) rename ColorControl/{ => Services/AMD}/ADLWrapper.cs (99%) rename ColorControl/{ => Services/AMD}/AmdDisplayInfo.cs (92%) rename ColorControl/{ => Services/AMD}/AmdPreset.cs (96%) rename ColorControl/{ => Services/AMD}/AmdService.cs (96%) rename ColorControl/{ => Services/Common}/GraphicsService.cs (96%) rename ColorControl/{ => Services/Common}/PresetBase.cs (95%) create mode 100644 ColorControl/Services/Common/QuickAccessForm.Designer.cs create mode 100644 ColorControl/Services/Common/QuickAccessForm.cs rename ColorControl/{LgGameBar.resx => Services/Common/QuickAccessForm.resx} (100%) rename ColorControl/{ => Services/Common}/ServiceBase.cs (84%) create mode 100644 ColorControl/Services/GameLauncher/GamePreset.cs create mode 100644 ColorControl/Services/GameLauncher/GameService.cs rename ColorControl/{ => Services/LG}/LgDevice.cs (98%) rename ColorControl/{ => Services/LG}/LgGameBar.Designer.cs (99%) rename ColorControl/{ => Services/LG}/LgGameBar.cs (97%) create mode 100644 ColorControl/Services/LG/LgGameBar.resx rename ColorControl/{ => Services/LG}/LgPreset.cs (97%) rename ColorControl/{ => Services/LG}/LgService.cs (98%) rename ColorControl/{ => Services/LG}/LgServiceConfig.cs (96%) rename ColorControl/{ => Services/LG}/RemoteControlForm.Designer.cs (99%) rename ColorControl/{ => Services/LG}/RemoteControlForm.cs (99%) rename ColorControl/{ => Services/LG}/RemoteControlForm.resx (100%) rename ColorControl/{ => Services/LG}/RemoteControlPanel.Designer.cs (98%) rename ColorControl/{ => Services/LG}/RemoteControlPanel.cs (98%) rename ColorControl/{ => Services/LG}/RemoteControlPanel.resx (100%) rename ColorControl/{ => Services/NVIDIA}/ColorDataConverter.cs (96%) rename ColorControl/{ => Services/NVIDIA}/NvDisplayInfo.cs (91%) rename ColorControl/{ => Services/NVIDIA}/NvPreset.cs (96%) rename ColorControl/{ => Services/NVIDIA}/NvService.cs (97%) rename {ColorControl/nspector => Nspector}/Common/Cache/CachedSettingValue.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Cache/CachedSettings.cs (100%) rename {ColorControl/nspector => Nspector}/Common/CustomSettings/CustomSetting.cs (100%) rename {ColorControl/nspector => Nspector}/Common/CustomSettings/CustomSettingNames.cs (100%) rename {ColorControl/nspector => Nspector}/Common/CustomSettings/CustomSettingValue.cs (100%) rename {ColorControl/nspector => Nspector}/Common/DrsDecrypterService.cs (98%) rename {ColorControl/nspector => Nspector}/Common/DrsImportService.cs (98%) rename {ColorControl/nspector => Nspector}/Common/DrsScannerService.cs (97%) rename {ColorControl/nspector => Nspector}/Common/DrsServiceLocator.cs (95%) rename {ColorControl/nspector => Nspector}/Common/DrsSessionScope.cs (100%) rename {ColorControl/nspector => Nspector}/Common/DrsSettingsMetaService.cs (99%) rename {ColorControl/nspector => Nspector}/Common/DrsSettingsService.cs (99%) rename {ColorControl/nspector => Nspector}/Common/DrsSettingsServiceBase.cs (97%) rename {ColorControl/nspector => Nspector}/Common/DrsUtil.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/AdminHelper.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/DropDownMenuScrollWheelHandler.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/InputBox.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/ListSort.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/ListViewGroupSorter.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/NoBorderRenderer.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/ShortcutResolver.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/SteamAppResolver.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/TempFile.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/UserSettings.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Helper/XMLHelper.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Import/ImportExportUitl.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Import/Profile.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Import/ProfileSetting.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Import/Profiles.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Import/SettingValueType.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/ConstantSettingMetaService.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/CustomSettingMetaService.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/DriverSettingMetaService.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/ISettingMetaService.cs (84%) rename {ColorControl/nspector => Nspector}/Common/Meta/MetaServiceItem.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/ScannedSettingMetaService.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/SettingMeta.cs (91%) rename {ColorControl/nspector => Nspector}/Common/Meta/SettingMetaSource.cs (100%) rename {ColorControl/nspector => Nspector}/Common/Meta/SettingValue.cs (94%) rename {ColorControl/nspector => Nspector}/Common/NvapiException.cs (100%) rename {ColorControl/nspector => Nspector}/Common/SettingItem.cs (92%) rename {ColorControl/nspector => Nspector}/Common/SettingViewMode.cs (100%) rename {ColorControl/nspector => Nspector}/Images/0_gear2.png (100%) rename {ColorControl/nspector => Nspector}/Images/1_gear2_2.png (100%) rename {ColorControl/nspector => Nspector}/Images/4_gear_nv2.png (100%) rename {ColorControl/nspector => Nspector}/Images/6_gear_inherit.png (100%) rename {ColorControl/nspector => Nspector}/Images/PortableDeviceStatus_3_16-011.png (100%) rename {ColorControl/nspector => Nspector}/Images/apply.png (100%) rename {ColorControl/nspector => Nspector}/Images/export1.png (100%) rename {ColorControl/nspector => Nspector}/Images/filter_user.png (100%) rename {ColorControl/nspector => Nspector}/Images/find_set2.png (100%) rename {ColorControl/nspector => Nspector}/Images/home_sm.png (100%) rename {ColorControl/nspector => Nspector}/Images/ieframe_1_18212.png (100%) rename {ColorControl/nspector => Nspector}/Images/ieframe_1_31073-002.png (100%) rename {ColorControl/nspector => Nspector}/Images/import1.png (100%) rename {ColorControl/nspector => Nspector}/Images/n1-016.png (100%) rename {ColorControl/nspector => Nspector}/Images/nv_btn.png (100%) rename {ColorControl/nspector => Nspector}/Images/shield.png (100%) rename {ColorControl/nspector => Nspector}/Images/shield16.ico (100%) rename {ColorControl/nspector => Nspector}/Images/text_binary.png (100%) rename {ColorControl/nspector => Nspector}/Images/transparent16.png (100%) rename {ColorControl/nspector => Nspector}/Images/window_application_add.png (100%) rename {ColorControl/nspector => Nspector}/Images/window_application_delete.png (100%) rename {ColorControl/nspector => Nspector}/ListViewEx.cs (100%) rename {ColorControl/nspector => Nspector}/Native/NVAPI/NvApiDriverSettings.cs (100%) rename {ColorControl/nspector => Nspector}/Native/NVAPI/NvApiDriverSettings.h (100%) rename {ColorControl/nspector => Nspector}/Native/NVAPI/NvApiDriverSettings.tt (100%) rename {ColorControl/nspector => Nspector}/Native/NVAPI/NvapiDrsWrapper.cs (95%) rename {ColorControl/nspector => Nspector}/Native/NativeArrayHelper.cs (100%) rename {ColorControl/nspector => Nspector}/Native/WINAPI/DragAcceptNativeHelper.cs (100%) rename {ColorControl/nspector => Nspector}/Native/WINAPI/MessageHelper.cs (100%) rename {ColorControl/nspector => Nspector}/Native/WINAPI/SafeNativeMethods.cs (100%) rename {ColorControl/nspector => Nspector}/Native/WINAPI/ShellLink.cs (100%) rename {ColorControl/nspector => Nspector}/Native/WINAPI/TaskBarList3.cs (100%) create mode 100644 Nspector/Nspector.csproj rename {ColorControl/nspector => Nspector}/Properties/Resources.Designer.cs (100%) rename {ColorControl/nspector => Nspector}/Properties/Resources.resx (99%) rename {ColorControl/nspector => Nspector}/app.manifest (100%) rename {ColorControl/nspector => Nspector}/frmBitEditor.Designer.cs (100%) rename {ColorControl/nspector => Nspector}/frmBitEditor.cs (100%) rename {ColorControl/nspector => Nspector}/frmBitEditor.resx (100%) rename {ColorControl/nspector => Nspector}/frmDrvSettings.Designer.cs (100%) rename {ColorControl/nspector => Nspector}/frmDrvSettings.cs (97%) rename {ColorControl/nspector => Nspector}/frmDrvSettings.resx (100%) rename {ColorControl/nspector => Nspector}/frmExportProfiles.Designer.cs (100%) rename {ColorControl/nspector => Nspector}/frmExportProfiles.cs (100%) rename {ColorControl/nspector => Nspector}/frmExportProfiles.resx (100%) rename {ColorControl/nspector => Nspector}/n1.ico (100%) rename {ColorControl => Nspector}/nspector/CustomSettingNames.xml (100%) rename {ColorControl => Nspector}/nspector/Reference.xml (100%) rename {ColorControl/nspector => Nspector}/nvidiaProfileInspector.csproj (100%) diff --git a/ColorControl.sln b/ColorControl.sln index 67a44de..db1f57d 100644 --- a/ColorControl.sln +++ b/ColorControl.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.0.32014.148 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorControl", "ColorControl\ColorControl.csproj", "{A6005D08-70F0-44CB-A384-9219EBA84F21}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nspector", "Nspector\Nspector.csproj", "{76797290-48F5-4A82-86C3-FAD25DAE4500}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,14 @@ Global {A6005D08-70F0-44CB-A384-9219EBA84F21}.Release|Any CPU.Build.0 = Release|Any CPU {A6005D08-70F0-44CB-A384-9219EBA84F21}.Release|x64.ActiveCfg = Release|x64 {A6005D08-70F0-44CB-A384-9219EBA84F21}.Release|x64.Build.0 = Release|x64 + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Debug|Any CPU.Build.0 = Debug|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Debug|x64.ActiveCfg = Debug|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Debug|x64.Build.0 = Debug|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Release|Any CPU.ActiveCfg = Release|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Release|Any CPU.Build.0 = Release|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Release|x64.ActiveCfg = Release|Any CPU + {76797290-48F5-4A82-86C3-FAD25DAE4500}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ColorControl/ColorControl.csproj b/ColorControl/ColorControl.csproj index e67d893..e34f189 100644 --- a/ColorControl/ColorControl.csproj +++ b/ColorControl/ColorControl.csproj @@ -1,6 +1,6 @@  - net6.0-windows10.0.20348.0 + net6.0-windows10.0.17763.0 WinExe false publish\ @@ -18,8 +18,8 @@ Maassoft Maassoft 0 - 6.0.0.0 - 6.0.0.0 + 7.0.0.0 + 7.0.0.0 false true false @@ -53,7 +53,10 @@ True Settings.settings - + + Form + + UserControl @@ -93,12 +96,9 @@ - - PreserveNewest - - - PreserveNewest - + + + SettingsSingleFileGenerator Settings.Designer.cs diff --git a/ColorControl/ExceptionExtensions.cs b/ColorControl/Common/ExceptionExtensions.cs similarity index 98% rename from ColorControl/ExceptionExtensions.cs rename to ColorControl/Common/ExceptionExtensions.cs index a1f18e5..9874ab3 100644 --- a/ColorControl/ExceptionExtensions.cs +++ b/ColorControl/Common/ExceptionExtensions.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; -namespace ColorControl +namespace ColorControl.Common { /// diff --git a/ColorControl/Common/ProcessExtensions.cs b/ColorControl/Common/ProcessExtensions.cs new file mode 100644 index 0000000..77134c3 --- /dev/null +++ b/ColorControl/Common/ProcessExtensions.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; + +namespace ColorControl.Common +{ + public static class ProcessExtensions + { + private static string FindIndexedProcessName(int pid, string processName, IEnumerable processes = null) + { + var processesByName = processes == null ? Process.GetProcessesByName(processName) : processes.Where(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)).ToArray(); + string processIndexedName = null; + + for (var index = 0; index < processesByName.Length; index++) + { + processIndexedName = index == 0 ? processName : processName + "#" + index; + var processId = new PerformanceCounter("Process", "ID Process", processIndexedName); + if ((int)processId.NextValue() == pid) + { + return processIndexedName; + } + } + + return processIndexedName; + } + + private static Process FindPidFromIndexedProcessName(string indexedProcessName, IEnumerable processes = null) + { + var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName); + var parentProcessId = (int)parentId.NextValue(); + + try + { + return processes == null ? Process.GetProcessById(parentProcessId) : processes.FirstOrDefault(p => p.Id == parentProcessId); + } + catch (Exception) + { + return null; + } + } + + public static Process Parent(this Process process, IEnumerable processes = null) + { + var indexedProcessName = FindIndexedProcessName(process.Id, process.ProcessName, processes); + if (indexedProcessName == null) + { + return null; + } + + return FindPidFromIndexedProcessName(indexedProcessName, processes); + } + } +} diff --git a/ColorControl/Utils.cs b/ColorControl/Common/Utils.cs similarity index 64% rename from ColorControl/Utils.cs rename to ColorControl/Common/Utils.cs index 2c200aa..8ce2d22 100644 --- a/ColorControl/Utils.cs +++ b/ColorControl/Common/Utils.cs @@ -1,8 +1,8 @@ -using Microsoft.Win32; +using ColorControl.Forms; +using Microsoft.Win32; using Microsoft.Win32.TaskScheduler; using Newtonsoft.Json; using Newtonsoft.Json.Linq; -using NStandard; using NWin32; using NWin32.NativeTypes; using System; @@ -23,7 +23,7 @@ using System.Windows.Forms; using Windows.Devices.Enumeration; using Windows.Devices.Enumeration.Pnp; -namespace ColorControl +namespace ColorControl.Common { static class Utils { @@ -36,23 +36,6 @@ namespace ColorControl Win = 8 } - public enum UserNotificationState : int - { - QUNS_NOT_PRESENT = 1, - QUNS_BUSY, - QUNS_RUNNING_D3D_FULL_SCREEN, - QUNS_PRESENTATION_MODE, - QUNS_ACCEPTS_NOTIFICATIONS, - QUNS_QUIET_TIME, - QUNS_APP - } - - public static UserNotificationState[] NotificationsDisabledStates = new[] { - UserNotificationState.QUNS_BUSY, - UserNotificationState.QUNS_RUNNING_D3D_FULL_SCREEN, - UserNotificationState.QUNS_PRESENTATION_MODE, - }; - [StructLayout(LayoutKind.Sequential, Pack = 4)] internal struct POWERBROADCAST_SETTING { @@ -80,12 +63,6 @@ namespace ColorControl [DllImport("user32.dll")] public static extern bool UnregisterHotKey(IntPtr hWnd, int id); - [DllImport("user32.dll")] - public extern static bool ShutdownBlockReasonCreate(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)] string pwszReason); - - [DllImport("user32.dll")] - public extern static bool ShutdownBlockReasonDestroy(IntPtr hWnd); - [DllImport("user32.dll")] public static extern bool EnumDisplaySettingsA(string deviceName, int modeNum, out DEVMODEA devMode); @@ -100,27 +77,14 @@ namespace ColorControl [return: MarshalAs(UnmanagedType.Bool)] public static extern bool FreeConsole(); - [DllImport("shell32.dll")] - public static extern int SHQueryUserNotificationState(out UserNotificationState pquns); - - [DllImport("user32.dll", SetLastError = true)] - public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId); - [DllImport(@"User32", SetLastError = true)] public static extern IntPtr RegisterPowerSettingNotification(IntPtr hRecipient, ref Guid PowerSettingGuid, Int32 Flags); [DllImport("User32.dll", SetLastError = true)] public static extern bool UnregisterPowerSettingNotification(IntPtr hWnd); - //[DllImport("Wtsapi32.dll")] - //public extern static bool WTSRegisterSessionNotification(IntPtr hWnd, uint dwFlags); - - //[DllImport("Wtsapi32.dll")] - //public extern static bool WTSUnRegisterSessionNotification(IntPtr hWnd); - private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); private static bool WinKeyDown = false; - private static UserNotificationState LastNotificationState; private static Keys[] KeysWithoutModifiers = new[] { Keys.F13, Keys.F14, Keys.F15, Keys.F16, Keys.F17, Keys.F18, Keys.F19, Keys.F20, Keys.F21, Keys.F22, Keys.F23, Keys.F24 }; public static Bitmap SubPixelShift(Bitmap bitmap) @@ -216,6 +180,34 @@ namespace ColorControl return (mods, key); } + public static Keys ShortcutToKeys(string shortcut) + { + var (mods, key) = ParseShortcut(shortcut); + + var keys = Keys.None; + + if (((uint)mods & (uint)ModKeys.Alt) > 0) + { + keys |= Keys.Alt; + } + if (((uint)mods & (uint)ModKeys.Control) > 0) + { + keys |= Keys.Control; + } + if (((uint)mods & (uint)ModKeys.Shift) > 0) + { + keys |= Keys.Shift; + } + if (((uint)mods & (uint)ModKeys.Win) > 0) + { + keys |= Keys.Control; + } + + keys |= (Keys)key; + + return keys; + } + internal static bool ExecuteElevated(string args) { var info = new ProcessStartInfo(Process.GetCurrentProcess().MainModule.FileName, args) @@ -413,16 +405,6 @@ namespace ColorControl } } - public static void SetNotifyIconText(NotifyIcon ni, string text) - { - text = text.Substring(0, Math.Min(text.Length, 127)); - Type t = typeof(NotifyIcon); - BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance; - t.GetField("text", hidden).SetValue(ni, text); - if ((bool)t.GetField("added", hidden).GetValue(ni)) - t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true }); - } - internal static Image GenerateGradientBitmap(int width, int height) { var bitmap = new Bitmap(512, height); @@ -554,7 +536,7 @@ namespace ColorControl } catch (Exception e) { - MessageForms.ErrorOk("Could not create/delete task: " + e.Message); + //MessageForms.ErrorOk("Could not create/delete task: " + e.Message); } } @@ -606,164 +588,6 @@ namespace ColorControl return true; } - public static ToolStripMenuItem BuildDropDownMenuEx(ContextMenuStrip mnuParent, string name, Type enumType, EventHandler clickEvent, object tag = null, int min = 0, int max = 0) - { - var subMenuName = $"{mnuParent.Name}_{name}"; - var subMenuItems = mnuParent.Items.Find(subMenuName, false); - - if (subMenuItems.Length > 0) - { - return subMenuItems[0] as ToolStripMenuItem; - } - - ToolStripMenuItem subMenuItem; - subMenuItem = (ToolStripMenuItem)mnuParent.Items.Add(name); - subMenuItem.Name = subMenuName; - - if (enumType != null) - { - foreach (var enumValue in Enum.GetValues(enumType)) - { - var itemText = (enumValue as IConvertible).GetDescription() ?? enumValue.ToString(); - var item = subMenuItem.DropDownItems.Add(itemText); - item.Tag = tag; - var strValue = enumValue.ToString(); - if (strValue.EndsWith("_")) - { - strValue = strValue.Substring(0, strValue.Length - 1); - } - item.AccessibleName = strValue; - item.Click += clickEvent; - } - } - else if (min >= 0 && max > min) - { - for (var i = 0; i <= 10; i++) - { - var value = i * (max / 10); - - var subSubItemName = $"{subMenuName}_{value}"; - - var item = subMenuItem.DropDownItems.Add(value.ToString()); - item.Name = subSubItemName; - item.Tag = tag; - item.Click += clickEvent; - } - } - else - { - subMenuItem.Tag = tag; - subMenuItem.Click += clickEvent; - } - - return subMenuItem; - } - - public static void BuildDropDownMenu(ToolStripDropDownItem mnuParent, string name, Type enumType, object colorData, string propertyName, EventHandler clickEvent) - { - PropertyInfo property = null; - var subMenuItems = mnuParent.DropDownItems.Find("miColorSettings_" + name, false); - ToolStripMenuItem subMenuItem; - if (subMenuItems.Length == 0) - { - subMenuItem = (ToolStripMenuItem)mnuParent.DropDownItems.Add(name); - subMenuItem.Name = "miColorSettings_" + name; - - if (colorData != null) - { - property = colorData.GetType().GetDeclaredProperty(propertyName); - subMenuItem.Tag = property; - } - - foreach (var enumValue in Enum.GetValues(enumType)) - { - var item = subMenuItem.DropDownItems.Add(enumValue.ToString()); - item.Tag = enumValue; - item.Click += clickEvent; - } - } - else - { - subMenuItem = (ToolStripMenuItem)subMenuItems[0]; - property = (PropertyInfo)subMenuItem.Tag; - } - - if (colorData == null) - { - return; - } - var value = property.GetValue(colorData); - - foreach (var item in subMenuItem.DropDownItems) - { - if (item is ToolStripMenuItem) - { - var menuItem = (ToolStripMenuItem)item; - if (menuItem.Tag != null) - { - menuItem.Checked = menuItem.Tag.Equals(value); - } - } - } - } - - public static void BuildComboBox(ComboBox comboBox, params T[] skip) where T : IConvertible - { - if (comboBox.Items.Count == 0) - { - foreach (var enumValue in Enum.GetValues(typeof(T))) - { - if (skip.Contains((T)enumValue)) - { - continue; - } - var item = new EnumComboBoxItem - { - Name = ((T)enumValue).GetDescription(), - Id = (int)enumValue - }; - - comboBox.Items.Add(item); - } - } - } - - public static int SetComboBoxEnumIndex(ComboBox comboBox, int value) - { - if (comboBox.Items.Count == 0) - { - return -1; - } - - var index = 0; - - for (var i = 0; i < comboBox.Items.Count; i++) - { - var item = comboBox.Items[i] as EnumComboBoxItem; - if (item.Id == value) - { - index = i; - break; - } - } - - comboBox.SelectedIndex = index; - - return index; - } - - public static T GetComboBoxEnumItem(ComboBox comboBox) where T : IConvertible - { - if (comboBox.SelectedIndex == -1) - { - return (T)Enum.Parse(typeof(T), "None"); - } - - var item = comboBox.SelectedItem as EnumComboBoxItem; - - return (T)Enum.Parse(typeof(T), item.Id.ToString()); - } - public static string FormatKeyboardShortcut(KeyEventArgs keyEvent) { var pressedModifiers = keyEvent.Modifiers; @@ -824,80 +648,6 @@ namespace ColorControl } } - public static void InitListView(ListView listView, IEnumerable columns) - { - foreach (var name in columns) - { - var columnName = name; - var parts = name.Split('|'); - - var width = 120; - if (parts.Length > 1) - { - width = int.Parse(parts[1]); - columnName = parts[0]; - } - - var header = listView.Columns.Add(columnName); - header.Width = width == 120 ? -2 : width; - } - } - - public static void AddOrUpdateListItem(ListView listView, List presets, Config config, T preset = null, ListViewItem specItem = null) where T : PresetBase - { - ListViewItem item = null; - if (preset == null) - { - item = listView.SelectedItems[0]; - preset = (T)item.Tag; - } - else - { - item = specItem; - } - - if (preset.id == 0) - { - preset.id = preset.GetHashCode(); - } - - var values = preset.GetDisplayValues(config); - - if (item == null) - { - item = listView.Items.Add(values[0]); - item.Tag = preset; - for (var i = 1; i < values.Count; i++) - { - item.SubItems.Add(values[i]); - } - if (!presets.Any(x => x.id == preset.id)) - { - presets.Add(preset); - } - } - else - { - item.Text = values[0]; - for (var i = 1; i < values.Count; i++) - { - if (item.SubItems.Count == i) - { - item.SubItems.Add(values[i]); - } - else - { - item.SubItems[i].Text = values[i]; - } - } - } - - if (listView.ListViewItemSorter is ListViewColumnSorter sorter && sorter?.Order != SortOrder.None) - { - listView.Sort(); - } - } - public static bool OpenConsole() { if (ConsoleOpened) @@ -942,9 +692,15 @@ namespace ColorControl return null; } - public static void StartProcess(string fileName, string arguments = null, bool hidden = false, bool wait = false) + public static void StartProcess(string fileName, string arguments = null, bool hidden = false, bool wait = false, bool setWorkingDir = false, bool elevate = false) { - var process = Process.Start(new ProcessStartInfo(fileName, arguments) { UseShellExecute = true, WindowStyle = hidden ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal }); + var process = Process.Start(new ProcessStartInfo(fileName, arguments) + { + Verb = elevate ? "runas" : string.Empty, // indicates to elevate privileges + UseShellExecute = true, + WindowStyle = hidden ? ProcessWindowStyle.Hidden : ProcessWindowStyle.Normal, + WorkingDirectory = setWorkingDir ? Path.GetDirectoryName(fileName) : null + }); if (wait) { process.WaitForExit(); @@ -966,79 +722,6 @@ namespace ColorControl } } - public static bool IsForegroundFullScreenAndDisabledNotifications(Screen screen = null) - { - return IsNotificationDisabled() && IsForegroundFullScreen(screen); - } - - public static bool IsNotificationDisabled() - { - var result = SHQueryUserNotificationState(out var state); - - if (result == NativeConstants.ERROR_SUCCESS && state != LastNotificationState) - { - Logger.Debug($"Detected NotificationState change from {LastNotificationState} to {state}"); - LastNotificationState = state; - } - - return NotificationsDisabledStates.Contains(state); - //return state != UserNotificationState.QUNS_ACCEPTS_NOTIFICATIONS && state != UserNotificationState.QUNS_QUIET_TIME; - } - - public static bool IsForegroundFullScreen(Screen screen = null) - { - if (screen == null) - { - screen = Screen.PrimaryScreen; - } - var hWnd = NativeMethods.GetForegroundWindow(); - - NativeMethods.GetWindowRect(hWnd, out var rect); - - /* in case you want the process name: - uint procId = 0; - GetWindowThreadProcessId(hWnd, out procId); - var proc = System.Diagnostics.Process.GetProcessById((int)procId); - Console.WriteLine(proc.ProcessName); - */ - - return screen.Bounds.Width <= (rect.right - rect.left) && screen.Bounds.Height <= (rect.bottom - rect.top); - } - - public static (uint, bool) GetForegroundProcessIdAndIfFullScreen(Screen screen = null) - { - if (screen == null) - { - screen = Screen.PrimaryScreen; - } - var hWnd = NativeMethods.GetForegroundWindow(); - - if (hWnd == IntPtr.Zero) - { - return (0, false); - } - - NativeMethods.GetWindowRect(hWnd, out var rect); - - GetWindowThreadProcessId(hWnd, out var processId); - - var isFullScreen = screen.Bounds.Width <= (rect.right - rect.left) && screen.Bounds.Height <= (rect.bottom - rect.top); - - return (processId, isFullScreen); - } - - public static Process GetForegroundFullScreenProcess(Screen screen = null) - { - var (processId, isFullScreen) = GetForegroundProcessIdAndIfFullScreen(screen); - - if (!isFullScreen) - { - return null; - } - - return Process.GetProcessById((int)processId); - } - public static void ParseWords(List target, string text) { target.Clear(); @@ -1113,63 +796,23 @@ namespace ColorControl return null; } - } - public class EnumComboBoxItem - { - public string Name; - public int Id; - - public override string ToString() + public static FileInfo SelectFile(string ext = "*.exe", string filter = "Application EXE Name|*.exe|Application Absolute Path|*.exe") { - return Name; - } - } + var openDialog = new OpenFileDialog(); + openDialog.DefaultExt = ext; + openDialog.Filter = filter; - public static class ProcessExtensions - { - private static string FindIndexedProcessName(int pid, string processName, IEnumerable processes = null) - { - var processesByName = processes == null ? Process.GetProcessesByName(processName) : processes.Where(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase)).ToArray(); - string processIndexedName = null; - - for (var index = 0; index < processesByName.Length; index++) + if (openDialog.ShowDialog() == DialogResult.OK) { - processIndexedName = index == 0 ? processName : processName + "#" + index; - var processId = new PerformanceCounter("Process", "ID Process", processIndexedName); - if ((int)processId.NextValue() == pid) - { - return processIndexedName; - } + return new FileInfo(openDialog.FileName); + //if (openDialog.FilterIndex == 2) + // applicationName = openDialog.FileName; + + //return applicationName; } - return processIndexedName; - } - - private static Process FindPidFromIndexedProcessName(string indexedProcessName, IEnumerable processes = null) - { - var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName); - var parentProcessId = (int)parentId.NextValue(); - - try - { - return processes == null ? Process.GetProcessById(parentProcessId) : processes.FirstOrDefault(p => p.Id == parentProcessId); - } - catch (Exception) - { - return null; - } - } - - public static Process Parent(this Process process, IEnumerable processes = null) - { - var indexedProcessName = FindIndexedProcessName(process.Id, process.ProcessName, processes); - if (indexedProcessName == null) - { - return null; - } - - return FindPidFromIndexedProcessName(indexedProcessName, processes); + return null; } } } diff --git a/ColorControl/WOL.cs b/ColorControl/Common/WOL.cs similarity index 99% rename from ColorControl/WOL.cs rename to ColorControl/Common/WOL.cs index 9810e06..16ccf48 100644 --- a/ColorControl/WOL.cs +++ b/ColorControl/Common/WOL.cs @@ -4,7 +4,7 @@ using System.Net.NetworkInformation; using System.Net; using System.Net.Sockets; -namespace ColorControl +namespace ColorControl.Common { class WOL { diff --git a/ColorControl/Config.cs b/ColorControl/Config.cs index 2b8753d..eab9607 100644 --- a/ColorControl/Config.cs +++ b/ColorControl/Config.cs @@ -25,6 +25,11 @@ namespace ColorControl public ListViewSortState NvPresetsSortState { get; set; } public ListViewSortState AmdPresetsSortState { get; set; } public ListViewSortState LgPresetsSortState { get; set; } + public ListViewSortState GamePresetsSortState { get; set; } + public string NvQuickAccessShortcut { get; set; } + public string AmdQuickAccessShortcut { get; set; } + public string LgQuickAccessShortcut { get; set; } + public string GameQuickAccessShortcut { get; set; } public Config() { @@ -39,6 +44,7 @@ namespace ColorControl LgPresetsSortState = new ListViewSortState(); NvPresetsSortState = new ListViewSortState(); AmdPresetsSortState = new ListViewSortState(); + GamePresetsSortState = new ListViewSortState(); } } } diff --git a/ColorControl/Forms/FormUtils.cs b/ColorControl/Forms/FormUtils.cs new file mode 100644 index 0000000..30c01ad --- /dev/null +++ b/ColorControl/Forms/FormUtils.cs @@ -0,0 +1,466 @@ +using ColorControl.Common; +using ColorControl.Services.Common; +using NStandard; +using NWin32; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace ColorControl.Forms +{ + static class FormUtils + { + public enum UserNotificationState : int + { + QUNS_NOT_PRESENT = 1, + QUNS_BUSY, + QUNS_RUNNING_D3D_FULL_SCREEN, + QUNS_PRESENTATION_MODE, + QUNS_ACCEPTS_NOTIFICATIONS, + QUNS_QUIET_TIME, + QUNS_APP + } + + public static UserNotificationState[] NotificationsDisabledStates = new[] { + UserNotificationState.QUNS_BUSY, + UserNotificationState.QUNS_RUNNING_D3D_FULL_SCREEN, + UserNotificationState.QUNS_PRESENTATION_MODE, + }; + + [DllImport("shell32.dll")] + public static extern int SHQueryUserNotificationState(out UserNotificationState pquns); + + [DllImport("user32.dll", SetLastError = true)] + public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId); + + private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); + private static UserNotificationState LastNotificationState; + + public static void SetNotifyIconText(NotifyIcon ni, string text) + { + text = text.Substring(0, Math.Min(text.Length, 127)); + Type t = typeof(NotifyIcon); + BindingFlags hidden = BindingFlags.NonPublic | BindingFlags.Instance; + t.GetField("text", hidden).SetValue(ni, text); + if ((bool)t.GetField("added", hidden).GetValue(ni)) + t.GetMethod("UpdateIcon", hidden).Invoke(ni, new object[] { true }); + } + + public static ToolStripMenuItem BuildDropDownMenuEx(ContextMenuStrip mnuParent, string name, Type enumType, EventHandler clickEvent, object tag = null, int min = 0, int max = 0) + { + var subMenuName = $"{mnuParent.Name}_{name}"; + var subMenuItems = mnuParent.Items.Find(subMenuName, false); + + if (subMenuItems.Length > 0) + { + return subMenuItems[0] as ToolStripMenuItem; + } + + ToolStripMenuItem subMenuItem; + subMenuItem = (ToolStripMenuItem)mnuParent.Items.Add(name); + subMenuItem.Name = subMenuName; + + if (enumType != null) + { + foreach (var enumValue in Enum.GetValues(enumType)) + { + var itemText = (enumValue as IConvertible).GetDescription() ?? enumValue.ToString(); + var item = subMenuItem.DropDownItems.Add(itemText); + item.Tag = tag; + var strValue = enumValue.ToString(); + if (strValue.EndsWith("_")) + { + strValue = strValue.Substring(0, strValue.Length - 1); + } + item.AccessibleName = strValue; + item.Click += clickEvent; + } + } + else if (min >= 0 && max > min) + { + for (var i = 0; i <= 10; i++) + { + var value = i * (max / 10); + + var subSubItemName = $"{subMenuName}_{value}"; + + var item = subMenuItem.DropDownItems.Add(value.ToString()); + item.Name = subSubItemName; + item.Tag = tag; + item.Click += clickEvent; + } + } + else + { + subMenuItem.Tag = tag; + subMenuItem.Click += clickEvent; + } + + return subMenuItem; + } + + public static void BuildDropDownMenu(ToolStripDropDownItem mnuParent, string name, Type enumType, object colorData, string propertyName, EventHandler clickEvent) + { + PropertyInfo property = null; + var subMenuItems = mnuParent.DropDownItems.Find("miColorSettings_" + name, false); + ToolStripMenuItem subMenuItem; + if (subMenuItems.Length == 0) + { + subMenuItem = (ToolStripMenuItem)mnuParent.DropDownItems.Add(name); + subMenuItem.Name = "miColorSettings_" + name; + + if (colorData != null) + { + property = colorData.GetType().GetDeclaredProperty(propertyName); + subMenuItem.Tag = property; + } + + foreach (var enumValue in Enum.GetValues(enumType)) + { + var item = subMenuItem.DropDownItems.Add(enumValue.ToString()); + item.Tag = enumValue; + item.Click += clickEvent; + } + } + else + { + subMenuItem = (ToolStripMenuItem)subMenuItems[0]; + property = (PropertyInfo)subMenuItem.Tag; + } + + if (colorData == null) + { + return; + } + var value = property.GetValue(colorData); + + foreach (var item in subMenuItem.DropDownItems) + { + if (item is ToolStripMenuItem) + { + var menuItem = (ToolStripMenuItem)item; + if (menuItem.Tag != null) + { + menuItem.Checked = menuItem.Tag.Equals(value); + } + } + } + } + + public static void BuildComboBox(ComboBox comboBox, params T[] skip) where T : IConvertible + { + if (comboBox.Items.Count == 0) + { + foreach (var enumValue in Enum.GetValues(typeof(T))) + { + if (skip.Contains((T)enumValue)) + { + continue; + } + var item = new EnumComboBoxItem + { + Name = ((T)enumValue).GetDescription(), + Id = (int)enumValue + }; + + comboBox.Items.Add(item); + } + } + } + + public static int SetComboBoxEnumIndex(ComboBox comboBox, int value) + { + if (comboBox.Items.Count == 0) + { + return -1; + } + + var index = 0; + + for (var i = 0; i < comboBox.Items.Count; i++) + { + var item = comboBox.Items[i] as EnumComboBoxItem; + if (item.Id == value) + { + index = i; + break; + } + } + + comboBox.SelectedIndex = index; + + return index; + } + + public static T GetComboBoxEnumItem(ComboBox comboBox) where T : IConvertible + { + if (comboBox.SelectedIndex == -1) + { + return (T)Enum.Parse(typeof(T), "None"); + } + + var item = comboBox.SelectedItem as EnumComboBoxItem; + + return (T)Enum.Parse(typeof(T), item.Id.ToString()); + } + + public static void InitListView(ListView listView, IEnumerable columns) + { + foreach (var name in columns) + { + var columnName = name; + var parts = name.Split('|'); + + var width = 120; + if (parts.Length > 1) + { + width = int.Parse(parts[1]); + columnName = parts[0]; + } + + var header = listView.Columns.Add(columnName); + header.Width = width == 120 ? -2 : width; + } + } + + public static void AddOrUpdateListItem(ListView listView, List presets, Config config, T preset = null, ListViewItem specItem = null) where T : PresetBase + { + ListViewItem item = null; + if (preset == null) + { + item = listView.SelectedItems[0]; + preset = (T)item.Tag; + } + else + { + item = specItem; + } + + if (preset.id == 0) + { + preset.id = preset.GetHashCode(); + } + + var values = preset.GetDisplayValues(config); + + if (item == null) + { + item = listView.Items.Add(values[0]); + item.Tag = preset; + item.Checked = preset.ShowInQuickAccess; + for (var i = 1; i < values.Count; i++) + { + item.SubItems.Add(values[i]); + } + if (!presets.Any(x => x.id == preset.id)) + { + presets.Add(preset); + } + } + else + { + item.Text = values[0]; + item.Checked = preset.ShowInQuickAccess; + for (var i = 1; i < values.Count; i++) + { + if (item.SubItems.Count == i) + { + item.SubItems.Add(values[i]); + } + else + { + item.SubItems[i].Text = values[i]; + } + } + } + + if (listView.ListViewItemSorter is ListViewColumnSorter sorter && sorter?.Order != SortOrder.None) + { + listView.Sort(); + } + } + + public static bool IsForegroundFullScreenAndDisabledNotifications(Screen screen = null) + { + return IsNotificationDisabled() && IsForegroundFullScreen(screen); + } + + public static bool IsNotificationDisabled() + { + var result = SHQueryUserNotificationState(out var state); + + if (result == NativeConstants.ERROR_SUCCESS && state != LastNotificationState) + { + Logger.Debug($"Detected NotificationState change from {LastNotificationState} to {state}"); + LastNotificationState = state; + } + + return NotificationsDisabledStates.Contains(state); + //return state != UserNotificationState.QUNS_ACCEPTS_NOTIFICATIONS && state != UserNotificationState.QUNS_QUIET_TIME; + } + + public static bool IsForegroundFullScreen(Screen screen = null) + { + if (screen == null) + { + screen = Screen.PrimaryScreen; + } + var hWnd = NativeMethods.GetForegroundWindow(); + + NativeMethods.GetWindowRect(hWnd, out var rect); + + /* in case you want the process name: + uint procId = 0; + GetWindowThreadProcessId(hWnd, out procId); + var proc = System.Diagnostics.Process.GetProcessById((int)procId); + Console.WriteLine(proc.ProcessName); + */ + + return screen.Bounds.Width <= (rect.right - rect.left) && screen.Bounds.Height <= (rect.bottom - rect.top); + } + + public static (uint, bool) GetForegroundProcessIdAndIfFullScreen(Screen screen = null) + { + if (screen == null) + { + screen = Screen.PrimaryScreen; + } + var hWnd = NativeMethods.GetForegroundWindow(); + + if (hWnd == IntPtr.Zero) + { + return (0, false); + } + + NativeMethods.GetWindowRect(hWnd, out var rect); + + GetWindowThreadProcessId(hWnd, out var processId); + + var isFullScreen = screen.Bounds.Width <= (rect.right - rect.left) && screen.Bounds.Height <= (rect.bottom - rect.top); + + return (processId, isFullScreen); + } + + public static Process GetForegroundFullScreenProcess(Screen screen = null) + { + var (processId, isFullScreen) = GetForegroundProcessIdAndIfFullScreen(screen); + + if (!isFullScreen) + { + return null; + } + + return Process.GetProcessById((int)processId); + } + + public static void EnableControls(Control parent, bool enable = true, IEnumerable excludedControls = null) + { + for (var i = 0; i < parent.Controls.Count; i++) + { + var control = parent.Controls[i]; + if (!excludedControls?.Contains(control) ?? true) + { + control.Enabled = enable; + } + } + } + + public static void AddStepToTextBox(TextBox textBox, string step) + { + var text = textBox.Text; + if (string.IsNullOrWhiteSpace(text)) + { + text = step; + } + else + { + var pos = textBox.SelectionStart; + while (pos < text.Length && text.CharAt(pos) != ',') + { + pos++; + } + if (pos == text.Length) + { + text += ", " + step; + } + else + { + text = text.Substring(0, pos + 1) + " " + step + ", " + text.Substring(pos + 1).Trim(); + } + } + textBox.Text = text.Trim(); + } + + public static T GetSelectedItemTag(this ListView listView) + { + if (listView.SelectedItems.Count > 0) + { + var item = listView.SelectedItems[0]; + return (T)item.Tag; + } + else + { + return default(T); + } + } + + public static void FireEvent(this Control ctrl, string eventName, params object[] eventParams) + { + //EventSelectedIndexChanged + var propertyInfo = ctrl.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); + var eventHandlerList = propertyInfo.GetValue(ctrl) as EventHandlerList; + + var headField = typeof(EventHandlerList).GetField("_head", BindingFlags.NonPublic | BindingFlags.Instance); + + var assembly = typeof(EventHandlerList).Assembly; + var listEntryType = assembly.GetTypes().FirstOrDefault(t => t.Name == "ListEntry"); + + var nextField = listEntryType.GetField("_next", BindingFlags.NonPublic | BindingFlags.Instance); + var handlerField = listEntryType.GetField("_handler", BindingFlags.NonPublic | BindingFlags.Instance); + + var entry = headField.GetValue(eventHandlerList); + Delegate foundHandler = null; + + while (entry != null) + { + var handler = handlerField.GetValue(entry) as Delegate; + + if (handler.Method.Name.Contains(eventName)) + { + foundHandler = handler; + break; + } + + entry = nextField.GetValue(entry); + } + + if (foundHandler == null) + { + return; + } + + var invocationList = foundHandler.GetInvocationList(); + foreach (var item in invocationList) + { + item.Method.Invoke(item.Target, eventParams); + } + } + + } + + public class EnumComboBoxItem + { + public string Name; + public int Id; + + public override string ToString() + { + return Name; + } + } +} diff --git a/ColorControl/ListViewColumnSorter.cs b/ColorControl/Forms/ListViewColumnSorter.cs similarity index 100% rename from ColorControl/ListViewColumnSorter.cs rename to ColorControl/Forms/ListViewColumnSorter.cs diff --git a/ColorControl/MessageForms.cs b/ColorControl/Forms/MessageForms.cs similarity index 85% rename from ColorControl/MessageForms.cs rename to ColorControl/Forms/MessageForms.cs index 1bca212..a8f3f89 100644 --- a/ColorControl/MessageForms.cs +++ b/ColorControl/Forms/MessageForms.cs @@ -1,10 +1,11 @@ -using System; +using ColorControl.Common; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows.Forms; -namespace ColorControl +namespace ColorControl.Forms { class MessageForms { @@ -13,7 +14,8 @@ namespace ColorControl Text, Numeric, DropDown, - Flags + Flags, + Shortcut, } public class FieldDefinition @@ -27,6 +29,19 @@ namespace ColorControl public object Value { get; set; } } + public class MessageForm : Form + { + public void edtShortcut_KeyDown(object sender, KeyEventArgs e) + { + ((TextBox)sender).Text = Utils.FormatKeyboardShortcut(e); + } + + public void edtShortcut_KeyUp(object sender, KeyEventArgs e) + { + Utils.HandleKeyboardShortcutUp(e); + } + } + public static Form MainForm; public static void WarningOk(string text) @@ -70,7 +85,7 @@ namespace ColorControl { var values = new List(); - var prompt = new Form() + var prompt = new MessageForm() { Width = 500, Height = 90 + (fields.Count() * 55), @@ -81,6 +96,7 @@ namespace ColorControl var top = 10; var boxes = new List(); + var counter = 1; foreach (var field in fields) { @@ -91,7 +107,7 @@ namespace ColorControl Control control; - switch(field.FieldType) + switch (field.FieldType) { case FieldType.Text: var textBox = new MaskedTextBox() { Left = 40, Top = top, Width = 400 }; @@ -111,6 +127,27 @@ namespace ColorControl control = textBox; break; + case FieldType.Shortcut: + var shortcutTextBox = new TextBox() + { + Left = 40, + Top = top, + Width = 200, + Name = $"edtShortcut_{counter}", + ReadOnly = true + }; + + shortcutTextBox.KeyDown += prompt.edtShortcut_KeyDown; + shortcutTextBox.KeyUp += prompt.edtShortcut_KeyUp; + + if (field.Value != null) + { + shortcutTextBox.Text = field.Value.ToString(); + } + + control = shortcutTextBox; + break; + case FieldType.Numeric: var numericEdit = new NumericUpDown() { Left = 40, Top = top, Width = 400 }; @@ -183,6 +220,7 @@ namespace ColorControl prompt.Controls.Add(control); boxes.Add(control); control.Tag = field; + counter++; } var confirmation = new Button() { Text = "OK", Left = 365, Width = 75, Top = prompt.ClientRectangle.Height - 30 }; diff --git a/ColorControl/TreeNodeBuilder.cs b/ColorControl/Forms/TreeNodeBuilder.cs similarity index 100% rename from ColorControl/TreeNodeBuilder.cs rename to ColorControl/Forms/TreeNodeBuilder.cs diff --git a/ColorControl/MainForm.Designer.cs b/ColorControl/MainForm.Designer.cs index 0e41b03..7efa371 100644 --- a/ColorControl/MainForm.Designer.cs +++ b/ColorControl/MainForm.Designer.cs @@ -32,6 +32,8 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); this.tcMain = new System.Windows.Forms.TabControl(); this.tabNVIDIA = new System.Windows.Forms.TabPage(); + this.btnNvSettings = new System.Windows.Forms.Button(); + this.chkNvShowInQuickAccess = new System.Windows.Forms.CheckBox(); this.lblNvPresetName = new System.Windows.Forms.Label(); this.edtNvPresetName = new System.Windows.Forms.TextBox(); this.btnAddModesNv = new System.Windows.Forms.Button(); @@ -77,6 +79,7 @@ this.btnApply = new System.Windows.Forms.Button(); this.lvNvPresets = new System.Windows.Forms.ListView(); this.tabAMD = new System.Windows.Forms.TabPage(); + this.chkAmdQuickAccess = new System.Windows.Forms.CheckBox(); this.lblAmdPresetName = new System.Windows.Forms.Label(); this.edtAmdPresetName = new System.Windows.Forms.TextBox(); this.btnAddAmd = new System.Windows.Forms.Button(); @@ -108,6 +111,8 @@ this.lvAmdPresets = new System.Windows.Forms.ListView(); this.tabLG = new System.Windows.Forms.TabPage(); this.scLgController = new System.Windows.Forms.SplitContainer(); + this.btnLgSettings = new System.Windows.Forms.Button(); + this.chkLgQuickAccess = new System.Windows.Forms.CheckBox(); this.cbxLgPcHdmiPort = new System.Windows.Forms.ComboBox(); this.lblLgPcHdmiPort = new System.Windows.Forms.Label(); this.edtLgPresetDescription = new System.Windows.Forms.TextBox(); @@ -158,11 +163,40 @@ this.mnuLgActions = new System.Windows.Forms.ToolStripMenuItem(); this.mnuLgNvPresets = new System.Windows.Forms.ToolStripMenuItem(); this.mnuLgAmdPresets = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuLgProgram = new System.Windows.Forms.ToolStripMenuItem(); this.btnCloneLg = new System.Windows.Forms.Button(); this.lblStepsLg = new System.Windows.Forms.Label(); this.btnLgDeviceFilterRefresh = new System.Windows.Forms.Button(); this.clbLgPower = new System.Windows.Forms.CheckedListBox(); this.lblLgError = new System.Windows.Forms.Label(); + this.tabGameLauncher = new System.Windows.Forms.TabPage(); + this.chkGameQuickAccess = new System.Windows.Forms.CheckBox(); + this.btnGameSettings = new System.Windows.Forms.Button(); + this.mnuGameActions = new System.Windows.Forms.ContextMenuStrip(this.components); + this.mnuGameNvInspector = new System.Windows.Forms.ToolStripMenuItem(); + this.miGameSetQuickAccessShortcut = new System.Windows.Forms.ToolStripMenuItem(); + this.chkGameRunAsAdmin = new System.Windows.Forms.CheckBox(); + this.lblGameParameters = new System.Windows.Forms.Label(); + this.edtGameParameters = new System.Windows.Forms.TextBox(); + this.btnGameBrowse = new System.Windows.Forms.Button(); + this.lblGameFilePath = new System.Windows.Forms.Label(); + this.edtGamePath = new System.Windows.Forms.TextBox(); + this.edtGamePrelaunchSteps = new System.Windows.Forms.TextBox(); + this.btnGameAddStep = new System.Windows.Forms.Button(); + this.mnuGameAddStep = new System.Windows.Forms.ContextMenuStrip(this.components); + this.mnuGameNvidiaPresets = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuGameAmdPresets = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuGameLgPresets = new System.Windows.Forms.ToolStripMenuItem(); + this.mnuGameStartProgram = new System.Windows.Forms.ToolStripMenuItem(); + this.lblGamePreLaunch = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.edtGameName = new System.Windows.Forms.TextBox(); + this.btnGameDelete = new System.Windows.Forms.Button(); + this.btnGameClone = new System.Windows.Forms.Button(); + this.btnGameSave = new System.Windows.Forms.Button(); + this.btnGameAdd = new System.Windows.Forms.Button(); + this.btnGameLaunch = new System.Windows.Forms.Button(); + this.lvGamePresets = new System.Windows.Forms.ListView(); this.tabOptions = new System.Windows.Forms.TabPage(); this.grpNvidiaOptions = new System.Windows.Forms.GroupBox(); this.lblDitheringMode = new System.Windows.Forms.Label(); @@ -209,6 +243,10 @@ this.lbPlugins = new System.Windows.Forms.ListBox(); this.label7 = new System.Windows.Forms.Label(); this.lblInfo = new System.Windows.Forms.Label(); + this.mnuNvSettings = new System.Windows.Forms.ContextMenuStrip(this.components); + this.miNvProfileInspector = new System.Windows.Forms.ToolStripMenuItem(); + this.miNvSettings = new System.Windows.Forms.ToolStripMenuItem(); + this.btnAmdSettings = new System.Windows.Forms.Button(); this.tcMain.SuspendLayout(); this.tabNVIDIA.SuspendLayout(); this.mnuNvPresets.SuspendLayout(); @@ -220,6 +258,9 @@ this.scLgController.SuspendLayout(); this.mnuLgExpert.SuspendLayout(); this.mnuLgButtons.SuspendLayout(); + this.tabGameLauncher.SuspendLayout(); + this.mnuGameActions.SuspendLayout(); + this.mnuGameAddStep.SuspendLayout(); this.tabOptions.SuspendLayout(); this.grpNvidiaOptions.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pbGradient)).BeginInit(); @@ -234,6 +275,7 @@ this.tabInfo.SuspendLayout(); this.grpNVIDIAInfo.SuspendLayout(); this.groupBox3.SuspendLayout(); + this.mnuNvSettings.SuspendLayout(); this.SuspendLayout(); // // tcMain @@ -244,6 +286,7 @@ this.tcMain.Controls.Add(this.tabNVIDIA); this.tcMain.Controls.Add(this.tabAMD); this.tcMain.Controls.Add(this.tabLG); + this.tcMain.Controls.Add(this.tabGameLauncher); this.tcMain.Controls.Add(this.tabOptions); this.tcMain.Controls.Add(this.tabLog); this.tcMain.Controls.Add(this.tabInfo); @@ -257,6 +300,8 @@ // // tabNVIDIA // + this.tabNVIDIA.Controls.Add(this.btnNvSettings); + this.tabNVIDIA.Controls.Add(this.chkNvShowInQuickAccess); this.tabNVIDIA.Controls.Add(this.lblNvPresetName); this.tabNVIDIA.Controls.Add(this.edtNvPresetName); this.tabNVIDIA.Controls.Add(this.btnAddModesNv); @@ -278,6 +323,30 @@ this.tabNVIDIA.Text = "NVIDIA controller"; this.tabNVIDIA.UseVisualStyleBackColor = true; // + // btnNvSettings + // + this.btnNvSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnNvSettings.Location = new System.Drawing.Point(1017, 428); + this.btnNvSettings.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnNvSettings.Name = "btnNvSettings"; + this.btnNvSettings.Size = new System.Drawing.Size(88, 27); + this.btnNvSettings.TabIndex = 59; + this.btnNvSettings.Text = "Settings..."; + this.btnNvSettings.UseVisualStyleBackColor = true; + this.btnNvSettings.Click += new System.EventHandler(this.btnNvSettings_Click); + // + // chkNvShowInQuickAccess + // + this.chkNvShowInQuickAccess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkNvShowInQuickAccess.AutoSize = true; + this.chkNvShowInQuickAccess.Location = new System.Drawing.Point(343, 465); + this.chkNvShowInQuickAccess.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.chkNvShowInQuickAccess.Name = "chkNvShowInQuickAccess"; + this.chkNvShowInQuickAccess.Size = new System.Drawing.Size(141, 19); + this.chkNvShowInQuickAccess.TabIndex = 45; + this.chkNvShowInQuickAccess.Text = "Show in Quick Access"; + this.chkNvShowInQuickAccess.UseVisualStyleBackColor = true; + // // lblNvPresetName // this.lblNvPresetName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -682,6 +751,7 @@ this.lvNvPresets.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.lvNvPresets.CheckBoxes = true; this.lvNvPresets.ContextMenuStrip = this.mnuNvPresets; this.lvNvPresets.FullRowSelect = true; this.lvNvPresets.Location = new System.Drawing.Point(7, 7); @@ -694,11 +764,15 @@ this.lvNvPresets.UseCompatibleStateImageBehavior = false; this.lvNvPresets.View = System.Windows.Forms.View.Details; this.lvNvPresets.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvLgPresets_ColumnClick); + this.lvNvPresets.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.lvNvPresets_ItemCheck); + this.lvNvPresets.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvNvPresets_ItemChecked); this.lvNvPresets.SelectedIndexChanged += new System.EventHandler(this.lvNvPresets_SelectedIndexChanged); this.lvNvPresets.DoubleClick += new System.EventHandler(this.btnApply_Click); // // tabAMD // + this.tabAMD.Controls.Add(this.btnAmdSettings); + this.tabAMD.Controls.Add(this.chkAmdQuickAccess); this.tabAMD.Controls.Add(this.lblAmdPresetName); this.tabAMD.Controls.Add(this.edtAmdPresetName); this.tabAMD.Controls.Add(this.btnAddAmd); @@ -720,6 +794,18 @@ this.tabAMD.Text = "AMD controller"; this.tabAMD.UseVisualStyleBackColor = true; // + // chkAmdQuickAccess + // + this.chkAmdQuickAccess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkAmdQuickAccess.AutoSize = true; + this.chkAmdQuickAccess.Location = new System.Drawing.Point(343, 465); + this.chkAmdQuickAccess.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.chkAmdQuickAccess.Name = "chkAmdQuickAccess"; + this.chkAmdQuickAccess.Size = new System.Drawing.Size(141, 19); + this.chkAmdQuickAccess.TabIndex = 46; + this.chkAmdQuickAccess.Text = "Show in Quick Access"; + this.chkAmdQuickAccess.UseVisualStyleBackColor = true; + // // lblAmdPresetName // this.lblAmdPresetName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -995,6 +1081,7 @@ this.lvAmdPresets.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.lvAmdPresets.CheckBoxes = true; this.lvAmdPresets.ContextMenuStrip = this.mnuAmdPresets; this.lvAmdPresets.FullRowSelect = true; this.lvAmdPresets.Location = new System.Drawing.Point(7, 7); @@ -1007,6 +1094,8 @@ this.lvAmdPresets.UseCompatibleStateImageBehavior = false; this.lvAmdPresets.View = System.Windows.Forms.View.Details; this.lvAmdPresets.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvLgPresets_ColumnClick); + this.lvAmdPresets.ItemCheck += new System.Windows.Forms.ItemCheckEventHandler(this.lvNvPresets_ItemCheck); + this.lvAmdPresets.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvAmdPresets_ItemChecked); this.lvAmdPresets.SelectedIndexChanged += new System.EventHandler(this.lvAmdPresets_SelectedIndexChanged); this.lvAmdPresets.DoubleClick += new System.EventHandler(this.btnApplyAmd_Click); // @@ -1031,6 +1120,8 @@ // // scLgController.Panel1 // + this.scLgController.Panel1.Controls.Add(this.btnLgSettings); + this.scLgController.Panel1.Controls.Add(this.chkLgQuickAccess); this.scLgController.Panel1.Controls.Add(this.cbxLgPcHdmiPort); this.scLgController.Panel1.Controls.Add(this.lblLgPcHdmiPort); this.scLgController.Panel1.Controls.Add(this.edtLgPresetDescription); @@ -1083,6 +1174,30 @@ this.scLgController.SplitterWidth = 5; this.scLgController.TabIndex = 43; // + // btnLgSettings + // + this.btnLgSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnLgSettings.Location = new System.Drawing.Point(804, 264); + this.btnLgSettings.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnLgSettings.Name = "btnLgSettings"; + this.btnLgSettings.Size = new System.Drawing.Size(88, 27); + this.btnLgSettings.TabIndex = 64; + this.btnLgSettings.Text = "Settings..."; + this.btnLgSettings.UseVisualStyleBackColor = true; + this.btnLgSettings.Click += new System.EventHandler(this.btnLgSettings_Click); + // + // chkLgQuickAccess + // + this.chkLgQuickAccess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkLgQuickAccess.AutoSize = true; + this.chkLgQuickAccess.Location = new System.Drawing.Point(341, 300); + this.chkLgQuickAccess.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.chkLgQuickAccess.Name = "chkLgQuickAccess"; + this.chkLgQuickAccess.Size = new System.Drawing.Size(96, 19); + this.chkLgQuickAccess.TabIndex = 63; + this.chkLgQuickAccess.Text = "Quick Access"; + this.chkLgQuickAccess.UseVisualStyleBackColor = true; + // // cbxLgPcHdmiPort // this.cbxLgPcHdmiPort.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; @@ -1274,7 +1389,7 @@ this.mnuLgOLEDMotionPro, this.miLgExpertSeparator1}); this.mnuLgExpert.Name = "mnuLgButtons"; - this.mnuLgExpert.Size = new System.Drawing.Size(321, 32); + this.mnuLgExpert.Size = new System.Drawing.Size(359, 32); this.mnuLgExpert.Opening += new System.ComponentModel.CancelEventHandler(this.mnuLgExpert_Opening); // // mnuLgOLEDMotionPro @@ -1283,7 +1398,7 @@ this.miLgEnableMotionPro, this.miLgDisableMotionPro}); this.mnuLgOLEDMotionPro.Name = "mnuLgOLEDMotionPro"; - this.mnuLgOLEDMotionPro.Size = new System.Drawing.Size(320, 22); + this.mnuLgOLEDMotionPro.Size = new System.Drawing.Size(358, 22); this.mnuLgOLEDMotionPro.Text = "Activate OLED Motion Pro (B9/C9/E9/W9/C2/G2 only)"; // // miLgEnableMotionPro @@ -1303,7 +1418,7 @@ // miLgExpertSeparator1 // this.miLgExpertSeparator1.Name = "miLgExpertSeparator1"; - this.miLgExpertSeparator1.Size = new System.Drawing.Size(317, 6); + this.miLgExpertSeparator1.Size = new System.Drawing.Size(355, 6); // // chkLgRemoteControlShow // @@ -1370,6 +1485,7 @@ this.lvLgPresets.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.lvLgPresets.CheckBoxes = true; this.lvLgPresets.FullRowSelect = true; this.lvLgPresets.Location = new System.Drawing.Point(6, 152); this.lvLgPresets.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); @@ -1381,6 +1497,7 @@ this.lvLgPresets.UseCompatibleStateImageBehavior = false; this.lvLgPresets.View = System.Windows.Forms.View.Details; this.lvLgPresets.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvLgPresets_ColumnClick); + this.lvLgPresets.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvLgPresets_ItemChecked); this.lvLgPresets.SelectedIndexChanged += new System.EventHandler(this.lvLgPresets_SelectedIndexChanged); this.lvLgPresets.DoubleClick += new System.EventHandler(this.lvLgPresets_DoubleClick); // @@ -1601,9 +1718,10 @@ this.mnuLgRcButtons, this.mnuLgActions, this.mnuLgNvPresets, - this.mnuLgAmdPresets}); + this.mnuLgAmdPresets, + this.mnuLgProgram}); this.mnuLgButtons.Name = "mnuLgButtons"; - this.mnuLgButtons.Size = new System.Drawing.Size(153, 92); + this.mnuLgButtons.Size = new System.Drawing.Size(153, 114); this.mnuLgButtons.Opening += new System.ComponentModel.CancelEventHandler(this.mnuLgButtons_Opening); // // mnuLgRcButtons @@ -1630,6 +1748,13 @@ this.mnuLgAmdPresets.Size = new System.Drawing.Size(152, 22); this.mnuLgAmdPresets.Text = "AMD presets"; // + // mnuLgProgram + // + this.mnuLgProgram.Name = "mnuLgProgram"; + this.mnuLgProgram.Size = new System.Drawing.Size(152, 22); + this.mnuLgProgram.Text = "Start Program"; + this.mnuLgProgram.Click += new System.EventHandler(this.mnuLgProgram_Click); + // // btnCloneLg // this.btnCloneLg.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); @@ -1700,6 +1825,335 @@ this.lblLgError.Text = "ErrorText"; this.lblLgError.Visible = false; // + // tabGameLauncher + // + this.tabGameLauncher.Controls.Add(this.chkGameQuickAccess); + this.tabGameLauncher.Controls.Add(this.btnGameSettings); + this.tabGameLauncher.Controls.Add(this.chkGameRunAsAdmin); + this.tabGameLauncher.Controls.Add(this.lblGameParameters); + this.tabGameLauncher.Controls.Add(this.edtGameParameters); + this.tabGameLauncher.Controls.Add(this.btnGameBrowse); + this.tabGameLauncher.Controls.Add(this.lblGameFilePath); + this.tabGameLauncher.Controls.Add(this.edtGamePath); + this.tabGameLauncher.Controls.Add(this.edtGamePrelaunchSteps); + this.tabGameLauncher.Controls.Add(this.btnGameAddStep); + this.tabGameLauncher.Controls.Add(this.lblGamePreLaunch); + this.tabGameLauncher.Controls.Add(this.label4); + this.tabGameLauncher.Controls.Add(this.edtGameName); + this.tabGameLauncher.Controls.Add(this.btnGameDelete); + this.tabGameLauncher.Controls.Add(this.btnGameClone); + this.tabGameLauncher.Controls.Add(this.btnGameSave); + this.tabGameLauncher.Controls.Add(this.btnGameAdd); + this.tabGameLauncher.Controls.Add(this.btnGameLaunch); + this.tabGameLauncher.Controls.Add(this.lvGamePresets); + this.tabGameLauncher.Location = new System.Drawing.Point(4, 24); + this.tabGameLauncher.Name = "tabGameLauncher"; + this.tabGameLauncher.Padding = new System.Windows.Forms.Padding(3); + this.tabGameLauncher.Size = new System.Drawing.Size(1114, 525); + this.tabGameLauncher.TabIndex = 6; + this.tabGameLauncher.Text = "Game Launcher"; + this.tabGameLauncher.UseVisualStyleBackColor = true; + // + // chkGameQuickAccess + // + this.chkGameQuickAccess.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkGameQuickAccess.AutoSize = true; + this.chkGameQuickAccess.Location = new System.Drawing.Point(353, 387); + this.chkGameQuickAccess.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.chkGameQuickAccess.Name = "chkGameQuickAccess"; + this.chkGameQuickAccess.Size = new System.Drawing.Size(141, 19); + this.chkGameQuickAccess.TabIndex = 44; + this.chkGameQuickAccess.Text = "Show in Quick Access"; + this.chkGameQuickAccess.UseVisualStyleBackColor = true; + // + // btnGameSettings + // + this.btnGameSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnGameSettings.ContextMenuStrip = this.mnuGameActions; + this.btnGameSettings.Location = new System.Drawing.Point(1018, 351); + this.btnGameSettings.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameSettings.Name = "btnGameSettings"; + this.btnGameSettings.Size = new System.Drawing.Size(88, 27); + this.btnGameSettings.TabIndex = 43; + this.btnGameSettings.Text = "Settings..."; + this.btnGameSettings.UseVisualStyleBackColor = true; + this.btnGameSettings.Click += new System.EventHandler(this.btnGameActions_Click); + // + // mnuGameActions + // + this.mnuGameActions.ImageScalingSize = new System.Drawing.Size(20, 20); + this.mnuGameActions.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuGameNvInspector, + this.miGameSetQuickAccessShortcut}); + this.mnuGameActions.Name = "mnuLgButtons"; + this.mnuGameActions.Size = new System.Drawing.Size(212, 48); + this.mnuGameActions.Opening += new System.ComponentModel.CancelEventHandler(this.mnuGameActions_Opening); + // + // mnuGameNvInspector + // + this.mnuGameNvInspector.Name = "mnuGameNvInspector"; + this.mnuGameNvInspector.Size = new System.Drawing.Size(211, 22); + this.mnuGameNvInspector.Text = "NVIDIA Profile Inspector"; + this.mnuGameNvInspector.Click += new System.EventHandler(this.mnuGameNvInspector_Click); + // + // miGameSetQuickAccessShortcut + // + this.miGameSetQuickAccessShortcut.Name = "miGameSetQuickAccessShortcut"; + this.miGameSetQuickAccessShortcut.Size = new System.Drawing.Size(211, 22); + this.miGameSetQuickAccessShortcut.Text = "Set Quick Access Shortcut"; + this.miGameSetQuickAccessShortcut.Click += new System.EventHandler(this.miGameSetQuickAccessShortcut_Click); + // + // chkGameRunAsAdmin + // + this.chkGameRunAsAdmin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.chkGameRunAsAdmin.AutoSize = true; + this.chkGameRunAsAdmin.Location = new System.Drawing.Point(881, 415); + this.chkGameRunAsAdmin.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.chkGameRunAsAdmin.Name = "chkGameRunAsAdmin"; + this.chkGameRunAsAdmin.Size = new System.Drawing.Size(135, 19); + this.chkGameRunAsAdmin.TabIndex = 42; + this.chkGameRunAsAdmin.Text = "Run as administrator"; + this.chkGameRunAsAdmin.UseVisualStyleBackColor = true; + // + // lblGameParameters + // + this.lblGameParameters.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lblGameParameters.AutoSize = true; + this.lblGameParameters.Location = new System.Drawing.Point(8, 445); + this.lblGameParameters.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblGameParameters.Name = "lblGameParameters"; + this.lblGameParameters.Size = new System.Drawing.Size(69, 15); + this.lblGameParameters.TabIndex = 41; + this.lblGameParameters.Text = "Parameters:"; + // + // edtGameParameters + // + this.edtGameParameters.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.edtGameParameters.Enabled = false; + this.edtGameParameters.Location = new System.Drawing.Point(112, 442); + this.edtGameParameters.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.edtGameParameters.Name = "edtGameParameters"; + this.edtGameParameters.Size = new System.Drawing.Size(665, 23); + this.edtGameParameters.TabIndex = 40; + // + // btnGameBrowse + // + this.btnGameBrowse.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameBrowse.ContextMenuStrip = this.mnuLgButtons; + this.btnGameBrowse.Enabled = false; + this.btnGameBrowse.Location = new System.Drawing.Point(785, 410); + this.btnGameBrowse.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameBrowse.Name = "btnGameBrowse"; + this.btnGameBrowse.Size = new System.Drawing.Size(88, 27); + this.btnGameBrowse.TabIndex = 39; + this.btnGameBrowse.Text = "Browse..."; + this.btnGameBrowse.UseVisualStyleBackColor = true; + this.btnGameBrowse.Click += new System.EventHandler(this.btnGameBrowse_Click); + // + // lblGameFilePath + // + this.lblGameFilePath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lblGameFilePath.AutoSize = true; + this.lblGameFilePath.Location = new System.Drawing.Point(8, 417); + this.lblGameFilePath.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblGameFilePath.Name = "lblGameFilePath"; + this.lblGameFilePath.Size = new System.Drawing.Size(51, 15); + this.lblGameFilePath.TabIndex = 38; + this.lblGameFilePath.Text = "File/URI:"; + // + // edtGamePath + // + this.edtGamePath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.edtGamePath.Enabled = false; + this.edtGamePath.Location = new System.Drawing.Point(112, 413); + this.edtGamePath.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.edtGamePath.Name = "edtGamePath"; + this.edtGamePath.Size = new System.Drawing.Size(665, 23); + this.edtGamePath.TabIndex = 37; + // + // edtGamePrelaunchSteps + // + this.edtGamePrelaunchSteps.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.edtGamePrelaunchSteps.Enabled = false; + this.edtGamePrelaunchSteps.Location = new System.Drawing.Point(112, 471); + this.edtGamePrelaunchSteps.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.edtGamePrelaunchSteps.Multiline = true; + this.edtGamePrelaunchSteps.Name = "edtGamePrelaunchSteps"; + this.edtGamePrelaunchSteps.Size = new System.Drawing.Size(665, 48); + this.edtGamePrelaunchSteps.TabIndex = 35; + // + // btnGameAddStep + // + this.btnGameAddStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameAddStep.ContextMenuStrip = this.mnuGameAddStep; + this.btnGameAddStep.Enabled = false; + this.btnGameAddStep.Location = new System.Drawing.Point(785, 470); + this.btnGameAddStep.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameAddStep.Name = "btnGameAddStep"; + this.btnGameAddStep.Size = new System.Drawing.Size(88, 27); + this.btnGameAddStep.TabIndex = 36; + this.btnGameAddStep.Text = "Add step"; + this.btnGameAddStep.UseVisualStyleBackColor = true; + this.btnGameAddStep.Click += new System.EventHandler(this.btnGameAddStep_Click); + // + // mnuGameAddStep + // + this.mnuGameAddStep.ImageScalingSize = new System.Drawing.Size(20, 20); + this.mnuGameAddStep.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.mnuGameNvidiaPresets, + this.mnuGameAmdPresets, + this.mnuGameLgPresets, + this.mnuGameStartProgram}); + this.mnuGameAddStep.Name = "mnuLgButtons"; + this.mnuGameAddStep.Size = new System.Drawing.Size(153, 92); + this.mnuGameAddStep.Opening += new System.ComponentModel.CancelEventHandler(this.mnuGameAddStep_Opening); + // + // mnuGameNvidiaPresets + // + this.mnuGameNvidiaPresets.Name = "mnuGameNvidiaPresets"; + this.mnuGameNvidiaPresets.Size = new System.Drawing.Size(152, 22); + this.mnuGameNvidiaPresets.Text = "NVIDIA presets"; + // + // mnuGameAmdPresets + // + this.mnuGameAmdPresets.Name = "mnuGameAmdPresets"; + this.mnuGameAmdPresets.Size = new System.Drawing.Size(152, 22); + this.mnuGameAmdPresets.Text = "AMD presets"; + // + // mnuGameLgPresets + // + this.mnuGameLgPresets.Name = "mnuGameLgPresets"; + this.mnuGameLgPresets.Size = new System.Drawing.Size(152, 22); + this.mnuGameLgPresets.Text = "LG presets"; + // + // mnuGameStartProgram + // + this.mnuGameStartProgram.Name = "mnuGameStartProgram"; + this.mnuGameStartProgram.Size = new System.Drawing.Size(152, 22); + this.mnuGameStartProgram.Text = "Start Program"; + this.mnuGameStartProgram.Click += new System.EventHandler(this.mnuGameStartProgram_Click); + // + // lblGamePreLaunch + // + this.lblGamePreLaunch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.lblGamePreLaunch.AutoSize = true; + this.lblGamePreLaunch.Location = new System.Drawing.Point(8, 477); + this.lblGamePreLaunch.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblGamePreLaunch.Name = "lblGamePreLaunch"; + this.lblGamePreLaunch.Size = new System.Drawing.Size(98, 15); + this.lblGamePreLaunch.TabIndex = 34; + this.lblGamePreLaunch.Text = "Pre-launch steps:"; + // + // label4 + // + this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(8, 388); + this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(42, 15); + this.label4.TabIndex = 33; + this.label4.Text = "Name:"; + // + // edtGameName + // + this.edtGameName.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.edtGameName.Enabled = false; + this.edtGameName.Location = new System.Drawing.Point(112, 384); + this.edtGameName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.edtGameName.Name = "edtGameName"; + this.edtGameName.Size = new System.Drawing.Size(233, 23); + this.edtGameName.TabIndex = 32; + // + // btnGameDelete + // + this.btnGameDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameDelete.Enabled = false; + this.btnGameDelete.Location = new System.Drawing.Point(291, 351); + this.btnGameDelete.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameDelete.Name = "btnGameDelete"; + this.btnGameDelete.Size = new System.Drawing.Size(88, 27); + this.btnGameDelete.TabIndex = 30; + this.btnGameDelete.Text = "Delete"; + this.btnGameDelete.UseVisualStyleBackColor = true; + this.btnGameDelete.Click += new System.EventHandler(this.btnGameDelete_Click); + // + // btnGameClone + // + this.btnGameClone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameClone.Enabled = false; + this.btnGameClone.Location = new System.Drawing.Point(103, 351); + this.btnGameClone.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameClone.Name = "btnGameClone"; + this.btnGameClone.Size = new System.Drawing.Size(88, 27); + this.btnGameClone.TabIndex = 29; + this.btnGameClone.Text = "Clone"; + this.btnGameClone.UseVisualStyleBackColor = true; + this.btnGameClone.Click += new System.EventHandler(this.btnGameClone_Click); + // + // btnGameSave + // + this.btnGameSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameSave.Enabled = false; + this.btnGameSave.Location = new System.Drawing.Point(387, 351); + this.btnGameSave.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameSave.Name = "btnGameSave"; + this.btnGameSave.Size = new System.Drawing.Size(88, 27); + this.btnGameSave.TabIndex = 28; + this.btnGameSave.Text = "Save"; + this.btnGameSave.UseVisualStyleBackColor = true; + this.btnGameSave.Click += new System.EventHandler(this.btnGameSave_Click); + // + // btnGameAdd + // + this.btnGameAdd.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameAdd.ContextMenuStrip = this.mnuNvPresets; + this.btnGameAdd.Location = new System.Drawing.Point(199, 351); + this.btnGameAdd.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameAdd.Name = "btnGameAdd"; + this.btnGameAdd.Size = new System.Drawing.Size(88, 27); + this.btnGameAdd.TabIndex = 25; + this.btnGameAdd.Text = "Add"; + this.btnGameAdd.UseVisualStyleBackColor = true; + this.btnGameAdd.Click += new System.EventHandler(this.btnGameAdd_Click); + // + // btnGameLaunch + // + this.btnGameLaunch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.btnGameLaunch.Enabled = false; + this.btnGameLaunch.Location = new System.Drawing.Point(8, 351); + this.btnGameLaunch.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnGameLaunch.Name = "btnGameLaunch"; + this.btnGameLaunch.Size = new System.Drawing.Size(88, 27); + this.btnGameLaunch.TabIndex = 24; + this.btnGameLaunch.Text = "Launch"; + this.btnGameLaunch.UseVisualStyleBackColor = true; + this.btnGameLaunch.Click += new System.EventHandler(this.btnGameLaunch_Click); + // + // lvGamePresets + // + this.lvGamePresets.AllowDrop = true; + this.lvGamePresets.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.lvGamePresets.CheckBoxes = true; + this.lvGamePresets.FullRowSelect = true; + this.lvGamePresets.Location = new System.Drawing.Point(8, 8); + this.lvGamePresets.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.lvGamePresets.MultiSelect = false; + this.lvGamePresets.Name = "lvGamePresets"; + this.lvGamePresets.ShowItemToolTips = true; + this.lvGamePresets.Size = new System.Drawing.Size(1098, 335); + this.lvGamePresets.TabIndex = 23; + this.lvGamePresets.UseCompatibleStateImageBehavior = false; + this.lvGamePresets.View = System.Windows.Forms.View.Details; + this.lvGamePresets.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.lvLgPresets_ColumnClick); + this.lvGamePresets.ItemChecked += new System.Windows.Forms.ItemCheckedEventHandler(this.lvGamePresets_ItemChecked); + this.lvGamePresets.SelectedIndexChanged += new System.EventHandler(this.lvGamePresets_SelectedIndexChanged); + this.lvGamePresets.DragDrop += new System.Windows.Forms.DragEventHandler(this.lvGamePresets_DragDrop); + this.lvGamePresets.DragEnter += new System.Windows.Forms.DragEventHandler(this.lvGamePresets_DragEnter); + this.lvGamePresets.DoubleClick += new System.EventHandler(this.lvGamePresets_DoubleClick); + // // tabOptions // this.tabOptions.Controls.Add(this.grpNvidiaOptions); @@ -2290,6 +2744,41 @@ this.lblInfo.TabIndex = 1; this.lblInfo.Text = "Info"; // + // mnuNvSettings + // + this.mnuNvSettings.ImageScalingSize = new System.Drawing.Size(20, 20); + this.mnuNvSettings.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.miNvProfileInspector, + this.miNvSettings}); + this.mnuNvSettings.Name = "mnuLgButtons"; + this.mnuNvSettings.Size = new System.Drawing.Size(202, 48); + // + // miNvProfileInspector + // + this.miNvProfileInspector.Name = "miNvProfileInspector"; + this.miNvProfileInspector.Size = new System.Drawing.Size(201, 22); + this.miNvProfileInspector.Text = "NVIDIA Profile Inspector"; + this.miNvProfileInspector.Click += new System.EventHandler(this.miNvProfileInspector_Click); + // + // miNvSettings + // + this.miNvSettings.Name = "miNvSettings"; + this.miNvSettings.Size = new System.Drawing.Size(201, 22); + this.miNvSettings.Text = "Settings"; + this.miNvSettings.Click += new System.EventHandler(this.miNvSettings_Click); + // + // btnAmdSettings + // + this.btnAmdSettings.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.btnAmdSettings.Location = new System.Drawing.Point(1017, 429); + this.btnAmdSettings.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnAmdSettings.Name = "btnAmdSettings"; + this.btnAmdSettings.Size = new System.Drawing.Size(88, 27); + this.btnAmdSettings.TabIndex = 60; + this.btnAmdSettings.Text = "Settings..."; + this.btnAmdSettings.UseVisualStyleBackColor = true; + this.btnAmdSettings.Click += new System.EventHandler(this.btnAmdSettings_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -2324,6 +2813,10 @@ this.scLgController.ResumeLayout(false); this.mnuLgExpert.ResumeLayout(false); this.mnuLgButtons.ResumeLayout(false); + this.tabGameLauncher.ResumeLayout(false); + this.tabGameLauncher.PerformLayout(); + this.mnuGameActions.ResumeLayout(false); + this.mnuGameAddStep.ResumeLayout(false); this.tabOptions.ResumeLayout(false); this.grpNvidiaOptions.ResumeLayout(false); this.grpNvidiaOptions.PerformLayout(); @@ -2345,6 +2838,7 @@ this.grpNVIDIAInfo.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); + this.mnuNvSettings.ResumeLayout(false); this.ResumeLayout(false); } @@ -2530,6 +3024,44 @@ private System.Windows.Forms.ToolStripMenuItem miNvResolutionIncluded; private System.Windows.Forms.ToolStripMenuItem mnuNvDriverSettings; private System.Windows.Forms.ToolStripMenuItem miNvDriverSettingsIncluded; + private System.Windows.Forms.ToolStripMenuItem mnuLgProgram; + private System.Windows.Forms.TabPage tabGameLauncher; + private System.Windows.Forms.Label lblGameParameters; + private System.Windows.Forms.TextBox edtGameParameters; + private System.Windows.Forms.Button btnGameBrowse; + private System.Windows.Forms.Label lblGameFilePath; + private System.Windows.Forms.TextBox edtGamePath; + private System.Windows.Forms.TextBox edtGamePrelaunchSteps; + private System.Windows.Forms.Button btnGameAddStep; + private System.Windows.Forms.Label lblGamePreLaunch; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.TextBox edtGameName; + private System.Windows.Forms.Button btnGameDelete; + private System.Windows.Forms.Button btnGameClone; + private System.Windows.Forms.Button btnGameSave; + private System.Windows.Forms.Button btnGameAdd; + private System.Windows.Forms.Button btnGameLaunch; + private System.Windows.Forms.ListView lvGamePresets; + private System.Windows.Forms.ContextMenuStrip mnuGameAddStep; + private System.Windows.Forms.ToolStripMenuItem mnuGameNvidiaPresets; + private System.Windows.Forms.ToolStripMenuItem mnuGameAmdPresets; + private System.Windows.Forms.ToolStripMenuItem mnuGameLgPresets; + private System.Windows.Forms.CheckBox chkGameRunAsAdmin; + private System.Windows.Forms.ToolStripMenuItem mnuGameStartProgram; + private System.Windows.Forms.Button btnGameSettings; + private System.Windows.Forms.ContextMenuStrip mnuGameActions; + private System.Windows.Forms.ToolStripMenuItem mnuGameNvInspector; + private System.Windows.Forms.CheckBox chkGameQuickAccess; + private System.Windows.Forms.ToolStripMenuItem miGameSetQuickAccessShortcut; + private System.Windows.Forms.CheckBox chkNvShowInQuickAccess; + private System.Windows.Forms.Button btnNvSettings; + private System.Windows.Forms.CheckBox chkLgQuickAccess; + private System.Windows.Forms.Button btnLgSettings; + private System.Windows.Forms.ContextMenuStrip mnuNvSettings; + private System.Windows.Forms.ToolStripMenuItem miNvProfileInspector; + private System.Windows.Forms.ToolStripMenuItem miNvSettings; + private System.Windows.Forms.CheckBox chkAmdQuickAccess; + private System.Windows.Forms.Button btnAmdSettings; } } diff --git a/ColorControl/MainForm.cs b/ColorControl/MainForm.cs index 57cdde9..396abc1 100644 --- a/ColorControl/MainForm.cs +++ b/ColorControl/MainForm.cs @@ -1,8 +1,15 @@ using ATI.ADL; +using ColorControl.Common; +using ColorControl.Forms; +using ColorControl.Services.AMD; +using ColorControl.Services.Common; +using ColorControl.Services.GameLauncher; +using ColorControl.Services.LG; +using ColorControl.Services.NVIDIA; using LgTv; using Newtonsoft.Json; using NLog; -using NonInvasiveKeyboardHookLibrary; +using nspector; using nspector.Common; using nspector.Common.Meta; using NStandard; @@ -33,6 +40,10 @@ namespace ColorControl private static bool UserExit = false; private static int SHORTCUTID_SCREENSAVER = -100; private static int SHORTCUTID_GAMEBAR = -101; + private static int SHORTCUTID_NVQA = -200; + private static int SHORTCUTID_AMDQA = -201; + private static int SHORTCUTID_LGQA = -202; + private static int SHORTCUTID_GAMEQA = -203; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); @@ -52,6 +63,7 @@ namespace ColorControl private ToolStripMenuItem _nvTrayMenu; private ToolStripMenuItem _amdTrayMenu; private ToolStripMenuItem _lgTrayMenu; + private ToolStripMenuItem _gameTrayMenu; private StartUpParams StartUpParams { get; } public string _lgTabMessage { get; private set; } @@ -64,10 +76,15 @@ namespace ColorControl private bool _updatingDitherSettings; private LgGameBar _gameBarForm; + private QuickAccessForm _gameQuickAccessForm; - private KeyboardHookManager _keyboardHookManager; + private GameService _gameService; + + //private KeyboardHookManager _keyboardHookManager; private IntPtr _screenStateNotify; + private Dictionary _shortcuts = new(); + public MainForm(AppContext appContext) { InitializeComponent(); @@ -83,6 +100,7 @@ namespace ColorControl _nvTrayMenu = new ToolStripMenuItem("NVIDIA presets"); _amdTrayMenu = new ToolStripMenuItem("AMD presets"); _lgTrayMenu = new ToolStripMenuItem("LG presets"); + _gameTrayMenu = new ToolStripMenuItem("Game Launcher"); _trayIcon = new NotifyIcon() { Icon = Icon, @@ -95,6 +113,7 @@ namespace ColorControl _nvTrayMenu, _amdTrayMenu, _lgTrayMenu, + _gameTrayMenu, new ToolStripSeparator(), new ToolStripMenuItem("Open", null, OpenForm), new ToolStripSeparator(), @@ -118,9 +137,12 @@ namespace ColorControl chkFixChromeFonts.Checked = Utils.IsChromeFixInstalled(); } + _shortcuts.Add(SHORTCUTID_SCREENSAVER, StartScreenSaver); + InitLgService(); InitNvService(); InitAmdService(); + InitGameService(); InitInfo(); @@ -146,6 +168,8 @@ namespace ColorControl InitSortState(lvNvPresets, _config.NvPresetsSortState); + InitShortcut(SHORTCUTID_NVQA, _config.NvQuickAccessShortcut, _nvService.ToggleQuickAccessForm); + _nvService.AfterApplyPreset += NvServiceAfterApplyPreset; } catch (Exception ex) @@ -170,6 +194,8 @@ namespace ColorControl InitSortState(lvAmdPresets, _config.AmdPresetsSortState); + InitShortcut(SHORTCUTID_AMDQA, _config.AmdQuickAccessShortcut, _amdService.ToggleQuickAccessForm); + _amdService.AfterApplyPreset += AmdServiceAfterApplyPreset; } catch (Exception) @@ -180,6 +206,34 @@ namespace ColorControl } } + private void InitGameService() + { + try + { + _gameService = new GameService(_dataDir, HandleExternalServiceForLgDevice); + FillGamePresets(); + + InitSortState(lvGamePresets, _config.GamePresetsSortState); + + InitShortcut(SHORTCUTID_GAMEQA, _config.GameQuickAccessShortcut, _gameService.ToggleQuickAccessForm); + } + catch (Exception e) + { + Logger.Error("Error initializing GameService: " + e.ToLogString()); + tcMain.TabPages.Remove(tabGameLauncher); + } + } + + private void InitShortcut(int shortcutId, string shortcut, Action action) + { + _shortcuts.Add(shortcutId, action); + + if (!string.IsNullOrEmpty(shortcut)) + { + Utils.RegisterShortcut(Handle, shortcutId, shortcut); + } + } + private void AmdServiceAfterApplyPreset(object sender, AmdPreset preset) { UpdateDisplayInfoItemsAmd(); @@ -218,10 +272,11 @@ namespace ColorControl LgDevice.ExternalServiceHandler = HandleExternalServiceForLgDevice; + InitShortcut(SHORTCUTID_GAMEBAR, _lgService.Config.GameBarShortcut, ToggleGameBar); + InitShortcut(SHORTCUTID_LGQA, _config.LgQuickAccessShortcut, _lgService.ToggleQuickAccessForm); + if (!string.IsNullOrEmpty(_lgService.Config.GameBarShortcut)) { - Utils.RegisterShortcut(Handle, SHORTCUTID_GAMEBAR, _lgService.Config.GameBarShortcut); - // New shortcut manager, not working yet //if (_keyboardHookManager == null) //{ @@ -278,6 +333,13 @@ namespace ColorControl return _amdService.ApplyPreset(parameters[0]); } + if (serviceName.Equals("StartProgram", StringComparison.OrdinalIgnoreCase)) + { + Utils.StartProcess(parameters[0], parameters.Length > 1 ? string.Join(" ", parameters.Skip(1)) : null, setWorkingDir: true); + + return true; + } + return false; } @@ -291,7 +353,7 @@ namespace ColorControl //} //else //{ - Text = Application.ProductName + " " + Application.ProductVersion; + Text = Application.ProductName + " " + Application.ProductVersion; //} lblInfo.Text = Text + " - " + _currentVersionInfo.LegalCopyright; @@ -334,7 +396,7 @@ namespace ColorControl private void FillNvPresets() { - Utils.InitListView(lvNvPresets, NvPreset.GetColumnNames()); + FormUtils.InitListView(lvNvPresets, NvPreset.GetColumnNames()); UpdateDisplayInfoItems(); @@ -347,7 +409,7 @@ namespace ColorControl private void FillAmdPresets() { - Utils.InitListView(lvAmdPresets, AmdPreset.GetColumnNames()); + FormUtils.InitListView(lvAmdPresets, AmdPreset.GetColumnNames()); UpdateDisplayInfoItemsAmd(); @@ -358,6 +420,17 @@ namespace ColorControl } } + private void FillGamePresets() + { + FormUtils.InitListView(lvGamePresets, GamePreset.GetColumnNames()); + + foreach (var preset in _gameService.GetPresets()) + { + AddOrUpdateItemGame(preset); + Utils.RegisterShortcut(Handle, preset.id, preset.shortcut); + } + } + private void UpdateDisplayInfoItems() { var displays = _nvService?.GetDisplayInfos(); @@ -411,7 +484,7 @@ namespace ColorControl text += "\n" + displayInfo.InfoLine; } - Utils.SetNotifyIconText(_trayIcon, text); + FormUtils.SetNotifyIconText(_trayIcon, text); } private void UpdateDisplayInfoItemsAmd() @@ -467,17 +540,22 @@ namespace ColorControl text += "\n" + displayInfo.InfoLine; } - Utils.SetNotifyIconText(_trayIcon, text); + FormUtils.SetNotifyIconText(_trayIcon, text); } private void AddOrUpdateItem(NvPreset preset = null) { - Utils.AddOrUpdateListItem(lvNvPresets, _nvService.GetPresets(), _config, preset); + FormUtils.AddOrUpdateListItem(lvNvPresets, _nvService.GetPresets(), _config, preset); } private void AddOrUpdateItemAmd(AmdPreset preset = null) { - Utils.AddOrUpdateListItem(lvAmdPresets, _amdService.GetPresets(), _config, preset); + FormUtils.AddOrUpdateListItem(lvAmdPresets, _amdService.GetPresets(), _config, preset); + } + + private void AddOrUpdateItemGame(GamePreset preset = null) + { + FormUtils.AddOrUpdateListItem(lvGamePresets, _gameService.GetPresets(), _config, preset); } private void btnApply_Click(object sender, EventArgs e) @@ -512,10 +590,12 @@ namespace ColorControl _nvService?.GlobalSave(); _amdService?.GlobalSave(); _lgService?.GlobalSave(); + _gameService?.GlobalSave(); SaveSortState(lvNvPresets.ListViewItemSorter, _config.NvPresetsSortState); SaveSortState(lvAmdPresets.ListViewItemSorter, _config.AmdPresetsSortState); SaveSortState(lvLgPresets.ListViewItemSorter, _config.LgPresetsSortState); + SaveSortState(lvGamePresets.ListViewItemSorter, _config.GamePresetsSortState); SaveConfig(); } @@ -536,23 +616,19 @@ namespace ColorControl var preset = GetSelectedNvPreset(); var enabled = preset != null; - btnApply.Enabled = enabled; - btnChange.Enabled = enabled; - edtNvPresetName.Enabled = enabled; - edtShortcut.Enabled = enabled; - btnNvPresetSave.Enabled = enabled; - btnClone.Enabled = enabled; - btnNvPresetDelete.Enabled = enabled; + FormUtils.EnableControls(tabNVIDIA, enabled, new List { lvNvPresets, btnAddModesNv }); - if (preset != null) + if (enabled) { edtNvPresetName.Text = preset.name; edtShortcut.Text = preset.shortcut; + chkNvShowInQuickAccess.Checked = preset.ShowInQuickAccess; } else { edtNvPresetName.Text = string.Empty; edtShortcut.Text = string.Empty; + chkNvShowInQuickAccess.Checked = false; } } @@ -565,12 +641,16 @@ namespace ColorControl control = container.ActiveControl; container = control as ContainerControl; } - + return control; } private bool IsShortcutControlFocused() { + if (Form.ActiveForm?.GetType().Name.Equals("MessageForm") == true) + { + return true; + } var control = FindFocusedControl(); return control?.Name.Contains("Shortcut") ?? false; } @@ -580,18 +660,13 @@ namespace ColorControl // 5. Catch when a HotKey is pressed ! if (m.Msg == NativeConstants.WM_HOTKEY && !IsShortcutControlFocused()) { - int id = m.WParam.ToInt32(); + var id = m.WParam.ToInt32(); + if (_shortcuts.TryGetValue(id, out var action)) + { + action(); + } // 6. Handle what will happen once a respective hotkey is pressed - if (id == SHORTCUTID_SCREENSAVER) - { - var screenSaver = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "scrnsave.scr"); - Process.Start("explorer.exe", screenSaver); - } - else if (id == SHORTCUTID_GAMEBAR) - { - ToggleGameBar(); - } else { var preset = _nvService?.GetPresets().FirstOrDefault(x => x.id == id); @@ -650,6 +725,12 @@ namespace ColorControl base.WndProc(ref m); } + private void StartScreenSaver() + { + var screenSaver = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "scrnsave.scr"); + Process.Start("explorer.exe", screenSaver); + } + private void edtShortcut_KeyDown(object sender, KeyEventArgs e) { ((TextBox)sender).Text = Utils.FormatKeyboardShortcut(e); @@ -674,10 +755,17 @@ namespace ColorControl return; } + if (string.IsNullOrEmpty(name) && chkNvShowInQuickAccess.Checked) + { + MessageForms.WarningOk("A name must be entered before enabling Quick Access."); + return; + } + var clear = !string.IsNullOrEmpty(preset.shortcut); preset.shortcut = shortcut; preset.name = name; + preset.ShowInQuickAccess = chkNvShowInQuickAccess.Checked; AddOrUpdateItem(); @@ -829,7 +917,8 @@ namespace ColorControl WindowState = FormWindowState.Minimized; } } - if (!IsDisposed) { + if (!IsDisposed) + { base.SetVisibleCore(value); } } @@ -881,6 +970,19 @@ namespace ColorControl } } + private GamePreset GetSelectedGamePreset() + { + if (lvGamePresets.SelectedItems.Count > 0) + { + var item = lvGamePresets.SelectedItems[0]; + return (GamePreset)item.Tag; + } + else + { + return null; + } + } + private void btnClone_Click(object sender, EventArgs e) { var preset = GetSelectedNvPreset(); @@ -968,10 +1070,10 @@ namespace ColorControl } } - Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Bit depth", typeof(ColorDataDepth), preset.colorData, "ColorDepth", nvPresetColorDataMenuItem_Click); - Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Format", typeof(ColorDataFormat), preset.colorData, "ColorFormat", nvPresetColorDataMenuItem_Click); - Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Dynamic range", typeof(ColorDataDynamicRange), preset.colorData, "DynamicRange", nvPresetColorDataMenuItem_Click); - Utils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Color space", typeof(ColorDataColorimetry), preset.colorData, "Colorimetry", nvPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Bit depth", typeof(ColorDataDepth), preset.colorData, "ColorDepth", nvPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Format", typeof(ColorDataFormat), preset.colorData, "ColorFormat", nvPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Dynamic range", typeof(ColorDataDynamicRange), preset.colorData, "DynamicRange", nvPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuNvPresetsColorSettings, "Color space", typeof(ColorDataColorimetry), preset.colorData, "Colorimetry", nvPresetColorDataMenuItem_Click); if (preset.displayName != _lastDisplayRefreshRates) { @@ -1283,7 +1385,7 @@ namespace ColorControl private void FillLgPresets() { - Utils.InitListView(lvLgPresets, LgPreset.GetColumnNames()); + FormUtils.InitListView(lvLgPresets, LgPreset.GetColumnNames()); foreach (var preset in _lgService.GetPresets()) { @@ -1294,7 +1396,7 @@ namespace ColorControl private void AddOrUpdateItemLg(LgPreset preset = null, ListViewItem specItem = null) { - Utils.AddOrUpdateListItem(lvLgPresets, _lgService.GetPresets(), _config, preset, specItem); + FormUtils.AddOrUpdateListItem(lvLgPresets, _lgService.GetPresets(), _config, preset, specItem); } private void btnCloneLg_Click(object sender, EventArgs e) @@ -1324,6 +1426,7 @@ namespace ColorControl btnApplyLg.Enabled = enabled; btnCloneLg.Enabled = enabled; edtNameLg.Enabled = enabled; + chkLgQuickAccess.Enabled = enabled; edtLgPresetDescription.Enabled = enabled; cbxLgPresetDevice.Enabled = enabled; edtShortcutLg.Enabled = enabled; @@ -1343,6 +1446,7 @@ namespace ColorControl if (preset != null) { edtNameLg.Text = preset.name; + chkLgQuickAccess.Checked = preset.ShowInQuickAccess; edtLgPresetDescription.Text = preset.Description; var lgApps = _lgService?.GetApps(); cbxLgApps.SelectedIndex = lgApps == null ? -1 : lgApps.FindIndex(x => x.appId.Equals(preset.appId)); @@ -1365,7 +1469,7 @@ namespace ColorControl var trigger = preset.Triggers.FirstOrDefault(); - Utils.SetComboBoxEnumIndex(cbxLgPresetTrigger, (int)(trigger?.Trigger ?? PresetTriggerType.None)); + FormUtils.SetComboBoxEnumIndex(cbxLgPresetTrigger, (int)(trigger?.Trigger ?? PresetTriggerType.None)); edtLgPresetTriggerConditions.Text = Utils.GetDescriptions(trigger != null ? (int)trigger.Conditions : 0).Join(", "); edtLgPresetTriggerConditions.Tag = trigger != null ? (int)trigger.Conditions : 0; @@ -1376,6 +1480,7 @@ namespace ColorControl else { edtNameLg.Text = string.Empty; + chkLgQuickAccess.Checked = false; edtLgPresetDescription.Text = string.Empty; cbxLgApps.SelectedIndex = -1; edtShortcutLg.Text = string.Empty; @@ -1417,6 +1522,7 @@ namespace ColorControl var clear = !string.IsNullOrEmpty(preset.shortcut); preset.name = name; + preset.ShowInQuickAccess = chkLgQuickAccess.Checked; preset.Description = edtLgPresetDescription.Text.Trim(); if (cbxLgPresetDevice.SelectedIndex == -1) @@ -1439,7 +1545,7 @@ namespace ColorControl preset.appId = lgApp.appId; } - var triggerType = Utils.GetComboBoxEnumItem(cbxLgPresetTrigger); + var triggerType = FormUtils.GetComboBoxEnumItem(cbxLgPresetTrigger); preset.UpdateTrigger(triggerType, (PresetConditionType)edtLgPresetTriggerConditions.Tag, edtLgPresetIncludedProcesses.Text, @@ -1557,7 +1663,7 @@ namespace ColorControl chkLgRemoteControlShow.Checked = _lgService.Config.ShowRemoteControl; scLgController.Panel2Collapsed = !_lgService.Config.ShowRemoteControl; - Utils.BuildComboBox(cbxLgPresetTrigger, PresetTriggerType.Resume, PresetTriggerType.Shutdown, PresetTriggerType.Standby, PresetTriggerType.Startup, PresetTriggerType.Reserved5, PresetTriggerType.ScreensaverStart, PresetTriggerType.ScreensaverStop); + FormUtils.BuildComboBox(cbxLgPresetTrigger, PresetTriggerType.Resume, PresetTriggerType.Shutdown, PresetTriggerType.Standby, PresetTriggerType.Startup, PresetTriggerType.Reserved5, PresetTriggerType.ScreensaverStart, PresetTriggerType.ScreensaverStop); if (!string.IsNullOrEmpty(_lgTabMessage)) { @@ -1689,7 +1795,8 @@ namespace ColorControl InitLgApps(); } - private void InitLgApps() { + private void InitLgApps() + { var lgApps = _lgService?.GetApps(); cbxLgApps.Items.Clear(); @@ -1711,45 +1818,25 @@ namespace ColorControl } } - private void UpdateTrayMenuNv() + private void UpdateTrayMenu(ToolStripMenuItem menu, IEnumerable presets, EventHandler eventHandler) { - var presets = _nvService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate || x.applyResolution || x.applyDriverSettings); - - _nvTrayMenu.DropDownItems.Clear(); + menu.DropDownItems.Clear(); foreach (var preset in presets) { var name = preset.GetTextForMenuItem(); + var keys = Keys.None; + if (!string.IsNullOrEmpty(preset.shortcut)) { - name += "\t" + preset.shortcut; + name += " " + preset.shortcut; + //keys = Utils.ShortcutToKeys(preset.shortcut); } - var item = new ToolStripMenuItem(name); + var item = new ToolStripMenuItem(name, null, null, keys); item.Tag = preset; - item.Click += TrayMenuItemNv_Click; - _nvTrayMenu.DropDownItems.Add(item); - } - } - - private void UpdateTrayMenuAmd() - { - var presets = _amdService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate); - - _amdTrayMenu.DropDownItems.Clear(); - - foreach (var preset in presets) - { - var name = preset.GetTextForMenuItem(); - if (!string.IsNullOrEmpty(preset.shortcut)) - { - name += "\t" + preset.shortcut; - } - - var item = new ToolStripMenuItem(name); - item.Tag = preset; - item.Click += TrayMenuItemAmd_Click; - _amdTrayMenu.DropDownItems.Add(item); + item.Click += eventHandler; + menu.DropDownItems.Add(item); } } @@ -1769,45 +1856,50 @@ namespace ColorControl ApplyAmdPreset(preset); } + private void TrayMenuItemGame_Click(object sender, EventArgs e) + { + var item = sender as ToolStripMenuItem; + var preset = (GamePreset)item.Tag; + + ApplyGamePreset(preset); + } + private void trayIconContextMenu_Popup(object sender, EventArgs e) { _nvTrayMenu.Visible = _nvService != null; if (_nvTrayMenu.Visible) { - UpdateTrayMenuNv(); + var presets = _nvService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate || x.applyResolution || x.applyDriverSettings); + + UpdateTrayMenu(_nvTrayMenu, presets, TrayMenuItemNv_Click); } _amdTrayMenu.Visible = _amdService != null; if (_amdTrayMenu.Visible) { - UpdateTrayMenuAmd(); + var presets = _amdService.GetPresets().Where(x => x.applyColorData || x.applyDithering || x.applyHDR || x.applyRefreshRate); + + UpdateTrayMenu(_amdTrayMenu, presets, TrayMenuItemAmd_Click); } _lgTrayMenu.Visible = _lgService != null; if (_lgTrayMenu.Visible) { - UpdateTrayMenuLg(); + var presets = _lgService.GetPresets().Where(x => !string.IsNullOrEmpty(x.appId) || x.steps.Any()); + + _lgTrayMenu.DropDownItems.Clear(); + + UpdateTrayMenu(_lgTrayMenu, presets, TrayMenuItemLg_Click); } - } - private void UpdateTrayMenuLg() - { - var presets = _lgService.GetPresets().Where(x => !string.IsNullOrEmpty(x.appId) || x.steps.Any()); - - _lgTrayMenu.DropDownItems.Clear(); - - foreach (var preset in presets) + _gameTrayMenu.Visible = _gameService != null; + if (_gameTrayMenu.Visible) { - var name = preset.name; - if (!string.IsNullOrEmpty(preset.shortcut)) - { - name += "\t" + preset.shortcut; - } + var presets = _gameService.GetPresets(); - var item = new ToolStripMenuItem(name); - item.Tag = preset; - item.Click += TrayMenuItemLg_Click; - _lgTrayMenu.DropDownItems.Add(item); + _gameTrayMenu.DropDownItems.Clear(); + + UpdateTrayMenu(_gameTrayMenu, presets, TrayMenuItemGame_Click); } } @@ -1831,6 +1923,12 @@ namespace ColorControl ApplyAmdPreset(preset); } + private void ApplySelectedGamePreset() + { + var preset = GetSelectedGamePreset(); + ApplyGamePreset(preset); + } + private void btnDeleteLg_Click(object sender, EventArgs e) { var preset = GetSelectedLgPreset(); @@ -1892,7 +1990,7 @@ namespace ColorControl } try { - var result = _amdService.ApplyPreset(preset, Program.AppContext); + var result = _amdService.ApplyPreset(preset); if (!result) { throw new Exception("Error while applying AMD preset. At least one setting could not be applied. Check the log for details."); @@ -1930,6 +2028,29 @@ namespace ColorControl } } + private bool ApplyGamePreset(GamePreset preset) + { + if (preset == null || _gameService == null) + { + return false; + } + try + { + var result = _gameService.ApplyPreset(preset, Program.AppContext); + if (!result) + { + throw new Exception("Error while applying Game-preset. At least one setting could not be applied. Check the log for details."); + } + + return true; + } + catch (Exception e) + { + MessageForms.ErrorOk($"Error applying Game-preset ({e.TargetSite.Name}): {e.Message}"); + return false; + } + } + private void LoadLog() { var filename = Path.Combine(_dataDir, "LogFile.txt"); @@ -2010,7 +2131,7 @@ namespace ColorControl { var item = sender as ToolStripItem; - AddToLgSteps(item.Text); + FormUtils.AddStepToTextBox(edtStepsLg, item.Text); } private void miLgAddAction_Click(object sender, EventArgs e) @@ -2080,11 +2201,11 @@ namespace ColorControl var values = MessageForms.ShowDialog("Choose value", new[] { new MessageForms.FieldDefinition - { - Label = "Choose desired " + title, - FieldType = MessageForms.FieldType.DropDown, - Values = dropDownValues - } + { + Label = "Choose desired " + title, + FieldType = MessageForms.FieldType.DropDown, + Values = dropDownValues + } }); if (!values.Any()) @@ -2105,7 +2226,7 @@ namespace ColorControl text += $"({value})"; } - AddToLgSteps(text); + FormUtils.AddStepToTextBox(edtStepsLg, text); } private void miLgAddNvPreset_Click(object sender, EventArgs e) @@ -2115,7 +2236,7 @@ namespace ColorControl var text = $"NvPreset({preset.name})"; - AddToLgSteps(text); + FormUtils.AddStepToTextBox(edtStepsLg, text); } private void miLgAddAmdPreset_Click(object sender, EventArgs e) @@ -2125,33 +2246,7 @@ namespace ColorControl var text = $"AmdPreset({preset.name})"; - AddToLgSteps(text); - } - - private void AddToLgSteps(string step) - { - var text = edtStepsLg.Text; - if (string.IsNullOrWhiteSpace(text)) - { - text = step; - } - else - { - var pos = edtStepsLg.SelectionStart; - while (pos < text.Length && text.CharAt(pos) != ',') - { - pos++; - } - if (pos == text.Length) - { - text += ", " + step; - } - else - { - text = text.Substring(0, pos + 1) + " " + step + ", " + text.Substring(pos + 1).Trim(); - } - } - edtStepsLg.Text = text.Trim(); + FormUtils.AddStepToTextBox(edtStepsLg, text); } private void clbLgPower_ItemCheck(object sender, ItemCheckEventArgs e) @@ -2413,7 +2508,8 @@ Do you want to continue?"; } } - private void ApplyNvPresetOnStartup(int attempts = 5) { + private void ApplyNvPresetOnStartup(int attempts = 5) + { var presetIdOrName = !string.IsNullOrEmpty(StartUpParams.NvidiaPresetIdOrName) ? StartUpParams.NvidiaPresetIdOrName : _config.NvPresetId_ApplyOnStartup.ToString(); @@ -2567,10 +2663,17 @@ Do you want to continue?"; return; } + if (string.IsNullOrEmpty(name) && chkAmdQuickAccess.Checked) + { + MessageForms.WarningOk("A name must be entered before enabling Quick Access."); + return; + } + var clear = !string.IsNullOrEmpty(preset.shortcut); preset.shortcut = shortcut; preset.name = name; + preset.ShowInQuickAccess = chkAmdQuickAccess.Checked; AddOrUpdateItemAmd(); @@ -2635,8 +2738,8 @@ Do you want to continue?"; } } - Utils.BuildDropDownMenu(mnuAmdColorSettings, "Color depth", typeof(ADLColorDepth), preset, "colorDepth", amdPresetColorDataMenuItem_Click); - Utils.BuildDropDownMenu(mnuAmdColorSettings, "Pixel format", typeof(ADLPixelFormat), preset, "pixelFormat", amdPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuAmdColorSettings, "Color depth", typeof(ADLColorDepth), preset, "colorDepth", amdPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuAmdColorSettings, "Pixel format", typeof(ADLPixelFormat), preset, "pixelFormat", amdPresetColorDataMenuItem_Click); if (preset.displayName != _lastDisplayRefreshRates) { @@ -2689,7 +2792,7 @@ Do you want to continue?"; miAmdDitheringIncluded.Checked = preset.applyDithering; - Utils.BuildDropDownMenu(mnuAmdDithering, "Mode", typeof(ADLDitherState), preset, "ditherState", amdPresetColorDataMenuItem_Click); + FormUtils.BuildDropDownMenu(mnuAmdDithering, "Mode", typeof(ADLDitherState), preset, "ditherState", amdPresetColorDataMenuItem_Click); miAmdHDRIncluded.Checked = preset.applyHDR; miAmdHDREnabled.Checked = preset.HDREnabled; @@ -2710,23 +2813,19 @@ Do you want to continue?"; var preset = GetSelectedAmdPreset(); var enabled = preset != null; - btnApplyAmd.Enabled = enabled; - btnChangeAmd.Enabled = enabled; - edtAmdPresetName.Enabled = enabled; - edtAmdShortcut.Enabled = enabled; - btnAmdPresetSave.Enabled = enabled; - btnCloneAmd.Enabled = enabled; - btnDeleteAmd.Enabled = enabled; + FormUtils.EnableControls(tabAMD, enabled, new List { lvAmdPresets, btnAddAmd }); - if (preset != null) + if (enabled) { edtAmdPresetName.Text = preset.name; edtAmdShortcut.Text = preset.shortcut; + chkAmdQuickAccess.Checked = preset.ShowInQuickAccess; } else { edtAmdPresetName.Text = string.Empty; edtAmdShortcut.Text = string.Empty; + chkAmdQuickAccess.Checked = false; } } @@ -2903,7 +3002,7 @@ Do you want to continue?"; { return; } - + var device = _lgService.SelectedDevice; if (device != null) @@ -2937,45 +3036,8 @@ Do you want to continue?"; item.Click += miLgAddAction_Click; } - if (_nvService != null) - { - mnuLgNvPresets.DropDownItems.Clear(); - - foreach (var nvPreset in _nvService.GetPresets()) - { - var text = nvPreset.name; - - if (!string.IsNullOrEmpty(text)) - { - var item = mnuLgNvPresets.DropDownItems.Add(text); - item.Tag = nvPreset; - item.Click += miLgAddNvPreset_Click; - } - } - } - - if (_amdService != null) - { - mnuLgAmdPresets.DropDownItems.Clear(); - - foreach (var amdPreset in _amdService.GetPresets()) - { - var text = amdPreset.name; - - if (!string.IsNullOrEmpty(text)) - { - var item = mnuLgAmdPresets.DropDownItems.Add(text); - item.Tag = amdPreset; - item.Click += miLgAddAmdPreset_Click; - } - } - } - - mnuLgNvPresets.Visible = _nvService != null; - mnuLgAmdPresets.Visible = _amdService != null; - - mnuLgNvPresets.Text = mnuLgNvPresets.DropDownItems.Count > 0 ? "NVIDIA presets" : "NVIDIA presets (no named presets found)"; - mnuLgAmdPresets.Text = mnuLgAmdPresets.DropDownItems.Count > 0 ? "AMD presets" : "AMD presets (no named presets found)"; + BuildServicePresetsMenu(mnuLgNvPresets, _nvService, "NVIDIA", miLgAddNvPreset_Click); + BuildServicePresetsMenu(mnuLgAmdPresets, _amdService, "AMD", miLgAddAmdPreset_Click); } private void btnLgDeviceConvertToCustom_Click(object sender, EventArgs e) @@ -2994,6 +3056,27 @@ Do you want to continue?" FillLgDevices(); } + private static void BuildServicePresetsMenu(ToolStripMenuItem menu, ServiceBase service, string name, EventHandler eventHandler) where T : PresetBase, new() + { + menu.DropDownItems.Clear(); + + foreach (var nvPreset in service?.GetPresets() ?? new List()) + { + var text = nvPreset.name; + + if (!string.IsNullOrEmpty(text)) + { + var item = menu.DropDownItems.Add(text); + item.Tag = nvPreset; + item.Click += eventHandler; + } + } + + menu.Visible = service != null; + + menu.Text = menu.DropDownItems.Count > 0 ? $"{name} presets" : $"{name} presets (no named presets found)"; + } + private void btnLgRemoteControlShow_Click(object sender, EventArgs e) { } @@ -3034,7 +3117,7 @@ Do you want to continue?" !a.Name.Contains("hdmiPc", StringComparison.OrdinalIgnoreCase) && (a.EnumType != null || a.MinValue >= 0 && a.MaxValue > a.MinValue))) { - var menu = Utils.BuildDropDownMenuEx(mnuLgExpert, action.Title, action.EnumType, btnLgExpertColorGamut_Click, action, (int)action.MinValue, (int)action.MaxValue); + var menu = FormUtils.BuildDropDownMenuEx(mnuLgExpert, action.Title, action.EnumType, btnLgExpertColorGamut_Click, action, (int)action.MinValue, (int)action.MaxValue); if (!gameBarActions.Contains(action)) { @@ -3074,7 +3157,7 @@ Do you want to continue?" foreach (var presetAction in presetActions) { - var menu = Utils.BuildDropDownMenuEx(mnuLgExpert, presetAction.Name, null, btnLgExpertPresetAction_Click, presetAction.Preset); + var menu = FormUtils.BuildDropDownMenuEx(mnuLgExpert, presetAction.Name, null, btnLgExpertPresetAction_Click, presetAction.Preset); } } @@ -3432,5 +3515,404 @@ The InStart and Software Update items are now visible under the Expert-button." AddOrUpdateItem(); } + + private void mnuLgProgram_Click(object sender, EventArgs e) + { + var file = Utils.SelectFile(); + + if (file != null) + { + FormUtils.AddStepToTextBox(edtStepsLg, $"StartProgram({file.FullName})"); + } + } + + private void lvGamePresets_SelectedIndexChanged(object sender, EventArgs _) + { + var preset = GetSelectedGamePreset(); + var enabled = preset != null; + + FormUtils.EnableControls(tabGameLauncher, enabled, new List { lvGamePresets, btnGameAdd }); + + if (preset != null) + { + edtGameName.Text = preset.name; + edtGamePath.Text = preset.Path; + edtGameParameters.Text = preset.Parameters; + chkGameRunAsAdmin.Checked = preset.RunAsAdministrator; + chkGameQuickAccess.Checked = preset.ShowInQuickAccess; + edtGamePrelaunchSteps.Text = string.Join(", ", preset.PreLaunchSteps); + } + else + { + edtGameName.Text = string.Empty; + edtGamePath.Text = string.Empty; + edtGameParameters.Text = string.Empty; + chkGameRunAsAdmin.Checked = false; + chkGameQuickAccess.Checked = false; + edtGamePrelaunchSteps.Text = string.Empty; + } + } + + private void lvGamePresets_DoubleClick(object sender, EventArgs e) + { + ApplySelectedGamePreset(); + } + + private void btnGameLaunch_Click(object sender, EventArgs e) + { + ApplySelectedGamePreset(); + } + + private void btnGameClone_Click(object sender, EventArgs e) + { + var preset = GetSelectedGamePreset(); + + var newPreset = preset.Clone(); + + AddOrUpdateItemGame(newPreset); + } + + private void btnGameAdd_Click(object sender, EventArgs e) + { + var file = Utils.SelectFile(); + + AddGamePreset(file); + } + + private void AddGamePreset(FileInfo file) + { + var preset = _gameService.CreateNewPreset(); + + if (file != null) + { + var versionInfo = FileVersionInfo.GetVersionInfo(file.FullName); + + preset.Path = file.FullName; + + var fileName = Path.GetFileNameWithoutExtension(preset.Path); + + preset.name = versionInfo.FileDescription ?? versionInfo.ProductName ?? fileName; + } + + AddOrUpdateItemGame(preset); + } + + private void btnGameSave_Click(object sender, EventArgs e) + { + var shortcut = string.Empty; + if (!Utils.ValidateShortcut(shortcut)) + { + return; + } + + var preset = GetSelectedGamePreset(); + + var name = edtGameName.Text.Trim(); + + if (name.Length == 0 || _gameService.GetPresets().Any(x => x.id != preset.id && x.name.Equals(name, StringComparison.OrdinalIgnoreCase))) + { + MessageForms.WarningOk("The name can not be empty and must be unique."); + return; + } + + preset.name = name; + preset.Path = edtGamePath.Text; + preset.Parameters = edtGameParameters.Text; + preset.RunAsAdministrator = chkGameRunAsAdmin.Checked; + preset.ShowInQuickAccess = chkGameQuickAccess.Checked; + + var clear = !string.IsNullOrEmpty(preset.shortcut); + + var shortcutChanged = !shortcut.Equals(preset.shortcut); + if (shortcutChanged) + { + preset.shortcut = shortcut; + } + + var text = edtGamePrelaunchSteps.Text; + + Utils.ParseWords(preset.PreLaunchSteps, text); + + AddOrUpdateItemGame(); + + if (shortcutChanged) + { + Utils.RegisterShortcut(Handle, preset.id, preset.shortcut, clear); + } + } + + private void btnGameBrowse_Click(object sender, EventArgs e) + { + var file = Utils.SelectFile(); + + if (file == null) + { + return; + } + + var preset = GetSelectedGamePreset(); + + preset.Path = file.FullName; + + edtGamePath.Text = preset.Path; + + if (string.IsNullOrEmpty(preset.name) || preset.name.StartsWith("New preset", StringComparison.OrdinalIgnoreCase)) + { + var fileName = Path.GetFileNameWithoutExtension(preset.Path); + + edtGameName.Text = fileName; + preset.name = fileName; + } + + AddOrUpdateItemGame(); + } + + private void btnGameDelete_Click(object sender, EventArgs e) + { + var preset = GetSelectedGamePreset(); + + if (preset == null) + { + return; + } + + if (!string.IsNullOrEmpty(preset.shortcut)) + { + Utils.UnregisterHotKey(Handle, preset.id); + } + + _gameService.GetPresets().Remove(preset); + + var item = lvGamePresets.SelectedItems[0]; + lvGamePresets.Items.Remove(item); + } + + private void mnuGameAddStep_Opening(object sender, CancelEventArgs e) + { + BuildServicePresetsMenu(mnuGameNvidiaPresets, _nvService, "NVIDIA", miGameAddPreset_Click); + BuildServicePresetsMenu(mnuGameAmdPresets, _amdService, "AMD", miGameAddPreset_Click); + BuildServicePresetsMenu(mnuGameLgPresets, _lgService, "LG", miGameAddPreset_Click); + } + + private void miGameAddPreset_Click(object sender, EventArgs e) + { + var item = sender as ToolStripItem; + var preset = item.Tag as PresetBase; + + var text = $"{preset.GetType().Name}({preset.name})"; + + FormUtils.AddStepToTextBox(edtGamePrelaunchSteps, text); + } + + private void btnGameAddStep_Click(object sender, EventArgs e) + { + mnuGameAddStep.Show(btnGameAddStep, btnGameAddStep.PointToClient(Cursor.Position)); + } + + private void mnuGameStartProgram_Click(object sender, EventArgs e) + { + var file = Utils.SelectFile(); + + if (file != null) + { + FormUtils.AddStepToTextBox(edtGamePrelaunchSteps, $"StartProgram({file.FullName})"); + } + } + + private void lvGamePresets_DragDrop(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + var files = (string[])e.Data.GetData(DataFormats.FileDrop); + var file = new FileInfo(files.First()); + + AddGamePreset(file); + } + } + + private void lvGamePresets_DragEnter(object sender, DragEventArgs e) + { + e.Effect = DragDropEffects.All; + } + + private void btnGameActions_Click(object sender, EventArgs e) + { + mnuGameActions.Show(btnGameSettings, btnGameSettings.PointToClient(Cursor.Position)); + } + + private void mnuGameNvInspector_Click(object sender, EventArgs e) + { + StartNvProfileInspector(); + } + + private string EditShortcut(string shortcut, string label = "Shortcut", string title = null) + { + var field = new MessageForms.FieldDefinition + { + Label = label, + FieldType = MessageForms.FieldType.Shortcut, + Value = shortcut + }; + var values = MessageForms.ShowDialog(title ?? "Set shortcut", new[] { field }); + if (!values.Any()) + { + return null; + } + + return values.First().Value.ToString(); + } + + + private void miGameSetQuickAccessShortcut_Click(object sender, EventArgs e) + { + var shortcut = EditShortcut(_config.GameQuickAccessShortcut); + + if (shortcut == null) + { + return; + } + + var clear = !string.IsNullOrEmpty(_config.GameQuickAccessShortcut); + + _config.GameQuickAccessShortcut = shortcut; + + Utils.RegisterShortcut(Handle, SHORTCUTID_GAMEQA, _config.GameQuickAccessShortcut, clear); + } + + private void btnNvSetQuickAccessShortcut_Click(object sender, EventArgs e) + { + } + + private void btnLgSettings_Click(object sender, EventArgs e) + { + var shortcut = EditShortcut(_config.LgQuickAccessShortcut, "Quick Access shortcut", "LG controller settings"); + + if (shortcut == null) + { + return; + } + + var clear = !string.IsNullOrEmpty(_config.LgQuickAccessShortcut); + + _config.LgQuickAccessShortcut = shortcut; + + Utils.RegisterShortcut(Handle, SHORTCUTID_LGQA, _config.LgQuickAccessShortcut, clear); + } + + private void mnuGameActions_Opening(object sender, CancelEventArgs e) + { + mnuGameNvInspector.Visible = _nvService != null; + } + + private void miNvProfileInspector_Click(object sender, EventArgs e) + { + StartNvProfileInspector(); + } + + private void StartNvProfileInspector() + { + var form = new frmDrvSettings(); + form.Show(); + } + + private void miNvSettings_Click(object sender, EventArgs e) + { + var shortcut = EditShortcut(_config.NvQuickAccessShortcut, "Quick Access shortcut", "NVIDIA controller settings"); + + if (shortcut == null) + { + return; + } + + var clear = !string.IsNullOrEmpty(_config.NvQuickAccessShortcut); + + _config.NvQuickAccessShortcut = shortcut; + + Utils.RegisterShortcut(Handle, SHORTCUTID_NVQA, _config.NvQuickAccessShortcut, clear); + } + + private void btnNvSettings_Click(object sender, EventArgs e) + { + mnuNvSettings.Show(btnNvSettings, btnNvSettings.PointToClient(Cursor.Position)); + } + + private void lvGamePresets_ItemChecked(object sender, ItemCheckedEventArgs e) + { + ListViewItemChecked(lvGamePresets, e); + } + + private void ListViewItemChecked(ListView listView, ItemCheckedEventArgs e) where T : PresetBase + { + var checkedPreset = (T)e.Item.Tag; + + if (checkedPreset == null || checkedPreset.ShowInQuickAccess == e.Item.Checked) + { + return; + } + + checkedPreset.ShowInQuickAccess = e.Item.Checked; + + var preset = listView.GetSelectedItemTag(); + + if (preset == checkedPreset) + { + listView.FireEvent("SelectedIndexChanged", listView, e); + } + } + + private void lvNvPresets_ItemChecked(object sender, ItemCheckedEventArgs e) + { + ListViewItemChecked(lvNvPresets, e); + } + + private void lvLgPresets_ItemChecked(object sender, ItemCheckedEventArgs e) + { + ListViewItemChecked(lvLgPresets, e); + } + + private void lvNvPresets_ItemCheck(object sender, ItemCheckEventArgs e) + { + var listView = sender as ListView; + + if (!listView.Focused) + { + return; + } + + var listItem = listView.Items[e.Index]; + + if (listItem.Tag == null) + { + MessageForms.WarningOk("Quick Access cannot be enabled for this item."); + e.NewValue = e.CurrentValue; + } + + if (e.NewValue == CheckState.Checked && string.IsNullOrEmpty(listItem.Text)) + { + MessageForms.WarningOk("A name must be entered before enabling Quick Access."); + e.NewValue = e.CurrentValue; + } + } + + private void lvAmdPresets_ItemChecked(object sender, ItemCheckedEventArgs e) + { + ListViewItemChecked(lvAmdPresets, e); + } + + private void btnAmdSettings_Click(object sender, EventArgs e) + { + var shortcut = EditShortcut(_config.AmdQuickAccessShortcut, "Quick Access shortcut", "AMD controller settings"); + + if (shortcut == null) + { + return; + } + + var clear = !string.IsNullOrEmpty(_config.AmdQuickAccessShortcut); + + _config.AmdQuickAccessShortcut = shortcut; + + Utils.RegisterShortcut(Handle, SHORTCUTID_AMDQA, _config.AmdQuickAccessShortcut, clear); + } } } \ No newline at end of file diff --git a/ColorControl/MainForm.resx b/ColorControl/MainForm.resx index bb2dd65..8f3dfb9 100644 --- a/ColorControl/MainForm.resx +++ b/ColorControl/MainForm.resx @@ -69,6 +69,15 @@ 147, 17 + + 418, 15 + + + 416, 50 + + + 15, 47 + diff --git a/ColorControl/CCD.cs b/ColorControl/Native/CCD.cs similarity index 100% rename from ColorControl/CCD.cs rename to ColorControl/Native/CCD.cs diff --git a/ColorControl/PnpDev.cs b/ColorControl/Native/PnpDev.cs similarity index 100% rename from ColorControl/PnpDev.cs rename to ColorControl/Native/PnpDev.cs diff --git a/ColorControl/RestartDetector.cs b/ColorControl/Native/RestartDetector.cs similarity index 100% rename from ColorControl/RestartDetector.cs rename to ColorControl/Native/RestartDetector.cs diff --git a/ColorControl/ScreenInterrogatory.cs b/ColorControl/Native/ScreenInterrogatory.cs similarity index 100% rename from ColorControl/ScreenInterrogatory.cs rename to ColorControl/Native/ScreenInterrogatory.cs diff --git a/ColorControl/UserSessionInfo.cs b/ColorControl/Native/UserSessionInfo.cs similarity index 100% rename from ColorControl/UserSessionInfo.cs rename to ColorControl/Native/UserSessionInfo.cs diff --git a/ColorControl/Program.cs b/ColorControl/Program.cs index dada269..f9be8de 100644 --- a/ColorControl/Program.cs +++ b/ColorControl/Program.cs @@ -1,4 +1,8 @@ -using Newtonsoft.Json; +using ColorControl.Common; +using ColorControl.Services.AMD; +using ColorControl.Services.LG; +using ColorControl.Services.NVIDIA; +using Newtonsoft.Json; using NLog; using NWin32; using System; diff --git a/ColorControl/ADL.cs b/ColorControl/Services/AMD/ADL.cs similarity index 100% rename from ColorControl/ADL.cs rename to ColorControl/Services/AMD/ADL.cs diff --git a/ColorControl/ADLWrapper.cs b/ColorControl/Services/AMD/ADLWrapper.cs similarity index 99% rename from ColorControl/ADLWrapper.cs rename to ColorControl/Services/AMD/ADLWrapper.cs index 1853e6e..10ca41e 100644 --- a/ColorControl/ADLWrapper.cs +++ b/ColorControl/Services/AMD/ADLWrapper.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using ADL_CONTEXT_HANDLE = System.IntPtr; -namespace ColorControl +namespace ColorControl.Services.AMD { enum ADLPixelFormat { diff --git a/ColorControl/AmdDisplayInfo.cs b/ColorControl/Services/AMD/AmdDisplayInfo.cs similarity index 92% rename from ColorControl/AmdDisplayInfo.cs rename to ColorControl/Services/AMD/AmdDisplayInfo.cs index 0a93571..700ddaf 100644 --- a/ColorControl/AmdDisplayInfo.cs +++ b/ColorControl/Services/AMD/AmdDisplayInfo.cs @@ -1,7 +1,7 @@ using ATI.ADL; using System.Collections.Generic; -namespace ColorControl +namespace ColorControl.Services.AMD { class AmdDisplayInfo { diff --git a/ColorControl/AmdPreset.cs b/ColorControl/Services/AMD/AmdPreset.cs similarity index 96% rename from ColorControl/AmdPreset.cs rename to ColorControl/Services/AMD/AmdPreset.cs index 3079152..8043e2e 100644 --- a/ColorControl/AmdPreset.cs +++ b/ColorControl/Services/AMD/AmdPreset.cs @@ -1,8 +1,9 @@ -using System; +using ColorControl.Services.Common; +using System; using System.Collections.Generic; using System.Text; -namespace ColorControl +namespace ColorControl.Services.AMD { class AmdPreset : PresetBase { @@ -32,7 +33,7 @@ namespace ColorControl primaryDisplay = true; } - public AmdPreset(AmdPreset preset): this() + public AmdPreset(AmdPreset preset) : this() { id = GetNewId(); @@ -99,7 +100,7 @@ namespace ColorControl return presets; } - public string GetTextForMenuItem() + public override string GetTextForMenuItem() { var sb = new StringBuilder(); if (!string.IsNullOrEmpty(name)) diff --git a/ColorControl/AmdService.cs b/ColorControl/Services/AMD/AmdService.cs similarity index 96% rename from ColorControl/AmdService.cs rename to ColorControl/Services/AMD/AmdService.cs index ab99033..f647bd3 100644 --- a/ColorControl/AmdService.cs +++ b/ColorControl/Services/AMD/AmdService.cs @@ -1,4 +1,6 @@ using ATI.ADL; +using ColorControl.Common; +using ColorControl.Services.Common; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -6,12 +8,14 @@ using System.IO; using System.Linq; using System.Windows.Forms; -namespace ColorControl +namespace ColorControl.Services.AMD { class AmdService : GraphicsService { private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); + public override string ServiceName => "AMD"; + private ADLDisplayInfo _currentDisplay; public AmdService(string dataPath) : base(dataPath, "AmdPresets.json") @@ -104,7 +108,7 @@ namespace ColorControl var preset = GetPresetByIdOrName(idOrName); if (preset != null) { - return ApplyPreset(preset, Program.AppContext); + return ApplyPreset(preset); } else { @@ -112,7 +116,7 @@ namespace ColorControl } } - public bool ApplyPreset(AmdPreset preset, AppContext appContext) + public override bool ApplyPreset(AmdPreset preset) { SetCurrentDisplay(preset); @@ -145,8 +149,8 @@ namespace ColorControl if (preset.applyRefreshRate) { { - if (!SetRefreshRate(preset.refreshRate)) - result = false; + if (!SetRefreshRate(preset.refreshRate)) + result = false; } } diff --git a/ColorControl/GraphicsService.cs b/ColorControl/Services/Common/GraphicsService.cs similarity index 96% rename from ColorControl/GraphicsService.cs rename to ColorControl/Services/Common/GraphicsService.cs index 7bc313e..6e1ca62 100644 --- a/ColorControl/GraphicsService.cs +++ b/ColorControl/Services/Common/GraphicsService.cs @@ -1,4 +1,5 @@ -using NWin32; +using ColorControl.Common; +using NWin32; using NWin32.NativeTypes; using System; using System.Collections.Generic; @@ -7,9 +8,9 @@ using System.Linq; using System.Runtime.InteropServices; using System.Threading; -namespace ColorControl +namespace ColorControl.Services.Common { - abstract class GraphicsService : ServiceBase where T : PresetBase + abstract class GraphicsService : ServiceBase where T : PresetBase, new() { private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger(); @@ -115,8 +116,8 @@ namespace ColorControl DEVMODEA devMode; while (NativeMethods.EnumDisplaySettingsA(displayName, i, out devMode)) { - if ((portrait ? devMode.dmPelsWidth < devMode.dmPelsHeight : devMode.dmPelsWidth > devMode.dmPelsHeight) && - (refreshRate == 0 || devMode.dmDisplayFrequency == refreshRate) && + if ((portrait ? devMode.dmPelsWidth < devMode.dmPelsHeight : devMode.dmPelsWidth > devMode.dmPelsHeight) && + (refreshRate == 0 || devMode.dmDisplayFrequency == refreshRate) && !list.Any(m => m.dmPelsWidth == devMode.dmPelsWidth && m.dmPelsHeight == devMode.dmPelsHeight)) { list.Add(devMode); diff --git a/ColorControl/PresetBase.cs b/ColorControl/Services/Common/PresetBase.cs similarity index 95% rename from ColorControl/PresetBase.cs rename to ColorControl/Services/Common/PresetBase.cs index 54c6d2e..8fa9b0e 100644 --- a/ColorControl/PresetBase.cs +++ b/ColorControl/Services/Common/PresetBase.cs @@ -1,11 +1,11 @@ -using System; +using ColorControl.Common; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; -using System.Text; -namespace ColorControl +namespace ColorControl.Services.Common { enum PresetTriggerType { @@ -72,7 +72,7 @@ namespace ColorControl var excluded = context.ChangedProcesses.Any(cp => ExcludedProcesses.Any(ep => cp.ProcessName.Equals(ep, StringComparison.OrdinalIgnoreCase))); var screenSizeCheck = (!Conditions.HasFlag(PresetConditionType.FullScreen) && !context.ForegroundProcessIsFullScreen) || - (context.ForegroundProcess != null && context.ForegroundProcessIsFullScreen && + (context.ForegroundProcess != null && context.ForegroundProcessIsFullScreen && (allProcesses || IncludedProcesses.Any(ip => context.ForegroundProcess.ProcessName.Equals(ip, StringComparison.OrdinalIgnoreCase)))); var notificationsDisabledCheck = !Conditions.HasFlag(PresetConditionType.NotificationsDisabled) || context.IsNotificationDisabled; @@ -115,6 +115,7 @@ namespace ColorControl public string shortcut { get; set; } public List Triggers { get; set; } public string Description { get; set; } + public bool ShowInQuickAccess { get; set; } private int _id; @@ -161,6 +162,11 @@ namespace ColorControl public abstract List GetDisplayValues(Config config = null); + public virtual string GetTextForMenuItem() + { + return name; + } + public void UpdateTrigger(PresetTriggerType triggerType, PresetConditionType conditions, string includedProcesses, string excludedProcesses) { if (!Triggers.Any()) diff --git a/ColorControl/Services/Common/QuickAccessForm.Designer.cs b/ColorControl/Services/Common/QuickAccessForm.Designer.cs new file mode 100644 index 0000000..09cdc45 --- /dev/null +++ b/ColorControl/Services/Common/QuickAccessForm.Designer.cs @@ -0,0 +1,124 @@ + +using System.Windows.Forms; + +namespace ColorControl.Services.Common +{ + partial class QuickAccessForm : Form where T : PresetBase, new() + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.components = new System.ComponentModel.Container(); + this.flowPanel = new System.Windows.Forms.FlowLayoutPanel(); + this.btnClose = new System.Windows.Forms.Button(); + this.lblTitle = new System.Windows.Forms.Label(); + this.tmrHide = new System.Windows.Forms.Timer(this.components); + this.SuspendLayout(); + // + // flowPanel + // + this.flowPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.flowPanel.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flowPanel.Location = new System.Drawing.Point(14, 33); + this.flowPanel.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.flowPanel.Name = "flowPanel"; + this.flowPanel.Size = new System.Drawing.Size(270, 339); + this.flowPanel.TabIndex = 0; + this.flowPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(this.flowPanel_MouseMove); + // + // btnClose + // + this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnClose.FlatAppearance.BorderColor = System.Drawing.Color.DarkGray; + this.btnClose.FlatAppearance.BorderSize = 0; + this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.Flat; + this.btnClose.ForeColor = System.Drawing.Color.White; + this.btnClose.Location = new System.Drawing.Point(280, 0); + this.btnClose.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.btnClose.Name = "btnClose"; + this.btnClose.Size = new System.Drawing.Size(16, 27); + this.btnClose.TabIndex = 1; + this.btnClose.TabStop = false; + this.btnClose.Text = "x"; + this.btnClose.UseVisualStyleBackColor = true; + this.btnClose.Click += new System.EventHandler(this.btnClose_Click); + // + // lblTitle + // + this.lblTitle.AutoSize = true; + this.lblTitle.ForeColor = System.Drawing.Color.White; + this.lblTitle.Location = new System.Drawing.Point(13, 6); + this.lblTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.lblTitle.Name = "lblTitle"; + this.lblTitle.Size = new System.Drawing.Size(77, 15); + this.lblTitle.TabIndex = 0; + this.lblTitle.Text = "Quick Access"; + // + // tmrHide + // + this.tmrHide.Interval = 5000; + this.tmrHide.Tick += new System.EventHandler(this.tmrHide_Tick); + // + // QuickAccessForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.BackColor = System.Drawing.Color.Black; + this.ClientSize = new System.Drawing.Size(298, 387); + this.Controls.Add(this.lblTitle); + this.Controls.Add(this.btnClose); + this.Controls.Add(this.flowPanel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.KeyPreview = true; + this.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "QuickAccessForm"; + this.Opacity = 0.8D; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; + this.Text = "RemoteControlForm"; + this.TopMost = true; + this.Activated += new System.EventHandler(this.LgGameBar_Activated); + this.Deactivate += new System.EventHandler(this.LgGameBar_Deactivate); + this.Shown += new System.EventHandler(this.RemoteControlForm_Shown); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.RemoteControlForm_KeyUp); + this.Move += new System.EventHandler(this.LgGameBar_Move); + this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.QuickAccessForm_PreviewKeyDown); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.FlowLayoutPanel flowPanel; + private System.Windows.Forms.Button btnClose; + private System.Windows.Forms.Label lblTitle; + private System.Windows.Forms.Timer tmrHide; + } +} \ No newline at end of file diff --git a/ColorControl/Services/Common/QuickAccessForm.cs b/ColorControl/Services/Common/QuickAccessForm.cs new file mode 100644 index 0000000..52de31b --- /dev/null +++ b/ColorControl/Services/Common/QuickAccessForm.cs @@ -0,0 +1,237 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Windows.Forms; + +namespace ColorControl.Services.Common +{ + partial class QuickAccessForm : Form where T : PresetBase, new() + { + private ServiceBase _service; + private List