将HGVersion.h中的函数挪到HGVersion类中
This commit is contained in:
parent
7bedcc75cf
commit
302824716a
|
@ -3,6 +3,7 @@
|
|||
#include "base/HGInc.h"
|
||||
#include "base/HGInfo.h"
|
||||
#include "base/HGMd5.h"
|
||||
#include "base/HGUtility.h"
|
||||
#include "cJSON.h"
|
||||
#include "curl/curl.h"
|
||||
#include <vector>
|
||||
|
@ -11,6 +12,7 @@
|
|||
#include <algorithm>
|
||||
#if defined(HG_CMP_MSC)
|
||||
#include <iphlpapi.h>
|
||||
#include <Dbghelp.h>
|
||||
#endif
|
||||
|
||||
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
||||
|
@ -22,11 +24,11 @@ static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
|
|||
return size * nmemb;
|
||||
}
|
||||
|
||||
bool GetServerConfig(ServerConfig& cfg)
|
||||
static bool GetServerConfig(bool &postCrashInfo, bool & postUserBehavior, bool &postDeviceInfo)
|
||||
{
|
||||
cfg.postCrashInfo = false;
|
||||
cfg.postUserBehavior = false;
|
||||
cfg.postDeviceInfo = false;
|
||||
postCrashInfo = false;
|
||||
postUserBehavior = false;
|
||||
postDeviceInfo = false;
|
||||
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
|
@ -76,11 +78,11 @@ bool GetServerConfig(ServerConfig& cfg)
|
|||
while (nullptr != p2)
|
||||
{
|
||||
if (0 == strcmp(p2->string, "report_switch"))
|
||||
cfg.postUserBehavior = (bool)p2->valueint;
|
||||
postUserBehavior = (bool)p2->valueint;
|
||||
else if (0 == strcmp(p2->string, "collapse_switch"))
|
||||
cfg.postCrashInfo = (bool)p2->valueint;
|
||||
postCrashInfo = (bool)p2->valueint;
|
||||
else if (0 == strcmp(p2->string, "device_info_switch"))
|
||||
cfg.postDeviceInfo = (bool)p2->valueint;
|
||||
postDeviceInfo = (bool)p2->valueint;
|
||||
|
||||
p2 = p2->next;
|
||||
}
|
||||
|
@ -324,6 +326,75 @@ static void GetMacAddrList(std::vector<std::string> &macList)
|
|||
#endif
|
||||
}
|
||||
|
||||
static std::string GetCurrVersion()
|
||||
{
|
||||
std::string version = "0.0.0.0";
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
#if defined(OEM_HANWANG)
|
||||
std::string regName = "SOFTWARE\\HanvonScan";
|
||||
#elif defined(OEM_LISICHENG)
|
||||
std::string regName = "SOFTWARE\\LanxumScan";
|
||||
#else
|
||||
std::string regName = "SOFTWARE\\HuaGoScan";
|
||||
#endif
|
||||
|
||||
HKEY hKey = nullptr;
|
||||
RegOpenKeyExA(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
||||
if (nullptr != hKey)
|
||||
{
|
||||
CHAR szData[MAX_PATH] = { 0 };
|
||||
DWORD cbData = MAX_PATH;
|
||||
if (ERROR_SUCCESS == RegQueryValueExA(hKey, "AppVersion", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
||||
{
|
||||
version = szData;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
#else
|
||||
#if defined(OEM_HANWANG)
|
||||
std::string appName = "com.hanvonchina.hanvonscan";
|
||||
#elif defined(OEM_LISICHENG)
|
||||
std::string appName = "com.lanxumchina.lanxumscan";
|
||||
#else
|
||||
std::string appName = "com.huagaochina.huagoscan";
|
||||
#endif
|
||||
|
||||
std::string cmd = "dpkg -l " + appName;
|
||||
FILE* fp = popen(cmd.c_str(), "r");
|
||||
if (nullptr != fp)
|
||||
{
|
||||
char buff[2048] = { 0 };
|
||||
fread(buff, 2048, 1, fp);
|
||||
|
||||
char* p = strstr(buff, appName.c_str());
|
||||
if (nullptr != p)
|
||||
{
|
||||
char* p2 = p + appName.size();
|
||||
while (!isdigit(*p2) && '.' != *p2)
|
||||
++p2;
|
||||
|
||||
int len = (int)strlen(p2);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (!isdigit(p2[i]) && '.' != p2[i])
|
||||
{
|
||||
p2[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
version = p2;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
static bool Greater(const std::string &str1, const std::string &str2)
|
||||
{
|
||||
return str1 > str2;
|
||||
|
@ -470,7 +541,7 @@ static bool PostInfo(int type, const std::string &crashFileUrl, const std::strin
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptionAddr)
|
||||
static bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptionAddr)
|
||||
{
|
||||
std::string crashFileUrl;
|
||||
bool ret = CrashFileUpload(crashFilePath, crashFileUrl);
|
||||
|
@ -482,81 +553,12 @@ bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptio
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool PostUserFeedback(const std::string &info, const std::string &contact)
|
||||
static bool PostUserFeedback(const std::string &info, const std::string &contact)
|
||||
{
|
||||
return PostInfo(4, "", "", info, contact, "feedback");
|
||||
}
|
||||
|
||||
std::string GetCurrVersion()
|
||||
{
|
||||
std::string version = "0.0.0.0";
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
#if defined(OEM_HANWANG)
|
||||
std::string regName = "SOFTWARE\\HanvonScan";
|
||||
#elif defined(OEM_LISICHENG)
|
||||
std::string regName = "SOFTWARE\\LanxumScan";
|
||||
#else
|
||||
std::string regName = "SOFTWARE\\HuaGoScan";
|
||||
#endif
|
||||
|
||||
HKEY hKey = nullptr;
|
||||
RegOpenKeyExA(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
||||
if (nullptr != hKey)
|
||||
{
|
||||
CHAR szData[MAX_PATH] = { 0 };
|
||||
DWORD cbData = MAX_PATH;
|
||||
if (ERROR_SUCCESS == RegQueryValueExA(hKey, "AppVersion", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
||||
{
|
||||
version = szData;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
#else
|
||||
#if defined(OEM_HANWANG)
|
||||
std::string appName = "com.hanvonchina.hanvonscan";
|
||||
#elif defined(OEM_LISICHENG)
|
||||
std::string appName = "com.lanxumchina.lanxumscan";
|
||||
#else
|
||||
std::string appName = "com.huagaochina.huagoscan";
|
||||
#endif
|
||||
|
||||
std::string cmd = "dpkg -l " + appName;
|
||||
FILE *fp = popen(cmd.c_str(), "r");
|
||||
if (nullptr != fp)
|
||||
{
|
||||
char buff[2048] = {0};
|
||||
fread(buff, 2048, 1, fp);
|
||||
|
||||
char *p = strstr(buff, appName.c_str());
|
||||
if (nullptr != p)
|
||||
{
|
||||
char *p2 = p + appName.size();
|
||||
while (!isdigit(*p2) && '.' != *p2)
|
||||
++p2;
|
||||
|
||||
int len = (int)strlen(p2);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (!isdigit(p2[i]) && '.' != p2[i])
|
||||
{
|
||||
p2[i] = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
version = p2;
|
||||
}
|
||||
|
||||
pclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
return version;
|
||||
}
|
||||
|
||||
bool GetVersionInfoList(std::list<VersionInfo>& versionList)
|
||||
static bool GetVersionInfoList(std::list<VersionInfo>& versionList)
|
||||
{
|
||||
versionList.clear();
|
||||
|
||||
|
@ -721,7 +723,7 @@ static std::vector<std::string> split(std::string strtem, char a)
|
|||
return strvec;
|
||||
}
|
||||
|
||||
int CompareVersion(const std::string& version1, const std::string& version2)
|
||||
static int CompareVersion(const std::string& version1, const std::string& version2)
|
||||
{
|
||||
std::vector<std::string> versionList1 = split(version1, '.');
|
||||
std::vector<std::string> versionList2 = split(version2, '.');
|
||||
|
@ -774,7 +776,7 @@ static int xferinfo2(void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t u
|
|||
return 0;
|
||||
}
|
||||
|
||||
bool HttpDownload(const std::string& url, const std::string& saveFilePath, HttpDownloadFunc func, void* param)
|
||||
static bool HttpDownload(const std::string& url, const std::string& saveFilePath, HttpDownloadFunc func, void* param)
|
||||
{
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
|
@ -812,3 +814,99 @@ bool HttpDownload(const std::string& url, const std::string& saveFilePath, HttpD
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// HGVersion Class
|
||||
|
||||
#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
|
||||
|
||||
HGVersion::HGVersion()
|
||||
{
|
||||
m_isPostCrashInfo = false;
|
||||
m_isPostUserBehavior = false;
|
||||
m_isPostDeviceInfo = false;
|
||||
m_thread = nullptr;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
GetServerConfig(m_isPostCrashInfo, m_isPostUserBehavior, m_isPostDeviceInfo);
|
||||
|
||||
if (m_isPostCrashInfo)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
SetUnhandledExceptionFilter(UnhandledExceptionFilterEx);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
HGVersion::~HGVersion()
|
||||
{
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
bool HGVersion::IsPostUserBehavior()
|
||||
{
|
||||
return m_isPostUserBehavior;
|
||||
}
|
||||
|
||||
bool HGVersion::IsPostDeviceInfo()
|
||||
{
|
||||
return m_isPostDeviceInfo;
|
||||
}
|
||||
|
||||
bool HGVersion::PostUserFeedback(const std::string& info, const std::string& contact)
|
||||
{
|
||||
return ::PostUserFeedback(info, contact);
|
||||
}
|
||||
|
||||
std::string HGVersion::GetCurrVersion()
|
||||
{
|
||||
return ::GetCurrVersion();
|
||||
}
|
||||
|
||||
bool HGVersion::GetVersionInfoList(std::list<VersionInfo>& versionList)
|
||||
{
|
||||
return ::GetVersionInfoList(versionList);
|
||||
}
|
||||
|
||||
int HGVersion::CompareVersion(const std::string& version1, const std::string& version2)
|
||||
{
|
||||
return ::CompareVersion(version1, version2);
|
||||
}
|
||||
|
||||
bool HGVersion::HttpDownload(const std::string& url, const std::string& saveFilePath, HttpDownloadFunc func, void* param)
|
||||
{
|
||||
return ::HttpDownload(url, saveFilePath, func, param);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
#ifndef __HGVERSION_H__
|
||||
#define __HGVERSION_H__
|
||||
|
||||
#include "base/HGDef.h"
|
||||
#include "base/HGInc.h"
|
||||
#include "base/HGThread.h"
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
struct ServerConfig
|
||||
{
|
||||
// 是否上传崩溃日志
|
||||
bool postCrashInfo;
|
||||
// 是否上传用户行为
|
||||
bool postUserBehavior;
|
||||
// 是否上传设备信息
|
||||
bool postDeviceInfo;
|
||||
};
|
||||
|
||||
struct VersionInfo
|
||||
{
|
||||
VersionInfo()
|
||||
|
@ -34,40 +27,51 @@ struct VersionInfo
|
|||
*/
|
||||
typedef int (*HttpDownloadFunc)(long long totalSize, long long nowSize, void *param);
|
||||
|
||||
// 获取服务器配置
|
||||
bool GetServerConfig(ServerConfig &cfg);
|
||||
class HGVersion
|
||||
{
|
||||
public:
|
||||
HGVersion();
|
||||
~HGVersion();
|
||||
|
||||
// 上传崩溃日志
|
||||
bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptionAddr);
|
||||
// 是否上传用户行为
|
||||
bool IsPostUserBehavior();
|
||||
// 上传用户行为
|
||||
bool PostOpenApp();
|
||||
bool PostCloseApp();
|
||||
bool PostLogin();
|
||||
bool PostLogout();
|
||||
|
||||
// 上传用户行为
|
||||
bool PostOpenApp();
|
||||
bool PostCloseApp();
|
||||
bool PostLogin();
|
||||
bool PostLogout();
|
||||
// 是否上传设备信息
|
||||
bool IsPostDeviceInfo();
|
||||
// 上传设备信息
|
||||
bool PostDeviceInfo(const std::string& type, const std::string& name, const std::string& fw, const std::string& sn);
|
||||
bool PostOpenDevice(const std::string& sn);
|
||||
bool PostCloseDevice(const std::string& sn);
|
||||
bool PostScanCount(const std::string& sn, int count);
|
||||
bool PostClearRollerCount(const std::string& sn);
|
||||
bool PostRollerCount(const std::string& sn, int count);
|
||||
bool PostHistoryCount(const std::string& sn, int count);
|
||||
|
||||
// 上传设备信息
|
||||
bool PostDeviceInfo(const std::string &type, const std::string &name, const std::string &fw, const std::string &sn);
|
||||
bool PostOpenDevice(const std::string &sn);
|
||||
bool PostCloseDevice(const std::string &sn);
|
||||
bool PostScanCount(const std::string &sn, int count);
|
||||
bool PostClearRollerCount(const std::string &sn);
|
||||
bool PostRollerCount(const std::string &sn, int count);
|
||||
bool PostHistoryCount(const std::string &sn, int count);
|
||||
// 上传用户反馈
|
||||
bool PostUserFeedback(const std::string& info, const std::string& contact);
|
||||
|
||||
// 上传用户反馈
|
||||
bool PostUserFeedback(const std::string &info, const std::string &contact);
|
||||
// 获取当前版本号
|
||||
std::string GetCurrVersion();
|
||||
|
||||
// 获取当前版本号
|
||||
std::string GetCurrVersion();
|
||||
// 获取服务器上所有版本的信息
|
||||
bool GetVersionInfoList(std::list<VersionInfo>& versionList);
|
||||
|
||||
// 获取服务器上所有版本的信息
|
||||
bool GetVersionInfoList(std::list<VersionInfo> &versionList);
|
||||
// 比较版本号, 负数表示version1<version2, 0表示相等,正数表示version1>version2
|
||||
int CompareVersion(const std::string& version1, const std::string& version2);
|
||||
|
||||
// 比较版本号, 负数表示version1<version2, 0表示相等,正数表示version1>version2
|
||||
int CompareVersion(const std::string& version1, const std::string& version2);
|
||||
// 下载HTTP文件
|
||||
bool HttpDownload(const std::string& url, const std::string& saveFilePath, HttpDownloadFunc func, void* param);
|
||||
|
||||
// 下载HTTP文件
|
||||
bool HttpDownload(const std::string& url, const std::string& saveFilePath, HttpDownloadFunc func, void *param);
|
||||
private:
|
||||
bool m_isPostCrashInfo;
|
||||
bool m_isPostUserBehavior;
|
||||
bool m_isPostDeviceInfo;
|
||||
HGThread m_thread;
|
||||
};
|
||||
|
||||
#endif /* __HGVERSION_H__ */
|
||||
|
|
|
@ -3,79 +3,24 @@
|
|||
#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
|
||||
|
||||
ServerConfig g_serverCfg;
|
||||
|
||||
#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);
|
||||
|
||||
GetServerConfig(g_serverCfg);
|
||||
|
||||
if (g_serverCfg.postCrashInfo)
|
||||
{
|
||||
#if defined(HG_CMP_MSC)
|
||||
SetUnhandledExceptionFilter(UnhandledExceptionFilterEx);
|
||||
#endif
|
||||
}
|
||||
|
||||
QTranslator translator_qt_;
|
||||
if (translator_qt_.load(":translation/qt_zh_CN.qm"))
|
||||
a.installTranslator(&translator_qt_);
|
||||
if (translator_qt_.load(":translation/qt_zh_CN.qm"))
|
||||
a.installTranslator(&translator_qt_);
|
||||
|
||||
QTranslator translator_qt;
|
||||
if (translator_qt.load(":translation/Scanner_zh_CN.qm"))
|
||||
a.installTranslator(&translator_qt);
|
||||
if (translator_qt.load(":translation/Scanner_zh_CN.qm"))
|
||||
a.installTranslator(&translator_qt);
|
||||
|
||||
MainWindow w;
|
||||
HGVersion version;
|
||||
MainWindow w(version);
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2);
|
||||
w.show();
|
||||
a.exec();
|
||||
|
||||
curl_global_cleanup();
|
||||
return 0;
|
||||
return a.exec();
|
||||
}
|
||||
|
|
|
@ -44,9 +44,10 @@
|
|||
#define PASSWORD_KEY 4
|
||||
#define MY_URL_SCHEME "inscanner"
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
MainWindow::MainWindow(class HGVersion& version, QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, m_version(version)
|
||||
, m_admin_loggedIn(false)
|
||||
, m_dpi(200)
|
||||
, m_currFilePath("")
|
||||
|
|
|
@ -52,7 +52,7 @@ class MainWindow : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
MainWindow(class HGVersion &version, QWidget *parent = nullptr);
|
||||
virtual ~MainWindow() override;
|
||||
|
||||
void exitFullScreen();
|
||||
|
@ -224,6 +224,7 @@ private:
|
|||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
class HGVersion &m_version;
|
||||
QString m_password;
|
||||
bool m_admin_loggedIn;
|
||||
HGImgView *m_view;
|
||||
|
|
Loading…
Reference in New Issue