2022-06-29 09:46:00 +00:00
|
|
|
|
#include "HGUpgrade.h"
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#include "base/HGDef.h"
|
|
|
|
|
#include "base/HGInc.h"
|
|
|
|
|
#include "base/HGMd5.h"
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#include "base/HGUtility.h"
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#include "curl/curl.h"
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#include <vector>
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <sstream>
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#include <algorithm>
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#include <HGString.h>
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
#include <iphlpapi.h>
|
2022-07-02 06:51:58 +00:00
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
#include <tlhelp32.h>
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
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");
|
2022-07-01 03:02:41 +00:00
|
|
|
|
if (nullptr != dir)
|
2022-06-30 11:13:53 +00:00
|
|
|
|
{
|
|
|
|
|
printf("opendir success\n");
|
|
|
|
|
|
|
|
|
|
struct dirent *ent;
|
|
|
|
|
while ((ent = readdir(dir)) != nullptr)
|
|
|
|
|
{
|
2022-07-01 03:02:41 +00:00
|
|
|
|
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;
|
2022-06-30 11:13:53 +00:00
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
printf("name %s\n", ent->d_name);
|
2022-06-30 11:13:53 +00:00
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
char addrPath[256];
|
|
|
|
|
sprintf(addrPath, "/sys/class/net/%s/address", ent->d_name);
|
2022-06-30 11:13:53 +00:00
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
FILE *file = fopen(addrPath, "rb");
|
|
|
|
|
if (nullptr != file)
|
|
|
|
|
{
|
|
|
|
|
char mac[1025] = {0};
|
|
|
|
|
fread(mac, 1, 1024, file);
|
2022-06-30 11:13:53 +00:00
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
int len = (int)strlen(mac);
|
|
|
|
|
for (int i = 0; i < len; ++i)
|
2022-06-30 11:13:53 +00:00
|
|
|
|
{
|
2022-07-01 03:02:41 +00:00
|
|
|
|
if (mac[i] == ':')
|
|
|
|
|
mac[i] = '-';
|
|
|
|
|
else if (mac[i] == '\n')
|
|
|
|
|
mac[i] = '\0';
|
2022-06-30 11:13:53 +00:00
|
|
|
|
}
|
2022-07-01 03:02:41 +00:00
|
|
|
|
|
|
|
|
|
if (strlen(mac) > 0)
|
2022-06-30 11:13:53 +00:00
|
|
|
|
{
|
2022-07-01 03:02:41 +00:00
|
|
|
|
macList.push_back(mac);
|
2022-06-30 11:13:53 +00:00
|
|
|
|
}
|
2022-07-01 03:02:41 +00:00
|
|
|
|
|
|
|
|
|
printf("mac %s\n", mac);
|
|
|
|
|
fclose(file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("fopen fail\n");
|
2022-06-30 11:13:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(dir);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
printf("opendir fail\n");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2022-06-29 09:46:00 +00:00
|
|
|
|
|
2022-06-30 08:42:46 +00:00
|
|
|
|
static std::string GetCurrVersion()
|
2022-06-29 09:46:00 +00:00
|
|
|
|
{
|
2022-06-30 08:42:46 +00:00
|
|
|
|
std::string version = "0.0.0.0";
|
|
|
|
|
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
2022-07-01 05:57:27 +00:00
|
|
|
|
#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
|
|
|
|
|
|
2022-06-30 11:13:53 +00:00
|
|
|
|
HKEY hKey = nullptr;
|
2022-07-01 05:57:27 +00:00
|
|
|
|
RegOpenKeyExA(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
2022-06-30 11:13:53 +00:00
|
|
|
|
if (nullptr != hKey)
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
|
|
|
|
CHAR szData[MAX_PATH] = { 0 };
|
|
|
|
|
DWORD cbData = MAX_PATH;
|
2022-06-30 11:13:53 +00:00
|
|
|
|
if (ERROR_SUCCESS == RegQueryValueExA(hKey, "AppVersion", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
|
|
|
|
version = szData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
}
|
|
|
|
|
#else
|
2022-07-01 05:57:27 +00:00
|
|
|
|
#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);
|
|
|
|
|
}
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return version;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 11:13:53 +00:00
|
|
|
|
static bool Greater(const std::string &str1, const std::string &str2)
|
|
|
|
|
{
|
|
|
|
|
return str1 > str2;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-30 08:42:46 +00:00
|
|
|
|
// type:1表示安装 2表示卸载 src:来源 desc: 说明
|
2022-07-01 03:02:41 +00:00
|
|
|
|
static bool PostInfo(int type, const std::string &desc)
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
|
|
|
|
bool ret = false;
|
|
|
|
|
CURL* curl = curl_easy_init();
|
2022-07-02 02:40:30 +00:00
|
|
|
|
if (nullptr != curl)
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
|
|
|
|
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());
|
|
|
|
|
|
2022-06-30 11:13:53 +00:00
|
|
|
|
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];
|
|
|
|
|
}
|
2022-06-30 08:42:46 +00:00
|
|
|
|
|
|
|
|
|
HGByte md5[16] = {0};
|
2022-06-30 11:13:53 +00:00
|
|
|
|
HGBase_MakeMd5((const HGByte *)strMacAddrTotal.c_str(), strMacAddrTotal.size(), md5);
|
2022-06-30 08:42:46 +00:00
|
|
|
|
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();
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
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";
|
|
|
|
|
|
2022-07-01 05:57:27 +00:00
|
|
|
|
FILE *fp = popen("cat /etc/issue | cut -d\' \' -f1", "r");
|
2022-07-01 03:02:41 +00:00
|
|
|
|
if (nullptr != fp)
|
|
|
|
|
{
|
|
|
|
|
char buff[1024] = {0};
|
|
|
|
|
fread(buff, 1024, 1, fp);
|
2022-07-01 05:57:27 +00:00
|
|
|
|
|
|
|
|
|
int len = (int)strlen(buff);
|
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (buff[i] == '\n')
|
|
|
|
|
buff[i] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
osName = buff;
|
|
|
|
|
pclose(fp);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 05:57:27 +00:00
|
|
|
|
fp = popen("arch", "r");
|
2022-07-01 03:02:41 +00:00
|
|
|
|
if (nullptr != fp)
|
|
|
|
|
{
|
|
|
|
|
char buff[1024] = {0};
|
|
|
|
|
fread(buff, 1024, 1, fp);
|
2022-07-01 05:57:27 +00:00
|
|
|
|
|
|
|
|
|
int len = (int)strlen(buff);
|
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (buff[i] == '\n')
|
|
|
|
|
buff[i] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2022-06-30 08:42:46 +00:00
|
|
|
|
char json[1024];
|
|
|
|
|
sprintf(json, "{\"type\":%d, \"mac\":\"%s\", \"localid\":\"%s\", \"v\":\"%s\", \"ref\":\"%s\", \"desc\":\"%s\"}",
|
2022-07-01 03:02:41 +00:00
|
|
|
|
type, macList[0].c_str(), md5Str, version.c_str(), source.c_str(), desc.c_str());
|
2022-06-30 08:42:46 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
|
|
curl_slist_free_all(headers);
|
|
|
|
|
|
|
|
|
|
std::string str_json = out.str(); // 返回值
|
|
|
|
|
printf("%s\n", str_json.c_str());
|
|
|
|
|
|
|
|
|
|
/* always cleanup */
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
2022-06-29 09:46:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
bool PostInstallInfo(const std::string &desc)
|
2022-06-29 09:46:00 +00:00
|
|
|
|
{
|
2022-07-01 03:02:41 +00:00
|
|
|
|
return PostInfo(1, desc);
|
2022-06-29 09:46:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
bool PostUninstallInfo(const std::string &desc)
|
2022-06-29 09:46:00 +00:00
|
|
|
|
{
|
2022-07-01 03:02:41 +00:00
|
|
|
|
return PostInfo(2, desc);
|
2022-06-30 08:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool Setup(const std::string& pkgPath)
|
|
|
|
|
{
|
|
|
|
|
bool ret = false;
|
2022-07-01 05:57:27 +00:00
|
|
|
|
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
|
|
|
|
|
PROCESS_INFORMATION ProcessInfo;
|
|
|
|
|
STARTUPINFOA StartupInfo;
|
|
|
|
|
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
|
|
|
|
|
StartupInfo.cb = sizeof(StartupInfo);
|
|
|
|
|
|
|
|
|
|
char command[256];
|
2022-07-02 01:53:31 +00:00
|
|
|
|
sprintf(command, "%s %s", pkgPath.c_str(), "/verysilent");
|
2022-06-30 11:13:53 +00:00
|
|
|
|
if (CreateProcessA(nullptr, command, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &StartupInfo, &ProcessInfo))
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
|
|
|
|
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
|
|
|
|
|
CloseHandle(ProcessInfo.hThread);
|
|
|
|
|
CloseHandle(ProcessInfo.hProcess);
|
|
|
|
|
ret = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
2022-07-01 05:57:27 +00:00
|
|
|
|
std::string cmd = "dpkg -i \"" + pkgPath + "\"";
|
|
|
|
|
if (0 == system(cmd.c_str()))
|
|
|
|
|
ret = true;
|
2022-06-30 08:42:46 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
bool Upgrade(const std::string& pkgPath, const std::string &desc)
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
|
|
|
|
bool ret = Setup(pkgPath);
|
|
|
|
|
if (ret)
|
2022-07-01 03:02:41 +00:00
|
|
|
|
PostInfo(1, desc);
|
2022-06-30 08:42:46 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
|
|
|
|
bool AppIsRun()
|
|
|
|
|
{
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
|
|
|
|
|
std::wstring appPath;
|
|
|
|
|
|
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
|
std::wstring regName = L"SOFTWARE\\HanvonScan";
|
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
|
std::wstring regName = L"SOFTWARE\\LanxumScan";
|
|
|
|
|
#else
|
|
|
|
|
std::wstring regName = L"SOFTWARE\\HuaGoScan";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HKEY hKey = nullptr;
|
|
|
|
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
|
|
|
|
if (nullptr != hKey)
|
|
|
|
|
{
|
|
|
|
|
WCHAR szData[MAX_PATH] = { 0 };
|
|
|
|
|
DWORD cbData = MAX_PATH;
|
|
|
|
|
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"Application", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
|
|
|
|
{
|
|
|
|
|
appPath = szData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (appPath.empty())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
HANDLE hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
|
if (hSnapshot != INVALID_HANDLE_VALUE)
|
|
|
|
|
{
|
|
|
|
|
PROCESSENTRY32 pe;
|
|
|
|
|
pe.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
|
BOOL bFindFirstProcess = ::Process32First(hSnapshot, &pe);
|
|
|
|
|
if (bFindFirstProcess)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
WCHAR exeFullPath[1024] = { 0 };
|
|
|
|
|
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe.th32ProcessID);
|
|
|
|
|
if (NULL != hProcess)
|
|
|
|
|
{
|
|
|
|
|
DWORD bufferLen = 1024;
|
|
|
|
|
::QueryFullProcessImageName(hProcess, 0, exeFullPath, &bufferLen);
|
|
|
|
|
::CloseHandle(hProcess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (0 == wcsicmp(exeFullPath, appPath.c_str()))
|
|
|
|
|
{
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while (::Process32Next(hSnapshot, &pe));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
::CloseHandle(hSnapshot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RunApp()
|
|
|
|
|
{
|
|
|
|
|
#if defined(HG_CMP_MSC)
|
|
|
|
|
|
|
|
|
|
std::wstring appPath;
|
|
|
|
|
|
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
|
std::wstring regName = L"SOFTWARE\\HanvonScan";
|
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
|
std::wstring regName = L"SOFTWARE\\LanxumScan";
|
|
|
|
|
#else
|
|
|
|
|
std::wstring regName = L"SOFTWARE\\HuaGoScan";
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
HKEY hKey = nullptr;
|
|
|
|
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
|
|
|
|
if (nullptr != hKey)
|
|
|
|
|
{
|
|
|
|
|
WCHAR szData[MAX_PATH] = { 0 };
|
|
|
|
|
DWORD cbData = MAX_PATH;
|
|
|
|
|
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"Application", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
|
|
|
|
{
|
|
|
|
|
appPath = szData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!appPath.empty())
|
|
|
|
|
{
|
|
|
|
|
ShellExecuteW(NULL, L"open", appPath.c_str(), NULL, NULL, SW_SHOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|