Change crashdump name logic

This commit is contained in:
2025-06-11 12:42:09 +02:00
parent 00c0cc2a26
commit a1510eb4fc

View File

@@ -33,9 +33,29 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic); void export_e3d_standalone(std::string in, std::string out, int flags, bool dynamic);
#ifdef WITHDUMPGEN #ifdef WITHDUMPGEN
#include <windows.h>
#include <dbghelp.h>
#include <ctime>
#include <string>
#include <sstream>
#include <iomanip>
#pragma comment(lib, "Dbghelp.lib")
LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo) LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo)
{ {
HANDLE hFile = CreateFileA("crash.dmp", GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); // Get current local time
SYSTEMTIME st;
GetLocalTime(&st);
// Format: crash_YYYY-MM-DD_HH-MM-SS.dmp
std::ostringstream oss;
oss << "crash_" << std::setw(4) << std::setfill('0') << st.wYear << "-" << std::setw(2) << std::setfill('0') << st.wMonth << "-" << std::setw(2) << std::setfill('0') << st.wDay << "_"
<< std::setw(2) << std::setfill('0') << st.wHour << "-" << std::setw(2) << std::setfill('0') << st.wMinute << "-" << std::setw(2) << std::setfill('0') << st.wSecond << ".dmp";
std::string filename = oss.str();
HANDLE hFile = CreateFileA(filename.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE) if (hFile != INVALID_HANDLE_VALUE)
{ {
MINIDUMP_EXCEPTION_INFORMATION dumpInfo; MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
@@ -45,10 +65,11 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS *ExceptionInfo)
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithDataSegs, &dumpInfo, nullptr, nullptr); MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpWithDataSegs, &dumpInfo, nullptr, nullptr);
CloseHandle(hFile); CloseHandle(hFile);
} }
return EXCEPTION_EXECUTE_HANDLER; return EXCEPTION_EXECUTE_HANDLER;
} }
#endif #endif