Skip to content

Commit

Permalink
Integrate single file exe
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Rhodes committed Feb 15, 2020
1 parent 72990a3 commit 654db89
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 45 deletions.
35 changes: 24 additions & 11 deletions SmartHunter/Core/Config/ConfigContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using SmartHunter.Ui.Windows;
using ErrorEventArgs = Newtonsoft.Json.Serialization.ErrorEventArgs;

namespace SmartHunter.Core.Config
Expand All @@ -28,15 +29,15 @@ public void HandleDeserializationError(object sender, ErrorEventArgs args)
Log.WriteException(args.ErrorContext.Error);
args.ErrorContext.Handled = true;
}

override protected void OnChanged()
{
Load();
}

void Load()
{
if (File.Exists(FullPathFileName))// && FileName.Equals("Config.json"))
if (File.Exists(FullPathFileName))
{
try
{
Expand All @@ -49,10 +50,12 @@ void Load()
}
}

var settings = new JsonSerializerSettings();
settings.Formatting = Formatting.Indented;
settings.ContractResolver = new ContractResolver();
settings.Error = HandleDeserializationError;
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ContractResolver = new ContractResolver(),
Error = HandleDeserializationError
};

// Solves dictionary/lists being added to instead of overwritten but causes problems elsewhere
// https://stackoverflow.com/questions/29113063/json-net-why-does-it-add-to-list-instead-of-overwriting
Expand Down Expand Up @@ -88,17 +91,27 @@ public void Save()

try
{
var settings = new JsonSerializerSettings();
settings.Formatting = Formatting.Indented;
settings.NullValueHandling = NullValueHandling.Ignore;
settings.ContractResolver = new ContractResolver();
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new ContractResolver()
};

settings.Converters.Add(new StringEnumConverter());
settings.Converters.Add(new StringFloatConverter());

var jsonString = JsonConvert.SerializeObject(Values, settings);

File.WriteAllText(FullPathFileName, jsonString);
using (var fileStream = new FileStream(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Write, 4096, FileOptions.None))
{
using var streamWriter = new StreamWriter(fileStream)
{
AutoFlush = true
};

streamWriter.Write(jsonString);
}

Log.WriteLine($"{FileName} saved");
}
Expand Down
5 changes: 5 additions & 0 deletions SmartHunter/Core/Helpers/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ public class Updater

public bool CheckForUpdates(bool forceCheck = false)
{
#if DEBUG

return false;
#endif

if (_needUpdates.Count == 0 || forceCheck == true)
{
try
Expand Down
71 changes: 37 additions & 34 deletions SmartHunter/SmartHunter.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<ProjectGuid>{F5F99CEF-1C16-48E6-A88B-1A66D3B53998}</ProjectGuid>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>false</Deterministic>
<LangVersion>latest</LangVersion>
<AssemblyTitle>SmartHunter</AssemblyTitle>
<Deterministic>false</Deterministic>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<OutputPath>bin\$(Configuration)</OutputPath>
<UseWPF>true</UseWPF>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<Target Name="PostBuild" BeforeTargets="PostBuildEvent">
<Exec Command="xcopy /E /Y &quot;$(ProjectDir)Ui\Resources&quot; &quot;$(TargetDir)&quot;" />
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>
<ItemGroup>
<Resource Include="Ui\Fonts\Roboto-Bold.ttf" />
<Resource Include="Ui\Fonts\Roboto-Medium.ttf" />
</ItemGroup>
</Project>
<PropertyGroup>
<ProjectGuid>{F5F99CEF-1C16-48E6-A88B-1A66D3B53998}</ProjectGuid>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>false</Deterministic>
<LangVersion>latest</LangVersion>
<AssemblyTitle>SmartHunter</AssemblyTitle>
<Deterministic>false</Deterministic>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<OutputPath>bin\$(Configuration)</OutputPath>
<UseWPF>true</UseWPF>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
</PropertyGroup>
<Target Name="PostBuild" BeforeTargets="PostBuildEvent">
<Exec Command="xcopy /E /Y &quot;$(ProjectDir)Ui\Resources&quot; &quot;$(TargetDir)&quot;"/>
</Target>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.1.0"/>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3"/>
</ItemGroup>
<ItemGroup>
<Resource Include="Ui\Fonts\Roboto-Bold.ttf"/>
<Resource Include="Ui\Fonts\Roboto-Medium.ttf"/>
</ItemGroup>
</Project>

0 comments on commit 654db89

Please sign in to comment.