public int StoreSettingsToProfile(string profileName, List <KeyValuePair <uint, string> > settings) { DrsSession((hSession) => { var hProfile = GetProfileHandle(hSession, profileName); foreach (var setting in settings) { var settingMeta = meta.GetSettingMeta(setting.Key); var settingType = settingMeta.SettingType; if (settingType == NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE) { var dword = DrsUtil.ParseDwordSettingValue(settingMeta, setting.Value); StoreDwordValue(hSession, hProfile, setting.Key, dword); } else if (settingType == NVDRS_SETTING_TYPE.NVDRS_WSTRING_TYPE) { var str = DrsUtil.ParseStringSettingValue(settingMeta, setting.Value); StoreStringValue(hSession, hProfile, setting.Key, str); } else if (settingType == NVDRS_SETTING_TYPE.NVDRS_BINARY_TYPE) { var bin = DrsUtil.ParseBinarySettingValue(settingMeta, setting.Value); StoreBinaryValue(hSession, hProfile, setting.Key, bin); } } SaveSettings(hSession); }); return(0); }
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, }); }