|
|
@@ -1,15 +1,28 @@
|
|
|
-#include "StdAfx.h"
|
|
|
-#include <shellapi.h>
|
|
|
+//#include "StdAfx.h"
|
|
|
+
|
|
|
#include "UpgradeRunFSM.h"
|
|
|
-#include "XUnzip.h"
|
|
|
+
|
|
|
#include "mod_UpgradeRun.h"
|
|
|
#include "iniutil.h"
|
|
|
#include "memutil.h"
|
|
|
#include "fileutil.h"
|
|
|
-#include <io.h>
|
|
|
+
|
|
|
#include <vector>
|
|
|
#include "EventCode.h"
|
|
|
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+
|
|
|
+#include <shellapi.h>
|
|
|
+#include <io.h>
|
|
|
+#include "XUnzip.h"
|
|
|
+
|
|
|
+#else
|
|
|
+
|
|
|
+#include <sys/utsname.h>
|
|
|
+
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
CUpgradeRunFSM::CUpgradeRunFSM(void)
|
|
|
{
|
|
|
//解决sonar扫描问题
|
|
|
@@ -505,14 +518,18 @@ bool CUpgradeRunFSM::IsManual()
|
|
|
assert(rc == Error_Succeed);
|
|
|
|
|
|
// 检查文件是否存在
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
DWORD attr = GetFileAttributesA(strConfigPath);
|
|
|
Dbg("check install config: %s, attr[0x%08X]", (const char*)strConfigPath, attr);
|
|
|
if (attr == INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
|
|
|
{
|
|
|
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("install config \"%s\" not exists",
|
|
|
- (const char*)strConfigPath));
|
|
|
+ LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("install config \"%s\" not exists",
|
|
|
+ (const char*)strConfigPath));
|
|
|
return false;
|
|
|
}
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
|
|
|
// InstallType=manual
|
|
|
char *p = inifile_read_str(strConfigPath, "Precondition", "InstallType", "");
|
|
|
@@ -598,11 +615,14 @@ ErrorCodeEnum CUpgradeRunFSM::NewUnzipPack()
|
|
|
|
|
|
ErrorCodeEnum CUpgradeRunFSM::UnzipPack()
|
|
|
{
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+
|
|
|
assert(!m_strInstallPack.IsNullOrEmpty());
|
|
|
|
|
|
// 设定解压临时目录
|
|
|
char szOldPath[MAX_PATH] = {};
|
|
|
GetCurrentDirectoryA(MAX_PATH, szOldPath);
|
|
|
+
|
|
|
|
|
|
CSimpleStringA strDownloadsPath;
|
|
|
auto rc = m_pEntity->GetFunction()->GetPath("Downloads", strDownloadsPath);
|
|
|
@@ -717,6 +737,8 @@ ErrorCodeEnum CUpgradeRunFSM::UncabPack()
|
|
|
|
|
|
SetCurrentDirectoryA(szOldPath);
|
|
|
return rc;
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+ return Error_Exception;
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CUpgradeRunFSM::DeleteInstallingPack()
|
|
|
@@ -728,8 +750,8 @@ ErrorCodeEnum CUpgradeRunFSM::DeleteInstallingPack()
|
|
|
assert(rc == Error_Succeed);
|
|
|
|
|
|
CSimpleStringA strZipFile = CSimpleStringA::Format("%s\\%s", (const char*)strDownloadsPath, (const char*)m_strInstallPack);
|
|
|
-
|
|
|
- DWORD attr = GetFileAttributesA(strZipFile);
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ DWORD attr = GetFileAttributesA(strZipFile);
|
|
|
if (attr == INVALID_FILE_ATTRIBUTES)
|
|
|
{
|
|
|
Dbg("pack [%s] not exists", strZipFile);
|
|
|
@@ -747,12 +769,19 @@ ErrorCodeEnum CUpgradeRunFSM::DeleteInstallingPack()
|
|
|
|
|
|
// 删除临时解压目录
|
|
|
DeleteUnzipDir();
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
|
|
|
DWORD CUpgradeRunFSM::waitSystem(const CSimpleStringA cmd, const CSimpleStringA par, BOOL nShow)
|
|
|
{
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
SHELLEXECUTEINFOA ShExecInfo = { 0 };
|
|
|
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
|
|
|
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
@@ -790,6 +819,8 @@ DWORD CUpgradeRunFSM::waitSystem(const CSimpleStringA cmd, const CSimpleStringA
|
|
|
//Sleep(100);
|
|
|
|
|
|
return exitCode;
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+ return -1;
|
|
|
}
|
|
|
|
|
|
DWORD CUpgradeRunFSM::SYSTEM_ON(CSimpleStringA cmdLine, BOOL isWait)
|
|
|
@@ -854,6 +885,10 @@ ErrorCodeEnum CUpgradeRunFSM::CheckInstallConfig(CAutoArray<CSimpleStringA> &cov
|
|
|
assert(rc == Error_Succeed);
|
|
|
|
|
|
// 检查文件是否存在
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
DWORD attr = GetFileAttributesA(strConfigPath);
|
|
|
Dbg("check install config: %s", (const char*)strConfigPath);
|
|
|
//assert((attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY));
|
|
|
@@ -864,7 +899,7 @@ ErrorCodeEnum CUpgradeRunFSM::CheckInstallConfig(CAutoArray<CSimpleStringA> &cov
|
|
|
strErrMsg = "run.ini不存在";
|
|
|
return Error_Unexpect;
|
|
|
}
|
|
|
-
|
|
|
+#endif // RVC_OS_WIN
|
|
|
CSystemStaticInfo sysInfo;
|
|
|
ZeroMemory(&sysInfo, sizeof(sysInfo));
|
|
|
rc = m_pEntity->GetFunction()->GetSystemStaticInfo(sysInfo);
|
|
|
@@ -976,42 +1011,56 @@ ErrorCodeEnum CUpgradeRunFSM::CheckInstallConfig(CAutoArray<CSimpleStringA> &cov
|
|
|
|
|
|
if (!strOSVersion.IsNullOrEmpty())
|
|
|
{
|
|
|
- OSVERSIONINFO osvi;
|
|
|
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
|
|
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
- GetVersionEx(&osvi);
|
|
|
- CVersion osVersion(osvi.dwMajorVersion, osvi.dwMinorVersion);
|
|
|
+ //查询系统版本
|
|
|
+ //OSVERSIONINFO osvi;
|
|
|
+ //ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
|
|
+ //osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
+ //GetVersionEx(&osvi);
|
|
|
+ //CVersion osVersion(osvi.dwMajorVersion, osvi.dwMinorVersion);
|
|
|
+ DWORD dwMajorVersion(0), dwMinorVersion(0);
|
|
|
+ if (getOSVersion(dwMajorVersion,dwMinorVersion)) {
|
|
|
+
|
|
|
+ CVersion osVersion(dwMajorVersion, dwMinorVersion);
|
|
|
+
|
|
|
+ DWORD dwMajor1(0), dwMinor1(0);
|
|
|
+ int n = sscanf(strOSVersion, "%d.%d", &dwMajor1, &dwMinor1);
|
|
|
+ CVersion beginVersion(dwMajor1, dwMinor1);
|
|
|
+
|
|
|
+ bool bMatch = false;
|
|
|
+ auto list = strOSVersion.Split('-');
|
|
|
+ if (list.GetCount() >= 2)
|
|
|
+ {
|
|
|
+ DWORD dwMajor2(0), dwMinor2(0);
|
|
|
+ n = sscanf(list[1], "%d.%d", &dwMajor2, &dwMinor2);
|
|
|
+ CVersion endVersion(dwMajor2, dwMinor2);
|
|
|
|
|
|
- DWORD dwMajor1(0), dwMinor1(0);
|
|
|
- int n = sscanf(strOSVersion, "%d.%d", &dwMajor1, &dwMinor1);
|
|
|
- CVersion beginVersion(dwMajor1, dwMinor1);
|
|
|
+ bMatch = osVersion >= beginVersion && osVersion <= endVersion;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (strOSVersion.IsEndWith("-"))
|
|
|
+ bMatch = osVersion >= beginVersion;
|
|
|
+ else
|
|
|
+ bMatch = osVersion == beginVersion;
|
|
|
+ }
|
|
|
|
|
|
- bool bMatch = false;
|
|
|
- auto list = strOSVersion.Split('-');
|
|
|
- if (list.GetCount() >= 2)
|
|
|
- {
|
|
|
- DWORD dwMajor2(0), dwMinor2(0);
|
|
|
- n = sscanf(list[1], "%d.%d", &dwMajor2, &dwMinor2);
|
|
|
- CVersion endVersion(dwMajor2, dwMinor2);
|
|
|
|
|
|
- bMatch = osVersion >= beginVersion && osVersion <= endVersion;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (strOSVersion.IsEndWith("-"))
|
|
|
- bMatch = osVersion >= beginVersion;
|
|
|
- else
|
|
|
- bMatch = osVersion == beginVersion;
|
|
|
- }
|
|
|
-
|
|
|
+ if (!bMatch)
|
|
|
+ {
|
|
|
+ LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("OS version mismatch, config: [%s], current: [%s]",
|
|
|
+ (const char*)strOSVersion, (const char*)osVersion.ToString()));
|
|
|
|
|
|
- if (!bMatch)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("OS version mismatch, config: [%s], current: [%s]",
|
|
|
- (const char*)strOSVersion, (const char*)osVersion.ToString()));
|
|
|
+ strErrMsg = CSimpleStringA::Format("操作系统版本不匹配(配置:%s, 当前:%s)", (const char*)strOSVersion, (const char*)osVersion.ToString());
|
|
|
+ return Error_NotMeetCondition;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ LogError(Severity_Low, Error_NotMeetCondition, 0, CSimpleStringA::Format("OS version get fail, config: [%s], current: [0.0.0.0]",
|
|
|
+ (const char*)strOSVersion));
|
|
|
|
|
|
- strErrMsg = CSimpleStringA::Format("操作系统版本不匹配(配置:%s, 当前:%s)", (const char*)strOSVersion, (const char*)osVersion.ToString());
|
|
|
+ strErrMsg = CSimpleStringA::Format("操作系统版本获取失败(配置:%s, 当前:0.0.0.0)", (const char*)strOSVersion);
|
|
|
return Error_NotMeetCondition;
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -1171,8 +1220,10 @@ ErrorCodeEnum CUpgradeRunFSM::InstallPack(bool &bSysInstall, bool &bLightPack, C
|
|
|
assert(rc == Error_Succeed);
|
|
|
|
|
|
// 检查文件是否存在
|
|
|
- DWORD attr = GetFileAttributesA(strConfigPath);
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ DWORD attr = GetFileAttributesA(strConfigPath);
|
|
|
assert((attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY));
|
|
|
+#endif // RVC_OS_WIN
|
|
|
|
|
|
// UpgradeVersion=1.1.2|A
|
|
|
char *p = inifile_read_str(strConfigPath, "Action", "UpgradeVersion", "");
|
|
|
@@ -1482,30 +1533,35 @@ bool CUpgradeRunFSM::IsFileMatch(const char *pszFilter, const char *pszFileName)
|
|
|
|
|
|
void getFiles(string path, vector<string>& files)
|
|
|
{
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ //查询文件
|
|
|
//文件句柄
|
|
|
long hFile = 0;
|
|
|
|
|
|
//文件信息
|
|
|
- struct _finddata_t fileinfo;
|
|
|
- string p;
|
|
|
- if((hFile = _findfirst(p.assign(path).append("\\*").c_str(),&fileinfo)) != -1)
|
|
|
- {
|
|
|
- do
|
|
|
- {
|
|
|
+ struct _finddata_t fileinfo;
|
|
|
+ string p;
|
|
|
+ if ((hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1)
|
|
|
+ {
|
|
|
+ do
|
|
|
+ {
|
|
|
//如果是目录,迭代之
|
|
|
//如果不是,加入列表
|
|
|
- if((fileinfo.attrib & _A_SUBDIR))
|
|
|
- {
|
|
|
- if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
|
|
|
- getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- files.push_back(p.assign(path).append("\\").append(fileinfo.name) );
|
|
|
- }
|
|
|
- }while(_findnext(hFile, &fileinfo) == 0);
|
|
|
- _findclose(hFile);
|
|
|
- }
|
|
|
+ if ((fileinfo.attrib & _A_SUBDIR))
|
|
|
+ {
|
|
|
+ if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0)
|
|
|
+ getFiles(p.assign(path).append("\\").append(fileinfo.name), files);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ files.push_back(p.assign(path).append("\\").append(fileinfo.name));
|
|
|
+ }
|
|
|
+ } while (_findnext(hFile, &fileinfo) == 0);
|
|
|
+ _findclose(hFile);
|
|
|
+ }
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
bool CUpgradeRunFSM::CheckNewRunFilesSign()
|
|
|
@@ -1640,4 +1696,33 @@ bool CUpgradeRunFSM::CheckNewRunFilesSign()
|
|
|
//}
|
|
|
|
|
|
return true;
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+bool CUpgradeRunFSM::getOSVersion(DWORD &dwMajorVersion, DWORD &dwMinorVersion)
|
|
|
+{
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ OSVERSIONINFO osvi;
|
|
|
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
|
|
|
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
+ GetVersionEx(&osvi);
|
|
|
+ dwMajorVersion = osvi.dwMajorVersion;
|
|
|
+ dwMinorVersion = osvi.dwMinorVersion;
|
|
|
+ return true;
|
|
|
+#else
|
|
|
+ struct utsname kernel_info;
|
|
|
+ int ret = uname(&kernel_info);
|
|
|
+ if (ret == 0) {
|
|
|
+ Dbg("get linux kernel version success: %s\n", kernel_info.release);
|
|
|
+ //char kversion[100] = { 0 };
|
|
|
+ //strncpy(kversion, kernel_info.release, strlen(kernel_info.release));
|
|
|
+ int n = sscanf((const char*)kernel_info.release, "%d.%d", &dwMajorVersion, &dwMinorVersion);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Dbg("get linux kernel version fail: %s\n", strerror(errno));
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+#endif // RVC_OS_WIN
|
|
|
+
|
|
|
+
|
|
|
+}
|