main.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include "login.h"
  2. #include <QApplication>
  3. #include <QFileInfo>
  4. #include <QSettings>
  5. #include "logproc.h"
  6. #include <windows.h>
  7. #include <DbgHelp.h>
  8. #include "CLogTrack.h"
  9. #include "client/windows/handler/exception_handler.h"
  10. long __stdcall CrashInfocallback(_EXCEPTION_POINTERS *pexcp)
  11. {
  12. //创建 Dump 文件
  13. HANDLE hDumpFile = ::CreateFile(
  14. L"client.dmp",
  15. GENERIC_WRITE,
  16. 0,
  17. NULL,
  18. CREATE_ALWAYS,
  19. FILE_ATTRIBUTE_NORMAL,
  20. NULL
  21. );
  22. if (hDumpFile != INVALID_HANDLE_VALUE)
  23. {
  24. //Dump信息
  25. MINIDUMP_EXCEPTION_INFORMATION dumpInfo;
  26. dumpInfo.ExceptionPointers = pexcp;
  27. dumpInfo.ThreadId = GetCurrentThreadId();
  28. dumpInfo.ClientPointers = TRUE;
  29. //写入Dump文件内容
  30. ::MiniDumpWriteDump(
  31. GetCurrentProcess(),
  32. GetCurrentProcessId(),
  33. hDumpFile,
  34. MiniDumpNormal,
  35. &dumpInfo,
  36. NULL,
  37. NULL
  38. );
  39. }
  40. EXCEPTION_RECORD* record = pexcp->ExceptionRecord;
  41. QString errCode(QString::number(record->ExceptionCode,16)),
  42. errAdr(QString::number((uint)record->ExceptionAddress,16));
  43. HWND task = nullptr;
  44. task=FindWindow(L"Shell_TrayWnd",nullptr);
  45. if(task)
  46. {
  47. ShowWindow(task,SW_SHOW);//隐藏任务栏
  48. }
  49. QMessageBox::critical(NULL,QString::fromLocal8Bit("程序崩溃"),
  50. QString::fromLocal8Bit("<FONT size=4><div><b>对于发生的错误,表示诚挚的歉意</b><br/></div>")+
  51. QString::fromLocal8Bit("<div>错误代码:%1</div><div>错误地址:%2</div></FONT>").arg(errCode).arg(errAdr),
  52. QMessageBox::Ok);
  53. myServerLog()<<QString::fromLocal8Bit("程序崩溃,错误代码:%1,错误地址:%2").arg(errCode).arg(errAdr);
  54. return 0;
  55. }
  56. bool callback(const wchar_t *dump_path, const wchar_t *id,
  57. void *context, EXCEPTION_POINTERS *exinfo,
  58. MDRawAssertionInfo *assertion,
  59. bool succeeded)
  60. {
  61. EXCEPTION_RECORD* record = exinfo->ExceptionRecord;
  62. QString errCode(QString::number(record->ExceptionCode, 16)),
  63. errAdr(QString::number((uint)record->ExceptionAddress, 16));
  64. HWND task = nullptr;
  65. task = FindWindow(L"Shell_TrayWnd", nullptr);
  66. if (task)
  67. {
  68. ShowWindow(task, SW_SHOW);//隐藏任务栏
  69. }
  70. QMessageBox::critical(NULL, QString::fromLocal8Bit("程序崩溃"),
  71. QString::fromLocal8Bit("<FONT size=4><div><b>对于发生的错误,表示诚挚的歉意</b><br/></div>") +
  72. QString::fromLocal8Bit("<div>错误代码:%1</div><div>错误地址:%2</div></FONT>").arg(errCode).arg(errAdr),
  73. QMessageBox::Ok);
  74. myDebug() << QString::fromLocal8Bit("程序崩溃,错误代码:%1,错误地址:%2").arg(errCode).arg(errAdr);
  75. return succeeded;
  76. }
  77. int main(int argc, char *argv[])
  78. {
  79. QApplication a(argc, argv);
  80. ::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CrashInfocallback);
  81. g_appInfoPtr = std::make_shared<CAppInfo>();
  82. QFileInfo file("coe.cfgi");
  83. QString sFilePath = file.absoluteFilePath();
  84. QSettings set(sFilePath, QSettings::IniFormat);
  85. g_appInfoPtr->m_bShowDebugInfo = set.value("config/debug", false).toBool();
  86. qInstallMessageHandler(CustomOutputMessage);
  87. // google_breakpad::ExceptionHandler eh(
  88. // L".", NULL, callback, NULL,
  89. // google_breakpad::ExceptionHandler::HANDLER_ALL);
  90. login w;
  91. w.show();
  92. if (argc > 1)
  93. {
  94. QString sParam = argv[1];
  95. if (sParam == "updateLauncher")
  96. {
  97. QString sSourceFile = g_appInfoPtr->m_sCacheFileDir + "uptemp/launcher.exe";
  98. QString sDestFileName = "launcher.exe";
  99. QFile file(sSourceFile);
  100. if (file.exists())
  101. {
  102. QFile::remove(sDestFileName);
  103. bool bcopy = file.copy(sDestFileName);
  104. myDebug() << bcopy;
  105. }
  106. return a.exec();
  107. }
  108. else if (sParam == "runClient")
  109. {
  110. return a.exec();
  111. }
  112. else
  113. {
  114. return 0;
  115. }
  116. }
  117. else
  118. {
  119. #ifdef _DEBUG
  120. return a.exec();
  121. #else
  122. return 0;
  123. #endif
  124. }
  125. }