From f3b3e5ed89c7bc7780b22b480e1c3c11caa60eb6 Mon Sep 17 00:00:00 2001 From: s_falahati Date: Sat, 20 Oct 2018 03:43:40 +0330 Subject: [PATCH] Libraries updated + XmlSerializer replaced by JsonConvert --- .../HeliosDisplayManagement.Shared.csproj | 18 +++---- HeliosDisplayManagement.Shared/Profile.cs | 53 +++++++------------ .../packages.config | 1 + ...iosDisplayManagement.ShellExtension.csproj | 12 ++--- .../HeliosDisplayManagement.csproj | 21 +++----- HeliosDisplayManagement/Steam/SteamGame.cs | 33 +++--------- 6 files changed, 50 insertions(+), 88 deletions(-) diff --git a/HeliosDisplayManagement.Shared/HeliosDisplayManagement.Shared.csproj b/HeliosDisplayManagement.Shared/HeliosDisplayManagement.Shared.csproj index 625126d..9162f3d 100644 --- a/HeliosDisplayManagement.Shared/HeliosDisplayManagement.Shared.csproj +++ b/HeliosDisplayManagement.Shared/HeliosDisplayManagement.Shared.csproj @@ -32,17 +32,18 @@ 4 - - ..\packages\EDIDParser.1.1.6347.28506\lib\net45\EDIDParser.dll - True + + ..\packages\EDIDParser.1.2.0.1\lib\net45\EDIDParser.dll ..\packages\IconLib.Unofficial.0.73.0\lib\net20\IconLib.dll True - - ..\packages\NvAPIWrapper.Net.0.5.6315.41439\lib\net45\NvAPIWrapper.Net.dll - True + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + + ..\packages\NvAPIWrapper.Net.0.6.0.4\lib\net45\NvAPIWrapper.dll @@ -50,9 +51,8 @@ - - ..\packages\WindowsDisplayAPI.1.0.6336.17084\lib\net45\WindowsDisplayAPI.dll - True + + ..\packages\WindowsDisplayAPI.1.1.0.2\lib\net45\WindowsDisplayAPI.dll diff --git a/HeliosDisplayManagement.Shared/Profile.cs b/HeliosDisplayManagement.Shared/Profile.cs index 62801c9..20dce88 100644 --- a/HeliosDisplayManagement.Shared/Profile.cs +++ b/HeliosDisplayManagement.Shared/Profile.cs @@ -10,9 +10,11 @@ using System.Xml.Linq; using System.Xml.Serialization; using WindowsDisplayAPI.DisplayConfig; using HeliosDisplayManagement.Shared.Resources; +using Newtonsoft.Json; using NvAPIWrapper.GPU; using NvAPIWrapper.Mosaic; using NvAPIWrapper.Native.Mosaic; +using Formatting = Newtonsoft.Json.Formatting; using Path = HeliosDisplayManagement.Shared.Topology.Path; namespace HeliosDisplayManagement.Shared @@ -35,6 +37,7 @@ namespace HeliosDisplayManagement.Shared } } + [JsonIgnore] public bool IsActive { get @@ -45,6 +48,7 @@ namespace HeliosDisplayManagement.Shared } } + [JsonIgnore] public bool IsPossible { get @@ -96,9 +100,10 @@ namespace HeliosDisplayManagement.Shared public Path[] Paths { get; set; } = new Path[0]; public static string ProfilesPath - => - System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - Assembly.GetExecutingAssembly().GetName().Name, $"DisplayProfiles_{Version.ToString(2)}.xml"); + { + get => System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + Assembly.GetExecutingAssembly().GetName().Name, $"DisplayProfiles_{Version.ToString(2)}.json"); + } /// public bool Equals(Profile other) @@ -114,14 +119,10 @@ namespace HeliosDisplayManagement.Shared { if (File.Exists(ProfilesPath)) { - var xml = File.ReadAllText(ProfilesPath, Encoding.Unicode); - if (!string.IsNullOrWhiteSpace(xml)) + var json = File.ReadAllText(ProfilesPath, Encoding.Unicode); + if (!string.IsNullOrWhiteSpace(json)) { - var serializer = XmlSerializer.FromTypes(new[] {typeof(Profile[])})[0]; - using (var reader = XmlReader.Create(new StringReader(xml))) - { - return (Profile[]) serializer.Deserialize(reader); - } + return JsonConvert.DeserializeObject(json); } } } @@ -161,29 +162,14 @@ namespace HeliosDisplayManagement.Shared { try { - var serializer = XmlSerializer.FromTypes(new[] {typeof(Profile[])})[0]; - var sb = new StringBuilder(); - using (var writer = XmlWriter.Create(sb)) - { - serializer.Serialize(writer, array.ToArray()); - } - var xml = sb.ToString(); - try - { - var doc = XDocument.Parse(xml); - xml = doc.ToString(); - } - catch - { - // ignored - } - if (!string.IsNullOrWhiteSpace(xml)) + var json = JsonConvert.SerializeObject(array.ToArray(), Formatting.Indented); + if (!string.IsNullOrWhiteSpace(json)) { var dir = System.IO.Path.GetDirectoryName(ProfilesPath); if (dir != null) { Directory.CreateDirectory(dir); - File.WriteAllText(ProfilesPath, xml, Encoding.Unicode); + File.WriteAllText(ProfilesPath, json, Encoding.Unicode); return true; } } @@ -264,15 +250,14 @@ namespace HeliosDisplayManagement.Shared public Profile Clone() { - var serializer = XmlSerializer.FromTypes(new[] {typeof(Profile)})[0]; - var sb = new StringBuilder(); - using (var writer = XmlWriter.Create(sb)) + try { - serializer.Serialize(writer, this); + var serialized = JsonConvert.SerializeObject(this); + return JsonConvert.DeserializeObject(serialized); } - using (var reader = XmlReader.Create(new StringReader(sb.ToString()))) + catch { - return (Profile) serializer.Deserialize(reader); + return null; } } } diff --git a/HeliosDisplayManagement.Shared/packages.config b/HeliosDisplayManagement.Shared/packages.config index 4f26df6..52f0fb3 100644 --- a/HeliosDisplayManagement.Shared/packages.config +++ b/HeliosDisplayManagement.Shared/packages.config @@ -2,6 +2,7 @@ + \ No newline at end of file diff --git a/HeliosDisplayManagement.ShellExtension/HeliosDisplayManagement.ShellExtension.csproj b/HeliosDisplayManagement.ShellExtension/HeliosDisplayManagement.ShellExtension.csproj index ec5ff0e..ca43273 100644 --- a/HeliosDisplayManagement.ShellExtension/HeliosDisplayManagement.ShellExtension.csproj +++ b/HeliosDisplayManagement.ShellExtension/HeliosDisplayManagement.ShellExtension.csproj @@ -31,9 +31,11 @@ 4 - - ..\packages\SharpShellTools.2.2.0.0\lib\SharpShell.dll - True + + ..\packages\SharpShellTools.2.2.1\lib\Apex.WinForms.dll + + + ..\packages\SharpShellTools.2.2.1\lib\SharpShell.dll @@ -57,9 +59,6 @@ True - - - ResXFileCodeGenerator @@ -77,6 +76,7 @@ + diff --git a/HeliosDisplayManagement/HeliosDisplayManagement.csproj b/HeliosDisplayManagement/HeliosDisplayManagement.csproj index 11b25bb..27ca355 100644 --- a/HeliosDisplayManagement/HeliosDisplayManagement.csproj +++ b/HeliosDisplayManagement/HeliosDisplayManagement.csproj @@ -54,26 +54,22 @@ Icon.ico - - ..\packages\CircularProgressBar.2.5.6403.13419\lib\net35-client\CircularProgressBar.dll - True + + ..\packages\CircularProgressBar.2.6.6823.24527\lib\net35-client\CircularProgressBar.dll ..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll - True - - ..\packages\HtmlAgilityPack.1.5.1\lib\Net45\HtmlAgilityPack.dll - True + + ..\packages\HtmlAgilityPack.1.8.7\lib\Net45\HtmlAgilityPack.dll ..\packages\IconLib.Unofficial.0.73.0\lib\net20\IconLib.dll True - - ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - True + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll @@ -83,9 +79,8 @@ - - ..\packages\WindowsDisplayAPI.1.0.6336.17084\lib\net45\WindowsDisplayAPI.dll - True + + ..\packages\WindowsDisplayAPI.1.1.0.2\lib\net45\WindowsDisplayAPI.dll ..\packages\WinFormAnimation.1.5.6298.3372\lib\net35-client\WinFormAnimation.dll diff --git a/HeliosDisplayManagement/Steam/SteamGame.cs b/HeliosDisplayManagement/Steam/SteamGame.cs index a911156..bcf8d3e 100644 --- a/HeliosDisplayManagement/Steam/SteamGame.cs +++ b/HeliosDisplayManagement/Steam/SteamGame.cs @@ -40,7 +40,7 @@ namespace HeliosDisplayManagement.Steam public static string GameIdsPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - Assembly.GetExecutingAssembly().GetName().Name, @"SteamGames.xml"); + Assembly.GetExecutingAssembly().GetName().Name, @"SteamGames.json"); public static string IconCache => @@ -192,29 +192,14 @@ namespace HeliosDisplayManagement.Steam { try { - var serializer = new XmlSerializer(typeof(SteamAppIdNamePair[])); - var sb = new StringBuilder(); - using (var writer = XmlWriter.Create(sb)) - { - serializer.Serialize(writer, gameIds.ToArray()); - } - var xml = sb.ToString(); - try - { - var doc = XDocument.Parse(xml); - xml = doc.ToString(); - } - catch - { - // ignored - } - if (!string.IsNullOrWhiteSpace(xml)) + var json = JsonConvert.SerializeObject(gameIds); + if (!string.IsNullOrWhiteSpace(json)) { var dir = Path.GetDirectoryName(GameIdsPath); if (dir != null) { Directory.CreateDirectory(dir); - File.WriteAllText(GameIdsPath, xml, Encoding.Unicode); + File.WriteAllText(GameIdsPath, json, Encoding.Unicode); } } } @@ -230,14 +215,10 @@ namespace HeliosDisplayManagement.Steam { if (File.Exists(GameIdsPath)) { - var xml = File.ReadAllText(GameIdsPath, Encoding.Unicode); - if (!string.IsNullOrWhiteSpace(xml)) + var json = File.ReadAllText(GameIdsPath, Encoding.Unicode); + if (!string.IsNullOrWhiteSpace(json)) { - var serializer = new XmlSerializer(typeof(SteamAppIdNamePair[])); - using (var reader = XmlReader.Create(new StringReader(xml))) - { - return (SteamAppIdNamePair[]) serializer.Deserialize(reader); - } + return JsonConvert.DeserializeObject(json); } } }