Skip to content

Commit

Permalink
Added exception handling, fixed missing DLLs
Browse files Browse the repository at this point in the history
  • Loading branch information
hlysine committed Oct 6, 2020
1 parent 28b75e4 commit 68f2156
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
3 changes: 2 additions & 1 deletion QuickDictionary/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:QuickDictionary"
StartupUri="MainWindow.xaml">
StartupUri="MainWindow.xaml"
Startup="Application_Startup">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down
40 changes: 40 additions & 0 deletions QuickDictionary/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -43,6 +44,45 @@ private void Application_Startup(object sender, StartupEventArgs e)
{
Current.Shutdown();
}

SetupExceptionHandling();
}

private void SetupExceptionHandling()
{
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
LogUnhandledException((Exception)e.ExceptionObject, "AppDomain.CurrentDomain.UnhandledException");

DispatcherUnhandledException += (s, e) =>
{
LogUnhandledException(e.Exception, "Application.Current.DispatcherUnhandledException");
e.Handled = true;
};

TaskScheduler.UnobservedTaskException += (s, e) =>
{
LogUnhandledException(e.Exception, "TaskScheduler.UnobservedTaskException");
e.SetObserved();
};
}

private void LogUnhandledException(Exception exception, string source)
{
StringBuilder message = new StringBuilder();
message.AppendLine($"Unhandled exception ({source})");
try
{
System.Reflection.AssemblyName assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName();
message.AppendLine($" in {assemblyName.Name} v{assemblyName.Version}");
}
catch (Exception ex)
{
}
message.AppendLine(exception.Message);
message.AppendLine(exception.StackTrace);
message.AppendLine();
message.AppendLine();
File.AppendAllText("log.txt", message.ToString());
}
}
}
2 changes: 1 addition & 1 deletion QuickDictionary/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private async void Window_SourceInitialized(object sender, EventArgs e)

using (var mgr = await UpdateManager.GitHubUpdateManager("https://github.com/Henry-YSLin/QuickDictionary"))
{
await mgr.UpdateApp((progress) => Dispatcher.Invoke(() => Title = title + $" - Updating {progress}%"));
await mgr.UpdateApp((progress) => Dispatcher.Invoke(() => Title = title + (progress > 95 ? "" : $" - Updating {progress}%")));
}
}

Expand Down
4 changes: 2 additions & 2 deletions QuickDictionary/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
27 changes: 27 additions & 0 deletions QuickDictionary/QuickDictionary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.1.0</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -217,6 +232,18 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion QuickDictionary/QuickDictionary.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<dependencies />
</metadata>
<files>
<file src="*.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*"/>
<file src="**.*" target="lib\net45\" exclude="*.pdb;*.nupkg;*.vshost.*;log.txt"/>
</files>
</package>

0 comments on commit 68f2156

Please sign in to comment.