Skip to content

Commit

Permalink
Remove Newtonsoft.Json as requirement to make it a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
PakL committed Aug 24, 2022
1 parent dfafbfd commit fe69587
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
33 changes: 27 additions & 6 deletions ProcessAffinityWatcher/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Windows.Forms;
using System.Diagnostics;
using System.Collections;
using Newtonsoft.Json;

namespace ProcessAffinityWatcher
{
Expand Down Expand Up @@ -211,17 +210,39 @@ private void ChkCPU_CheckedChanged(object sender, EventArgs e)
private Dictionary<string, int> GetAffinitySettings()
{
//Debug.WriteLine("Settings loaded: " + Properties.Settings.Default.AffinitySettings);
Dictionary<string, int> settings = JsonConvert.DeserializeObject<Dictionary<string, int>>(Properties.Settings.Default.AffinitySettings);
if (settings == null)

Dictionary<string, int> settings = new Dictionary<string, int>();
string s = Properties.Settings.Default.AffinitySettings;
if(s != null && s.Length > 0)
{
settings = new Dictionary<string, int>();
string[] parts = s.Split('\\');
foreach (string p in parts)
{
string[] processAffinity = p.Split(new char[1] { ':' }, 2);
if(processAffinity.Length == 2)
{
try
{
settings.Add(processAffinity[0], int.Parse(processAffinity[1]));
} catch { }
}
}
}

return settings;
}

private void SaveAffinitySettings(Dictionary<string, int> settings)
{
Properties.Settings.Default.AffinitySettings = JsonConvert.SerializeObject(settings);
string[] parts = new string[settings.Count];
int i = 0;
foreach(string key in settings.Keys)
{
parts[i] = key + ":" + settings[key];
i++;
}

Properties.Settings.Default.AffinitySettings = String.Join("\\", parts);
Properties.Settings.Default.Save();
}

Expand Down Expand Up @@ -351,7 +372,7 @@ private void MainForm_Resize(object sender, EventArgs e)

private void btnInfo_Click(object sender, EventArgs e)
{
MessageBox.Show("Created by Pakl (pakl.dev) under the MIT license.\nIncludes Newtonsoft.Json. JamesNK/Newtonsoft.Json is licensed under the MIT License.\n\nThe MIT License (MIT)\n\nProcessAffinityWatcher Copyright(c) 2022 Pascal Pohl\nNewtonsoft.Json Copyright(c) 2007 James Newton - King\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", "Product Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBox.Show("Created by Pakl (pakl.dev) under the MIT license.\n\nThe MIT License (MIT)\n\nCopyright(c) 2022 Pascal Pohl\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.", "Product Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}

Expand Down
Binary file removed ProcessAffinityWatcher/Newtonsoft.Json.dll
Binary file not shown.
5 changes: 0 additions & 5 deletions ProcessAffinityWatcher/ProcessAffinityWatcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@
<TargetZone>LocalIntranet</TargetZone>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -107,7 +104,6 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down Expand Up @@ -135,7 +131,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="cpuaffinity.ico" />
<EmbeddedResource Include="Newtonsoft.Json.dll" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
4 changes: 0 additions & 4 deletions ProcessAffinityWatcher/packages.config

This file was deleted.

0 comments on commit fe69587

Please sign in to comment.