private void UpdateSettings(IntPtr hSession, IntPtr hProfile, Profile importProfile, string profileName) { var alreadySet = new HashSet <uint>(); var settings = GetProfileSettings(hSession, hProfile); foreach (var setting in settings) { var isCurrentProfile = setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION; var isPredefined = setting.isCurrentPredefined == 1; if (isCurrentProfile) { bool exitsValueInImport = ExistsImportValue(setting.settingId, importProfile); var importSetting = GetImportProfileSetting(setting.settingId, importProfile); var decryptedSetting = setting; _DecrypterService.DecryptSettingIfNeeded(profileName, ref decryptedSetting); if (isPredefined && exitsValueInImport && ImportExportUitl.AreDrsSettingEqualToProfileSetting(decryptedSetting, importSetting)) { alreadySet.Add(setting.settingId); } else if (exitsValueInImport) { var updatedSetting = ImportExportUitl.ConvertProfileSettingToDrsSetting(importSetting); StoreSetting(hSession, hProfile, updatedSetting); alreadySet.Add(setting.settingId); } else if (!isPredefined) { nvw.DRS_DeleteProfileSetting(hSession, hProfile, setting.settingId); } } } foreach (var setting in importProfile.Settings) { if (!alreadySet.Contains(setting.SettingId)) { var newSetting = ImportExportUitl.ConvertProfileSettingToDrsSetting(setting); try { StoreSetting(hSession, hProfile, newSetting); } catch (NvapiException ex) { if (ex.Status != NvAPI_Status.NVAPI_SETTING_NOT_FOUND) { throw; } } } } }
private Profile CreateProfileForExport(IntPtr hSession, string profileName, bool includePredefined) { var result = new Profile(); var hProfile = GetProfileHandle(hSession, profileName); if (hProfile != IntPtr.Zero) { result.ProfileName = profileName; var apps = GetProfileApplications(hSession, hProfile); foreach (var app in apps) { result.Executeables.Add(app.appName); } var settings = GetProfileSettings(hSession, hProfile); foreach (var setting in settings) { var isPredefined = setting.isCurrentPredefined == 1; var isCurrentProfile = setting.settingLocation == NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION; if (isCurrentProfile && (!isPredefined || includePredefined)) { var exportSetting = setting; _DecrypterService.DecryptSettingIfNeeded(profileName, ref exportSetting); var profileSetting = ImportExportUitl .ConvertDrsSettingToProfileSetting(exportSetting); result.Settings.Add(profileSetting); } } } return(result); }