diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c001ddf..68281f235 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,8 @@ if(MSVC) set(CMAKE_CXX_FLAGS_RELEASE "/Ox /MD") # Visual Studio: No Optimization, Multi-threaded Debug DLL, Debug Symbols set(CMAKE_CXX_FLAGS_DEBUG "/Od /MDd /Zi") + + add_compile_definitions(_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) elseif(CMAKE_COMPILER_IS_GNUCXX) # linux/gcc, bsd/gcc, windows/mingw include(CheckCXXCompilerFlag) diff --git a/cmake/NSIS.template.in b/cmake/NSIS.template.in index dc4412ff3..f1e4beb00 100644 --- a/cmake/NSIS.template.in +++ b/cmake/NSIS.template.in @@ -235,6 +235,13 @@ ${If} $PortableMode = 0 WriteUninstaller "$INSTDIR\uninstall.exe" ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2 IntFmt $0 "0x%08X" $0 + + ; Enable Windows 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" + 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" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cockatrice" "DisplayIcon" "$INSTDIR\cockatrice.exe" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cockatrice" "DisplayName" "Cockatrice" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Cockatrice" "DisplayVersion" "@CPACK_PACKAGE_VERSION_MAJOR@.@CPACK_PACKAGE_VERSION_MINOR@.@CPACK_PACKAGE_VERSION_PATCH@" diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 77136cde3..91a933278 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -61,6 +61,34 @@ static void CockatriceLogger(QtMsgType type, const QMessageLogContext &ctx, cons Logger::getInstance().log(type, ctx, message); } +#ifdef Q_OS_WIN +// clang-format off +#include +#include +#include +#pragma comment(lib, "DbgHelp.lib") // Link the DbgHelp library +// clang-format on + +LONG WINAPI CockatriceUnhandledExceptionFilter(EXCEPTION_POINTERS *pExceptionPointers) +{ + HANDLE hDumpFile = + CreateFile(_T("cockatrice.crash.dmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + if (hDumpFile != INVALID_HANDLE_VALUE) { + MINIDUMP_EXCEPTION_INFORMATION dumpInfo; + dumpInfo.ExceptionPointers = pExceptionPointers; + dumpInfo.ThreadId = GetCurrentThreadId(); + dumpInfo.ClientPointers = TRUE; + + MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpWithFullMemory, &dumpInfo, + NULL, NULL); + CloseHandle(hDumpFile); + } + + return EXCEPTION_EXECUTE_HANDLER; +} +#endif + void installNewTranslator() { QString lang = SettingsCache::instance().getLang(); @@ -93,10 +121,10 @@ void installNewTranslator() QString const generateClientID() { QString macList; - foreach (QNetworkInterface interface, QNetworkInterface::allInterfaces()) { - if (interface.hardwareAddress() != "") - if (interface.hardwareAddress() != "00:00:00:00:00:00:00:E0") - macList += interface.hardwareAddress() + "."; + foreach (QNetworkInterface networkInterface, QNetworkInterface::allInterfaces()) { + if (networkInterface.hardwareAddress() != "") + if (networkInterface.hardwareAddress() != "00:00:00:00:00:00:00:E0") + macList += networkInterface.hardwareAddress() + "."; } QString strClientID = QCryptographicHash::hash(macList.toUtf8(), QCryptographicHash::Sha1).toHex().right(15); return strClientID; @@ -104,6 +132,10 @@ QString const generateClientID() int main(int argc, char *argv[]) { +#ifdef Q_OS_WIN + SetUnhandledExceptionFilter(CockatriceUnhandledExceptionFilter); +#endif + QApplication app(argc, argv); QObject::connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));