mirror of
https://github.com/Orbmu2k/nvidiaProfileInspector.git
synced 2026-04-19 05:37:32 -04:00
Allow scanned setting values to use friendly names from XMLs
After merging from all sources, scanned entries that match a friendly-named entry are deduplicated, games it was found in are appended to the friendly-named entry and the scanned duplicate is removed. e.g. "8xS [Combined] (Mass Effect)" instead of both "8xS [Combined]" and "0x00000018 (Mass Effect)" appearing separately. Hoping there won't be any settings that have issues with this, but if there are we can always revert
This commit is contained in:
@@ -155,6 +155,13 @@ namespace nvidiaProfileInspector.Common
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool ValuesEqual<T>(T a, T b)
|
||||
{
|
||||
if (a is byte[] ba && b is byte[] bb)
|
||||
return ba.SequenceEqual(bb);
|
||||
return EqualityComparer<T>.Default.Equals(a, b);
|
||||
}
|
||||
|
||||
private List<SettingValue<T>> MergeSettingValues<T>(List<SettingValue<T>> a, List<SettingValue<T>> b)
|
||||
{
|
||||
if (b == null)
|
||||
@@ -170,12 +177,12 @@ namespace nvidiaProfileInspector.Common
|
||||
{
|
||||
var currentNonScannedValues = a.Where(xa => xa.ValueSource != SettingMetaSource.ScannedSettings).Select(xa => xa.Value).ToList();
|
||||
|
||||
var newNonScannedValues = b.Where(xb => !currentNonScannedValues.Contains(xb.Value)).ToList();
|
||||
var newNonScannedValues = b.Where(xb => !currentNonScannedValues.Any(cv => ValuesEqual(cv, xb.Value))).ToList();
|
||||
a.AddRange(newNonScannedValues);
|
||||
|
||||
foreach (var settingValue in a)
|
||||
{
|
||||
var bVal = b.FirstOrDefault(x => x.Value.Equals(settingValue.Value) && settingValue.ValueSource != SettingMetaSource.ScannedSettings);
|
||||
var bVal = b.FirstOrDefault(x => ValuesEqual(x.Value, settingValue.Value) && settingValue.ValueSource != SettingMetaSource.ScannedSettings);
|
||||
if (bVal != null && bVal.ValueName != null)
|
||||
{
|
||||
settingValue.ValueName = bVal.ValueName;
|
||||
@@ -192,6 +199,26 @@ namespace nvidiaProfileInspector.Common
|
||||
return a.ToList();
|
||||
}
|
||||
|
||||
private List<SettingValue<T>> DeduplicateScannedValues<T>(List<SettingValue<T>> values)
|
||||
{
|
||||
var scanned = values.Where(x => x.ValueSource == SettingMetaSource.ScannedSettings).ToList();
|
||||
foreach (var sc in scanned)
|
||||
{
|
||||
var match = values.FirstOrDefault(x => x.ValueSource != SettingMetaSource.ScannedSettings
|
||||
&& ValuesEqual(x.Value, sc.Value));
|
||||
if (match != null)
|
||||
{
|
||||
var scName = sc.ValueName ?? "";
|
||||
var parenIdx = scName.LastIndexOf(" (");
|
||||
if (parenIdx >= 0)
|
||||
match.ValueName = match.ValueName + scName.Substring(parenIdx);
|
||||
}
|
||||
}
|
||||
values.RemoveAll(x => x.ValueSource == SettingMetaSource.ScannedSettings
|
||||
&& values.Any(ns => ns.ValueSource != SettingMetaSource.ScannedSettings && ValuesEqual(ns.Value, x.Value)));
|
||||
return values;
|
||||
}
|
||||
|
||||
private List<SettingValue<byte[]>> GetBinaryValues(uint settingId)
|
||||
{
|
||||
var result = new List<SettingValue<byte[]>>();
|
||||
@@ -201,7 +228,7 @@ namespace nvidiaProfileInspector.Common
|
||||
result = MergeSettingValues(result, service.Service.GetBinaryValues(settingId));
|
||||
}
|
||||
|
||||
return result;
|
||||
return DeduplicateScannedValues(result);
|
||||
}
|
||||
|
||||
private List<SettingValue<string>> GetStringValues(uint settingId)
|
||||
@@ -213,7 +240,7 @@ namespace nvidiaProfileInspector.Common
|
||||
result = MergeSettingValues(result, service.Service.GetStringValues(settingId));
|
||||
}
|
||||
|
||||
return result;
|
||||
return DeduplicateScannedValues(result);
|
||||
}
|
||||
|
||||
private List<SettingValue<uint>> GetDwordValues(uint settingId)
|
||||
@@ -225,6 +252,8 @@ namespace nvidiaProfileInspector.Common
|
||||
result = MergeSettingValues(result, service.Service.GetDwordValues(settingId));
|
||||
}
|
||||
|
||||
result = DeduplicateScannedValues(result);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
result = (from v in result.Where(x => 1 == 1
|
||||
|
||||
@@ -90,10 +90,7 @@ namespace nvidiaProfileInspector.UI.ViewModels
|
||||
items.AddRange(BinaryValues.Where(v => !string.IsNullOrEmpty(v.ValueName))
|
||||
.Select(v => new SettingValueItem { ValueName = v.ValueName, Source = v.ValueSource }));
|
||||
}
|
||||
_cachedValueNameItems = items
|
||||
.OrderBy(v => v.Source == SettingMetaSource.CustomSettings ? 0 : 1)
|
||||
.ThenBy(v => v.Source == SettingMetaSource.ReferenceSettings ? 0 : 1)
|
||||
.ToList();
|
||||
_cachedValueNameItems = items;
|
||||
}
|
||||
return _cachedValueNameItems;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user