Skip to content

Commit

Permalink
Merge pull request #22 from Drommedhar/logging
Browse files Browse the repository at this point in the history
# 2.0.5.1
* Write dump on unhandled crash
* Adjust logging for more readable information
  • Loading branch information
Drommedhar authored Nov 2, 2024
2 parents 21ebd09 + fa9517c commit 5aa8141
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 15 deletions.
78 changes: 76 additions & 2 deletions DlssUpdater/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
using System.IO;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Policy;
using System.Windows.Threading;
using AdonisUI.Controls;
using DlssUpdater.Helpers;
using DlssUpdater.Services;
using DlssUpdater.Singletons;
using DlssUpdater.Singletons.AntiCheatChecker;
Expand Down Expand Up @@ -101,11 +106,80 @@ private async void OnExit(object sender, ExitEventArgs e)
_host.Dispose();
}

const string ISSUE_BUTTON_ID = "GithubIssue";
/// <summary>
/// Occurs when an exception is thrown by an application but not handled.
/// </summary>
private void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
// For more info see https://docs.microsoft.com/en-us/dotnet/api/system.windows.application.dispatcherunhandledexception?view=windowsdesktop-6.0
var time = DateTime.UtcNow.ToString("s").Replace(":", ".");
var file = $"Dumps/{time}.dmp";
CreateMiniDump(file);

var messageBox = new MessageBoxModel
{
Caption = "Fatal error",
Text = $"Application has crashed unexpectedly. A dump file was created at '{file}'. Please provide this in your github issue (as a download link).\n" +
$"To open a new issue click the corresponding button below.",
Buttons = [
MessageBoxButtons.Ok(),
MessageBoxButtons.Custom("Open github issue", ISSUE_BUTTON_ID),
]
};

_ = AdonisUI.Controls.MessageBox.Show(messageBox);
if((string)messageBox.ButtonPressed.Id == ISSUE_BUTTON_ID)
{
var body = $"&body={Uri.EscapeDataString($"Encountered an unhandled exception: \n ```{e.Exception}```")}";
var labels = "&labels=exception";
var title = $"&title=Unhandled%20Exception - '{e.Exception.Message}'";
var url = $"https://github.com/Drommedhar/DlssUpdater/issues/new?assignees=&labels=bug&projects=&template=bug_report.md" +
$"{title}{labels}{body}";
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
}

e.Handled = true;
}

public static class MINIDUMP_TYPE
{
public const int MiniDumpNormal = 0x00000000;
public const int MiniDumpWithDataSegs = 0x00000001;
public const int MiniDumpWithFullMemory = 0x00000002;
public const int MiniDumpWithHandleData = 0x00000004;
public const int MiniDumpFilterMemory = 0x00000008;
public const int MiniDumpScanMemory = 0x00000010;
public const int MiniDumpWithUnloadedModules = 0x00000020;
public const int MiniDumpWithIndirectlyReferencedMemory = 0x00000040;
public const int MiniDumpFilterModulePaths = 0x00000080;
public const int MiniDumpWithProcessThreadData = 0x00000100;
public const int MiniDumpWithPrivateReadWriteMemory = 0x00000200;
public const int MiniDumpWithoutOptionalData = 0x00000400;
public const int MiniDumpWithFullMemoryInfo = 0x00000800;
public const int MiniDumpWithThreadInfo = 0x00001000;
public const int MiniDumpWithCodeSegs = 0x00002000;
}

[DllImport("dbghelp.dll")]
public static extern bool MiniDumpWriteDump(IntPtr hProcess,
Int32 ProcessId,
IntPtr hFile,
int DumpType,
IntPtr ExceptionParam,
IntPtr UserStreamParam,
IntPtr CallackParam);

private static void CreateMiniDump(string file)
{
DirectoryHelper.EnsureDirectoryExists("Dumps");
using FileStream fs = new(file, FileMode.Create);
using Process process = Process.GetCurrentProcess();
MiniDumpWriteDump(process.Handle,
process.Id,
fs.SafeFileHandle.DangerousGetHandle(),
MINIDUMP_TYPE.MiniDumpWithFullMemory,
IntPtr.Zero,
IntPtr.Zero,
IntPtr.Zero);
}
}
3 changes: 2 additions & 1 deletion DlssUpdater/DLSSUpdater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<SelfContained>true</SelfContained>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<SignAssembly>False</SignAssembly>
<AssemblyVersion>2.0.4.0</AssemblyVersion>
<AssemblyVersion>2.0.5.1</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -33,6 +33,7 @@
<PackageReference Include="AdonisUI.ClassicTheme" Version="1.17.1" />
<PackageReference Include="Microsoft.Security.Extensions" Version="1.3.0" />
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="System.Drawing.Common" Version="8.0.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.1" />
Expand Down
6 changes: 2 additions & 4 deletions DlssUpdater/Defines/GameInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class GameInfo : ObservableObject, IEquatable<GameInfo>
}
[ObservableProperty] public Visibility _removeVisible;

