From d98372bf391fc5d798ca8160afe02b8ba87b6cfa Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sat, 16 Oct 2021 09:37:52 +1300 Subject: [PATCH] Patch Profiles that are missing GDI settings This will ensure that existing display profiles will at least load. Anyone with refresh settings changes or BPC or other device context settings will need to recreate their display profiles. --- DisplayMagician/Properties/AssemblyInfo.cs | 4 +-- DisplayMagicianShared/ProfileRepository.cs | 32 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/DisplayMagician/Properties/AssemblyInfo.cs b/DisplayMagician/Properties/AssemblyInfo.cs index bb8088d..e88ca59 100644 --- a/DisplayMagician/Properties/AssemblyInfo.cs +++ b/DisplayMagician/Properties/AssemblyInfo.cs @@ -26,8 +26,8 @@ using System.Resources; [assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")] // Version information -[assembly: AssemblyVersion("2.0.1.127")] -[assembly: AssemblyFileVersion("2.0.1.127")] +[assembly: AssemblyVersion("2.0.1.129")] +[assembly: AssemblyFileVersion("2.0.1.129")] [assembly: NeutralResourcesLanguageAttribute( "en" )] [assembly: CLSCompliant(true)] diff --git a/DisplayMagicianShared/ProfileRepository.cs b/DisplayMagicianShared/ProfileRepository.cs index ec773a1..e036981 100644 --- a/DisplayMagicianShared/ProfileRepository.cs +++ b/DisplayMagicianShared/ProfileRepository.cs @@ -818,6 +818,7 @@ namespace DisplayMagicianShared JObject NVIDIADisplayConfig = (JObject)profile.SelectToken("NVIDIADisplayConfig"); NVIDIADisplayConfig.Add("ColorConfig",defaultColorConfig); changedJson = true; + SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Patched missing NVIDIA Color Config in profile {profile.SelectToken("Name")} (index {i})."); } } } @@ -830,6 +831,37 @@ namespace DisplayMagicianShared SharedLogger.logger.Error($"ProfileRepository/MigrateJsonToLatestVersion: Exception while trying to process the Profiles json data to migrate any older feature to the latest version."); } + // Now we try and add a default Windows GDI Device Context if there isn't one + try + { + SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Looking for missing Windows GDI Device Context."); + + // Create a default object + Dictionary GdiDisplaySettings = new Dictionary(); + JObject defaultGdiDisplaySettings = (JObject)JToken.FromObject(GdiDisplaySettings); + for (int i = 0; i < root.Count; i++) + { + JObject profile = (JObject)root[i]; + JObject result = (JObject)profile.SelectToken("WindowsDisplayConfig.GdiDisplaySettings"); + if (result == null) + { + + JObject WindowsDisplayConfig = (JObject)profile.SelectToken("WindowsDisplayConfig"); + WindowsDisplayConfig.Add("GdiDisplaySettings", defaultGdiDisplaySettings); + changedJson = true; + SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Patched missing Windows GDI Device Context in profile {profile.SelectToken("Name")} (index {i})."); + } + } + } + catch (JsonReaderException ex) + { + SharedLogger.logger.Error($"ProfileRepository/MigrateJsonToLatestVersion: JSONReaderException while trying to process the Profiles json data to migrate any older feature to the latest version."); + } + catch (Exception ex) + { + SharedLogger.logger.Error($"ProfileRepository/MigrateJsonToLatestVersion: Exception while trying to process the Profiles json data to migrate any older feature to the latest version."); + } + // Now write the changed json to the json string but only if we've changed something if (changedJson) {