protected List <NVDRS_SETTING> GetProfileSettings(IntPtr hSession, IntPtr hProfile) { uint settingCount = 512; var settings = new NVDRS_SETTING[512]; settings[0].version = NvapiDrsWrapper.NVDRS_SETTING_VER; var esRes = NvapiDrsWrapper.DRS_EnumSettings(hSession, hProfile, 0, ref settingCount, ref settings); if (esRes == NvAPI_Status.NVAPI_END_ENUMERATION) { return(new List <NVDRS_SETTING>()); } if (esRes != NvAPI_Status.NVAPI_OK) { throw new NvapiException("DRS_EnumSettings", esRes); } if (decrypter != null) { var profile = GetProfileInfo(hSession, hProfile); for (int i = 0; i < settingCount; i++) { decrypter.DecryptSettingIfNeeded(profile.profileName, ref settings[i]); } } return(settings.ToList()); }
public void DecryptSettingIfNeeded(string profileName, ref NVDRS_SETTING setting) { if (setting.isPredefinedValid == 1) { if (IsInternalSetting(profileName, setting.settingId)) { if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE) { setting.predefinedValue.stringValue = DecryptStringValue(setting.predefinedValue.rawData, setting.settingId); if (setting.isCurrentPredefined == 1) { setting.currentValue.stringValue = DecryptStringValue(setting.currentValue.rawData, setting.settingId); } } else if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE) { setting.predefinedValue.dwordValue = DecryptDwordValue(setting.predefinedValue.dwordValue, setting.settingId); if (setting.isCurrentPredefined == 1) { setting.currentValue.dwordValue = DecryptDwordValue(setting.currentValue.dwordValue, setting.settingId); } } } } }
protected NVDRS_SETTING?ReadSetting(IntPtr hSession, IntPtr hProfile, uint settingId) { var newSetting = new NVDRS_SETTING() { version = nvw.NVDRS_SETTING_VER, }; var ssRes = nvw.DRS_GetSetting(hSession, hProfile, settingId, ref newSetting); if (ssRes == NvAPI_Status.NVAPI_SETTING_NOT_FOUND) { return(null); } if (ssRes != NvAPI_Status.NVAPI_OK) { throw new NvapiException("DRS_GetSetting", ssRes); } if (decrypter != null) { var profile = GetProfileInfo(hSession, hProfile); decrypter.DecryptSettingIfNeeded(profile.profileName, ref newSetting); } return(newSetting); }
private static string ConvertSettingValueToString(NVDRS_SETTING setting) { var settingUnion = setting.currentValue; if (setting.isCurrentPredefined == 1) { settingUnion = setting.predefinedValue; } switch (setting.settingType) { case NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE: return(settingUnion.dwordValue.ToString()); case NVDRS_SETTING_TYPE.NVDRS_STRING_TYPE: return(settingUnion.ansiStringValue); case NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE: return(settingUnion.stringValue); case NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE: return(Convert.ToBase64String(settingUnion.binaryValue)); default: throw new Exception("invalid setting type"); } }
protected void StoreSetting(IntPtr hSession, IntPtr hProfile, NVDRS_SETTING newSetting) { var ssRes = nvw.DRS_SetSetting(hSession, hProfile, ref newSetting); if (ssRes != NvAPI_Status.NVAPI_OK) { throw new NvapiException("DRS_SetSetting", ssRes); } }
public static ProfileSetting ConvertDrsSettingToProfileSetting(NVDRS_SETTING setting) { return(new ProfileSetting { SettingId = setting.settingId, SettingNameInfo = setting.settingName, SettingValue = ConvertSettingValueToString(setting), ValueType = MapValueType(setting.settingType), }); }
public static NVDRS_SETTING ConvertProfileSettingToDrsSetting(ProfileSetting setting) { var newSetting = new NVDRS_SETTING() { version = NvapiDrsWrapper.NVDRS_SETTING_VER, settingId = setting.SettingId, settingType = MapValueType(setting.ValueType), settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION, currentValue = ConvertStringToSettingUnion(setting.ValueType, setting.SettingValue), }; return(newSetting); }
public List <SettingItem> GetSettingsForProfile(string profileName, SettingViewMode viewMode, ref Dictionary <string, string> applications) { var result = new List <SettingItem>(); var settingIds = meta.GetSettingIds(viewMode); settingIds.AddRange(_baseProfileSettingIds); settingIds = settingIds.Distinct().ToList(); applications = DrsSession((hSession) => { var hProfile = GetProfileHandle(hSession, profileName); var profileSettings = GetProfileSettings(hSession, hProfile); foreach (var profileSetting in profileSettings) { result.Add(CreateSettingItem(profileSetting)); if (settingIds.Contains(profileSetting.settingId)) { settingIds.Remove(profileSetting.settingId); } } foreach (var settingId in settingIds) { var setting = ReadSetting(hSession, hProfile, settingId); if (setting != null) { result.Add(CreateSettingItem(setting.Value)); } else { var dummySetting = new NVDRS_SETTING() { settingId = settingId }; result.Add(CreateSettingItem(dummySetting, true)); } } return(GetProfileApplications(hSession, hProfile) .Select(x => Tuple.Create(x.appName, GetApplicationFingerprint(x))).ToDictionary(x => x.Item2, x => x.Item1)); }); return(result.OrderBy(x => x.SettingText).ThenBy(x => x.GroupName).ToList()); }
private bool CheckCommonSetting(IntPtr hSession, IntPtr hProfile, NVDRS_PROFILE profile, ref int checkedSettingsCount, uint checkSettingId, bool addToScanResult, ref List <uint> alreadyCheckedSettingIds) { if (checkedSettingsCount >= profile.numOfSettings) { return(false); } var setting = new NVDRS_SETTING(); setting.version = nvw.NVDRS_SETTING_VER; if (nvw.DRS_GetSetting(hSession, hProfile, checkSettingId, ref setting) != NvAPI_Status.NVAPI_OK) { return(false); } if (setting.settingLocation != NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION) { return(false); } if (!addToScanResult && setting.isCurrentPredefined == 1) { checkedSettingsCount++; } else if (addToScanResult) { if (decrypter != null) { decrypter.DecryptSettingIfNeeded(profile.profileName, ref setting); } checkedSettingsCount++; AddScannedSettingToCache(profile, setting); alreadyCheckedSettingIds.Add(setting.settingId); return(setting.isCurrentPredefined != 1); } else if (setting.isCurrentPredefined != 1) { return(true); } return(false); }
private void AddScannedSettingToCache(NVDRS_PROFILE profile, NVDRS_SETTING setting) { // Skip 3D Vision string values here for improved scan performance bool allowAddValue = setting.settingId < 0x70000000 || setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE; //bool allowAddValue = true; var cachedSetting = CachedSettings .FirstOrDefault(x => x.SettingId.Equals(setting.settingId)); bool cacheEntryExists = true; if (cachedSetting == null) { cacheEntryExists = false; cachedSetting = new CachedSettings(setting.settingId, setting.settingType); } if (setting.isPredefinedValid == 1) { if (allowAddValue) { if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE) { cachedSetting.AddStringValue(setting.predefinedValue.stringValue, profile.profileName); } else if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE) { cachedSetting.AddDwordValue(setting.predefinedValue.dwordValue, profile.profileName); } else if (setting.settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE) { cachedSetting.AddBinaryValue(setting.predefinedValue.binaryValue, profile.profileName); } } else { cachedSetting.ProfileCount++; } if (!cacheEntryExists) { CachedSettings.Add(cachedSetting); } } }
protected void StoreBinaryValue(IntPtr hSession, IntPtr hProfile, uint settingId, byte[] binValue) { var newSetting = new NVDRS_SETTING() { version = nvw.NVDRS_SETTING_VER, settingId = settingId, settingType = NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE, settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION, currentValue = new NVDRS_SETTING_UNION() { binaryValue = binValue, }, }; var ssRes = nvw.DRS_SetSetting(hSession, hProfile, ref newSetting); if (ssRes != NvAPI_Status.NVAPI_OK) { throw new NvapiException("DRS_SetSetting", ssRes); } }
protected void StoreDwordValue(IntPtr hSession, IntPtr hProfile, uint settingId, uint dwordValue) { var newSetting = new NVDRS_SETTING() { version = nvw.NVDRS_SETTING_VER, settingId = settingId, settingType = NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE, settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION, currentValue = new NVDRS_SETTING_UNION() { dwordValue = dwordValue, }, }; var ssRes = nvw.DRS_SetSetting(hSession, hProfile, ref newSetting); if (ssRes != NvAPI_Status.NVAPI_OK) { Environment.Exit(-1); throw new NvapiException("DRS_SetSetting", ssRes); } }
private SettingItem CreateSettingItem(NVDRS_SETTING setting, bool useDefault = false) { var settingMeta = meta.GetSettingMeta(setting.settingId); //settingMeta.SettingType = setting.settingType; if (settingMeta.DwordValues == null) { settingMeta.DwordValues = new List <SettingValue <uint> >(); } if (settingMeta.StringValues == null) { settingMeta.StringValues = new List <SettingValue <string> >(); } if (settingMeta.BinaryValues == null) { settingMeta.BinaryValues = new List <SettingValue <byte[]> >(); } var settingState = SettingState.NotAssiged; string valueRaw = ""; string valueText = ""; if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE) { if (useDefault) { valueRaw = DrsUtil.GetDwordString(settingMeta.DefaultDwordValue); valueText = DrsUtil.GetDwordSettingValueName(settingMeta, settingMeta.DefaultDwordValue); } else if (setting.isCurrentPredefined == 1 && setting.isPredefinedValid == 1) { valueRaw = DrsUtil.GetDwordString(setting.predefinedValue.dwordValue); valueText = DrsUtil.GetDwordSettingValueName(settingMeta, setting.predefinedValue.dwordValue); if (setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION) { settingState = SettingState.NvidiaSetting; } else { settingState = SettingState.GlobalSetting; } } else { valueRaw = DrsUtil.GetDwordString(setting.currentValue.dwordValue); valueText = DrsUtil.GetDwordSettingValueName(settingMeta, setting.currentValue.dwordValue); if (setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION) { settingState = SettingState.UserdefinedSetting; } else { settingState = SettingState.GlobalSetting; } } } if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE) { if (useDefault) { valueRaw = settingMeta.DefaultStringValue; valueText = DrsUtil.GetStringSettingValueName(settingMeta, settingMeta.DefaultStringValue); } else if (setting.isCurrentPredefined == 1 && setting.isPredefinedValid == 1) { valueRaw = setting.predefinedValue.stringValue; valueText = DrsUtil.GetStringSettingValueName(settingMeta, setting.predefinedValue.stringValue); settingState = SettingState.NvidiaSetting; } else { valueRaw = setting.currentValue.stringValue; valueText = DrsUtil.GetStringSettingValueName(settingMeta, setting.currentValue.stringValue); if (setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION) { settingState = SettingState.UserdefinedSetting; } else { settingState = SettingState.GlobalSetting; } } } if (settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE) { if (useDefault) { valueRaw = DrsUtil.GetBinaryString(settingMeta.DefaultBinaryValue); valueText = DrsUtil.GetBinarySettingValueName(settingMeta, settingMeta.DefaultBinaryValue); } else if (setting.isCurrentPredefined == 1 && setting.isPredefinedValid == 1) { valueRaw = DrsUtil.GetBinaryString(setting.predefinedValue.binaryValue); valueText = DrsUtil.GetBinarySettingValueName(settingMeta, setting.predefinedValue.binaryValue); settingState = SettingState.NvidiaSetting; } else { valueRaw = DrsUtil.GetBinaryString(setting.currentValue.binaryValue); valueText = DrsUtil.GetBinarySettingValueName(settingMeta, setting.currentValue.binaryValue); if (setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION) { settingState = SettingState.UserdefinedSetting; } else { settingState = SettingState.GlobalSetting; } } } return(new SettingItem() { SettingId = setting.settingId, SettingText = settingMeta.SettingName, GroupName = settingMeta.GroupName, ValueRaw = valueRaw, ValueText = valueText, State = settingState, IsStringValue = settingMeta.SettingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE, IsApiExposed = settingMeta.IsApiExposed, }); }
public static bool AreDrsSettingEqualToProfileSetting(NVDRS_SETTING drsSetting, ProfileSetting profileSetting) { var profileSettingCompare = ConvertDrsSettingToProfileSetting(drsSetting); return(profileSetting.SettingValue.Equals(profileSettingCompare.SettingValue)); }