Skip to content

Commit 78eda31

Browse files
committed
Newtonsoft.Json dependency removed (smaller .exe file)
1 parent 4e17baa commit 78eda31

6 files changed

Lines changed: 54 additions & 45 deletions

File tree

OpenHardwareMonitor.csproj

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
3-
<Import Project="..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props" Condition="Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" />
43
<PropertyGroup>
54
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
65
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -10,7 +9,7 @@
109
<OutputType>WinExe</OutputType>
1110
<NoStandardLibraries>false</NoStandardLibraries>
1211
<AssemblyName>OpenHardwareMonitor</AssemblyName>
13-
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1413
<FileAlignment>512</FileAlignment>
1514
<RootNamespace>OpenHardwareMonitor</RootNamespace>
1615
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
@@ -66,17 +65,12 @@
6665
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
6766
</PropertyGroup>
6867
<ItemGroup>
69-
<Reference Include="Costura, Version=4.1.0.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
70-
<HintPath>..\packages\Costura.Fody.4.1.0\lib\net40\Costura.dll</HintPath>
71-
</Reference>
72-
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
73-
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
74-
</Reference>
7568
<Reference Include="System" />
7669
<Reference Include="System.Configuration.Install" />
7770
<Reference Include="System.Design" />
7871
<Reference Include="System.Drawing" />
7972
<Reference Include="System.Management" />
73+
<Reference Include="System.Web.Extensions" />
8074
<Reference Include="System.Windows.Forms" />
8175
<Reference Include="System.Xml" />
8276
</ItemGroup>
@@ -352,6 +346,7 @@
352346
<Compile Include="GUI\SensorNode.cs" />
353347
<Compile Include="Utilities\EmbeddedResources.cs" />
354348
<Compile Include="Utilities\IconFactory.cs" />
349+
<Compile Include="Utilities\SerializerHelper.cs" />
355350
<Compile Include="Utilities\SystemTools.cs" />
356351
<Compile Include="Utilities\Updater.cs" />
357352
<Compile Include="WMI\Hardware.cs" />
@@ -398,7 +393,6 @@
398393
<EmbeddedResource Include="Hardware\WinRing0x64.sys" />
399394
<None Include="Controls\Tree\ClassDiagram.cd" />
400395
<None Include="Controls\Tree\NodeControls\ClassDiagram.cd" />
401-
<None Include="packages.config" />
402396
<None Include="Resources\app.manifest">
403397
<SubType>Designer</SubType>
404398
</None>
@@ -525,12 +519,4 @@
525519
</PostBuildEventDependsOn>
526520
<PostBuildEvent>rem echo @(VersionNumber) &gt; ..\version.txt</PostBuildEvent>
527521
</PropertyGroup>
528-
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
529-
<PropertyGroup>
530-
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
531-
</PropertyGroup>
532-
<Error Condition="!Exists('..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.4.1.0\build\Costura.Fody.props'))" />
533-
<Error Condition="!Exists('..\packages\Fody.6.6.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.6.6.3\build\Fody.targets'))" />
534-
</Target>
535-
<Import Project="..\packages\Fody.6.6.3\build\Fody.targets" Condition="Exists('..\packages\Fody.6.6.3\build\Fody.targets')" />
536522
</Project>

Properties/Resources.Designer.cs

Lines changed: 19 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Utilities/PersistentSettings.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.IO;
66
using System.Text;
77
using System.Xml;
8-
using Newtonsoft.Json;
98
using OpenHardwareMonitor.Hardware;
109

1110
namespace OpenHardwareMonitor {
@@ -18,7 +17,7 @@ public void Load(string fileName) {
1817
if (!File.Exists(fileName)) return;
1918
try {
2019
var json = File.ReadAllText(fileName);
21-
settings = JsonConvert.DeserializeObject<IDictionary<string, string>>(json);
20+
settings = json.FromJson<IDictionary<string, string>>();
2221
}
2322
catch (Exception) {
2423
LoadOld(fileName);
@@ -66,8 +65,7 @@ public void LoadOld(string fileName) {
6665
}
6766

6867
public void Save(string fileName) {
69-
var json = JsonConvert.SerializeObject(settings, Newtonsoft.Json.Formatting.Indented);
70-
File.WriteAllText(fileName, json);
68+
settings.ToJsonFile(fileName);
7169
}
7270

7371
public void SaveOld(string fileName) {

Utilities/SerializerHelper.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.IO;
2+
using System.Web.Script.Serialization;
3+
4+
namespace OpenHardwareMonitor {
5+
6+
public static class SerializerHelper {
7+
8+
internal static string ToJson(this object value) {
9+
var serializer = new JavaScriptSerializer();
10+
return serializer.Serialize(value);
11+
}
12+
13+
internal static T FromJson<T>(this string json) {
14+
var serializer = new JavaScriptSerializer();
15+
return serializer.Deserialize<T>(json);
16+
}
17+
18+
public static void ToJsonFile(this object value, string filePath) {
19+
File.WriteAllText(filePath, value.ToJson());
20+
}
21+
22+
public static T ReadJsonFile<T>(string fileName) where T : class {
23+
T result = null;
24+
if (File.Exists(fileName))
25+
result = File.ReadAllText(fileName).FromJson<T>();
26+
return result;
27+
}
28+
}
29+
}

Utilities/Updater.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Reflection;
66
using System.Text;
77
using System.Windows.Forms;
8-
using Newtonsoft.Json;
98

109
namespace OpenHardwareMonitor.Utilities {
1110

@@ -75,7 +74,7 @@ internal static void CheckForUpdates(bool silent) {
7574
//newVersionUrl = $"https://github.com/{GithubLandingPage}/releases/download/{newVersion}/{selfFileName}";
7675

7776
var jsonString = GetJsonData($"https://api.github.com/repos/{GITHUB_LANDING_PAGE}/releases").TrimEnd();
78-
var releases = JsonConvert.DeserializeObject<GitHubRelease[]>(jsonString);
77+
var releases = jsonString.FromJson<GitHubRelease[]>();
7978
if (releases == null || releases.Length == 0)
8079
throw new Exception("Error getting list of releases.");
8180

packages.config

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)