windows下增加崩溃处理

This commit is contained in:
luoliangyi 2022-07-02 15:59:09 +08:00
parent 4cbf6be1dc
commit 5b101e1464
5 changed files with 57 additions and 12 deletions

View File

@ -259,7 +259,7 @@ static bool Greater(const std::string &str1, const std::string &str2)
return str1 > str2;
}
static bool PostCrashInfo(const std::string &crashFileUrl, const std::string &desc)
static bool PostCrashInfo(const std::string &crashFileUrl, const std::string &exceptionAddr, const std::string &desc)
{
bool ret = false;
CURL* curl = curl_easy_init();
@ -359,7 +359,7 @@ static bool PostCrashInfo(const std::string &crashFileUrl, const std::string &de
char json[1024];
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\", \"crashaddress\":\"%s\", \"crash_data\":\"%s\"}",
3, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str(), "0x00000000", crashFileUrl.c_str());
3, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str(), exceptionAddr.c_str(), crashFileUrl.c_str());
struct curl_slist* headers = nullptr;
headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8");
@ -390,13 +390,13 @@ static bool PostCrashInfo(const std::string &crashFileUrl, const std::string &de
return ret;
}
bool PostCrashInfo(const char* crashFilePath)
bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptionAddr)
{
std::string crashFileUrl;
bool ret = CrashFileUpload(crashFilePath, crashFileUrl);
if (ret)
{
ret = PostCrashInfo(crashFileUrl, "collapse");
ret = PostCrashInfo(crashFileUrl, exceptionAddr, "collapse");
}
return ret;

View File

@ -36,7 +36,7 @@ typedef int (*HttpDownloadFunc)(long long totalSize, long long nowSize, void *pa
bool GetServerConfig(ServerConfig &cfg);
// 上传崩溃日志
bool PostCrashInfo(const char* crashFilePath);
bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptionAddr);
// 上传用户使用习惯
bool PostUserHabits(const std::list<std::string>& habits);

View File

@ -3,11 +3,58 @@
#include <QApplication>
#include <QTranslator>
#include <QScreen>
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "base/HGUtility.h"
#include "HGVersion.h"
#include "curl/curl.h"
#if defined(HG_CMP_MSC)
#include <Dbghelp.h>
#endif
#if defined(HG_CMP_MSC)
static LONG WINAPI UnhandledExceptionFilterEx(struct _EXCEPTION_POINTERS *ExceptionInfo)
{
HGChar tmpPath[256];
HGBase_GetTmpFileName("dmp", tmpPath, 256);
HANDLE hFile = CreateFileA(tmpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hFile)
{
return EXCEPTION_EXECUTE_HANDLER;
}
MINIDUMP_EXCEPTION_INFORMATION mdei;
mdei.ThreadId = GetCurrentThreadId();
mdei.ExceptionPointers = ExceptionInfo;
mdei.ClientPointers = TRUE;
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &mdei, NULL, NULL);
CloseHandle(hFile);
char exceptionAddr[32] = {0};
#ifdef _WIN64
sprintf(exceptionAddr, "0x%016p", ExceptionInfo->ExceptionRecord->ExceptionAddress);
#else
sprintf(exceptionAddr, "0x%08p", ExceptionInfo->ExceptionRecord->ExceptionAddress);
#endif
// 上传
PostCrashInfo(tmpPath, exceptionAddr);
HGBase_DeleteFile(tmpPath);
return EXCEPTION_EXECUTE_HANDLER;
}
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
curl_global_init(CURL_GLOBAL_ALL);
#if defined(HG_CMP_MSC)
SetUnhandledExceptionFilter(UnhandledExceptionFilterEx);
#endif
QTranslator translator_qt_;
if (translator_qt_.load(":translation/qt_zh_CN.qm"))
a.installTranslator(&translator_qt_);
@ -20,5 +67,8 @@ int main(int argc, char *argv[])
QScreen *screen = QGuiApplication::primaryScreen();
w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2);
w.show();
return a.exec();
a.exec();
curl_global_cleanup();
return 0;
}

View File

@ -39,8 +39,6 @@
#include "HGUIGlobal.h"
#include "HGString.h"
#include "app_cfg.h"
#include "HGVersion.h"
#include "curl/curl.h"
#include <assert.h>
#define PASSWORD_KEY 4
@ -67,8 +65,6 @@ MainWindow::MainWindow(QWidget *parent)
{
ui->setupUi(this);
curl_global_init(CURL_GLOBAL_ALL);
#if defined(OEM_HANWANG)
this->setWindowIcon(QIcon(":images/image_rsc/logo/Hanvon_logo1.ico"));
this->setWindowTitle(tr("HanvonScan"));
@ -292,7 +288,6 @@ MainWindow::~MainWindow()
cur_dev_.close();
sane_exit();
curl_global_cleanup();
delete ui;
}

View File

@ -27,7 +27,7 @@ win32 {
DEFINES += CURL_STATICLIB
INCLUDEPATH += $$PWD/../../../third_party/libcurl/windows/include
LIBS += -ladvapi32 -lIphlpapi -lwldap32 -lws2_32
LIBS += -ladvapi32 -lIphlpapi -lwldap32 -lws2_32 -ldbghelp
contains(QT_ARCH, i386) {
LIBS += -L../../../../sdk/lib/win/x86/Release -lHGBase -lHGImgFmt -lHGImgProc -lsane