main.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. /*
  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. myDebug()<<QString::fromLocal8Bit("程序崩溃,错误代码:%1,错误地址:%2").arg(errCode).arg(errAdr);
  55. return 0;
  56. }
  57. */
  58. bool callback(const wchar_t *dump_path, const wchar_t *id,
  59. void *context, EXCEPTION_POINTERS *exinfo,
  60. MDRawAssertionInfo *assertion,
  61. bool succeeded)
  62. {
  63. EXCEPTION_RECORD* record = exinfo->ExceptionRecord;
  64. QString errCode(QString::number(record->ExceptionCode, 16)),
  65. errAdr(QString::number((uint)record->ExceptionAddress, 16));
  66. HWND task = nullptr;
  67. task = FindWindow(L"Shell_TrayWnd", nullptr);
  68. if (task)
  69. {
  70. ShowWindow(task, SW_SHOW);//隐藏任务栏
  71. }
  72. QMessageBox::critical(NULL, QString::fromLocal8Bit("程序崩溃"),
  73. QString::fromLocal8Bit("<FONT size=4><div><b>对于发生的错误,表示诚挚的歉意</b><br/></div>") +
  74. QString::fromLocal8Bit("<div>错误代码:%1</div><div>错误地址:%2</div></FONT>").arg(errCode).arg(errAdr),
  75. QMessageBox::Ok);
  76. myDebug() << QString::fromLocal8Bit("程序崩溃,错误代码:%1,错误地址:%2").arg(errCode).arg(errAdr);
  77. return succeeded;
  78. }
  79. /*
  80. int mydiv(int x, int y)
  81. {
  82. int *z=0;
  83. *z = x / y;
  84. return *z;
  85. }
  86. */
  87. int main(int argc, char *argv[])
  88. {
  89. QApplication a(argc, argv);
  90. //::SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)CrashInfocallback);
  91. g_appInfoPtr = std::make_shared<CAppInfo>();
  92. QFileInfo file("coe.cfgi");
  93. QString sFilePath = file.absoluteFilePath();
  94. QSettings set(sFilePath, QSettings::IniFormat);
  95. g_appInfoPtr->m_bShowDebugInfo = set.value("config/debug", false).toBool();
  96. qInstallMessageHandler(CustomOutputMessage);
  97. google_breakpad::ExceptionHandler eh(
  98. L".", NULL, callback, NULL,
  99. google_breakpad::ExceptionHandler::HANDLER_ALL);
  100. // printf("9/3=%d\n", mydiv(9, 3));
  101. //printf("9/0=%d\n", mydiv(9, 0)); //程序将在此崩溃
  102. login w;
  103. w.show();
  104. if (argc > 1)
  105. {
  106. QString sParam = argv[1];
  107. if (sParam == "updateLauncher")
  108. {
  109. QString sSourceFile = g_appInfoPtr->m_sCacheFileDir + "launcher.exe";
  110. QString sDestFileName = "launcher.exe";
  111. QFile file(sSourceFile);
  112. if (file.exists())
  113. {
  114. QFile::remove(sDestFileName);
  115. bool bcopy = file.copy(sDestFileName);
  116. myDebug() << bcopy;
  117. }
  118. return a.exec();
  119. }
  120. else if (sParam == "runClient")
  121. {
  122. return a.exec();
  123. }
  124. else
  125. {
  126. return 0;
  127. }
  128. }
  129. else
  130. {
  131. return a.exec();
  132. //return 0;
  133. }
  134. }