From 0ebace48833a7ba4a3ae7462727486d28d37e791 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Thu, 4 Mar 2010 02:17:34 +0000 Subject: [PATCH] - Add the game log to the crash report. I don't know why I didn't think to do this sooner. Since we're already sending everything to a rich edit control hidden in the background, we can just grab its contents for the report. - Use code page 1252 when previewing text files in the crash dialog. SVN r2185 (trunk) --- src/win32/i_crash.cpp | 97 +++++++++++++++++++++++++++++++++++++------ src/win32/i_main.cpp | 8 ++-- 2 files changed, 89 insertions(+), 16 deletions(-) diff --git a/src/win32/i_crash.cpp b/src/win32/i_crash.cpp index 5996be87a..727e4b7ed 100644 --- a/src/win32/i_crash.cpp +++ b/src/win32/i_crash.cpp @@ -503,6 +503,71 @@ void __cdecl Writef (HANDLE file, const char *format, ...) WriteFile (file, buffer, len, &len, NULL); } +//========================================================================== +// +// WriteLogFileStreamer +// +// The callback function to stream a Rich Edit's contents to a file. +// +//========================================================================== + +static DWORD CALLBACK WriteLogFileStreamer(DWORD_PTR cookie, LPBYTE buffer, LONG cb, LONG *pcb) +{ + DWORD didwrite; + LONG p, pp; + + // Replace gray foreground color with black. + static const char *badfg = "\\red223\\green223\\blue223;"; + // 4321098 765432109 876543210 + // 2 1 0 + for (p = pp = 0; p < cb; ++p) + { + if (buffer[p] == badfg[pp]) + { + ++pp; + if (pp == 25) + { + buffer[p - 1] = buffer[p - 2] = buffer[p - 3] = + buffer[p - 9] = buffer[p -10] = buffer[p -11] = + buffer[p -18] = buffer[p -19] = buffer[p -20] = '0'; + break; + } + } + else + { + pp = 0; + } + } + + if (!WriteFile((HANDLE)cookie, buffer, cb, &didwrite, NULL)) + { + return 1; + } + *pcb = didwrite; + return 0; +} + +//========================================================================== +// +// WriteLogFile +// +// Writes the contents of a Rich Edit control to a file. +// +//========================================================================== + +HANDLE WriteLogFile(HWND edit) +{ + HANDLE file; + + file = CreateTempFile(); + if (file != INVALID_HANDLE_VALUE) + { + EDITSTREAM streamer = { (DWORD_PTR)file, 0, WriteLogFileStreamer }; + SendMessage(edit, EM_STREAMOUT, SF_RTF, (LPARAM)&streamer); + } + return file; +} + //========================================================================== // // CreateCrashLog @@ -511,7 +576,7 @@ void __cdecl Writef (HANDLE file, const char *format, ...) // //========================================================================== -void CreateCrashLog (char *custominfo, DWORD customsize) +void CreateCrashLog (char *custominfo, DWORD customsize, HWND richlog) { // Do not collect information more than once. if (NumFiles != 0) @@ -561,6 +626,10 @@ void CreateCrashLog (char *custominfo, DWORD customsize) AddFile (file, "local.txt"); } } + if (richlog != NULL) + { + AddFile (WriteLogFile(richlog), "log.rtf"); + } CloseHandle (DbgProcess); } @@ -1984,7 +2053,6 @@ static INT_PTR CALLBACK CrashDlgProc (HWND hDlg, UINT message, WPARAM wParam, LP static INT_PTR CALLBACK DetailsDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { - HGDIOBJ font; HWND ctrl; int i, j; @@ -1996,15 +2064,9 @@ static INT_PTR CALLBACK DetailsDlgProc (HWND hDlg, UINT message, WPARAM wParam, pEnableThemeDialogTexture (hDlg, ETDT_ENABLETAB); } - // Set up the file contents display: Use a fixed width font, - // no undos. The control's userdata stores the index of the - // file currently displayed. + // Set up the file contents display: No undos. The control's + // userdata stores the index of the file currently displayed. ctrl = GetDlgItem (hDlg, IDC_CRASHFILECONTENTS); - font = GetStockObject (ANSI_FIXED_FONT); - if (font != INVALID_HANDLE_VALUE) - { - SendMessage (ctrl, WM_SETFONT, (WPARAM)font, FALSE); - } SendMessage (ctrl, EM_SETUNDOLIMIT, 0, 0); SetWindowLongPtr (ctrl, GWLP_USERDATA, -1); SetEditControl (ctrl, GetDlgItem(hDlg, IDC_CRASHFILESIZE), 0); @@ -2178,6 +2240,8 @@ static void SetEditControl (HWND edit, HWND sizedisplay, int filenum) EDITSTREAM stream; DWORD size; POINT pt = { 0, 0 }; + const char *rtf = NULL; + HGDIOBJ font; // Don't refresh the control if it's already showing the file we want. if (GetWindowLongPtr (edit, GWLP_USERDATA) == filenum) @@ -2201,10 +2265,19 @@ static void SetEditControl (HWND edit, HWND sizedisplay, int filenum) SetFilePointer (TarFiles[filenum].File, 0, NULL, FILE_BEGIN); SendMessage (edit, EM_SETSCROLLPOS, 0, (LPARAM)&pt); + // Set the font now, in case log.rtf was previously viewed, because + // that file changes it. + font = GetStockObject (ANSI_FIXED_FONT); + if (font != INVALID_HANDLE_VALUE) + { + SendMessage (edit, WM_SETFONT, (WPARAM)font, FALSE); + } + // Text files are streamed in as-is. // Binary files are streamed in as color-coded hex dumps. stream.dwError = 0; - if (strstr (TarFiles[filenum].Filename, ".txt") != NULL) + if (strstr (TarFiles[filenum].Filename, ".txt") != NULL || + (rtf = strstr (TarFiles[filenum].Filename, ".rtf")) != NULL) { CHARFORMAT beBlack; @@ -2215,7 +2288,7 @@ static void SetEditControl (HWND edit, HWND sizedisplay, int filenum) SendMessage (edit, EM_SETCHARFORMAT, 0, (LPARAM)&beBlack); stream.dwCookie = (DWORD_PTR)TarFiles[filenum].File; stream.pfnCallback = StreamEditText; - SendMessage (edit, EM_STREAMIN, SF_TEXT, (LPARAM)&stream); + SendMessage (edit, EM_STREAMIN, rtf ? SF_RTF : SF_TEXT | SF_USECODEPAGE | (1252 << 16), (LPARAM)&stream); } else { diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index 026c86637..a76380bda 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -105,7 +105,7 @@ // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); -void CreateCrashLog (char *custominfo, DWORD customsize); +void CreateCrashLog (char *custominfo, DWORD customsize, HWND richedit); void DisplayCrashLog (); extern BYTE *ST_Util_BitsForBitmap (BITMAPINFO *bitmap_info); @@ -1176,7 +1176,7 @@ LONG WINAPI CatchAllExceptions (LPEXCEPTION_POINTERS info) CrashPointers = *info; DoomSpecificInfo (custominfo, 16384); - CreateCrashLog (custominfo, (DWORD)strlen(custominfo)); + CreateCrashLog (custominfo, (DWORD)strlen(custominfo), ConWindow); // If the main thread crashed, then make it clean up after itself. // Otherwise, put the crashing thread to sleep and signal the main thread to clean up. @@ -1248,7 +1248,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int n *(int *)0 = 0; } __except(CrashPointers = *GetExceptionInformation(), - CreateCrashLog (__argv[1], 9), EXCEPTION_EXECUTE_HANDLER) + CreateCrashLog (__argv[1], 9, NULL), EXCEPTION_EXECUTE_HANDLER) { } DisplayCrashLog (); @@ -1261,7 +1261,7 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE nothing, LPSTR cmdline, int n infiniterecursion(1); } __except(CrashPointers = *GetExceptionInformation(), - CreateCrashLog (__argv[1], 14), EXCEPTION_EXECUTE_HANDLER) + CreateCrashLog (__argv[1], 14, NULL), EXCEPTION_EXECUTE_HANDLER) { } DisplayCrashLog ();