diff --git a/nspector/Common/DrsSettingsService.cs b/nspector/Common/DrsSettingsService.cs index bc9e8f6..b2f4e61 100644 --- a/nspector/Common/DrsSettingsService.cs +++ b/nspector/Common/DrsSettingsService.cs @@ -549,7 +549,7 @@ namespace nspector.Common }); } - private string GetApplicationFingerprint(NVDRS_APPLICATION_V3 application) + private string GetApplicationFingerprint(NVDRS_APPLICATION_V4 application) { return $"{application.appName}|{application.fileInFolder}|{application.userFriendlyName}|{application.launcher}"; } diff --git a/nspector/Common/DrsSettingsServiceBase.cs b/nspector/Common/DrsSettingsServiceBase.cs index f3464cc..1b12104 100644 --- a/nspector/Common/DrsSettingsServiceBase.cs +++ b/nspector/Common/DrsSettingsServiceBase.cs @@ -215,9 +215,9 @@ namespace nspector.Common protected void AddApplication(IntPtr hSession, IntPtr hProfile, string applicationName) { - var newApp = new NVDRS_APPLICATION_V3() + var newApp = new NVDRS_APPLICATION_V4() { - version = nvw.NVDRS_APPLICATION_VER_V3, + version = nvw.NVDRS_APPLICATION_VER_V4, appName = applicationName, }; @@ -227,7 +227,7 @@ namespace nspector.Common } - protected void DeleteApplication(IntPtr hSession, IntPtr hProfile, NVDRS_APPLICATION_V3 application) + protected void DeleteApplication(IntPtr hSession, IntPtr hProfile, NVDRS_APPLICATION_V4 application) { var caRes = nvw.DRS_DeleteApplicationEx(hSession, hProfile, ref application); if (caRes != NvAPI_Status.NVAPI_OK) @@ -285,16 +285,16 @@ namespace nspector.Common return settings.ToList(); } - protected List GetProfileApplications(IntPtr hSession, IntPtr hProfile) + protected List GetProfileApplications(IntPtr hSession, IntPtr hProfile) { uint appCount = 512; - var apps = new NVDRS_APPLICATION_V3[512]; - apps[0].version = NvapiDrsWrapper.NVDRS_APPLICATION_VER_V3; + var apps = new NVDRS_APPLICATION_V4[512]; + apps[0].version = NvapiDrsWrapper.NVDRS_APPLICATION_VER_V4; var esRes = NvapiDrsWrapper.DRS_EnumApplications(hSession, hProfile, 0, ref appCount, ref apps); if (esRes == NvAPI_Status.NVAPI_END_ENUMERATION) - return new List(); + return new List(); if (esRes != NvAPI_Status.NVAPI_OK) throw new NvapiException("DRS_EnumApplications", esRes); diff --git a/nspector/Native/NVAPI/NvapiDrsWrapper.cs b/nspector/Native/NVAPI/NvapiDrsWrapper.cs index 7f9d522..34d2943 100644 --- a/nspector/Native/NVAPI/NvapiDrsWrapper.cs +++ b/nspector/Native/NVAPI/NvapiDrsWrapper.cs @@ -344,7 +344,8 @@ namespace nspector.Native.NVAPI2 [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)] internal struct NVDRS_APPLICATION_V3 { - public uint isMetro { get { return ((uint)((bitvector1 & 1))); } set { bitvector1 = ((uint)((value | bitvector1))); } } + public bool isMetro { get { return (bitvector1 & 1) != 0; } set { if (value) bitvector1 |= 1; else bitvector1 &= ~1u; } } + public bool isCommandLine { get { return (bitvector1 & 2) != 0; } set { if (value) bitvector1 |= 2; else bitvector1 &= ~2u; } } public uint version; public uint isPredefined; @@ -359,6 +360,27 @@ namespace nspector.Native.NVAPI2 private uint bitvector1; } + [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)] + internal struct NVDRS_APPLICATION_V4 + { + public bool isMetro { get { return (bitvector1 & 1) != 0; } set { if (value) bitvector1 |= 1; else bitvector1 &= ~1u; } } + public bool isCommandLine { get { return (bitvector1 & 2) != 0; } set { if (value) bitvector1 |= 2; else bitvector1 &= ~2u; } } + + public uint version; + public uint isPredefined; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)] + public string appName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)] + public string userFriendlyName; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)] + public string launcher; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)] + public string fileInFolder; + private uint bitvector1; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)] + public string commandLine; + } + [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Unicode)] internal struct NVDRS_PROFILE { @@ -388,7 +410,8 @@ namespace nspector.Native.NVAPI2 public static uint NVDRS_APPLICATION_VER_V1 = MAKE_NVAPI_VERSION(1); public static uint NVDRS_APPLICATION_VER_V2 = MAKE_NVAPI_VERSION(2); public static uint NVDRS_APPLICATION_VER_V3 = MAKE_NVAPI_VERSION(3); - public static uint NVDRS_APPLICATION_VER = NVDRS_APPLICATION_VER_V3; + public static uint NVDRS_APPLICATION_VER_V4 = MAKE_NVAPI_VERSION(4); + public static uint NVDRS_APPLICATION_VER = NVDRS_APPLICATION_VER_V4; public static uint NVDRS_PROFILE_VER = MAKE_NVAPI_VERSION(1); public const uint OGL_IMPLICIT_GPU_AFFINITY_NUM_VALUES = 1; @@ -549,11 +572,11 @@ namespace nspector.Native.NVAPI2 public static readonly DRS_GetNumProfilesDelegate DRS_GetNumProfiles; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate NvAPI_Status DRS_CreateApplicationDelegate(IntPtr hSession, IntPtr hProfile, ref NVDRS_APPLICATION_V3 pApplication); + public delegate NvAPI_Status DRS_CreateApplicationDelegate(IntPtr hSession, IntPtr hProfile, ref NVDRS_APPLICATION_V4 pApplication); public static readonly DRS_CreateApplicationDelegate DRS_CreateApplication; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate NvAPI_Status DRS_DeleteApplicationExDelegate(IntPtr hSession, IntPtr hProfile, ref NVDRS_APPLICATION_V3 pApp); + public delegate NvAPI_Status DRS_DeleteApplicationExDelegate(IntPtr hSession, IntPtr hProfile, ref NVDRS_APPLICATION_V4 pApp); public static readonly DRS_DeleteApplicationExDelegate DRS_DeleteApplicationEx; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -561,7 +584,7 @@ namespace nspector.Native.NVAPI2 public static readonly DRS_DeleteApplicationDelegate DRS_DeleteApplication; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate NvAPI_Status DRS_GetApplicationInfoDelegate(IntPtr hSession, IntPtr hProfile, [MarshalAs(UnmanagedType.LPWStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]StringBuilder appName, ref NVDRS_APPLICATION_V3 pApplication); + public delegate NvAPI_Status DRS_GetApplicationInfoDelegate(IntPtr hSession, IntPtr hProfile, [MarshalAs(UnmanagedType.LPWStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]StringBuilder appName, ref NVDRS_APPLICATION_V4 pApplication); public static readonly DRS_GetApplicationInfoDelegate DRS_GetApplicationInfo; [UnmanagedFunctionPointer(CallingConvention.Cdecl)] @@ -587,7 +610,7 @@ namespace nspector.Native.NVAPI2 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate NvAPI_Status DRS_FindApplicationByNameDelegate(IntPtr hSession, [MarshalAs(UnmanagedType.LPWStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]StringBuilder appName, ref IntPtr phProfile, ref NVDRS_APPLICATION_V3 pApplication); + public delegate NvAPI_Status DRS_FindApplicationByNameDelegate(IntPtr hSession, [MarshalAs(UnmanagedType.LPWStr, SizeConst = (int)NvapiDrsWrapper.NVAPI_UNICODE_STRING_MAX)]StringBuilder appName, ref IntPtr phProfile, ref NVDRS_APPLICATION_V4 pApplication); public static readonly DRS_FindApplicationByNameDelegate DRS_FindApplicationByName; public static NvAPI_Status DRS_SetSetting(IntPtr hSession, IntPtr hProfile, ref NVDRS_SETTING pSetting) diff --git a/nspector/frmDrvSettings.cs b/nspector/frmDrvSettings.cs index 890d794..329ead4 100644 --- a/nspector/frmDrvSettings.cs +++ b/nspector/frmDrvSettings.cs @@ -42,6 +42,8 @@ namespace nspector private bool isDevMode = false; + private Dictionary _groupCollapsedStates = new(); + protected override void WndProc(ref Message m) { switch (m.Msg) @@ -190,6 +192,8 @@ namespace nspector } } + ApplySearchFilter(); + lvSettings.EndUpdate(); GC.Collect(); @@ -209,7 +213,6 @@ namespace nspector } } } - } private void RefreshProfilesCombo() @@ -550,8 +553,6 @@ namespace nspector LoadGroupStates(Path.Combine(AppContext.BaseDirectory, "HiddenGroups.ini")); } - private Dictionary _groupCollapsedStates = new(); - private void lvSettings_GroupStateChanged(object sender, GroupStateChangedEventArgs e) { _groupCollapsedStates[e.Group.Header] = e.IsCollapsed; @@ -580,11 +581,11 @@ namespace nspector private bool LoadGroupStates(string filePath) { - _groupCollapsedStates.Clear(); - if (!File.Exists(filePath)) return false; + _groupCollapsedStates.Clear(); + try { foreach (var line in File.ReadAllLines(filePath)) @@ -707,8 +708,6 @@ namespace nspector DeleteSelectedValue(); else ResetSelectedValue(); - - ApplySearchFilter(); } ToolTip appPathsTooltip = new ToolTip() { InitialDelay = 250 }; @@ -921,8 +920,6 @@ namespace nspector catch { } StoreChangesOfProfileToDriver(); - - ApplySearchFilter(); } private void tsbBitValueEditor_Click(object sender, EventArgs e) @@ -1402,69 +1399,52 @@ namespace nspector else if (!e.Control && (e.KeyCode >= Keys.A && e.KeyCode <= Keys.Z || e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9 || e.KeyCode >= Keys.NumPad0 && e.KeyCode <= Keys.NumPad9 || - e.KeyCode == Keys.Space || e.KeyCode == Keys.OemPeriod)) + e.KeyCode == Keys.Space || e.KeyCode == Keys.OemPeriod || + e.KeyCode == Keys.Back)) { - txtFilter.Visible = true; txtFilter.Focus(); - txtFilter.Text += e.Shift ? e.KeyCode.ToString() : e.KeyCode.ToString().ToLower(); + if (e.KeyCode == Keys.Back) + { + if (txtFilter.Text.Length > 0) + { + txtFilter.Text = txtFilter.Text.Substring(0, txtFilter.Text.Length - 1); + } + } + else + { + txtFilter.Text += e.Shift ? e.KeyCode.ToString() : e.KeyCode.ToString().ToLower(); + } txtFilter.SelectionStart = txtFilter.Text.Length; e.SuppressKeyPress = true; e.Handled = true; } - } - private CancellationTokenSource cts; - - private void ApplySearchFilter(CancellationTokenSource cts = null) + private void ApplySearchFilter() { var lowerInput = txtFilter.Text.Trim().ToLowerInvariant(); - if (cts != null && cts.Token.IsCancellationRequested) return; - - Invoke(new Action(() => + if (string.IsNullOrEmpty(lowerInput)) { - RefreshCurrentProfile(); + return; + } - if (string.IsNullOrEmpty(lowerInput)) + lvSettings.BeginUpdate(); + foreach (ListViewItem itm in lvSettings.Items) + { + if (!itm.Text.ToLowerInvariant().Contains(lowerInput)) { - return; + itm.Remove(); } - - lvSettings.BeginUpdate(); - foreach (ListViewItem itm in lvSettings.Items) - { - if (!itm.Text.ToLowerInvariant().Contains(lowerInput)) - { - itm.Remove(); - } - } - lvSettings.EndUpdate(); - - txtFilter.Focus(); // Setting listbox sometimes steals focus away - })); + } + lvSettings.EndUpdate(); } private async void txtFilter_TextChanged(object sender, EventArgs e) { - cts?.Cancel(); - cts = new CancellationTokenSource(); + RefreshCurrentProfile(); - try - { - await Task.Delay(250, cts.Token); // search filter can be slow, wait for user to stop typing for ~250ms before we start refresh - - if (cts.Token.IsCancellationRequested) return; - - await Task.Run(() => - { - ApplySearchFilter(cts); - }); - } - catch (TaskCanceledException) - { - // Ignore cancellation - } + txtFilter.Focus(); // Setting listbox sometimes steals focus away } private void EnableDevmode()