// Token: 0x0600032E RID: 814 RVA: 0x00012254 File Offset: 0x00010454 private void SaveToRegistry(string objectXml) { Exception ex; IRegistryKey registryKey = Dependencies.RegistryKeyProvider.TryOpenKey(SharedHelper.AmRegKeyRoot, ref ex); if (ex != null) { throw ex; } if (registryKey != null) { using (registryKey) { registryKey.SetValue("LastKnownGoodConfig", objectXml, RegistryValueKind.String); } } }
public MareRegHandlerTests() { RegKeyFake = A.Fake <IRegistryKey>(); A.CallTo(() => RegKeyFake.GetSubKeyNames()).Returns(new string[] { "1" }); A.CallTo(() => RegKeyFake.GetValue("KMD_EnableInternalLargePage", null)).Returns(0); A.CallTo(() => RegKeyFake.GetValue("EnableCrossFireAutoLink", null)).Returns(0); A.CallTo(() => RegKeyFake.GetValue("EnableUlps", null)).Returns(0); A.CallTo(() => RegKeyFake.GetValue("DriverDesc", null)).Returns("FAKE_GPU"); A.CallTo(() => RegKeyFake.SetValue(A <string> .Ignored, A <object> .Ignored, A <RegistryValueKind> .Ignored)).DoesNothing(); A.CallTo(() => RegKeyFake.OpenSubKey(A <string> .Ignored, A <bool> .Ignored)).Returns(RegKeyFake); RegFake = A.Fake <IRegistry>(); A.CallTo(() => RegFake.OpenSubKey(A <string> .Ignored)).Returns(RegKeyFake); MsgBoxFake = A.Fake <IMessageBox>(); A.CallTo(() => MsgBoxFake.Show(A <string> .Ignored)).DoesNothing(); }
public Task <bool> Set(RegistrySettingGroup settingGroup, Values values) { using IRegistryKey? key = this.OpenKey(settingGroup.RootKeyName, settingGroup.KeyPath, true); if (key != null) { foreach ((Setting setting, object?value) in values) { // TODO: Infer value kind from the setting data type, or set it explicitly. RegistryValueKind valueKind = RegistryValueKind.Unknown;// RegistrySettingsHandler.GetValueKind(setting.DataType); key?.SetValue(setting.Name, value, valueKind); } } return(Task.FromResult(key != null)); }
private void RecurseCopyKey(IRegistryKey sourceKey, IRegistryKey destinationKey) { //copy all the values foreach (var valueName in sourceKey.GetValueNames()) { var objValue = sourceKey.GetValue(valueName); var valKind = sourceKey.GetValueKind(valueName); destinationKey.SetValue(valueName, objValue, valKind); } //For Each subKey //Create a new subKey in destinationKey //Call myself foreach (var sourceSubKeyName in sourceKey.GetSubKeyNames()) { var sourceSubKey = sourceKey.OpenSubKey(sourceSubKeyName); var destSubKey = destinationKey.CreateSubKey(sourceSubKeyName); RecurseCopyKey(sourceSubKey, destSubKey); } }
/// <summary> /// Saves the active changes to the current theme. /// /// This is needed to be performed before enabling high-contrast because when high-contrast is de-activated it /// loads the settings (such as the wallpaper) from the last used .theme file, rather than the applied settings. /// /// These means, any unsaved theme customisations will be lost. /// /// Theme files are described in https://docs.microsoft.com/en-us/windows/desktop/controls/themesfileformat-overview /// </summary> /// <param name="currentThemeFile"> /// The current theme file used by the OS. This will be used as a base to create a new theme file, and currently /// applied settings will be added to it.</param> /// <param name="saveAs">The file to write the saved theme to.</param> private async Task SaveCurrentTheme(string currentThemeFile, string saveAs) { this.logger.LogInformation($"Saving current theme, using {currentThemeFile}."); bool isValid = false; Dictionary <string, string>?themeData = null; try { // Read the .theme file that's currently being used. Ini themeReader = new(); await themeReader.ReadFile(currentThemeFile); themeData = themeReader.ReadData(); isValid = themeData.ContainsKey("MasterThemeSelector.MTSM"); } catch (IOException e) { this.logger.LogInformation(e, $"Unable to read {currentThemeFile}."); } if (!isValid || themeData is null) { string defaultTheme = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "resources\\Themes\\aero.theme"); if (currentThemeFile != defaultTheme) { // OBSERVATION: this code is re-entrant; also note that if the aero.theme file is corrupt...this might reenter infinitely until the stack was full await this.SaveCurrentTheme(defaultTheme, saveAs); } return; } else if (themeData.ContainsKey("VisualStyles.HighContrast")) { // Only save the current theme if it is not high-contrast. return; } using IRegistryKey hKeyCurrentUser = this.registry.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default); // Wallpaper using IRegistryKey desktopKey = hKeyCurrentUser.OpenSubKey(@"Control Panel\Desktop", false); themeData["Theme.DisplayName"] = "morphic"; themeData["Control Panel\\Desktop.Wallpaper"] = desktopKey.GetValue("WallPaper")?.ToString() ?? string.Empty; themeData["Control Panel\\Desktop.TileWallpaper"] = desktopKey.GetValue("TileWallPaper")?.ToString() ?? string.Empty; themeData["Control Panel\\Desktop.WallpaperStyle"] = desktopKey.GetValue("WallPaperStyle")?.ToString() ?? string.Empty; using IRegistryKey wallpapersKey = hKeyCurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\Wallpapers"); string?backgroundType = wallpapersKey.GetValue("backgroundType")?.ToString(); if (backgroundType != "2") { // It's not a slide-show, remove the entire section. themeData.Keys.Where(k => k.StartsWith("Slideshow")) .ToList() .ForEach(k => themeData.Remove(k)); } // Colours using IRegistryKey colorsKey = hKeyCurrentUser.OpenSubKey(@"Control Panel\Colors"); foreach (string valueName in colorsKey.GetValueNames()) { if (colorsKey.GetValue(valueName, null) is string value) { themeData[$"Control Panel\\Colors.{valueName}"] = value; } } // if the directory for the saveAs file doesn't exist, create it now var saveAsPath = Path.GetDirectoryName(saveAs); if (Directory.Exists(saveAsPath) == false) { Directory.CreateDirectory(saveAsPath); } Ini writer = new(); await writer.ReadFile(currentThemeFile); writer.WriteData(themeData !); await writer.WriteFile(saveAs); // Make windows use this theme file when restoring high-contrast. using IRegistryKey highContrastKey = hKeyCurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\HighContrast"); highContrastKey.SetValue("Pre-High Contrast Scheme", saveAs); }