crashDlg.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include ".\crashdlg.h"
  2. #include ".\configdlg.h"
  3. #include ".\resource.h"
  4. #include ".\settings.h"
  5. #include "exceptionhandler.h"
  6. #include <strsafe.h>
  7. extern Settings settings;
  8. extern PEXCEPTION_POINTERS gExceptionInfo;
  9. BOOL CALLBACK CrashDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  10. {
  11. UNREFERENCED_PARAMETER(lParam);
  12. switch (uMsg)
  13. {
  14. case WM_INITDIALOG:
  15. {
  16. // as we're loading things, make sure we've got a decent icon size to use in the second usage
  17. HICON hIcon = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(102),IMAGE_ICON,48,48,LR_SHARED);
  18. SetClassLongPtr(hwndDlg, GCLP_HICON, (LONG_PTR)hIcon);
  19. HWND hwndPrg = GetDlgItem(hwndDlg, IDC_PRG_COLLECT);
  20. SendMessage(hwndPrg, PBM_SETRANGE, 0, MAKELPARAM(0,100));
  21. SendMessage(hwndPrg, PBM_SETPOS, 0, 0);
  22. // this will make sure that we've got the logo shown even when using a localised version
  23. SendDlgItemMessage(hwndDlg,IDC_BMP_LOGO,STM_SETIMAGE,IMAGE_ICON,(LPARAM)hIcon);
  24. SetDlgItemText(hwndDlg, IDC_LBL_STEP, L"Analyzing settings...");
  25. settings.ClearTempData();
  26. wchar_t waPath[2*_MAX_PATH] = {0};
  27. if (GetModuleFileName( NULL, waPath, 2*_MAX_PATH ))
  28. {
  29. settings.WriteWinamp(waPath);
  30. }
  31. SetTimer(hwndDlg, 123, 1000, NULL);
  32. break;
  33. }
  34. case WM_TIMER:
  35. if (wParam == 123)
  36. {
  37. KillTimer(hwndDlg,wParam);
  38. HWND hwndPrg = GetDlgItem(hwndDlg, IDC_PRG_COLLECT);
  39. SetDlgItemText(hwndDlg, IDC_LBL_STEP, L"Generating log file...");
  40. SendMessage(hwndPrg, PBM_SETPOS, 30, 0);
  41. UpdateWindow(hwndDlg);
  42. if (settings.createLOG) settings.WriteLogCollectResult(CreateLog(gExceptionInfo, L"Winamp"));
  43. SetDlgItemText(hwndDlg, IDC_LBL_STEP, L"Generating dump file...");
  44. SendMessage(hwndPrg, PBM_SETPOS, 50, 0);
  45. UpdateWindow(hwndDlg);
  46. if (settings.createDMP) settings.WriteDmpCollectResult(CreateDump(gExceptionInfo));
  47. SetDlgItemText(hwndDlg, IDC_LBL_STEP, L"Starting error reporter...");
  48. SendMessage(hwndPrg, PBM_SETPOS, 90, 0);
  49. UpdateWindow(hwndDlg);
  50. STARTUPINFO si = {0};
  51. si.cb = sizeof(si);
  52. si.dwFlags = STARTF_USESHOWWINDOW;
  53. si.wShowWindow = SW_SHOW;
  54. PROCESS_INFORMATION pi = {0};
  55. wchar_t reporter[512] = {0}, waPlugPath[MAX_PATH] = {0}, cmd[512] = {0}, *waPath = 0;
  56. GetModuleFileName( NULL, waPlugPath, MAX_PATH);
  57. CreatePathFromFullName(&waPath, waPlugPath);
  58. StringCchPrintf(reporter, 512, L"%s\\reporter.exe", waPath);
  59. StringCchPrintf(cmd, 512, L" \"%s\"", settings.GetPath());
  60. if (CreateProcess(
  61. reporter, // name of executable module
  62. cmd, // command line string
  63. NULL, // process attributes
  64. NULL, // thread attributes
  65. FALSE, // handle inheritance option
  66. 0, // creation flags
  67. NULL, // new environment block
  68. NULL, // current directory name
  69. &si, // startup information
  70. &pi)) // process information
  71. {
  72. SetDlgItemText(hwndDlg, IDC_LBL_STEP, L"Done.");
  73. SetTimer(hwndDlg, 126, 200, NULL);
  74. }
  75. else
  76. {
  77. SetDlgItemText(hwndDlg, IDC_LBL_STEP, L"Error. Unable to run reporter.");
  78. SetTimer(hwndDlg, 126, 3000, NULL);
  79. }
  80. SendMessage(hwndPrg, PBM_SETPOS, 100, 0);
  81. UpdateWindow(hwndDlg);
  82. }
  83. else if (wParam == 126)
  84. {
  85. KillTimer(hwndDlg,wParam);
  86. DestroyWindow(hwndDlg);
  87. }
  88. break;
  89. }
  90. return FALSE;
  91. }