Libraries updated + XmlSerializer replaced by JsonConvert

This commit is contained in:
s_falahati
2018-10-20 03:43:40 +03:30
parent 9b1291f44f
commit f3b3e5ed89
6 changed files with 50 additions and 88 deletions

View File

@ -32,17 +32,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="EDIDParser, Version=1.1.6347.28506, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EDIDParser.1.1.6347.28506\lib\net45\EDIDParser.dll</HintPath>
<Private>True</Private>
<Reference Include="EDIDParser, Version=1.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\EDIDParser.1.2.0.1\lib\net45\EDIDParser.dll</HintPath>
</Reference>
<Reference Include="IconLib, Version=0.73.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IconLib.Unofficial.0.73.0\lib\net20\IconLib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NvAPIWrapper.Net, Version=0.5.6315.41439, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NvAPIWrapper.Net.0.5.6315.41439\lib\net45\NvAPIWrapper.Net.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NvAPIWrapper, Version=0.6.0.3, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\NvAPIWrapper.Net.0.6.0.4\lib\net45\NvAPIWrapper.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -50,9 +51,8 @@
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="WindowsDisplayAPI, Version=1.0.6336.17084, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsDisplayAPI.1.0.6336.17084\lib\net45\WindowsDisplayAPI.dll</HintPath>
<Private>True</Private>
<Reference Include="WindowsDisplayAPI, Version=1.1.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsDisplayAPI.1.1.0.2\lib\net45\WindowsDisplayAPI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>

View File

@ -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");
}
/// <inheritdoc />
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<Profile[]>(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<Profile>(serialized);
}
using (var reader = XmlReader.Create(new StringReader(sb.ToString())))
catch
{
return (Profile) serializer.Deserialize(reader);
return null;
}
}
}

View File

@ -2,6 +2,7 @@
<packages>
<package id="EDIDParser" version="1.2.0.1" targetFramework="net45" />
<package id="IconLib.Unofficial" version="0.73.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="11.0.2" targetFramework="net45" />
<package id="NvAPIWrapper.Net" version="0.6.0.4" targetFramework="net45" />
<package id="WindowsDisplayAPI" version="1.1.0.2" targetFramework="net45" />
</packages>

View File

@ -31,9 +31,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="SharpShell, Version=2.2.0.0, Culture=neutral, PublicKeyToken=f14dc899472fe6fb, processorArchitecture=MSIL">
<HintPath>..\packages\SharpShellTools.2.2.0.0\lib\SharpShell.dll</HintPath>
<Private>True</Private>
<Reference Include="Apex.WinForms, Version=1.6.0.0, Culture=neutral, PublicKeyToken=98d06957926c086d, processorArchitecture=MSIL">
<HintPath>..\packages\SharpShellTools.2.2.1\lib\Apex.WinForms.dll</HintPath>
</Reference>
<Reference Include="SharpShell, Version=2.2.1.0, Culture=neutral, PublicKeyToken=f14dc899472fe6fb, processorArchitecture=MSIL">
<HintPath>..\packages\SharpShellTools.2.2.1\lib\SharpShell.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -57,9 +59,6 @@
<DesignTime>True</DesignTime>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@ -77,6 +76,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="Resources\Run_x16.png" />
<None Include="Resources\Shortcut_x16.png" />
<None Include="Resources\Edit_x16.png" />

View File

@ -54,26 +54,22 @@
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="CircularProgressBar, Version=2.5.6403.13419, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CircularProgressBar.2.5.6403.13419\lib\net35-client\CircularProgressBar.dll</HintPath>
<Private>True</Private>
<Reference Include="CircularProgressBar, Version=2.6.6823.24527, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CircularProgressBar.2.6.6823.24527\lib\net35-client\CircularProgressBar.dll</HintPath>
</Reference>
<Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
<HintPath>..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="HtmlAgilityPack, Version=1.5.1.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.5.1\lib\Net45\HtmlAgilityPack.dll</HintPath>
<Private>True</Private>
<Reference Include="HtmlAgilityPack, Version=1.8.7.0, Culture=neutral, PublicKeyToken=bd319b19eaf3b43a, processorArchitecture=MSIL">
<HintPath>..\packages\HtmlAgilityPack.1.8.7\lib\Net45\HtmlAgilityPack.dll</HintPath>
</Reference>
<Reference Include="IconLib, Version=0.73.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\IconLib.Unofficial.0.73.0\lib\net20\IconLib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
@ -83,9 +79,8 @@
<Reference Include="System.XML" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml.Serialization" />
<Reference Include="WindowsDisplayAPI, Version=1.0.6336.17084, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsDisplayAPI.1.0.6336.17084\lib\net45\WindowsDisplayAPI.dll</HintPath>
<Private>True</Private>
<Reference Include="WindowsDisplayAPI, Version=1.1.0.1, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WindowsDisplayAPI.1.1.0.2\lib\net45\WindowsDisplayAPI.dll</HintPath>
</Reference>
<Reference Include="WinFormAnimation, Version=1.5.6298.3372, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\WinFormAnimation.1.5.6298.3372\lib\net35-client\WinFormAnimation.dll</HintPath>

View File

@ -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<SteamAppIdNamePair[]>(json);
}
}
}