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"
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#include "version/HGVersion.h"
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
2022-07-02 06:51:58 +00:00
|
|
|
|
#include <shellapi.h>
|
|
|
|
|
#include <tlhelp32.h>
|
2022-08-18 09:11:25 +00:00
|
|
|
|
#include <psapi.h>
|
2022-06-30 11:13:53 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
bool AppIsRun(const std::string& appName)
|
2022-06-30 11:13:53 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
if (appName == HGVERSION_APPNAME_SCANNER)
|
2022-06-30 11:13:53 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
2022-06-30 11:13:53 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
std::wstring appPath;
|
2022-06-30 11:13:53 +00:00
|
|
|
|
|
2022-07-01 05:57:27 +00:00
|
|
|
|
#if defined(OEM_HANWANG)
|
2022-07-14 03:52:11 +00:00
|
|
|
|
std::wstring regName = L"SOFTWARE\\HanvonScan";
|
2022-07-01 05:57:27 +00:00
|
|
|
|
#elif defined(OEM_LISICHENG)
|
2022-07-14 03:52:11 +00:00
|
|
|
|
std::wstring regName = L"SOFTWARE\\LanxumScan";
|
2022-07-01 05:57:27 +00:00
|
|
|
|
#else
|
2022-07-14 03:52:11 +00:00
|
|
|
|
std::wstring regName = L"SOFTWARE\\HuaGoScan";
|
2022-07-01 05:57:27 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
HKEY hKey = nullptr;
|
|
|
|
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
|
|
|
|
if (nullptr != hKey)
|
2022-07-01 05:57:27 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
WCHAR szData[MAX_PATH] = { 0 };
|
|
|
|
|
DWORD cbData = MAX_PATH;
|
|
|
|
|
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"Application", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
2022-07-01 05:57:27 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
appPath = szData;
|
2022-07-01 05:57:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2022-06-30 11:13:53 +00:00
|
|
|
|
}
|
2022-06-30 08:42:46 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
if (appPath.empty())
|
2022-06-30 08:42:46 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
return false;
|
2022-06-30 08:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
bool ret = false;
|
|
|
|
|
HANDLE hSnapshot = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
|
|
|
|
if (hSnapshot != INVALID_HANDLE_VALUE)
|
2022-07-01 03:02:41 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
PROCESSENTRY32 pe;
|
|
|
|
|
pe.dwSize = sizeof(PROCESSENTRY32);
|
|
|
|
|
BOOL bFindFirstProcess = ::Process32First(hSnapshot, &pe);
|
|
|
|
|
if (bFindFirstProcess)
|
2022-07-01 05:57:27 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
WCHAR exeFullPath[1024] = { 0 };
|
2022-08-18 09:11:25 +00:00
|
|
|
|
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pe.th32ProcessID);
|
2022-07-14 03:52:11 +00:00
|
|
|
|
if (nullptr != hProcess)
|
|
|
|
|
{
|
2022-08-22 07:18:07 +00:00
|
|
|
|
::GetModuleFileNameExW(hProcess, NULL, exeFullPath, 1024);
|
2022-07-14 03:52:11 +00:00
|
|
|
|
::CloseHandle(hProcess);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (0 == wcsicmp(exeFullPath, appPath.c_str()))
|
|
|
|
|
{
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while (::Process32Next(hSnapshot, &pe));
|
2022-07-01 05:57:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
::CloseHandle(hSnapshot);
|
2022-07-01 03:02:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
std::string cmd;
|
|
|
|
|
std::string appPath;
|
2022-07-22 01:46:34 +00:00
|
|
|
|
#if defined (UOS)
|
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
|
cmd = "ps -wef | grep HanvonScan";
|
|
|
|
|
appPath = "/opt/apps/com.hanvonchina.hanvonscan/files/bin/HanvonScan";
|
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
|
cmd = "ps -wef | grep LanxumScan";
|
|
|
|
|
appPath = "/opt/apps/com.lanxumchina.lanxumscan/files/bin/LanxumScan";
|
|
|
|
|
#else
|
|
|
|
|
cmd = "ps -wef | grep HuaGoScan";
|
|
|
|
|
appPath = "/opt/apps/com.huagaochina.huagoscan/files/bin/HuaGoScan";
|
|
|
|
|
#endif
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#else
|
2022-07-22 01:46:34 +00:00
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
|
cmd = "ps -wef | grep HanvonScan";
|
|
|
|
|
appPath = "/opt/apps/scanner-driver-hanvon/HanvonScan";
|
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
|
cmd = "ps -wef | grep LanxumScan";
|
|
|
|
|
appPath = "/opt/apps/scanner-driver-lanxum/LanxumScan";
|
|
|
|
|
#else
|
|
|
|
|
cmd = "ps -wef | grep HuaGoScan";
|
|
|
|
|
appPath = "/opt/apps/scanner-driver-huagao/HuaGoScan";
|
|
|
|
|
#endif
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
bool ret = false;
|
|
|
|
|
FILE *fp = popen(cmd.c_str(), "r");
|
2022-07-01 03:02:41 +00:00
|
|
|
|
if (nullptr != fp)
|
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
char data[2048] = {0};
|
|
|
|
|
while (data == fgets(data, 2048, fp))
|
2022-07-01 05:57:27 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
if (nullptr != strstr(data, appPath.c_str()))
|
|
|
|
|
{
|
|
|
|
|
ret = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-07-01 05:57:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-01 03:02:41 +00:00
|
|
|
|
pclose(fp);
|
|
|
|
|
}
|
2022-06-30 08:42:46 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
return ret;
|
2022-06-30 08:42:46 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#endif
|
2022-06-30 08:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
return false;
|
2022-06-30 08:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
void RunApp(const std::string& appName)
|
2022-07-02 06:51:58 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
if (appName == HGVERSION_APPNAME_SCANNER)
|
2022-07-02 06:51:58 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#if defined(HG_CMP_MSC)
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
std::wstring appPath;
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#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
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
HKEY hKey = nullptr;
|
|
|
|
|
RegOpenKeyExW(HKEY_LOCAL_MACHINE, regName.c_str(), 0, KEY_QUERY_VALUE, &hKey);
|
|
|
|
|
if (nullptr != hKey)
|
2022-07-02 06:51:58 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
WCHAR szData[MAX_PATH] = { 0 };
|
|
|
|
|
DWORD cbData = MAX_PATH;
|
|
|
|
|
if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"Application", nullptr, nullptr, (LPBYTE)szData, &cbData))
|
2022-07-02 06:51:58 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
appPath = szData;
|
|
|
|
|
}
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
RegCloseKey(hKey);
|
2022-07-02 06:51:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
if (!appPath.empty())
|
2022-07-04 01:16:14 +00:00
|
|
|
|
{
|
2022-07-14 03:52:11 +00:00
|
|
|
|
ShellExecuteW(nullptr, L"open", appPath.c_str(), nullptr, nullptr, SW_SHOW);
|
2022-07-04 01:16:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#else
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
std::string appPath;
|
2022-07-22 01:46:34 +00:00
|
|
|
|
#if defined (UOS)
|
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
|
appPath = "sh /opt/apps/com.hanvonchina.hanvonscan/files/bin/HanvonScan.sh &";
|
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
|
appPath = "sh /opt/apps/com.lanxumchina.lanxumscan/files/bin/LanxumScan.sh &";
|
|
|
|
|
#else
|
|
|
|
|
appPath = "sh /opt/apps/com.huagaochina.huagoscan/files/bin/HuaGoScan.sh &";
|
|
|
|
|
#endif
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#else
|
2022-07-22 01:46:34 +00:00
|
|
|
|
#if defined(OEM_HANWANG)
|
|
|
|
|
appPath = "sh /opt/apps/scanner-driver-hanvon/HanvonScan.sh &";
|
|
|
|
|
#elif defined(OEM_LISICHENG)
|
|
|
|
|
appPath = "sh /opt/apps/scanner-driver-lanxum/LanxumScan.sh &";
|
|
|
|
|
#else
|
|
|
|
|
appPath = "sh /opt/apps/scanner-driver-huagao/HuaGoScan.sh &";
|
|
|
|
|
#endif
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#endif
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
system(appPath.c_str());
|
2022-07-02 06:51:58 +00:00
|
|
|
|
|
2022-07-14 03:52:11 +00:00
|
|
|
|
#endif
|
2022-07-02 06:51:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|