@@ -35,6 +35,8 @@ _EXCEPTION_POINTERS g_exceptionPointers = { 0 };
3535EXCEPTION_RECORD g_exceptionRecord = { 0 };
3636CONTEXT g_exceptionContext = { 0 };
3737
38+ constexpr const char * DumpFileNamePrefix = " Crash" ;
39+
3840void MiniDumper::initMiniDumper (const AsciiString& userDirPath)
3941{
4042 DEBUG_ASSERTCRASH (TheMiniDumper == NULL , (" MiniDumper::initMiniDumper called on already created instance" ));
@@ -71,9 +73,9 @@ MiniDumper::MiniDumper()
7173 m_dumpObjectsSubState = 0 ;
7274 m_dmaRawBlockIndex = 0 ;
7375#endif
74- memset ( m_dumpDir, 0 , ARRAY_SIZE (m_dumpDir)) ;
75- memset ( m_dumpFile, 0 , ARRAY_SIZE (m_dumpFile)) ;
76- memset ( m_executablePath, 0 , ARRAY_SIZE (m_executablePath)) ;
76+ m_dumpDir[ 0 ] = 0 ;
77+ m_dumpFile[ 0 ] = 0 ;
78+ m_executablePath[ 0 ] = 0 ;
7779};
7880
7981LONG WINAPI MiniDumper::DumpingExceptionFilter (struct _EXCEPTION_POINTERS * e_info)
@@ -214,8 +216,9 @@ Bool MiniDumper::IsDumpThreadStillRunning() const
214216
215217Bool MiniDumper::InitializeDumpDirectory (const AsciiString& userDirPath)
216218{
217- constexpr Int MaxExtendedFileCount = 2 ;
218- constexpr Int MaxMiniFileCount = 10 ;
219+ constexpr const Int MaxExtendedFileCount = 2 ;
220+ constexpr const Int MaxFullFileCount = 2 ;
221+ constexpr const Int MaxMiniFileCount = 10 ;
219222
220223 strlcpy (m_dumpDir, userDirPath.str (), ARRAY_SIZE (m_dumpDir));
221224 strlcat (m_dumpDir, " CrashDumps\\ " , ARRAY_SIZE (m_dumpDir));
@@ -228,9 +231,10 @@ Bool MiniDumper::InitializeDumpDirectory(const AsciiString& userDirPath)
228231 }
229232 }
230233
231- // Clean up old files (we keep a maximum of 10 small and 2 extended)
232- KeepNewestFiles (m_dumpDir, " CrashX*" , MaxExtendedFileCount);
233- KeepNewestFiles (m_dumpDir, " CrashM*" , MaxMiniFileCount);
234+ // Clean up old files (we keep a maximum of 10 small, 2 extended and 2 full)
235+ KeepNewestFiles (m_dumpDir, DUMP_TYPE_GAMEMEMORY, MaxExtendedFileCount);
236+ KeepNewestFiles (m_dumpDir, DUMP_TYPE_FULL, MaxFullFileCount);
237+ KeepNewestFiles (m_dumpDir, DUMP_TYPE_MINIMAL, MaxMiniFileCount);
234238
235239 return true ;
236240}
@@ -354,16 +358,16 @@ void MiniDumper::CreateMiniDump(DumpType dumpType)
354358 SYSTEMTIME sysTime;
355359 ::GetLocalTime (&sysTime);
356360#if RTS_GENERALS
357- Char product = ' G' ;
361+ const Char product = ' G' ;
358362#elif RTS_ZEROHOUR
359- Char product = ' Z' ;
363+ const Char product = ' Z' ;
360364#endif
361- Char dumpTypeSpecifier = dumpType == DUMP_TYPE_MINIMAL ? ' M ' : ' X ' ;
365+ Char dumpTypeSpecifier = static_cast <Char>( dumpType) ;
362366 DWORD currentProcessId = ::GetCurrentProcessId ();
363367
364368 // m_dumpDir is stored with trailing backslash in Initialize
365- snprintf (m_dumpFile, ARRAY_SIZE (m_dumpFile), " %sCrash %c%c-%04d%02d%02d-%02d%02d%02d-%s-pid%ld.dmp" ,
366- m_dumpDir, dumpTypeSpecifier, product, sysTime.wYear , sysTime.wMonth ,
369+ snprintf (m_dumpFile, ARRAY_SIZE (m_dumpFile), " %s%s %c%c-%04d%02d%02d-%02d%02d%02d-%s-pid%ld.dmp" ,
370+ m_dumpDir, DumpFileNamePrefix, dumpTypeSpecifier, product, sysTime.wYear , sysTime.wMonth ,
367371 sysTime.wDay , sysTime.wHour , sysTime.wMinute , sysTime.wSecond ,
368372 GitShortSHA1, currentProcessId);
369373
@@ -456,7 +460,8 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
456460 // Only include data segments for the game and ntdll modules to keep dump size low
457461 if (output.ModuleWriteFlags & ModuleWriteDataSeg)
458462 {
459- if (::StrCmpIW (input.Module .FullPath , m_executablePath) && !::StrStrIW (input.Module .FullPath , L" ntdll.dll" ))
463+ if (::StrCmpIW (input.Module .FullPath , m_executablePath) && !::StrStrIW (input.Module .FullPath , L" ntdll.dll" ) &&
464+ !::StrStrIW (input.Module .FullPath , L" kernel32.dll" ))
460465 {
461466 // Exclude data segments for the module
462467 output.ModuleWriteFlags &= (~ModuleWriteDataSeg);
@@ -645,10 +650,10 @@ bool MiniDumper::CompareByLastWriteTime(const FileInfo& a, const FileInfo& b)
645650 return ::CompareFileTime (&a.lastWriteTime , &b.lastWriteTime ) > 0 ;
646651}
647652
648- void MiniDumper::KeepNewestFiles (const std::string& directory, const std::string& fileWildcard , const Int keepCount)
653+ void MiniDumper::KeepNewestFiles (const std::string& directory, const DumpType dumpType , const Int keepCount)
649654{
650655 // directory already contains trailing backslash
651- std::string searchPath = directory + fileWildcard ;
656+ std::string searchPath = directory + DumpFileNamePrefix + static_cast <Char>(dumpType) + " * " ;
652657 WIN32_FIND_DATA findData;
653658 HANDLE hFind = ::FindFirstFile (searchPath.c_str (), &findData);
654659
0 commit comments