Merge branch 'master' of http://192.168.100.140:8099/sane/code_app
This commit is contained in:
commit
9eaa462aee
|
@ -1,937 +0,0 @@
|
|||
#include "HGVersion.h"
|
||||
#include "base/HGDef.h"
|
||||
#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>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#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)
|
||||
{
|
||||
std::string data((const char*) ptr, (size_t) size * nmemb);
|
||||
|
||||
*((std::stringstream*) stream) << data << std::endl;
|
||||
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
static bool GetServerConfig(bool &postCrashInfo, bool & postUserBehavior, bool &postDeviceInfo)
|
||||
{
|
||||
postCrashInfo = false;
|
||||
postUserBehavior = false;
|
||||
postDeviceInfo = false;
|
||||
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
if (nullptr != curl)
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
std::string url = "http://up.appqy.com/api/ver/setting";
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
|
||||
struct curl_slist* headers = nullptr;
|
||||
headers = curl_slist_append(headers, "Accept-Encoding:gzip, deflate, sdch");
|
||||
headers = curl_slist_append(headers, "Accept-Language:zh-CN,zh;q=0.8");
|
||||
headers = curl_slist_append(headers, "Connection:keep-alive");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||
else
|
||||
{
|
||||
std::string str_json = out.str(); // 返回值
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str());
|
||||
|
||||
cJSON* json = cJSON_Parse(str_json.c_str());
|
||||
if (nullptr != json)
|
||||
{
|
||||
cJSON* p = json->child;
|
||||
while (nullptr != p)
|
||||
{
|
||||
if (0 == strcmp(p->string, "code") && p->type == cJSON_Number)
|
||||
{
|
||||
if (1 == p->valueint)
|
||||
ret = true;
|
||||
}
|
||||
else if (0 == strcmp(p->string, "data") && p->type == cJSON_Object)
|
||||
{
|
||||
cJSON* p2 = p->child;
|
||||
while (nullptr != p2)
|
||||
{
|
||||
if (0 == strcmp(p2->string, "report_switch"))
|
||||
postUserBehavior = (bool)p2->valueint;
|
||||
else if (0 == strcmp(p2->string, "collapse_switch"))
|
||||
postCrashInfo = (bool)p2->valueint;
|
||||
else if (0 == strcmp(p2->string, "device_info_switch"))
|
||||
postDeviceInfo = (bool)p2->valueint;
|
||||
|
||||
p2 = p2->next;
|
||||
}
|
||||
}
|
||||
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
}
|
||||
|
||||
curl_slist_free_all(headers);
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int xferinfo(void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "ulnow=%lld, ultotal=%lld", ulnow, ultotal);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool CrashFileUpload(const std::string &filePath, std::string &crashFileUrl)
|
||||
{
|
||||
crashFileUrl.clear();
|
||||
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
if (nullptr != curl)
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
struct curl_httppost* formpost = nullptr;
|
||||
struct curl_httppost* lastptr = nullptr;
|
||||
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "file", CURLFORM_FILE, filePath.c_str(), CURLFORM_END);
|
||||
curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "submit", CURLFORM_COPYCONTENTS, "Submit", CURLFORM_END);
|
||||
|
||||
std::string url = "http://up.appqy.com/api/coollapse/upload";
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||
else
|
||||
{
|
||||
std::string str_json = out.str(); // 返回值
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str());
|
||||
|
||||
cJSON* json = cJSON_Parse(str_json.c_str());
|
||||
if (nullptr != json)
|
||||
{
|
||||
cJSON* p = json->child;
|
||||
while (nullptr != p)
|
||||
{
|
||||
if (0 == strcmp(p->string, "code") && p->type == cJSON_Number)
|
||||
{
|
||||
if (1 == p->valueint)
|
||||
ret = true;
|
||||
}
|
||||
else if (0 == strcmp(p->string, "data") && p->type == cJSON_Object)
|
||||
{
|
||||
cJSON* p2 = p->child;
|
||||
while (nullptr != p2)
|
||||
{
|
||||
if (0 == strcmp(p2->string, "url") && p2->type == cJSON_String)
|
||||
crashFileUrl = p2->valuestring;
|
||||
|
||||
p2 = p2->next;
|
||||
}
|
||||
}
|
||||
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
}
|
||||
|
||||
/* then cleanup the formpost chain */
|
||||
curl_formfree(formpost);
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void GetMacAddrList(std::vector<std::string> &macList)
|
||||
{
|
||||
macList.clear();
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
|
||||
PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulOutBufLen);
|
||||
|
||||
ULONG nRet = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
|
||||
if (ERROR_BUFFER_OVERFLOW == nRet)
|
||||
{
|
||||
free(pAdapterInfo);
|
||||
pAdapterInfo = nullptr;
|
||||
pAdapterInfo = (PIP_ADAPTER_INFO)malloc(ulOutBufLen);
|
||||
|
||||
nRet = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen);
|
||||
}
|
||||
|
||||
if (ERROR_SUCCESS == nRet)
|
||||
{
|
||||
PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
|
||||
while (nullptr != pAdapter)
|
||||
{
|
||||
DWORD dwCharacteristics = 0;
|
||||
|
||||
HKEY hKey = nullptr;
|
||||
RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002bE10318}", 0, KEY_ENUMERATE_SUB_KEYS, &hKey);
|
||||
if (nullptr != hKey)
|
||||
{
|
||||
DWORD dwIndex = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
CHAR szValueName[256];
|
||||
if (ERROR_SUCCESS != RegEnumKeyA(hKey, dwIndex, szValueName, 256))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
HKEY hKey2 = nullptr;
|
||||
RegOpenKeyExA(hKey, szValueName, 0, KEY_QUERY_VALUE, &hKey2);
|
||||
if (nullptr != hKey2)
|
||||
{
|
||||
DWORD dwType;
|
||||
CHAR szData[256] = { 0 };
|
||||
DWORD cbData = 256;
|
||||
if (ERROR_SUCCESS == RegQueryValueExA(hKey2, "NetCfgInstanceId", nullptr, &dwType, (LPBYTE)szData, &cbData) && REG_SZ == dwType)
|
||||
{
|
||||
if (0 == _stricmp(szData, pAdapter->AdapterName))
|
||||
{
|
||||
if (ERROR_SUCCESS == RegQueryValueExA(hKey2, "Characteristics", nullptr, &dwType, (LPBYTE)szData, &cbData) && REG_DWORD == dwType)
|
||||
{
|
||||
dwCharacteristics = *(DWORD*)szData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RegCloseKey(hKey2);
|
||||
}
|
||||
|
||||
++dwIndex;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
if ((dwCharacteristics & 0x4))
|
||||
{
|
||||
std::string strMacAddr;
|
||||
for (UINT i = 0; i < pAdapter->AddressLength; i++)
|
||||
{
|
||||
char str[10];
|
||||
sprintf(str, "%02x", pAdapter->Address[i]);
|
||||
strMacAddr += str;
|
||||
if (i != pAdapter->AddressLength - 1)
|
||||
strMacAddr += "-";
|
||||
}
|
||||
|
||||
macList.push_back(strMacAddr);
|
||||
}
|
||||
|
||||
pAdapter = pAdapter->Next;
|
||||
}
|
||||
}
|
||||
|
||||
free(pAdapterInfo);
|
||||
pAdapterInfo = nullptr;
|
||||
#else
|
||||
DIR *dir = opendir("/sys/class/net");
|
||||
if (nullptr != dir)
|
||||
{
|
||||
printf("opendir success\n");
|
||||
|
||||
struct dirent *ent;
|
||||
while ((ent = readdir(dir)) != nullptr)
|
||||
{
|
||||
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
if (strstr(ent->d_name, "docker") == ent->d_name || strstr(ent->d_name, "sit") == ent->d_name
|
||||
|| strstr(ent->d_name, "ip6tnl") == ent->d_name || strcmp(ent->d_name, "lo") == 0)
|
||||
continue;
|
||||
|
||||
printf("name %s\n", ent->d_name);
|
||||
|
||||
char addrPath[256];
|
||||
sprintf(addrPath, "/sys/class/net/%s/address", ent->d_name);
|
||||
|
||||
FILE *file = fopen(addrPath, "rb");
|
||||
if (nullptr != file)
|
||||
{
|
||||
char mac[1025] = {0};
|
||||
fread(mac, 1, 1024, file);
|
||||
|
||||
int len = (int)strlen(mac);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (mac[i] == ':')
|
||||
mac[i] = '-';
|
||||
else if (mac[i] == '\n')
|
||||
mac[i] = '\0';
|
||||
}
|
||||
|
||||
if (strlen(mac) > 0)
|
||||
{
|
||||
macList.push_back(mac);
|
||||
}
|
||||
|
||||
printf("mac %s\n", mac);
|
||||
fclose(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("fopen fail\n");
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("opendir fail\n");
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
static bool PostInfo(int type, const std::string &crashFileUrl, const std::string &exceptionAddr,
|
||||
const std::string &feedbackInfo, const std::string &feedbackContact, const std::string &desc)
|
||||
{
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
if (nullptr != curl)
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
std::string url = "http://up.appqy.com/api/recode";
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
|
||||
std::vector<std::string> macList;
|
||||
GetMacAddrList(macList);
|
||||
if (macList.empty())
|
||||
macList.push_back("00-00-00-00-00-00");
|
||||
|
||||
std::sort(macList.begin(), macList.end(), Greater);
|
||||
std::string strMacAddrTotal;
|
||||
for (int i = 0; i < (int)macList.size(); ++i)
|
||||
{
|
||||
strMacAddrTotal += macList[i];
|
||||
}
|
||||
|
||||
HGByte md5[16] = {0};
|
||||
HGBase_MakeMd5((const HGByte *)strMacAddrTotal.c_str(), strMacAddrTotal.size(), md5);
|
||||
char md5Str[64] = {0};
|
||||
char *pstr = md5Str;
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
sprintf(pstr, "%02x", md5[i]);
|
||||
pstr += 2;
|
||||
}
|
||||
|
||||
std::string version = GetCurrVersion();
|
||||
|
||||
std::string osName, archName, oemName;
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
osName = "Windows";
|
||||
archName = "unknown";
|
||||
|
||||
SYSTEM_INFO si;
|
||||
GetNativeSystemInfo(&si);
|
||||
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
|
||||
archName = "x64";
|
||||
else if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
|
||||
archName = "x86";
|
||||
|
||||
#else
|
||||
osName = "Linux";
|
||||
archName = "unknown";
|
||||
|
||||
FILE *fp = popen("cat /etc/issue | cut -d\' \' -f1", "r");
|
||||
if (nullptr != fp)
|
||||
{
|
||||
char buff[1024] = {0};
|
||||
fread(buff, 1024, 1, fp);
|
||||
|
||||
int len = (int)strlen(buff);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (buff[i] == '\n')
|
||||
buff[i] = '\0';
|
||||
}
|
||||
|
||||
osName = buff;
|
||||
pclose(fp);
|
||||
}
|
||||
|
||||
fp = popen("arch", "r");
|
||||
if (nullptr != fp)
|
||||
{
|
||||
char buff[1024] = {0};
|
||||
fread(buff, 1024, 1, fp);
|
||||
|
||||
int len = (int)strlen(buff);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (buff[i] == '\n')
|
||||
buff[i] = '\0';
|
||||
}
|
||||
|
||||
archName = buff;
|
||||
pclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OEM_HANWANG)
|
||||
oemName = "Hanvon";
|
||||
#elif defined(OEM_LISICHENG)
|
||||
oemName = "Lanxum";
|
||||
#else
|
||||
oemName = "Huago";
|
||||
#endif
|
||||
|
||||
std::string source = osName + "-" + archName + "-" + oemName;
|
||||
|
||||
char json[1024];
|
||||
if (3 == type)
|
||||
{
|
||||
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\", \"crashaddress\":\"%s\", \"crash_data\":\"%s\"}",
|
||||
type, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str(), exceptionAddr.c_str(), crashFileUrl.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(4 == type);
|
||||
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\", \"content\":\"%s\", \"contact\":\"%s\"}",
|
||||
type, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str(), feedbackInfo.c_str(), feedbackContact.c_str());
|
||||
}
|
||||
|
||||
struct curl_slist* headers = nullptr;
|
||||
headers = curl_slist_append(headers, "Content-Type:application/json;charset=UTF-8");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||
else
|
||||
{
|
||||
std::string str_json = out.str(); // 返回值
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str());
|
||||
|
||||
cJSON* json = cJSON_Parse(str_json.c_str());
|
||||
if (nullptr != json)
|
||||
{
|
||||
cJSON* p = json->child;
|
||||
while (nullptr != p)
|
||||
{
|
||||
if (0 == strcmp(p->string, "code") && p->type == cJSON_Number)
|
||||
{
|
||||
if (1 == p->valueint)
|
||||
ret = true;
|
||||
}
|
||||
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
}
|
||||
|
||||
curl_slist_free_all(headers);
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool PostCrashInfo(const std::string& crashFilePath, const std::string& exceptionAddr)
|
||||
{
|
||||
std::string crashFileUrl;
|
||||
bool ret = CrashFileUpload(crashFilePath, crashFileUrl);
|
||||
if (ret && !crashFileUrl.empty())
|
||||
{
|
||||
ret = PostInfo(3, crashFileUrl, exceptionAddr, "", "", "collapse");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool PostUserFeedback(const std::string &info, const std::string &contact)
|
||||
{
|
||||
return PostInfo(4, "", "", info, contact, "feedback");
|
||||
}
|
||||
|
||||
static bool GetVersionInfoList(std::list<VersionInfo>& versionList)
|
||||
{
|
||||
versionList.clear();
|
||||
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
if (nullptr != curl)
|
||||
{
|
||||
std::stringstream out;
|
||||
|
||||
std::string osName, archName, oemName;
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
osName = "Windows";
|
||||
|
||||
#ifdef _WIN64
|
||||
archName = "x64";
|
||||
#else
|
||||
archName = "x86";
|
||||
#endif
|
||||
|
||||
#else
|
||||
osName = "Linux";
|
||||
archName = "unknown";
|
||||
|
||||
FILE *fp = popen("cat /etc/issue | cut -d\' \' -f1", "r");
|
||||
if (nullptr != fp)
|
||||
{
|
||||
char buff[1024] = {0};
|
||||
fread(buff, 1024, 1, fp);
|
||||
|
||||
int len = (int)strlen(buff);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (buff[i] == '\n')
|
||||
buff[i] = '\0';
|
||||
}
|
||||
|
||||
osName = buff;
|
||||
pclose(fp);
|
||||
}
|
||||
|
||||
fp = popen("arch", "r");
|
||||
if (nullptr != fp)
|
||||
{
|
||||
char buff[1024] = {0};
|
||||
fread(buff, 1024, 1, fp);
|
||||
|
||||
int len = (int)strlen(buff);
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
if (buff[i] == '\n')
|
||||
buff[i] = '\0';
|
||||
}
|
||||
|
||||
archName = buff;
|
||||
pclose(fp);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OEM_HANWANG)
|
||||
oemName = "Hanvon";
|
||||
#elif defined(OEM_LISICHENG)
|
||||
oemName = "Lanxum";
|
||||
#else
|
||||
oemName = "Huago";
|
||||
#endif
|
||||
|
||||
std::string url = "http://up.appqy.com/api/ver?app=Scanner&oem=" + oemName + "&cpu=" + archName + "&sys=" + osName;
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
|
||||
struct curl_slist* headers = nullptr;
|
||||
headers = curl_slist_append(headers, "Accept-Encoding:gzip, deflate, sdch");
|
||||
headers = curl_slist_append(headers, "Accept-Language:zh-CN,zh;q=0.8");
|
||||
headers = curl_slist_append(headers, "Connection:keep-alive");
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||
else
|
||||
{
|
||||
std::string str_json = out.str(); // 返回值
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "str_json=%s", str_json.c_str());
|
||||
|
||||
cJSON* json = cJSON_Parse(str_json.c_str());
|
||||
if (nullptr != json)
|
||||
{
|
||||
cJSON* p = json->child;
|
||||
while (nullptr != p)
|
||||
{
|
||||
if (0 == strcmp(p->string, "code") && p->type == cJSON_Number)
|
||||
{
|
||||
if (1 == p->valueint)
|
||||
ret = true;
|
||||
}
|
||||
else if (0 == strcmp(p->string, "data") && p->type == cJSON_Array)
|
||||
{
|
||||
cJSON* p2 = p->child;
|
||||
while (nullptr != p2)
|
||||
{
|
||||
VersionInfo version;
|
||||
|
||||
cJSON* p3 = p2->child;
|
||||
while (nullptr != p3)
|
||||
{
|
||||
if (0 == strcmp(p3->string, "full") && p3->type == cJSON_String)
|
||||
version.url = p3->valuestring;
|
||||
else if (0 == strcmp(p3->string, "size") && p3->type == cJSON_String)
|
||||
version.size = atoi(p3->valuestring);
|
||||
else if (0 == strcmp(p3->string, "desc") && p3->type == cJSON_String)
|
||||
version.desc = p3->valuestring;
|
||||
else if (0 == strcmp(p3->string, "bug") && p3->type == cJSON_String)
|
||||
version.bugInfo = p3->valuestring;
|
||||
else if (0 == strcmp(p3->string, "md5") && p3->type == cJSON_String)
|
||||
version.md5 = p3->valuestring;
|
||||
else if (0 == strcmp(p3->string, "v") && p3->type == cJSON_String)
|
||||
version.version = p3->valuestring;
|
||||
|
||||
p3 = p3->next;
|
||||
}
|
||||
|
||||
versionList.push_back(version);
|
||||
p2 = p2->next;
|
||||
}
|
||||
}
|
||||
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
}
|
||||
|
||||
curl_slist_free_all(headers);
|
||||
/* always cleanup */
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static std::vector<std::string> split(std::string strtem, char a)
|
||||
{
|
||||
std::vector<std::string> strvec;
|
||||
|
||||
std::string::size_type pos1, pos2;
|
||||
pos2 = strtem.find(a);
|
||||
pos1 = 0;
|
||||
while (std::string::npos != pos2)
|
||||
{
|
||||
strvec.push_back(strtem.substr(pos1, pos2 - pos1));
|
||||
|
||||
pos1 = pos2 + 1;
|
||||
pos2 = strtem.find(a, pos1);
|
||||
}
|
||||
strvec.push_back(strtem.substr(pos1));
|
||||
|
||||
return strvec;
|
||||
}
|
||||
|
||||
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, '.');
|
||||
|
||||
int size1 = versionList1.size();
|
||||
int size2 = versionList2.size();
|
||||
|
||||
int i = 0;
|
||||
while (i < size1 && i < size2)
|
||||
{
|
||||
if (atoi(versionList1[i].c_str()) < atoi(versionList2[i].c_str()))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (atoi(versionList1[i].c_str()) > atoi(versionList2[i].c_str()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
if (i == size1 && i < size2)
|
||||
return -1;
|
||||
else if (i < size1 && i == size2)
|
||||
return 1;
|
||||
|
||||
assert(i == size1 && i == size2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t curlWriteFunction(void *ptr, size_t size, size_t nmemb, FILE *stream)
|
||||
{
|
||||
return fwrite(ptr, size, nmemb, stream);
|
||||
}
|
||||
|
||||
struct myprogress
|
||||
{
|
||||
HttpDownloadFunc func;
|
||||
void* param;
|
||||
};
|
||||
|
||||
static int xferinfo2(void* p, curl_off_t dltotal, curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||
{
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "ulnow=%lld, ultotal=%lld", ulnow, ultotal);
|
||||
|
||||
struct myprogress *myp = (struct myprogress *)p;
|
||||
if (nullptr != myp->func)
|
||||
return myp->func(dltotal, dlnow, myp->param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool HttpDownload(const std::string& url, const std::string& saveFilePath, HttpDownloadFunc func, void* param)
|
||||
{
|
||||
bool ret = false;
|
||||
CURL* curl = curl_easy_init();
|
||||
if (nullptr != curl)
|
||||
{
|
||||
FILE *fp = fopen(saveFilePath.c_str(), "wb"); // 打开文件,准备写入
|
||||
if (nullptr != fp)
|
||||
{
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 2);
|
||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlWriteFunction);
|
||||
|
||||
struct myprogress prog;
|
||||
prog.func = func;
|
||||
prog.param = param;
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &prog);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, xferinfo2);
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
||||
|
||||
/* Perform the request, res will get the return code */
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
/* Check for errors */
|
||||
if (res != CURLE_OK)
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s", curl_easy_strerror(res));
|
||||
else
|
||||
ret = true;
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// HGVersion Class
|
||||
|
||||
#if defined(HG_CMP_MSC)
|
||||
static LONG WINAPI UnhandledExceptionFilterEx(struct _EXCEPTION_POINTERS* ExceptionInfo)
|
||||
{
|
||||
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "Unhandled Exception!!!");
|
||||
|
||||
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,77 +0,0 @@
|
|||
#ifndef __HGVERSION_H__
|
||||
#define __HGVERSION_H__
|
||||
|
||||
#include "base/HGDef.h"
|
||||
#include "base/HGInc.h"
|
||||
#include "base/HGThread.h"
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
struct VersionInfo
|
||||
{
|
||||
VersionInfo()
|
||||
{
|
||||
size = 0;
|
||||
}
|
||||
|
||||
std::string version;
|
||||
std::string desc;
|
||||
std::string bugInfo;
|
||||
std::string url;
|
||||
unsigned long long size;
|
||||
std::string md5;
|
||||
};
|
||||
|
||||
/* http下载进度回调
|
||||
* 返回值: 如果需要停止下载,返回非0;否则返回0
|
||||
*/
|
||||
typedef int (*HttpDownloadFunc)(long long totalSize, long long nowSize, void *param);
|
||||
|
||||
class HGVersion
|
||||
{
|
||||
public:
|
||||
HGVersion();
|
||||
~HGVersion();
|
||||
|
||||
// 是否上传用户行为
|
||||
bool IsPostUserBehavior();
|
||||
// 上传用户行为
|
||||
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 PostUserFeedback(const std::string& info, const std::string& contact);
|
||||
|
||||
// 获取当前版本号
|
||||
std::string GetCurrVersion();
|
||||
|
||||
// 获取服务器上所有版本的信息
|
||||
bool GetVersionInfoList(std::list<VersionInfo>& versionList);
|
||||
|
||||
// 比较版本号, 负数表示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);
|
||||
|
||||
private:
|
||||
bool m_isPostCrashInfo;
|
||||
bool m_isPostUserBehavior;
|
||||
bool m_isPostDeviceInfo;
|
||||
HGThread m_thread;
|
||||
};
|
||||
|
||||
#endif /* __HGVERSION_H__ */
|
|
@ -1,17 +1,27 @@
|
|||
#include "dialog_updateprogress.h"
|
||||
#include "ui_dialog_updateprogress.h"
|
||||
#include "base/HGUtility.h"
|
||||
#include "base/HGMd5.h"
|
||||
#include <QMessageBox>
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
Dialog_updateProgress::Dialog_updateProgress(class HGVersion &version, const QString &url, QWidget *parent) :
|
||||
Dialog_updateProgress::Dialog_updateProgress(HGDll dll, HGVersionMgr mgr, const QString &url,
|
||||
const QString &versionNum, const QString &md5, QWidget *parent) :
|
||||
QDialog(parent)
|
||||
, m_version(version)
|
||||
, m_versionDll(dll)
|
||||
, m_versionMgr(mgr)
|
||||
, m_url(url)
|
||||
, m_versionNum(versionNum)
|
||||
, m_md5(md5)
|
||||
, ui(new Ui::Dialog_updateProgress)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->progressBar->setValue(0);
|
||||
|
||||
connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(finish()), this, SLOT(on_finish()), Qt::QueuedConnection);
|
||||
|
||||
m_stopThread = false;
|
||||
HGBase_OpenThread(ThreadFunc, this, &m_thread);
|
||||
|
@ -28,7 +38,7 @@ Dialog_updateProgress::~Dialog_updateProgress()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
int Dialog_updateProgress::HttpDownloadThreadFunc(long long totalSize, long long nowSize, void *param)
|
||||
HGInt Dialog_updateProgress::HttpDownloadThreadFunc(HGULonglong totalSize, HGULonglong nowSize, HGPointer param)
|
||||
{
|
||||
Dialog_updateProgress *p = (Dialog_updateProgress *)param;
|
||||
if (p->m_stopThread)
|
||||
|
@ -52,9 +62,53 @@ void Dialog_updateProgress::ThreadFunc(HGThread thread, HGPointer param)
|
|||
HGChar cfgPath[512];
|
||||
HGBase_GetConfigPath(cfgPath, 512);
|
||||
HGBase_CreateDir(cfgPath);
|
||||
strcat(cfgPath, "123.exe");
|
||||
strcat(cfgPath, (p->m_versionNum + QString("%1").arg(".exe")).toLatin1().data());
|
||||
|
||||
QFile cfgFile(cfgPath);
|
||||
cfgFile.open(QFile::ReadOnly);
|
||||
QByteArray fileMsg = cfgFile.readAll();
|
||||
cfgFile.close();
|
||||
QString md5 = QCryptographicHash::hash(fileMsg , QCryptographicHash::Md5).toHex();
|
||||
|
||||
bool ret = true;
|
||||
if(!p->isFileExists(cfgPath) || md5 != p->m_md5)
|
||||
{
|
||||
typedef HGResult (HGAPI *Func)(HGVersionMgr, const HGChar *, const HGChar *, HGHttpDownloadFunc, HGPointer);
|
||||
Func func = NULL;
|
||||
ret = HGBase_GetDllProcAddress(p->m_versionDll, "HGVersion_HttpDownload", (HGPointer *)&func);
|
||||
if (NULL != func)
|
||||
{
|
||||
func(p->m_versionMgr, p->m_url.toStdString().c_str(), cfgPath, HttpDownloadThreadFunc, p);
|
||||
}
|
||||
if (ret)
|
||||
{
|
||||
QString curPath = QDir::currentPath();
|
||||
QString tmpPath = QDir::tempPath();
|
||||
QFile file(curPath);
|
||||
file.copy("HuagoScanUpgrade.exe", tmpPath);
|
||||
#if defined(HG_CMP_MSC)
|
||||
file.copy("msvcp140.dll", tmpPath);
|
||||
file.copy("Qt5Core.dll", tmpPath);
|
||||
file.copy("Qt5Gui.dll", tmpPath);
|
||||
file.copy("Qt5Widgets.dll", tmpPath);
|
||||
file.copy("vcruntime140.dll", tmpPath);
|
||||
#endif
|
||||
|
||||
emit p->finish();
|
||||
emit p->upgradeApp();
|
||||
}
|
||||
else
|
||||
{
|
||||
emit p->finish();
|
||||
QFile::remove(cfgPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
emit p->finish();
|
||||
emit p->upgradeApp();
|
||||
}
|
||||
|
||||
p->m_version.HttpDownload(p->m_url.toStdString(), cfgPath, HttpDownloadThreadFunc, p);
|
||||
}
|
||||
|
||||
void Dialog_updateProgress::on_updateProgress(int value)
|
||||
|
@ -62,6 +116,11 @@ void Dialog_updateProgress::on_updateProgress(int value)
|
|||
ui->progressBar->setValue(value);
|
||||
}
|
||||
|
||||
void Dialog_updateProgress::on_finish()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
void Dialog_updateProgress::on_pushButton_clicked()
|
||||
{
|
||||
m_stopThread = true;
|
||||
|
@ -70,6 +129,12 @@ void Dialog_updateProgress::on_pushButton_clicked()
|
|||
close();
|
||||
}
|
||||
|
||||
bool Dialog_updateProgress::isFileExists(const std::string &filepath)
|
||||
{
|
||||
struct stat buffer;
|
||||
return (stat(filepath.c_str(), &buffer) == 0);
|
||||
}
|
||||
|
||||
void Dialog_updateProgress::closeEvent(QCloseEvent* e)
|
||||
{
|
||||
(void)e;
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#include <QDialog>
|
||||
#include "base/HGThread.h"
|
||||
#include "HGVersion.h"
|
||||
#include "base/HGDll.h"
|
||||
#include "version/HGVersion.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
namespace Ui {
|
||||
|
@ -15,26 +16,34 @@ class Dialog_updateProgress : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit Dialog_updateProgress(class HGVersion &version, const QString &url, QWidget *parent = nullptr);
|
||||
explicit Dialog_updateProgress(HGDll dll, HGVersionMgr mgr, const QString &url,
|
||||
const QString &versionNum, const QString &md5, QWidget *parent = nullptr);
|
||||
~Dialog_updateProgress();
|
||||
private:
|
||||
static int HttpDownloadThreadFunc(long long totalSize, long long nowSize, void *param);
|
||||
static HGInt HttpDownloadThreadFunc(HGULonglong totalSize, HGULonglong nowSize, HGPointer param);
|
||||
static void ThreadFunc(HGThread thread, HGPointer param);
|
||||
|
||||
signals:
|
||||
void updateProgress(int value);
|
||||
void finish();
|
||||
void upgradeApp();
|
||||
private slots:
|
||||
void on_updateProgress(int value);
|
||||
void on_finish();
|
||||
|
||||
void on_pushButton_clicked();
|
||||
bool isFileExists(const std::string& filepath);
|
||||
protected:
|
||||
virtual void closeEvent(QCloseEvent* e);
|
||||
|
||||
private:
|
||||
Ui::Dialog_updateProgress *ui;
|
||||
|
||||
class HGVersion &m_version;
|
||||
HGDll m_versionDll;
|
||||
HGVersionMgr m_versionMgr;
|
||||
QString m_url;
|
||||
QString m_versionNum;
|
||||
QString m_md5;
|
||||
bool m_stopThread;
|
||||
HGThread m_thread;
|
||||
};
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QScreen>
|
||||
#include "HGVersion.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -17,8 +16,7 @@ int main(int argc, char *argv[])
|
|||
if (translator_qt.load(":translation/Scanner_zh_CN.qm"))
|
||||
a.installTranslator(&translator_qt);
|
||||
|
||||
HGVersion version;
|
||||
MainWindow w(version);
|
||||
MainWindow w;
|
||||
QScreen *screen = QGuiApplication::primaryScreen();
|
||||
w.move((screen->size().width() - w.width()) / 2, (screen->size().height() - w.height()) / 2);
|
||||
w.show();
|
||||
|
|
|
@ -45,10 +45,11 @@
|
|||
#define PASSWORD_KEY 4
|
||||
#define MY_URL_SCHEME "inscanner"
|
||||
|
||||
MainWindow::MainWindow(class HGVersion& version, QWidget *parent)
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
, m_version(version)
|
||||
, m_versionDll(NULL)
|
||||
, m_versionMgr(NULL)
|
||||
, m_admin_loggedIn(false)
|
||||
, m_dpi(200)
|
||||
, m_currFilePath("")
|
||||
|
@ -67,16 +68,46 @@ MainWindow::MainWindow(class HGVersion& version, QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
std::string versionDllName;
|
||||
|
||||
#if defined(OEM_HANWANG)
|
||||
this->setWindowIcon(QIcon(":images/image_rsc/logo/Hanvon_logo1.ico"));
|
||||
this->setWindowTitle(tr("HanvonScan"));
|
||||
#if defined(HG_CMP_MSC)
|
||||
versionDllName = "HWVersion.dll";
|
||||
#else
|
||||
versionDllName = "HWVersion.so";
|
||||
#endif
|
||||
#elif defined(OEM_LISICHENG)
|
||||
this->setWindowIcon(QIcon(":images/image_rsc/logo/Lanxum_logo.ico"));
|
||||
this->setWindowTitle(tr("LanxumScan"));
|
||||
#if defined(HG_CMP_MSC)
|
||||
versionDllName = "LSCVersion.dll";
|
||||
#else
|
||||
versionDllName = "LSCVersion.so";
|
||||
#endif
|
||||
#else
|
||||
this->setWindowIcon(QIcon(":images/image_rsc/logo/logo.ico"));
|
||||
this->setWindowTitle(tr("HuaGoScan"));
|
||||
#if defined(HG_CMP_MSC)
|
||||
versionDllName = "HGVersion.dll";
|
||||
#else
|
||||
versionDllName = "HGVersion.so";
|
||||
#endif
|
||||
#endif
|
||||
|
||||
HGBase_CreateDll(versionDllName.c_str(), &m_versionDll);
|
||||
if (NULL != m_versionDll)
|
||||
{
|
||||
typedef HGResult (HGAPI *Func)(HGVersionMgr *);
|
||||
Func func = NULL;
|
||||
HGBase_GetDllProcAddress(m_versionDll, "HGVersion_CreateMgr", (HGPointer *)&func);
|
||||
if (NULL != func)
|
||||
{
|
||||
func(&m_versionMgr);
|
||||
}
|
||||
}
|
||||
|
||||
this->setAutoFillBackground(true);
|
||||
this->setPalette(QPalette(QColor(230, 230, 230)));
|
||||
|
||||
|
@ -87,6 +118,7 @@ MainWindow::MainWindow(class HGVersion& version, QWidget *parent)
|
|||
resize(950, 720);
|
||||
}
|
||||
|
||||
if (NULL == m_versionDll)
|
||||
ui->actionact_update->setVisible(false);
|
||||
|
||||
m_config.load();
|
||||
|
@ -292,6 +324,21 @@ MainWindow::~MainWindow()
|
|||
cur_dev_.close();
|
||||
sane_exit();
|
||||
|
||||
typedef HGResult (HGAPI *Func)(HGVersionMgr);
|
||||
Func func = NULL;
|
||||
HGBase_GetDllProcAddress(m_versionDll, "HGVersion_DestroyMgr", (HGPointer *)&func);
|
||||
if (NULL != func)
|
||||
{
|
||||
func(m_versionMgr);
|
||||
m_versionMgr = NULL;
|
||||
}
|
||||
|
||||
if (NULL != m_versionDll)
|
||||
{
|
||||
HGBase_DestroyDll(m_versionDll);
|
||||
m_versionDll = NULL;
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
@ -1084,17 +1131,41 @@ void MainWindow::on_statusInfoDblClick()
|
|||
|
||||
void MainWindow::on_update(QListWidgetItem *item)
|
||||
{
|
||||
std::string curVersion;
|
||||
|
||||
typedef HGResult (HGAPI *Func)(const HGChar*, HGChar*, HGUInt);
|
||||
Func func = NULL;
|
||||
HGBase_GetDllProcAddress(m_versionDll, "HGVersion_GetCurrVersion", (HGPointer *)&func);
|
||||
if (NULL != func)
|
||||
{
|
||||
HGChar ver[256] = {0};
|
||||
func(HGVERSION_APPNAME_SCANNER, ver, 256);
|
||||
curVersion = ver;
|
||||
}
|
||||
|
||||
HGInt result = 0;
|
||||
|
||||
typedef HGResult (HGAPI *Func2)(const HGChar*, const HGChar*, HGInt*);
|
||||
Func2 func2 = NULL;
|
||||
HGBase_GetDllProcAddress(m_versionDll, "HGVersion_CompareVersion", (HGPointer *)&func2);
|
||||
if (NULL != func2)
|
||||
{
|
||||
func2(curVersion.c_str(), item->text().toStdString().c_str(), &result);
|
||||
}
|
||||
|
||||
m_listwidget->close();
|
||||
if(0 == m_version.CompareVersion(m_version.GetCurrVersion(), item->text().toStdString()))
|
||||
if(0 == result)
|
||||
{
|
||||
QMessageBox::information(this, "tip", "Already in current version");
|
||||
return;
|
||||
}else
|
||||
{
|
||||
QString url = item->data(Qt::UserRole).toString();
|
||||
QString versionNum = item->text();
|
||||
QString md5 = item->data(Qt::UserRole+1).toString();
|
||||
|
||||
Dialog_updateProgress dlg(m_version, url);
|
||||
dlg.exec();
|
||||
Dialog_updateProgress *dlg = new Dialog_updateProgress(m_versionDll, m_versionMgr, url, versionNum, md5);
|
||||
dlg->exec();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3113,17 +3184,26 @@ void MainWindow::on_actionact_update_triggered()
|
|||
m_listwidget = new QListWidget;
|
||||
m_listwidget->setWindowTitle("chose the version");
|
||||
|
||||
std::list<VersionInfo> versionList;
|
||||
if(m_version.GetVersionInfoList(versionList))
|
||||
{
|
||||
std::list<VersionInfo>::iterator iter;
|
||||
HGVersionInfo versionInfo[64];
|
||||
HGUInt count = 0;
|
||||
|
||||
for(iter = versionList.begin(); iter != versionList.end(); ++iter)
|
||||
typedef HGResult (HGAPI *Func)(HGVersionMgr, const HGChar*, HGVersionInfo *, HGUInt, HGUInt *);
|
||||
Func func = NULL;
|
||||
HGBase_GetDllProcAddress(m_versionDll, "HGVersion_GetVersionList", (HGPointer *)&func);
|
||||
if (NULL != func)
|
||||
{
|
||||
func(m_versionMgr, HGVERSION_APPNAME_SCANNER, versionInfo, 64, &count);
|
||||
}
|
||||
|
||||
if(count > 0)
|
||||
{
|
||||
for(HGUInt i = 0; i < count; ++i)
|
||||
{
|
||||
QListWidgetItem *listwidgetItem = new QListWidgetItem;
|
||||
listwidgetItem->setText(QString(iter->version.c_str()));
|
||||
listwidgetItem->setData(Qt::UserRole, iter->url.c_str());
|
||||
listwidgetItem->setToolTip(iter->desc.c_str() + tr(" buginfo: ") + iter->bugInfo.c_str());
|
||||
listwidgetItem->setText(QString(versionInfo[i].version));
|
||||
listwidgetItem->setData(Qt::UserRole, versionInfo[i].url);
|
||||
listwidgetItem->setData(Qt::UserRole+1, versionInfo[i].md5);
|
||||
listwidgetItem->setToolTip(versionInfo[i].desc + tr(" buginfo: ") + versionInfo[i].bugInfo);
|
||||
m_listwidget->addItem(listwidgetItem);
|
||||
connect(m_listwidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(on_update(QListWidgetItem*)), Qt::QueuedConnection);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@
|
|||
#include "sane/sane_ex.h"
|
||||
#include "config.h"
|
||||
#include "dialog_aquireinto.h"
|
||||
#include "base/HGDll.h"
|
||||
#include "imgfmt/HGImgFmt.h"
|
||||
#include "HGVersion.h"
|
||||
#include "version/HGVersion.h"
|
||||
#include "device_menu.h"
|
||||
#include "sane_device.h"
|
||||
|
||||
|
@ -54,7 +55,7 @@ class MainWindow : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(class HGVersion &version, QWidget *parent = nullptr);
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
virtual ~MainWindow() override;
|
||||
|
||||
void exitFullScreen();
|
||||
|
@ -229,7 +230,8 @@ private:
|
|||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
class HGVersion &m_version;
|
||||
HGDll m_versionDll;
|
||||
HGVersionMgr m_versionMgr;
|
||||
QString m_password;
|
||||
bool m_admin_loggedIn;
|
||||
HGImgView *m_view;
|
||||
|
|
|
@ -24,29 +24,23 @@ TARGET = HuaGoScan
|
|||
|
||||
win32 {
|
||||
DEFINES += _CRT_SECURE_NO_WARNINGS
|
||||
DEFINES += CURL_STATICLIB
|
||||
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/windows/include
|
||||
LIBS += -ladvapi32 -lIphlpapi -lwldap32 -lws2_32 -ldbghelp
|
||||
|
||||
contains(QT_ARCH, i386) {
|
||||
LIBS += -L../../../../sdk/lib/win/x86/Release -lHGBase -lHGImgFmt -lHGImgProc -lsane
|
||||
CONFIG(release, debug|release) {
|
||||
LIBS += -L../../../third_party/libcurl/windows/lib/x86 -llibcurl
|
||||
DESTDIR = ../../../../release/win/x86/Release/
|
||||
}
|
||||
CONFIG(debug, debug|release) {
|
||||
LIBS += -L../../../third_party/libcurl/windows/lib/x86 -llibcurld
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
LIBS += -L../../../../sdk/lib/win/x64/Release -lHGBase -lHGImgFmt -lHGImgProc -lsane
|
||||
CONFIG(release, debug|release) {
|
||||
LIBS += -L../../../third_party/libcurl/windows/lib/x64 -llibcurl
|
||||
DESTDIR = ../../../../release/win/x64/Release/
|
||||
}
|
||||
CONFIG(debug, debug|release) {
|
||||
LIBS += -L../../../third_party/libcurl/windows/lib/x64 -llibcurld
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,9 +55,6 @@ unix {
|
|||
message('UOS')
|
||||
DEFINES += UOS
|
||||
contains(ARCH, x86_64){
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/uos/amd64/include
|
||||
LIBS += -L../../../third_party/libcurl/uos/amd64/lib -lcurl
|
||||
LIBS += -L../../../third_party/zlib/uos/amd64/lib -lz
|
||||
LIBS += -L../../../../release/uos/x86_64 -lHGBase -lHGImgFmt -lHGImgProc -lsane-hgsane -lhgdriver
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = ../../../../release/uos/x86_64/
|
||||
|
@ -73,9 +64,6 @@ unix {
|
|||
}
|
||||
}
|
||||
contains(ARCH, aarch64){
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/uos/aarch64/include
|
||||
LIBS += -L../../../third_party/libcurl/uos/aarch64/lib -lcurl
|
||||
LIBS += -L../../../third_party/zlib/uos/aarch64/lib -lz
|
||||
LIBS += -L../../../../release/uos/aarch64 -lHGBase -lHGImgFmt -lHGImgProc -lsane-hgsane -lhgdriver
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = ../../../../release/uos/aarch64/
|
||||
|
@ -85,9 +73,6 @@ unix {
|
|||
}
|
||||
}
|
||||
contains(ARCH, mips64){
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/uos/mips64/include
|
||||
LIBS += -L../../../third_party/libcurl/uos/mips64/lib -lcurl
|
||||
LIBS += -L../../../third_party/zlib/uos/mips64/lib -lz
|
||||
LIBS += -L../../../../release/uos/mips64 -lHGBase -lHGImgFmt -lHGImgProc -lsane-hgsane -lhgdriver
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = ../../../../release/uos/mips64/
|
||||
|
@ -100,9 +85,6 @@ unix {
|
|||
message('KYLIN')
|
||||
DEFINES += KYLIN
|
||||
contains(ARCH, x86_64){
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/kylin/amd64/include
|
||||
LIBS += -L../../../third_party/libcurl/kylin/amd64/lib -lcurl
|
||||
LIBS += -L../../../third_party/zlib/kylin/amd64/lib -lz
|
||||
LIBS += -L../../../../release/kylin/x86_64 -lHGBase -lHGImgFmt -lHGImgProc -lsane-hgsane -lhgdriver
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = ../../../../release/kylin/x86_64/
|
||||
|
@ -112,9 +94,6 @@ unix {
|
|||
}
|
||||
}
|
||||
contains(ARCH, aarch64){
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/kylin/aarch64/include
|
||||
LIBS += -L../../../third_party/libcurl/kylin/aarch64/lib -lcurl
|
||||
LIBS += -L../../../third_party/zlib/kylin/aarch64/lib -lz
|
||||
LIBS += -L../../../../release/kylin/aarch64 -lHGBase -lHGImgFmt -lHGImgProc -lsane-hgsane -lhgdriver
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = ../../../../release/kylin/aarch64/
|
||||
|
@ -124,9 +103,6 @@ unix {
|
|||
}
|
||||
}
|
||||
contains(ARCH, mips64){
|
||||
INCLUDEPATH += $$PWD/../../../third_party/libcurl/kylin/mips64/include
|
||||
LIBS += -L../../../third_party/libcurl/kylin/mips64/lib -lcurl
|
||||
LIBS += -L../../../third_party/zlib/kylin/mips64/lib -lz
|
||||
LIBS += -L../../../../release/kylin/mips64 -lHGBase -lHGImgFmt -lHGImgProc -lsane-hgsane -lhgdriver
|
||||
CONFIG(release, debug|release) {
|
||||
DESTDIR = ../../../../release/kylin/mips64/
|
||||
|
@ -144,7 +120,6 @@ INCLUDEPATH += $$PWD/../../../modules/
|
|||
INCLUDEPATH += $$PWD/../../../../sdk/include/
|
||||
|
||||
SOURCES += \
|
||||
../../../app/scanner/HGVersion.cpp \
|
||||
../../../app/scanner/app_cfg.cpp \
|
||||
../../../app/scanner/cutdialog.cpp \
|
||||
../../../app/scanner/cutpapertool.cpp \
|
||||
|
@ -190,7 +165,6 @@ SOURCES += \
|
|||
../../../app/scanner/dialog_updateprogress.cpp
|
||||
|
||||
HEADERS += \
|
||||
../../../app/scanner/HGVersion.h \
|
||||
../../../app/scanner/app_cfg.h \
|
||||
../../../app/scanner/cutdialog.h \
|
||||
../../../app/scanner/cutpapertool.h \
|
||||
|
|
Loading…
Reference in New Issue