|
@@ -32,6 +32,7 @@
|
|
|
|
|
|
#include "path.h"
|
|
#include "path.h"
|
|
#include "toolkit.h"
|
|
#include "toolkit.h"
|
|
|
|
+#include "charset.h"
|
|
#include <string>
|
|
#include <string>
|
|
#include <iostream>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <sstream>
|
|
@@ -47,9 +48,6 @@
|
|
|
|
|
|
typedef unsigned long long ULLINT;
|
|
typedef unsigned long long ULLINT;
|
|
|
|
|
|
-
|
|
|
|
-#define SLEEP(interval) std::this_thread::sleep_for(std::chrono::milliseconds(interval))
|
|
|
|
-
|
|
|
|
namespace SP
|
|
namespace SP
|
|
{
|
|
{
|
|
namespace Module
|
|
namespace Module
|
|
@@ -168,96 +166,6 @@ namespace Module
|
|
|
|
|
|
namespace Comm
|
|
namespace Comm
|
|
{
|
|
{
|
|
-
|
|
|
|
-/** Rely on ${OTHER_LIB_BASE_DIR}/libpublicFun and library target libpublicFun*/
|
|
|
|
-struct LogNotiyMessageStruct
|
|
|
|
-{
|
|
|
|
- std::string Reason;
|
|
|
|
- std::string ErrMsg;
|
|
|
|
- std::string RebootTime;
|
|
|
|
-
|
|
|
|
- LogNotiyMessageStruct(const CSimpleStringA& reason, const CSimpleStringA& errmsg, const CSimpleStringA& rebootTime)
|
|
|
|
- :Reason(reason.GetData()), ErrMsg(reason.GetData()), RebootTime(reason.GetData())
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- LogNotiyMessageStruct(const std::string& reason, const std::string& errmsg, const std::string& rebootTime)
|
|
|
|
- :Reason(reason), ErrMsg(errmsg), RebootTime(rebootTime)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- LogNotiyMessageStruct(const char* reason, const char* errmsg, char* rebootTime)
|
|
|
|
- :Reason(reason), ErrMsg(errmsg), RebootTime(rebootTime)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- LogNotiyMessageStruct(const char* errmsg)
|
|
|
|
- :Reason(""), ErrMsg(errmsg), RebootTime("")
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- std::string ToJsonString() const {
|
|
|
|
- std::map<std::string, std::string> srcData;
|
|
|
|
- srcData.insert(std::make_pair("reason", Reason));
|
|
|
|
- srcData.insert(std::make_pair("errmsg", ErrMsg));
|
|
|
|
- srcData.insert(std::make_pair("rebootTime", RebootTime));
|
|
|
|
- auto ret = generateJsonStr(srcData);
|
|
|
|
- if (ret.first) {
|
|
|
|
- return ret.second;
|
|
|
|
- } else {
|
|
|
|
- return ErrMsg;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-struct LogCommNotiyStruct
|
|
|
|
-{
|
|
|
|
- NotifyLevelEnum eLevel;
|
|
|
|
- ErrorCodeEnum eSysCode;
|
|
|
|
- DWORD dwUserCode;
|
|
|
|
- LogCommNotiyStruct() :eLevel(Notify_None), eSysCode(Error_Unexpect), dwUserCode(0) {}
|
|
|
|
-
|
|
|
|
- LogCommNotiyStruct(NotifyLevelEnum level, ErrorCodeEnum errorCode, DWORD dwUserCode)
|
|
|
|
- :eLevel(level), eSysCode(errorCode), dwUserCode(dwUserCode) {}
|
|
|
|
-
|
|
|
|
- LogCommNotiyStruct(NotifyLevelEnum level, ErrorCodeEnum errorCode)
|
|
|
|
- :eLevel(level), eSysCode(errorCode), dwUserCode(0)
|
|
|
|
- { }
|
|
|
|
-
|
|
|
|
- virtual ~LogCommNotiyStruct() {}
|
|
|
|
-
|
|
|
|
- virtual void Notify(const LogNotiyMessageStruct& notifyMessage)
|
|
|
|
- {
|
|
|
|
- LogNotify(eLevel, eSysCode, dwUserCode, notifyMessage.ToJsonString().c_str());
|
|
|
|
- }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-struct LogInfoNotiyStruct : public LogCommNotiyStruct
|
|
|
|
-{
|
|
|
|
- LogInfoNotiyStruct(ErrorCodeEnum errorCode, DWORD dwUserCode)
|
|
|
|
- :LogCommNotiyStruct(Notify_Info, errorCode, dwUserCode){}
|
|
|
|
- ~LogInfoNotiyStruct() {}
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-struct LogWarnNotiyStruct : public LogCommNotiyStruct
|
|
|
|
-{
|
|
|
|
- LogWarnNotiyStruct(ErrorCodeEnum errorCode, DWORD dwUserCode)
|
|
|
|
- :LogCommNotiyStruct(Notify_Warn, errorCode, dwUserCode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- ~LogWarnNotiyStruct() {}
|
|
|
|
-
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-struct LogErrorNotiyStruct : public LogCommNotiyStruct
|
|
|
|
-{
|
|
|
|
- LogErrorNotiyStruct(ErrorCodeEnum errorCode, DWORD dwUserCode)
|
|
|
|
- :LogCommNotiyStruct(Notify_Error, errorCode, dwUserCode)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- ~LogErrorNotiyStruct() {}
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
static BOOL IsFirsRunAppAfterSystemBoot(CEntityBase* pEntity, DWORD theReportUserCode = 0)
|
|
static BOOL IsFirsRunAppAfterSystemBoot(CEntityBase* pEntity, DWORD theReportUserCode = 0)
|
|
{
|
|
{
|
|
BOOL result(FALSE);
|
|
BOOL result(FALSE);
|
|
@@ -284,119 +192,6 @@ static BOOL IsFirsRunAppAfterSystemBoot(CEntityBase* pEntity, DWORD theReportUse
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
-inline
|
|
|
|
-CSimpleStringA GetCurrMachineType(CEntityBase* pEntity)
|
|
|
|
-{
|
|
|
|
- CSystemStaticInfo sysInfo;
|
|
|
|
- pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
|
- return sysInfo.strMachineType;
|
|
|
|
-}
|
|
|
|
- enum Site
|
|
|
|
- {
|
|
|
|
- CMB_UNKNOWN,
|
|
|
|
- CMB_LIB, /** 行内大堂*/
|
|
|
|
- CMB_FLB, /** 离行机器*/
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-#define SITE_ENUM_TYPE(MACRO) \
|
|
|
|
- MACRO(LIB)\
|
|
|
|
- MACRO(FLB)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-#define ENUM_MAP_CONVERT(elem) \
|
|
|
|
- if (streq(lpcszSiteName, "CMB."#elem) == 0) return CMB_##elem;
|
|
|
|
-/*!
|
|
|
|
- * convert cmb site name to enum type.
|
|
|
|
- */
|
|
|
|
-static Site Str2Site(LPCSTR lpcszSiteName)
|
|
|
|
-{
|
|
|
|
- if (lpcszSiteName == NULL || strlen(lpcszSiteName) == 0)
|
|
|
|
- return CMB_UNKNOWN;
|
|
|
|
- SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
|
|
|
|
- return CMB_UNKNOWN;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#undef ENUM_MAP_CONVERT
|
|
|
|
-#define ENUM_MAP_CONVERT(elem) case CMB_##elem: return "CMB."#elem;
|
|
|
|
-
|
|
|
|
-static LPCSTR Site2Str(Site site)
|
|
|
|
-{
|
|
|
|
- switch (site) {
|
|
|
|
- SITE_ENUM_TYPE(ENUM_MAP_CONVERT)
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- return "Unkown";
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
- enum What
|
|
|
|
- {
|
|
|
|
- RVC_UNKNOWN,
|
|
|
|
- RVC_Stand2S, /** 落地式大机*/
|
|
|
|
- RVC_PAD, /** PAD*/
|
|
|
|
- RVC_Desk2S, /** 低柜双屏*/
|
|
|
|
- RVC_CardStore, /** 卡库*/
|
|
|
|
- RVC_CardPrinter, /** 制卡机*/
|
|
|
|
- RVC_Stand1SPlus /** 单屏大机*/
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
-#define MACHINE_ENUM_TYPE(MACRO) \
|
|
|
|
- MACRO(Stand2S)\
|
|
|
|
- MACRO(PAD)\
|
|
|
|
- MACRO(Desk2S)\
|
|
|
|
- MACRO(CardStore)\
|
|
|
|
- MACRO(CardPrinter)\
|
|
|
|
- MACRO(Stand1SPlus)
|
|
|
|
-
|
|
|
|
-#undef ENUM_MAP_CONVERT
|
|
|
|
-#define ENUM_MAP_CONVERT(elem) \
|
|
|
|
- if (streq(lpcszTypeName, "RVC."#elem) == 0) return RVC_##elem;
|
|
|
|
-/*!
|
|
|
|
- * convert cmb site name to enum type.
|
|
|
|
- */
|
|
|
|
-static What Str2Type(LPCSTR lpcszTypeName)
|
|
|
|
-{
|
|
|
|
- if (lpcszTypeName == NULL || strlen(lpcszTypeName) == 0)
|
|
|
|
- return RVC_UNKNOWN;
|
|
|
|
- MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
|
|
|
|
- return RVC_UNKNOWN;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-#undef ENUM_MAP_CONVERT
|
|
|
|
-#define ENUM_MAP_CONVERT(elem) case RVC_##elem: return "RVC."#elem;
|
|
|
|
-
|
|
|
|
-static LPCSTR Type2Str(What what)
|
|
|
|
-{
|
|
|
|
- switch (what) {
|
|
|
|
- MACHINE_ENUM_TYPE(ENUM_MAP_CONVERT)
|
|
|
|
- default:
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- return "Unkown";
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-struct TerminalMachineInfo
|
|
|
|
-{
|
|
|
|
- Site site;
|
|
|
|
- What type;
|
|
|
|
- struct {
|
|
|
|
- WORD minor;
|
|
|
|
- WORD major;
|
|
|
|
- } gen;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-inline TerminalMachineInfo GetTerminalMachineInfo(CEntityBase* pEntity)
|
|
|
|
-{
|
|
|
|
- CSystemStaticInfo sysInfo;
|
|
|
|
- TerminalMachineInfo termInfo;
|
|
|
|
- pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
|
- termInfo.site = Str2Site(sysInfo.strSite);
|
|
|
|
- termInfo.type = Str2Type(sysInfo.strMachineType);
|
|
|
|
- termInfo.gen.major = sysInfo.MachineVersion.GetMajor();
|
|
|
|
- termInfo.gen.minor = sysInfo.MachineVersion.GetMinor();
|
|
|
|
- return termInfo;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
inline ULLINT RVCGetTickCount()
|
|
inline ULLINT RVCGetTickCount()
|
|
{
|
|
{
|
|
#ifdef RVC_OS_WIN
|
|
#ifdef RVC_OS_WIN
|
|
@@ -414,6 +209,9 @@ inline ULLINT RVCGetTickCount()
|
|
|
|
|
|
namespace Util
|
|
namespace Util
|
|
{
|
|
{
|
|
|
|
+ /**
|
|
|
|
+ * Need to delete *hexBuf if (*hexBuf) not null
|
|
|
|
+ */
|
|
static int StrBuf2HexBuf(const char* strBuf, PBYTE* hexBuf)
|
|
static int StrBuf2HexBuf(const char* strBuf, PBYTE* hexBuf)
|
|
{
|
|
{
|
|
int len = strlen(strBuf);
|
|
int len = strlen(strBuf);
|
|
@@ -443,7 +241,7 @@ static int HexBuf2StrBuf(PBYTE hexBuf, char** strBuf, DWORD len)
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+/*
|
|
//tips: need to delete result char*
|
|
//tips: need to delete result char*
|
|
static char* ConvertBytesToHexStr(BYTE* pBuf, int nLen)
|
|
static char* ConvertBytesToHexStr(BYTE* pBuf, int nLen)
|
|
{
|
|
{
|
|
@@ -531,31 +329,7 @@ static bool IsNoStr(const char* str)
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
-}
|
|
|
|
-
|
|
|
|
-static DWORD GetDuration(const SYSTEMTIME& time1, const SYSTEMTIME& time2)
|
|
|
|
-{
|
|
|
|
-#if defined(RVC_OS_WIN)
|
|
|
|
-
|
|
|
|
- ULARGE_INTEGER fTime1;/*FILETIME*/
|
|
|
|
- ULARGE_INTEGER fTime2;/*FILETIME*/
|
|
|
|
-
|
|
|
|
- SystemTimeToFileTime(&time1, (FILETIME*)&fTime1);
|
|
|
|
- SystemTimeToFileTime(&time2, (FILETIME*)&fTime2);
|
|
|
|
-
|
|
|
|
- unsigned __int64 dft = fTime2.QuadPart - fTime1.QuadPart;
|
|
|
|
- return DWORD(dft / 10000);
|
|
|
|
-
|
|
|
|
-#else
|
|
|
|
- ///**TODO(Gifur@9/3/2021): Bug 不能这样简单的实现,考虑凌晨,切换月份甚至是年份 */
|
|
|
|
- DWORD s1, s2;
|
|
|
|
- s1 = (time1.wMinute * 60 + time1.wSecond) * 1000 + time1.wMilliseconds;
|
|
|
|
- s2 = (time2.wMinute * 60 + time2.wSecond) * 1000 + time2.wMilliseconds;
|
|
|
|
-
|
|
|
|
- return s2 - s1;
|
|
|
|
-
|
|
|
|
-#endif //RVC_OS_WIN
|
|
|
|
-}
|
|
|
|
|
|
+}*/
|
|
|
|
|
|
static std::string formatTime(const SYSTEMTIME& time)
|
|
static std::string formatTime(const SYSTEMTIME& time)
|
|
{
|
|
{
|
|
@@ -575,26 +349,12 @@ static bool ShellExecute(const std::string& cmd, std::string& succResult, std::s
|
|
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
ZeroMemory(&si, sizeof(si));
|
|
si.cb = sizeof(si);
|
|
si.cb = sizeof(si);
|
|
- // 设置STARTUPINFO的wShowWindow成员为SW_HIDE,以隐藏窗口
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
si.wShowWindow = SW_HIDE;
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
-
|
|
|
|
- // 使用CreateProcess启动程序
|
|
|
|
- if (!CreateProcess(NULL, // 不使用模块名
|
|
|
|
- ps, // 命令行
|
|
|
|
- NULL, // 不继承进程句柄
|
|
|
|
- NULL, // 不继承线程句柄
|
|
|
|
- FALSE, // 不继承句柄
|
|
|
|
- CREATE_NO_WINDOW, // 没有创建标志
|
|
|
|
- NULL, // 使用父进程的环境块
|
|
|
|
- NULL, // 使用父进程的当前目录
|
|
|
|
- &si, // 指向STARTUPINFO的指针
|
|
|
|
- &pi) // 指向PROCESS_INFORMATION的指针
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (!CreateProcess(NULL, ps, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
|
|
errResult = errResult + "CreateProcess failed with error:" + strerror(GetLastError());
|
|
errResult = errResult + "CreateProcess failed with error:" + strerror(GetLastError());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
// 等待程序结束,并获取其退出状态
|
|
// 等待程序结束,并获取其退出状态
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
WaitForSingleObject(pi.hProcess, INFINITE);
|
|
DWORD exitCode;
|
|
DWORD exitCode;
|
|
@@ -602,7 +362,6 @@ static bool ShellExecute(const std::string& cmd, std::string& succResult, std::s
|
|
errResult = errResult + "GetExitCodeProcess failed with error code " + strerror(GetLastError());
|
|
errResult = errResult + "GetExitCodeProcess failed with error code " + strerror(GetLastError());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- // 关闭进程和线程句柄
|
|
|
|
CloseHandle(pi.hProcess);
|
|
CloseHandle(pi.hProcess);
|
|
CloseHandle(pi.hThread);
|
|
CloseHandle(pi.hThread);
|
|
|
|
|
|
@@ -611,7 +370,6 @@ static bool ShellExecute(const std::string& cmd, std::string& succResult, std::s
|
|
errResult = errResult + "The program exited with code:" + strerror(exitCode);
|
|
errResult = errResult + "The program exited with code:" + strerror(exitCode);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
return true;
|
|
return true;
|
|
#else
|
|
#else
|
|
char buf_ps[1024];
|
|
char buf_ps[1024];
|
|
@@ -645,98 +403,23 @@ static CSimpleStringA generateConsumeTimeJson(const CSimpleStringA& entityName,
|
|
}
|
|
}
|
|
|
|
|
|
#if defined(_MSC_VER)
|
|
#if defined(_MSC_VER)
|
|
-static char* ConvertUtf8ToGBK(const char* strUtf8)
|
|
|
|
-{
|
|
|
|
- int len = MultiByteToWideChar(CP_UTF8, 0, strUtf8, -1, NULL, 0);
|
|
|
|
- WCHAR* wszGBK = new WCHAR[len + 1];
|
|
|
|
- memset(wszGBK, 0, len * 2 + 2);
|
|
|
|
- MultiByteToWideChar(CP_UTF8, 0, strUtf8, -1, wszGBK, len);
|
|
|
|
-
|
|
|
|
- len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
|
|
|
|
- char* szGBK = new char[len + 1];
|
|
|
|
- memset(szGBK, 0, len + 1);
|
|
|
|
- WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL);
|
|
|
|
- delete[] wszGBK;
|
|
|
|
-
|
|
|
|
- return szGBK;
|
|
|
|
-}
|
|
|
|
|
|
|
|
-static void ConvertUtf8ToGBK(std::string& str)
|
|
|
|
|
|
+static void ConvertUtf82GBK(std::string& str)
|
|
{
|
|
{
|
|
char* dst = ConvertUtf8ToGBK(str.c_str());
|
|
char* dst = ConvertUtf8ToGBK(str.c_str());
|
|
str = dst;
|
|
str = dst;
|
|
- delete[] dst;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static char* ConvertGBKToUtf8(const char* gbk, int* n)
|
|
|
|
-{
|
|
|
|
- int len = MultiByteToWideChar(CP_ACP, 0, gbk, -1, NULL, 0);
|
|
|
|
- WCHAR* wszGBK = new WCHAR[len + 1];
|
|
|
|
- memset(wszGBK, 0, len * 2 + 2);
|
|
|
|
- MultiByteToWideChar(CP_ACP, 0, gbk, -1, wszGBK, len);
|
|
|
|
-
|
|
|
|
- len = WideCharToMultiByte(CP_UTF8, 0, wszGBK, -1, NULL, 0, NULL, NULL);
|
|
|
|
- char* szUtf8 = new char[len + 1];
|
|
|
|
- memset(szUtf8, 0, len + 1);
|
|
|
|
- WideCharToMultiByte(CP_UTF8, 0, wszGBK, -1, szUtf8, len, NULL, NULL);
|
|
|
|
-
|
|
|
|
- delete[] wszGBK;
|
|
|
|
- *n = len - 1;
|
|
|
|
- return szUtf8;
|
|
|
|
|
|
+ if(dst) free(dst);
|
|
}
|
|
}
|
|
|
|
|
|
-static void ConvertGBKToUtf8(std::string& str)
|
|
|
|
|
|
+static void ConvertGBK2Utf8(std::string& str)
|
|
{
|
|
{
|
|
int len = 0;
|
|
int len = 0;
|
|
char* dst = ConvertGBKToUtf8(str.c_str(), &len);
|
|
char* dst = ConvertGBKToUtf8(str.c_str(), &len);
|
|
str = dst;
|
|
str = dst;
|
|
- delete[] dst;
|
|
|
|
|
|
+ if (dst) free(dst);
|
|
}
|
|
}
|
|
-#endif //_MSC_VER
|
|
|
|
|
|
|
|
-static std::string W2S(const std::wstring wstr)
|
|
|
|
-{
|
|
|
|
-#if defined(_MSC_VER)
|
|
|
|
- char* str = NULL;
|
|
|
|
- int n = ::WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
|
|
|
|
- if (n > 0) {
|
|
|
|
- str = new char[n + 1];
|
|
|
|
- if (str == NULL) {
|
|
|
|
- return std::string();
|
|
|
|
- }
|
|
|
|
- std::memset(str, 0, sizeof(char) * (n + 1));
|
|
|
|
- ::WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &str[0], n, NULL, NULL);
|
|
|
|
- std::string strr(str);
|
|
|
|
- delete [] str;
|
|
|
|
- return strr;
|
|
|
|
- }
|
|
|
|
-#else
|
|
|
|
- ///*TODO(80374374@3/7/2023): */
|
|
|
|
#endif //_MSC_VER
|
|
#endif //_MSC_VER
|
|
- return std::string();
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static std::wstring S2W(const std::string str)
|
|
|
|
-{
|
|
|
|
-#if defined(_MSC_VER)
|
|
|
|
- wchar_t* wstr = NULL;
|
|
|
|
- int n = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
|
|
|
|
- if (n > 0) {
|
|
|
|
- wstr = new wchar_t[n + 1];
|
|
|
|
- if (wstr == NULL) {
|
|
|
|
- return std::wstring();
|
|
|
|
- }
|
|
|
|
- std::memset(wstr, 0, (n + 1) * sizeof(wchar_t));
|
|
|
|
- ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, &wstr[0], n);
|
|
|
|
- std::wstring strr(wstr);
|
|
|
|
- delete [] wstr;
|
|
|
|
- return strr;
|
|
|
|
- }
|
|
|
|
-#else
|
|
|
|
- ///*TODO(80374374@3/7/2023): */
|
|
|
|
-#endif //_MSC_VER
|
|
|
|
- return std::wstring();
|
|
|
|
-}
|
|
|
|
|
|
|
|
enum DataTypeToMask
|
|
enum DataTypeToMask
|
|
{
|
|
{
|
|
@@ -1076,219 +759,8 @@ static ErrorCodeEnum GetINETMacAddresses(CAutoArray<NetworkAdapterItem>& netList
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-static std::vector<NetworkAdapterItem> GetNetAdapterItems()
|
|
|
|
-{
|
|
|
|
- std::vector<NetworkAdapterItem> results;
|
|
|
|
-#if defined(_MSC_VER)
|
|
|
|
- ULONG flags = GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_INCLUDE_GATEWAYS;
|
|
|
|
- ULONG family = AF_UNSPEC;
|
|
|
|
- PIP_ADAPTER_ADDRESSES address_ptr = nullptr;
|
|
|
|
- ULONG out_buf_len = 15000;
|
|
|
|
- DWORD ret_val = 0;
|
|
|
|
- PIP_ADAPTER_ADDRESSES cur_addr_ptr = nullptr;
|
|
|
|
- PIP_ADAPTER_UNICAST_ADDRESS unicast_ptr = nullptr;
|
|
|
|
- PIP_ADAPTER_ANYCAST_ADDRESS anycast_ptr = nullptr;
|
|
|
|
- PIP_ADAPTER_MULTICAST_ADDRESS multicast_ptr = nullptr;
|
|
|
|
- PIP_ADAPTER_DNS_SERVER_ADDRESS dns_server_ptr = nullptr;
|
|
|
|
- IP_ADAPTER_PREFIX* prefix_ptr = nullptr;
|
|
|
|
-
|
|
|
|
- do {
|
|
|
|
- address_ptr = (PIP_ADAPTER_ADDRESSES)malloc(out_buf_len);
|
|
|
|
- if (address_ptr == nullptr) {
|
|
|
|
- return results;
|
|
|
|
- }
|
|
|
|
- ret_val = GetAdaptersAddresses(family, flags, NULL, address_ptr, &out_buf_len);
|
|
|
|
- if (ERROR_BUFFER_OVERFLOW == ret_val) {
|
|
|
|
- free(address_ptr);
|
|
|
|
- }
|
|
|
|
- } while (ret_val == ERROR_BUFFER_OVERFLOW);
|
|
|
|
-
|
|
|
|
- if (NO_ERROR == ret_val) {
|
|
|
|
- cur_addr_ptr = address_ptr;
|
|
|
|
- while (cur_addr_ptr) {
|
|
|
|
- std::string description = Util::W2S(cur_addr_ptr->Description);
|
|
|
|
- bool is_local = IsLocalAdapter(cur_addr_ptr->AdapterName);
|
|
|
|
- std::string friend_name = Util::W2S(cur_addr_ptr->FriendlyName);
|
|
|
|
- NetworkAdapterItem item;
|
|
|
|
- item.idx = cur_addr_ptr->IfIndex;
|
|
|
|
- item.adapter_name = cur_addr_ptr->AdapterName;
|
|
|
|
- item.description = description;
|
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(">>>>>>>>>>>>>>> friendly name: %s", friend_name.c_str());
|
|
|
|
- item.friend_name = friend_name;
|
|
|
|
- if (is_local) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Adapter Desc: %s", description.c_str());
|
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Adapter Name: %s", cur_addr_ptr->AdapterName);
|
|
|
|
- item.isLocal = true;
|
|
|
|
- }
|
|
|
|
- if (cur_addr_ptr->PhysicalAddressLength != 0) {
|
|
|
|
- char sz_addr[32] = { 0 };
|
|
|
|
- std::stringstream str;
|
|
|
|
- for (int i = 0; i < (int)cur_addr_ptr->PhysicalAddressLength; i++) {
|
|
|
|
- if (i == ((int)cur_addr_ptr->PhysicalAddressLength - 1))
|
|
|
|
- sprintf_s(sz_addr, "%.2X", (int)cur_addr_ptr->PhysicalAddress[i]);
|
|
|
|
- else
|
|
|
|
- sprintf_s(sz_addr, "%.2X:", (int)cur_addr_ptr->PhysicalAddress[i]);
|
|
|
|
- str << sz_addr;
|
|
|
|
- }
|
|
|
|
- item.mac = str.str();
|
|
|
|
- }
|
|
|
|
- item.type = cur_addr_ptr->IfType;
|
|
|
|
- item.operStatus = cur_addr_ptr->OperStatus;
|
|
|
|
- switch (cur_addr_ptr->IfType) {
|
|
|
|
- case MIB_IF_TYPE_OTHER:
|
|
|
|
- break;
|
|
|
|
- case MIB_IF_TYPE_ETHERNET:
|
|
|
|
- break;
|
|
|
|
- case MIB_IF_TYPE_TOKENRING:
|
|
|
|
- break;
|
|
|
|
- case MIB_IF_TYPE_FDDI:
|
|
|
|
- break;
|
|
|
|
- case MIB_IF_TYPE_PPP:
|
|
|
|
- break;
|
|
|
|
- case MIB_IF_TYPE_LOOPBACK:
|
|
|
|
- break;
|
|
|
|
- case MIB_IF_TYPE_SLIP:
|
|
|
|
- break;
|
|
|
|
- case IF_TYPE_IEEE80211:
|
|
|
|
- break;
|
|
|
|
- case IF_TYPE_WWANPP:
|
|
|
|
- case IF_TYPE_WWANPP2:
|
|
|
|
- //WWAN devices
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Unknown type %d", cur_addr_ptr->IfType);
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- unicast_ptr = cur_addr_ptr->FirstUnicastAddress;
|
|
|
|
- while (unicast_ptr) {
|
|
|
|
- char ip[120] = { 0 };
|
|
|
|
- if (AF_INET == unicast_ptr->Address.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET, &((sockaddr_in*)unicast_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- } else if (AF_INET6 == unicast_ptr->Address.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET6, &((sockaddr_in*)unicast_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- }
|
|
|
|
- unicast_ptr = unicast_ptr->Next;
|
|
|
|
- }
|
|
|
|
- if (cur_addr_ptr->Dhcpv4Server.lpSockaddr) {
|
|
|
|
- char ip[120] = { 0 };
|
|
|
|
- if (AF_INET == cur_addr_ptr->Dhcpv4Server.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET, &((sockaddr_in*)cur_addr_ptr->Dhcpv4Server.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- } else if (AF_INET6 == cur_addr_ptr->Dhcpv4Server.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET6, &((sockaddr_in*)cur_addr_ptr->Dhcpv4Server.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- }
|
|
|
|
- item.dhcp = ip;
|
|
|
|
- }
|
|
|
|
- dns_server_ptr = cur_addr_ptr->FirstDnsServerAddress;
|
|
|
|
- while (dns_server_ptr) {
|
|
|
|
- char ip[120] = { 0 };
|
|
|
|
- if (AF_INET == dns_server_ptr->Address.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET, &((sockaddr_in*)dns_server_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- } else if (AF_INET6 == dns_server_ptr->Address.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET6, &((sockaddr_in*)dns_server_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- }
|
|
|
|
- dns_server_ptr = dns_server_ptr->Next;
|
|
|
|
- }
|
|
|
|
- auto gateway_ptr = cur_addr_ptr->FirstGatewayAddress;
|
|
|
|
- while (gateway_ptr) {
|
|
|
|
- char ip[120] = { 0 };
|
|
|
|
- if (AF_INET == gateway_ptr->Address.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET, &((sockaddr_in*)gateway_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- } else if (AF_INET6 == gateway_ptr->Address.lpSockaddr->sa_family) {
|
|
|
|
- inet_ntop(PF_INET6, &((sockaddr_in*)gateway_ptr->Address.lpSockaddr)->sin_addr, ip, sizeof(ip));
|
|
|
|
- }
|
|
|
|
- gateway_ptr = gateway_ptr->Next;
|
|
|
|
- }
|
|
|
|
- results.push_back(item);
|
|
|
|
- cur_addr_ptr = cur_addr_ptr->Next;
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetAdaptersAddresses failed with error: %d", ret_val);
|
|
|
|
- }
|
|
|
|
- free(address_ptr);
|
|
|
|
-#else
|
|
|
|
-///*TODO(80374374@3/7/2023): */
|
|
|
|
-#endif //_MSC_VER
|
|
|
|
- return results;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static BOOL CheckLANConnectStatus()
|
|
|
|
-{
|
|
|
|
-#if defined(_MSC_VER)
|
|
|
|
- DWORD dwFlag(0);
|
|
|
|
- BOOL bRet = InternetGetConnectedState(&dwFlag, 0);
|
|
|
|
-
|
|
|
|
- if ((dwFlag & INTERNET_CONNECTION_CONFIGURED) == INTERNET_CONNECTION_CONFIGURED) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system has a valid connection to the Internet, but it might or might not be currently connected.");
|
|
|
|
- }
|
|
|
|
- if ((dwFlag & INTERNET_CONNECTION_LAN) == INTERNET_CONNECTION_LAN) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system uses a local area network to connect to the Internet.");
|
|
|
|
- }
|
|
|
|
- if ((dwFlag & INTERNET_CONNECTION_MODEM) == INTERNET_CONNECTION_MODEM) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system uses a modem to connect to the Internet.");
|
|
|
|
- }
|
|
|
|
- if ((dwFlag & INTERNET_CONNECTION_MODEM_BUSY) == INTERNET_CONNECTION_MODEM_BUSY) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("No longer used: INTERNET_CONNECTION_MODEM_BUSY");
|
|
|
|
- }
|
|
|
|
- if ((dwFlag & INTERNET_CONNECTION_OFFLINE) == INTERNET_CONNECTION_OFFLINE) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system is in offline mode.");
|
|
|
|
- }
|
|
|
|
- if ((dwFlag & INTERNET_CONNECTION_PROXY) == INTERNET_CONNECTION_PROXY) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system uses a proxy server to connect to the Internet.");
|
|
|
|
- }
|
|
|
|
- if ((dwFlag & INTERNET_RAS_INSTALLED) == INTERNET_RAS_INSTALLED) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Local system has RAS installed.");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (bRet) {
|
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("InternetGetConnectedState Succeed: 0x%08X", dwFlag);
|
|
|
|
- } else {
|
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("InternetGetConnectedState failed: 0x%08X, GLE=%u", dwFlag, GetLastError());
|
|
|
|
- }
|
|
|
|
- return bRet;
|
|
|
|
-#else
|
|
|
|
- return FALSE;
|
|
|
|
-#endif //_MSC_VER
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static std::string GetWWWInfoThroughDig(const std::string& wwwUrl)
|
|
|
|
-{
|
|
|
|
- std::string succStr, errStr;
|
|
|
|
- std::string runStr("dig ");
|
|
|
|
- runStr += wwwUrl;
|
|
|
|
- if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
|
|
|
|
- return succStr;
|
|
|
|
- } else {
|
|
|
|
- return std::string("ShellExecute(") + wwwUrl + ") failed";
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
}//Net
|
|
}//Net
|
|
|
|
|
|
-namespace FileSystem {
|
|
|
|
-
|
|
|
|
- static DWORD FetchFileSize(const char* filePath)
|
|
|
|
- {
|
|
|
|
- int fileSize = 0;
|
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
|
- struct stat statbuf;
|
|
|
|
- ZeroMemory(&statbuf, sizeof(statbuf));
|
|
|
|
- stat(filePath, &statbuf);
|
|
|
|
- fileSize = statbuf.st_size;
|
|
|
|
-#else
|
|
|
|
-
|
|
|
|
- HANDLE hFile;
|
|
|
|
- hFile = CreateFile(filePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
- if (hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
- fileSize = GetFileSize(hFile, NULL);
|
|
|
|
- CloseHandle(hFile);
|
|
|
|
- }
|
|
|
|
-#endif //RVC_OS_LINUX
|
|
|
|
- return fileSize;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
} // mod
|
|
} // mod
|
|
} // sp
|
|
} // sp
|
|
|
|
|