mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Fixed broken apply profile logic
Changed an AND to a NAND and now it works.
This commit is contained in:
parent
8d060edf83
commit
c5b06988dd
@ -26,8 +26,8 @@ using System.Resources;
|
||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||
|
||||
// Version information
|
||||
[assembly: AssemblyVersion("2.0.1.75")]
|
||||
[assembly: AssemblyFileVersion("2.0.1.75")]
|
||||
[assembly: AssemblyVersion("2.0.1.89")]
|
||||
[assembly: AssemblyFileVersion("2.0.1.89")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
|
@ -402,15 +402,27 @@ namespace DisplayMagician
|
||||
#pragma warning disable IDE0059 // Unnecessary assignment of a value
|
||||
List<ShortcutItem> shortcuts = new List<ShortcutItem>();
|
||||
#pragma warning restore IDE0059 // Unnecessary assignment of a value
|
||||
|
||||
List<string> jsonErrors = new List<string>();
|
||||
try
|
||||
{
|
||||
_allShortcuts = JsonConvert.DeserializeObject<List<ShortcutItem>>(json, new JsonSerializerSettings
|
||||
|
||||
|
||||
JsonSerializerSettings mySerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Include,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
|
||||
{
|
||||
jsonErrors.Add($"JSON.net Error: {args.ErrorContext.Error.Source}:{args.ErrorContext.Error.StackTrace} - {args.ErrorContext.Error.Message} | InnerException:{args.ErrorContext.Error.InnerException.Source}:{args.ErrorContext.Error.InnerException.StackTrace} - {args.ErrorContext.Error.InnerException.Message}");
|
||||
args.ErrorContext.Handled = true;
|
||||
},
|
||||
};
|
||||
|
||||
_allShortcuts = JsonConvert.DeserializeObject<List<ShortcutItem>>(json, mySerializerSettings);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -418,6 +430,15 @@ namespace DisplayMagician
|
||||
throw new Exception("ShortcutRepository/LoadShortcuts: Tried to parse the JSON in the {_shortcutStorageJsonFileName} but the JsonConvert threw an exception. There is an error in the SHortcut JSON file!");
|
||||
}
|
||||
|
||||
// If we have any JSON.net errors, then we need to records them in the logs
|
||||
if (jsonErrors.Count > 0)
|
||||
{
|
||||
foreach (string jsonError in jsonErrors)
|
||||
{
|
||||
logger.Error($"ShortcutRepository/LoadShortcuts: {jsonErrors}");
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup all the Profile Names in the Saved Profiles
|
||||
// and link the profiles to the Shortcuts as we only
|
||||
// store the profile names to allow users to uodate profiles
|
||||
@ -499,17 +520,24 @@ namespace DisplayMagician
|
||||
}
|
||||
|
||||
|
||||
List<string> jsonErrors = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
logger.Debug($"ShortcutRepository/SaveShortcuts: Converting the objects to JSON format.");
|
||||
|
||||
var json = JsonConvert.SerializeObject(_allShortcuts, Formatting.Indented, new JsonSerializerSettings
|
||||
JsonSerializerSettings mySerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Include,
|
||||
DefaultValueHandling = DefaultValueHandling.Populate,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
|
||||
});
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
|
||||
{
|
||||
jsonErrors.Add($"JSON.net Error: {args.ErrorContext.Error.Source}:{args.ErrorContext.Error.StackTrace} - {args.ErrorContext.Error.Message} | InnerException:{args.ErrorContext.Error.InnerException.Source}:{args.ErrorContext.Error.InnerException.StackTrace} - {args.ErrorContext.Error.InnerException.Message}");
|
||||
args.ErrorContext.Handled = true;
|
||||
},
|
||||
};
|
||||
var json = JsonConvert.SerializeObject(_allShortcuts, Formatting.Indented, mySerializerSettings);
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
@ -525,6 +553,15 @@ namespace DisplayMagician
|
||||
logger.Error(ex, $"ShortcutRepository/SaveShortcuts: Unable to save the shortcut repository to the {_shortcutStorageJsonFileName}.");
|
||||
}
|
||||
|
||||
// If we have any JSON.net errors, then we need to records them in the logs
|
||||
if (jsonErrors.Count > 0)
|
||||
{
|
||||
foreach (string jsonError in jsonErrors)
|
||||
{
|
||||
logger.Error($"ProfileRepository/SaveProfiles: {jsonErrors}");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -681,7 +681,7 @@ namespace DisplayMagicianShared
|
||||
WinLibrary winLibrary = WinLibrary.GetLibrary();
|
||||
if (nvidiaLibrary.IsInstalled)
|
||||
{
|
||||
if (!nvidiaLibrary.IsActiveConfig(_nvidiaDisplayConfig) && !winLibrary.IsActiveConfig(_windowsDisplayConfig))
|
||||
if (!(nvidiaLibrary.IsActiveConfig(_nvidiaDisplayConfig) && winLibrary.IsActiveConfig(_windowsDisplayConfig)))
|
||||
{
|
||||
if (nvidiaLibrary.IsPossibleConfig(_nvidiaDisplayConfig))
|
||||
{
|
||||
@ -742,7 +742,7 @@ namespace DisplayMagicianShared
|
||||
WinLibrary winLibrary = WinLibrary.GetLibrary();
|
||||
if (amdLibrary.IsInstalled)
|
||||
{
|
||||
if (!amdLibrary.IsActiveConfig(_amdDisplayConfig) && !winLibrary.IsActiveConfig(_windowsDisplayConfig))
|
||||
if (!(amdLibrary.IsActiveConfig(_amdDisplayConfig) && winLibrary.IsActiveConfig(_windowsDisplayConfig)))
|
||||
{
|
||||
if (amdLibrary.IsPossibleConfig(_amdDisplayConfig))
|
||||
{
|
||||
@ -1542,6 +1542,7 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
return (Name ?? Language.UN_TITLED_PROFILE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ using DisplayMagicianShared.AMD;
|
||||
using DisplayMagicianShared.NVIDIA;
|
||||
using DisplayMagicianShared.Windows;
|
||||
using System.Runtime.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace DisplayMagicianShared
|
||||
{
|
||||
@ -693,11 +694,17 @@ namespace DisplayMagicianShared
|
||||
SharedLogger.logger.Error(ex, $"ProfileRepository/LoadProfiles: Tried to read the JSON file {_profileStorageJsonFileName} to memory but File.ReadAllTextthrew an exception.");
|
||||
}
|
||||
|
||||
// Migrate any previous entries to the latest version of the file format to the latest one
|
||||
json = MigrateJsonToLatestVersion(json);
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
List<string> jsonErrors = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
_allProfiles = JsonConvert.DeserializeObject<List<ProfileItem>>(json, new JsonSerializerSettings
|
||||
JsonSerializerSettings mySerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
MissingMemberHandling = MissingMemberHandling.Error,
|
||||
NullValueHandling = NullValueHandling.Include,
|
||||
@ -706,13 +713,33 @@ namespace DisplayMagicianShared
|
||||
//DefaultValueHandling = DefaultValueHandling.Ignore,
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
||||
});
|
||||
|
||||
Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
|
||||
{
|
||||
jsonErrors.Add($"JSON.net Error: {args.ErrorContext.Error.Source}:{args.ErrorContext.Error.StackTrace} - {args.ErrorContext.Error.Message} | InnerException:{args.ErrorContext.Error.InnerException.Source}:{args.ErrorContext.Error.InnerException.StackTrace} - {args.ErrorContext.Error.InnerException.Message}");
|
||||
args.ErrorContext.Handled = true;
|
||||
},
|
||||
};
|
||||
_allProfiles = JsonConvert.DeserializeObject<List<ProfileItem>>(json, mySerializerSettings);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SharedLogger.logger.Error(ex, $"ProfileRepository/LoadProfiles: Tried to parse the JSON in the {_profileStorageJsonFileName} but the JsonConvert threw an exception.");
|
||||
}
|
||||
|
||||
// If we have any JSON.net errors, then we need to records them in the logs
|
||||
if (jsonErrors.Count > 0)
|
||||
{
|
||||
foreach (string jsonError in jsonErrors)
|
||||
{
|
||||
SharedLogger.logger.Error($"ProfileRepository/LoadProfiles: {jsonErrors}");
|
||||
}
|
||||
}
|
||||
|
||||
// We need to try and
|
||||
|
||||
|
||||
SharedLogger.logger.Debug($"ProfileRepository/LoadProfiles: Finding the current profile in the Profile Repository");
|
||||
|
||||
// Go through all the profiles and set up the needed structures (such as the Screens list)
|
||||
@ -749,6 +776,68 @@ namespace DisplayMagicianShared
|
||||
IsPossibleRefresh();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string MigrateJsonToLatestVersion(string json)
|
||||
{
|
||||
|
||||
bool changedJson = false;
|
||||
JArray root = new JArray();
|
||||
try
|
||||
{
|
||||
SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Processing the Profiles json data to migrate any older feature to the latest version.");
|
||||
root = JArray.Parse(json);
|
||||
}
|
||||
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 we try and add a default NVIDIA Color Settings if there isn't one
|
||||
try
|
||||
{
|
||||
SharedLogger.logger.Trace($"ProfileRepository/MigrateJsonToLatestVersion: Looking for missing NVIDIA Color Config.");
|
||||
|
||||
// Create a default object
|
||||
NVIDIA_DISPLAY_CONFIG myDefaultConfig = new NVIDIA_DISPLAY_CONFIG();
|
||||
myDefaultConfig.ColorConfig.ColorData = new Dictionary<uint, NV_COLOR_DATA_V5>();
|
||||
JObject defaultColorConfig = (JObject)JToken.FromObject(myDefaultConfig.ColorConfig);
|
||||
|
||||
for (int i=0; i < root.Count; i++)
|
||||
{
|
||||
JObject profile = (JObject)root[i];
|
||||
JObject result = (JObject)profile.SelectToken("NVIDIADisplayConfig.ColorConfig.ColorData");
|
||||
if (result == null)
|
||||
{
|
||||
|
||||
JObject NVIDIADisplayConfig = (JObject)profile.SelectToken("NVIDIADisplayConfig");
|
||||
NVIDIADisplayConfig.Add("ColorConfig",defaultColorConfig);
|
||||
changedJson = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
json = root.ToString(Formatting.Indented);
|
||||
}
|
||||
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static bool SaveProfiles()
|
||||
@ -782,11 +871,14 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
SharedLogger.logger.Debug($"ProfileRepository/SaveProfiles: Profiles folder {AppProfileStoragePath} exists.");
|
||||
}
|
||||
|
||||
List<string> jsonErrors = new List<string>();
|
||||
|
||||
try
|
||||
{
|
||||
SharedLogger.logger.Debug($"ProfileRepository/SaveProfiles: Converting the objects to JSON format.");
|
||||
|
||||
var json = JsonConvert.SerializeObject(_allProfiles, Formatting.Indented, new JsonSerializerSettings
|
||||
JsonSerializerSettings mySerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Include,
|
||||
//NullValueHandling = NullValueHandling.Ignore,
|
||||
@ -795,7 +887,13 @@ namespace DisplayMagicianShared
|
||||
TypeNameHandling = TypeNameHandling.Auto,
|
||||
MissingMemberHandling = MissingMemberHandling.Error,
|
||||
ObjectCreationHandling = ObjectCreationHandling.Replace,
|
||||
});
|
||||
Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
|
||||
{
|
||||
jsonErrors.Add($"JSON.net Error: {args.ErrorContext.Error.Source}:{args.ErrorContext.Error.StackTrace} - {args.ErrorContext.Error.Message} | InnerException:{args.ErrorContext.Error.InnerException.Source}:{args.ErrorContext.Error.InnerException.StackTrace} - {args.ErrorContext.Error.InnerException.Message}");
|
||||
args.ErrorContext.Handled = true;
|
||||
},
|
||||
};
|
||||
var json = JsonConvert.SerializeObject(_allProfiles, Formatting.Indented, mySerializerSettings);
|
||||
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
@ -811,6 +909,15 @@ namespace DisplayMagicianShared
|
||||
SharedLogger.logger.Error(ex, $"ProfileRepository/SaveProfiles: Unable to save the profile repository to the {_profileStorageJsonFileName}.");
|
||||
}
|
||||
|
||||
// If we have any JSON.net errors, then we need to records them in the logs
|
||||
if (jsonErrors.Count > 0)
|
||||
{
|
||||
foreach (string jsonError in jsonErrors)
|
||||
{
|
||||
SharedLogger.logger.Error($"ProfileRepository/SaveProfiles: {jsonErrors}");
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user