[JsonIgnore] public AntiCheatProvider AntiCheat;
[JsonIgnore] public AntiCheatProvider AntiCheat = AntiCheatProvider.None;

[ObservableProperty] [JsonIgnore] public GameInfo _self;

Expand Down Expand Up @@ -98,8 +98,6 @@ public GameInfo(string gameName, string gamePath, LibraryType type)
foreach (DllType dllType in Enum.GetValues(typeof(DllType))) InstalledDlls.Add(dllType, new InstalledPackage());

Self = this;
AntiCheat = App.GetService<AntiCheatChecker>()!.Check(gamePath);
SetAntiCheatImage();
_updater = App.GetService<DllUpdater>()!;
_logger = App.GetService<NLog.Logger>()!;
_libPage = App.GetService<LibraryPage>()!;
Expand Down Expand Up @@ -161,7 +159,7 @@ await Task.Run(() =>
foreach (var (dll, info) in InstalledDlls)
{
var allFiles = Directory.GetFiles(GamePath, GetDllName(dll), SearchOption.AllDirectories);
_logger.Debug($"Found '{allFiles?.Length.ToString() ?? "0"} files' for {GetDllName(dll)} in {GameName}");
//_logger.Debug($"Found '{allFiles?.Length.ToString() ?? "0"} files' for {GetDllName(dll)} in {GameName}");
if (allFiles is null || allFiles.Length == 0)
{
continue;
Expand Down
3 changes: 2 additions & 1 deletion DlssUpdater/GameLibrary/EpicGames/EpicGamesLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,12 @@ private async Task<List<GameInfo>> getGames()
await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
_logger.Debug($"EpicGames: '{info.GamePath}' has DLSS dll and is being added.");
ret.Add(info);
}
else
{
_logger.Debug($"EpicGames: '{info.GameName}' does not have any DLSS dll and is being ignored.");
_logger.Debug($"EpicGames: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
}
}
catch (Exception ex)
Expand Down
3 changes: 2 additions & 1 deletion DlssUpdater/GameLibrary/GOGLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ private async Task<List<GameInfo>> getGames()
await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
_logger.Debug($"GOG: '{info.GamePath}' has DLSS dll and is being added.");
ret.Add(info);
}
else
{
_logger.Debug($"GOG: '{info.GameName}' does not have any DLSS dll and is being ignored.");
_logger.Debug($"GOG: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
}
}
finally
Expand Down
8 changes: 6 additions & 2 deletions DlssUpdater/GameLibrary/Steam/SteamLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ private async Task<List<GameInfo>> getGames(List<LibraryFolder> folder)
}

await info.GatherInstalledVersions();
if (info.HasInstalledDlls()) return info;
if (info.HasInstalledDlls())
{
_logger.Debug($"Steam: '{info.GamePath}' has DLSS dll and is being added.");
return info;
}

_logger.Debug($"Steam: '{info.GameName}' does not have any DLSS dll and is being ignored.");
_logger.Debug($"Steam: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion DlssUpdater/GameLibrary/UbisoftConnectLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ private async Task<List<GameInfo>> getGames()
{
info.SetGameImageUri(imageUri);
}
_logger.Debug($"Ubisoft connect: '{info.GamePath}' has DLSS dll and is being added.");
ret.Add(info);
}
else
{
_logger.Debug($"Ubisoft connect: '{info.GameName}' does not have any DLSS dll and is being ignored.");
_logger.Debug($"Ubisoft connect: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
}
}
finally
Expand Down
3 changes: 2 additions & 1 deletion DlssUpdater/GameLibrary/XboxLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ private async Task<List<GameInfo>> getGames()
await info.GatherInstalledVersions();
if (info.HasInstalledDlls())
{
_logger.Debug($"Xbox: '{info.GamePath}' has DLSS dll and is being added.");
ret.Add(info);
}
else
{
_logger.Debug($"Xbox: '{info.GameName}' does not have any DLSS dll and is being ignored.");
_logger.Debug($"Xbox: '{info.GamePath}' does not have any DLSS dll and is being ignored.");
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion DlssUpdater/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 2.0.5.0
# 2.0.5.1
* Write dump on unhandled crash
* Adjust logging for more readable information

# 2.0.5.0
* Executable is now properly signed
* Splashscreen shows progress for each library
* Correctly remove games from library if they are no logner reported by launcher
Expand Down
2 changes: 1 addition & 1 deletion DlssUpdater/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2.0.5.0"
"version": "2.0.5.1"
}

0 comments on commit 5aa8141

Please sign in to comment.