mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2025-12-05 20:39:59 -08:00
Fix Windows Crash Reporter (#5493)
* Fix Windows Crash Reporter * Fix NSIS template
This commit is contained in:
@@ -238,7 +238,7 @@ ${If} $PortableMode = 0
|
|||||||
|
|
||||||
; Enable Windows User-Mode Dumps
|
; Enable Windows User-Mode Dumps
|
||||||
; https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps
|
; https://learn.microsoft.com/en-us/windows/win32/wer/collecting-user-mode-dumps
|
||||||
WriteRegStr HKLM "Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\cockatrice.exe" "DumpFolder" "%LOCALAPPDATA%\CrashDumps\Cockatrice"
|
WriteRegExpandStr HKLM "Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\cockatrice.exe" "DumpFolder" "%LOCALAPPDATA%\CrashDumps\Cockatrice"
|
||||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\cockatrice.exe" "DumpCount" "5"
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\cockatrice.exe" "DumpCount" "5"
|
||||||
WriteRegDWORD HKLM "Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\cockatrice.exe" "DumpType" "2"
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\Windows Error Reporting\LocalDumps\cockatrice.exe" "DumpType" "2"
|
||||||
|
|
||||||
|
|||||||
@@ -65,26 +65,46 @@ static void CockatriceLogger(QtMsgType type, const QMessageLogContext &ctx, cons
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <DbgHelp.h>
|
#include <DbgHelp.h>
|
||||||
#include <tchar.h>
|
#include <ShlObj.h>
|
||||||
|
#include <ctime>
|
||||||
|
#include <filesystem>
|
||||||
#pragma comment(lib, "DbgHelp.lib") // Link the DbgHelp library
|
#pragma comment(lib, "DbgHelp.lib") // Link the DbgHelp library
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
LONG WINAPI CockatriceUnhandledExceptionFilter(EXCEPTION_POINTERS *pExceptionPointers)
|
LONG WINAPI CockatriceUnhandledExceptionFilter(EXCEPTION_POINTERS *exceptionPointers)
|
||||||
{
|
{
|
||||||
HANDLE hDumpFile =
|
std::filesystem::path path;
|
||||||
CreateFile(_T("cockatrice.crash.dmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
||||||
|
|
||||||
if (hDumpFile != INVALID_HANDLE_VALUE) {
|
// Find %LOCALAPPDATA% (or cheat at finding it)
|
||||||
MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
|
wchar_t *localAppDataFolder;
|
||||||
dumpInfo.ExceptionPointers = pExceptionPointers;
|
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
|
||||||
dumpInfo.ThreadId = GetCurrentThreadId();
|
path = std::filesystem::temp_directory_path().parent_path().parent_path();
|
||||||
dumpInfo.ClientPointers = TRUE;
|
} else {
|
||||||
|
path = std::filesystem::path(localAppDataFolder);
|
||||||
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpWithFullMemory, &dumpInfo,
|
|
||||||
NULL, NULL);
|
|
||||||
CloseHandle(hDumpFile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plan on writing crash files into %LOCALAPPDATA%/CrashDumps/Cockatrice/cockatrice.crash.*.dmp
|
||||||
|
path /= "CrashDumps";
|
||||||
|
path /= "Cockatrice";
|
||||||
|
if (!std::filesystem::exists(path)) {
|
||||||
|
std::filesystem::create_directories(path);
|
||||||
|
}
|
||||||
|
path /= "cockatrice.crash." + std::to_string(std::time(0)) + ".dmp";
|
||||||
|
|
||||||
|
// Create and write crash files
|
||||||
|
HANDLE hDumpFile =
|
||||||
|
CreateFile(path.wstring().c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||||
|
|
||||||
|
MINIDUMP_EXCEPTION_INFORMATION mei;
|
||||||
|
mei.ExceptionPointers = exceptionPointers;
|
||||||
|
mei.ThreadId = GetCurrentThreadId();
|
||||||
|
mei.ClientPointers = 1;
|
||||||
|
|
||||||
|
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpWithFullMemory, &mei, nullptr,
|
||||||
|
nullptr);
|
||||||
|
|
||||||
|
CloseHandle(hDumpFile);
|
||||||
|
|
||||||
return EXCEPTION_EXECUTE_HANDLER;
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user