main.cpp 4.1 KB

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