|
|
@@ -667,147 +667,6 @@ bool SpEntityPrivilege::GetSysUpgradeResult(const char *pszResultLog, ErrorCodeE
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-// 执行系统外升级
|
|
|
-ErrorCodeEnum SpEntityPrivilege::BeginSysPackInstall(const char *pszPackageName, CSimpleStringA &strErrMsg)
|
|
|
-{
|
|
|
- // 创建安装包日志文件
|
|
|
- strErrMsg = "";
|
|
|
- WriteInstallLog(pszPackageName, CSimpleStringA::Format("begin install os pack: [%s]", pszPackageName));
|
|
|
-
|
|
|
- CSimpleStringA strDownloadsPath;
|
|
|
- auto rc = GetPath("Downloads", strDownloadsPath);
|
|
|
- TOOLKIT_ASSERT(rc == Error_Succeed);
|
|
|
-
|
|
|
- CSimpleStringA strUnzipPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadsPath, (const char*)pszPackageName);
|
|
|
- if (strUnzipPath.IsEndWith(".zip") || strUnzipPath.IsEndWith(".cab"))
|
|
|
- strUnzipPath = strUnzipPath.SubString(0, strUnzipPath.GetLength() - 4);
|
|
|
-
|
|
|
- auto strConfigPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "Run.ini", (const char*)strUnzipPath);
|
|
|
-
|
|
|
- // 检查文件是否存在
|
|
|
- DWORD attr = GetFileAttributesA(strConfigPath);
|
|
|
- TOOLKIT_ASSERT((attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY));
|
|
|
-
|
|
|
- // ToRun=install.bat
|
|
|
- char *p = inifile_read_str(strConfigPath, "Action", "ToRun", "");
|
|
|
- CSimpleStringA strToRun = p;
|
|
|
- FREE(p);
|
|
|
-
|
|
|
- //TOOLKIT_ASSERT(!strToCopy.IsNullOrEmpty());
|
|
|
- if (strToRun.IsNullOrEmpty())
|
|
|
- {
|
|
|
- strErrMsg = "未定义执行文件[ToRun]";
|
|
|
- LogError(Severity_Low, Error_Null, 0, "file to run not define");
|
|
|
- return Error_Null;
|
|
|
- }
|
|
|
-
|
|
|
- ErrorCodeEnum eErrorCode = Error_Succeed;
|
|
|
- auto list = strToRun.Split(',');
|
|
|
- for (int i = 0; i < list.GetCount(); i++)
|
|
|
- {
|
|
|
- auto &file = list[i];
|
|
|
-
|
|
|
- CSimpleStringA strSourcePath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUnzipPath, (const char*)file);
|
|
|
- if (ExistsFileA(strSourcePath))
|
|
|
- {
|
|
|
-#ifdef _WIN32
|
|
|
- // 如果是Wow64模式,需屏蔽System32重定向
|
|
|
- PVOID pRedirectOldValue(NULL);
|
|
|
- bool bIsWow64 = IsWow64Process();
|
|
|
- if (bIsWow64)
|
|
|
- {
|
|
|
- if (!Wow64DisableWow64FsRedirection(&pRedirectOldValue))
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Wow64DisableWow64FsRedirection fail: %d", GetLastError());
|
|
|
- else
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Wow64DisableWow64FsRedirection succ");
|
|
|
- }
|
|
|
-#endif //_WIN32
|
|
|
-
|
|
|
- // xkm@20161114: 执行完成,从result.txt中读取安装结果
|
|
|
- system(strSourcePath);
|
|
|
-
|
|
|
- CSimpleStringA strResultLog = strUnzipPath + SPLIT_SLASH_STR "result.log";
|
|
|
- if (!GetSysUpgradeResult(strResultLog, eErrorCode, strErrMsg))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get upgrade result from result.log fail, %s", (const char*)strErrMsg);
|
|
|
- /** ?? [Gifur@202268]*/
|
|
|
- eErrorCode = Error_Succeed;
|
|
|
- strErrMsg = "";
|
|
|
- }
|
|
|
-
|
|
|
-#ifdef _WIN32
|
|
|
- // 如果是Wow64模式,恢复System32重定向
|
|
|
- if (bIsWow64)
|
|
|
- {
|
|
|
- if (!Wow64RevertWow64FsRedirection(pRedirectOldValue))
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Wow64RevertWow64FsRedirection fail: %d", GetLastError());
|
|
|
- else
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Wow64RevertWow64FsRedirection succ");
|
|
|
- }
|
|
|
-#endif //_WIN32
|
|
|
-
|
|
|
- if (eErrorCode != Error_Succeed)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_UpdateFailed, 0, CSimpleStringA::Format("run file [%s] error: %s(%d)", (const char*)file, (const char*)strErrMsg, eErrorCode));
|
|
|
- WriteInstallLog(pszPackageName, CSimpleStringA::Format("run file [%s] error: %s(%d)", (const char*)file, (const char*)strErrMsg, eErrorCode));
|
|
|
- return eErrorCode;
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- strErrMsg = "指定执行文件不存在";
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("file [%s] to run not exists", (const char*)strSourcePath));
|
|
|
- WriteInstallLog(pszPackageName, CSimpleStringA::Format("file [%s] to run not exists", (const char*)strSourcePath));
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- WriteInstallLog(pszPackageName, "install sys pack succ");
|
|
|
-
|
|
|
- // 登录到安装记录文件中
|
|
|
- sp_env_t *env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- CSimpleStringA strPackName = pszPackageName;
|
|
|
-
|
|
|
- char *pszSysPacks = inifile_read_str(cfg->install_ini_path, "Main", "SysPack", "");
|
|
|
- CSimpleStringA strSysPacks = pszSysPacks;
|
|
|
- FREE(pszSysPacks);
|
|
|
-
|
|
|
- if (!strSysPacks.IsNullOrEmpty())
|
|
|
- strSysPacks += ",";
|
|
|
-
|
|
|
- strSysPacks += pszPackageName;
|
|
|
- inifile_write_str(cfg->install_ini_path, "Main", "SysPack", strSysPacks);
|
|
|
- inifile_format_write(cfg->install_ini_path, strPackName, "InstalledDate", "0x%08X", y2k_time_now());
|
|
|
- inifile_write_str(cfg->install_ini_path, strPackName, "PackState", "U");
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("install sys pack [%s] succ", (const char*)strPackName);
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-// 判断是否是已安装的系统外升级包
|
|
|
-ErrorCodeEnum SpEntityPrivilege::IsInstalledSysPack(const char *pszPackageName)
|
|
|
-{
|
|
|
- // 登录到安装记录文件中
|
|
|
- sp_env_t *env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- CSimpleStringA strPackName = pszPackageName;
|
|
|
-
|
|
|
- // 查询系统外升级包
|
|
|
- char *p = inifile_read_str(cfg->install_ini_path, "Main", "SysPack", "");
|
|
|
- CSimpleStringA strSysPackList = p;
|
|
|
- FREE(p);
|
|
|
-
|
|
|
- if (!strSysPackList.IsNullOrEmpty() && (strSysPackList.IndexOf(strPackName)!= -1))
|
|
|
- {
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
-
|
|
|
- return Error_Unexpect;
|
|
|
-}
|
|
|
-
|
|
|
// File*A.*
|
|
|
bool SpEntityPrivilege::IsFileMatch(const char *pszFilter, const char *pszFileName)
|
|
|
{
|
|
|
@@ -877,197 +736,6 @@ CSimpleStringA SpEntityPrivilege::GetFileDirectory(const char *pszFullPath)
|
|
|
return CSimpleStringA(pszFullPath, i);
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum SpEntityPrivilege::RollBackToHistoryVersion(CVersion historyVersion)
|
|
|
-{
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- // 判断目标版本是否小于当前版本
|
|
|
- auto &v = cfg->install_ini->install_version;
|
|
|
- CVersion curVersion(v.major, v.minor, v.revision, v.build);
|
|
|
- if (curVersion <= historyVersion)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Param, 0, CSimpleStringA::Format("history version [%s] >= current version [%s]",
|
|
|
- (const char*)historyVersion.ToString(), (const char*)curVersion.ToString()));
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
-
|
|
|
- // 修改当前Install.ini配置
|
|
|
- CInstallInfo info= {};
|
|
|
- auto rc = GetInstallInfo(historyVersion, info);
|
|
|
- if (rc != Error_Succeed)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("history version [%s] to rollback not exist", (const char*)historyVersion.ToString()));
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
-
|
|
|
- // 检查对应文件夹是否存在
|
|
|
- CSimpleStringA strHisVersion = historyVersion.ToString();
|
|
|
- CSimpleStringA strHisVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", env->dir->root_ver_path, (const char*)strHisVersion);
|
|
|
- if (!ExistsDirA(strHisVerPath))
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("history version dir [%s] not exists", (const char*)strHisVerPath));
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
-
|
|
|
- // 修改当前版本状态为倒回R
|
|
|
- int nRet = inifile_write_str(cfg->install_ini_path, curVersion.ToString(), "InstallState", "R");
|
|
|
-
|
|
|
- // 更新回退次数
|
|
|
- auto nTotalRollbackCount = inifile_read_int(cfg->install_ini_path, curVersion.ToString(), "TotalRollbackCount", 0);
|
|
|
- nTotalRollbackCount++;
|
|
|
- nRet = inifile_write_int(cfg->install_ini_path, curVersion.ToString(), "TotalRollbackCount", nTotalRollbackCount);
|
|
|
- if (-1 == nRet)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Unexpect, 0, "inifile_write_int TotalRollbackCount");
|
|
|
- }
|
|
|
- LOG_TRACE("inifile_write_int, nTotalRollbackCount[%d]", nTotalRollbackCount);
|
|
|
-
|
|
|
- // 修改active.txt文件
|
|
|
- CSimpleStringA strActiveFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "active.txt", env->dir->root_ver_path);
|
|
|
- auto result = UpdateActiveTxt(strActiveFile, strHisVersion, true);
|
|
|
- if (result == Error_Succeed) {
|
|
|
- LOG_TRACE("set rollback to history version [%s] succeed", (const char*)strHisVersion);
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum SpEntityPrivilege::UpgradeToNewVersion(bool bToSysInstall)
|
|
|
-{
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- // 修改当前Install.ini配置
|
|
|
- auto &v = cfg->install_ini->install_version;
|
|
|
- CVersion curVersion(v.major, v.minor, v.revision, v.build);
|
|
|
- int nRet = inifile_write_str(cfg->install_ini_path, curVersion.ToString(), "InstallState", "U"); // 已升级
|
|
|
-
|
|
|
- // 取到新版本
|
|
|
- char *p = inifile_read_str(cfg->install_ini_path, "Main", "LatterInstallVersion", "");
|
|
|
- CSimpleStringA strNewVer = p;
|
|
|
- FREE(p);
|
|
|
- //TOOLKIT_ASSERT(!strNewVer.IsNullOrEmpty());
|
|
|
- if (strNewVer.IsNullOrEmpty())
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Unexpect, 0, "install.ini Main LatterInstallVersion is null");
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", env->dir->root_ver_path, (const char*)strNewVer);
|
|
|
-
|
|
|
- // 修改新版本install.ini
|
|
|
- auto strNewInstallIni = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "install.ini", (const char*)strNewVerPath);
|
|
|
- TOOLKIT_ASSERT(ExistsFileA(strNewInstallIni));
|
|
|
-
|
|
|
- // 取新版本安装包名称
|
|
|
- p = inifile_read_str(strNewInstallIni, strNewVer, "InstallPack", "");
|
|
|
- CSimpleStringA strPackName = p;
|
|
|
- FREE(p);
|
|
|
- TOOLKIT_ASSERT(!strPackName.IsNullOrEmpty());
|
|
|
- WriteInstallLog(strPackName, "Upgrade to new version");
|
|
|
-
|
|
|
- nRet &= inifile_write_str(strNewInstallIni, curVersion.ToString(), "InstallState", "U"); // 已升级
|
|
|
- nRet &= inifile_write_str(strNewInstallIni, strNewVer, "InstallState", "S"); // 设置启动
|
|
|
-
|
|
|
- BOOL bSetSucc = (nRet == 0);
|
|
|
- // 修改active.txt配置
|
|
|
- CSimpleStringA strActiveFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "active.txt", env->dir->root_ver_path);
|
|
|
- if (bSetSucc && Error_Succeed == UpdateActiveTxt(strActiveFile, strNewVer, true)) {
|
|
|
- bSetSucc = TRUE;
|
|
|
- }
|
|
|
- else {
|
|
|
- bSetSucc = FALSE;
|
|
|
- }
|
|
|
-
|
|
|
- // 修改内存配置
|
|
|
- if (bSetSucc)
|
|
|
- {
|
|
|
- sp_version_t newVersion = {};
|
|
|
- sscanf((const char*)strNewVer, "%d.%d.%d.%d", &newVersion.major, &newVersion.minor, &newVersion.revision, &newVersion.build);
|
|
|
- auto newVerInfo = sp_cfg_find_version_info(cfg, &newVersion);
|
|
|
- if (newVerInfo != NULL)
|
|
|
- newVerInfo->install_state = Install_SetToStart;
|
|
|
-
|
|
|
- LOG_TRACE("set new version [%s] active", (const char*)strNewVer);
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Unexpect, 0, "switch to new version fail");
|
|
|
- }
|
|
|
- return Error_Unexpect;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum SpEntityPrivilege::SetRunSucceed()
|
|
|
-{
|
|
|
- sp_env_t *env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- // 修改内存状态
|
|
|
- auto pVerInfo = sp_cfg_find_version_info(cfg, &cfg->install_ini->install_version);
|
|
|
- pVerInfo->install_state = Install_Active; // 安装成功
|
|
|
-
|
|
|
- // 设置后一版本状态为倒回
|
|
|
- if (sp_version_is_valid(&cfg->install_ini->latter_install_version))
|
|
|
- {
|
|
|
- // 修改后一版本安装文件状态为倒回
|
|
|
- auto &latterVer = cfg->install_ini->latter_install_version;
|
|
|
- char tmp[MAX_PATH];
|
|
|
- auto rc = sp_dir_get_path_version(env->dir, latterVer.major, latterVer.minor, latterVer.revision, latterVer.build, SP_DIR_INSTALL_INI,
|
|
|
- NULL, tmp, MAX_PATH, detect_env_test_mode(env->cfg->args->test_mode));
|
|
|
-
|
|
|
- if (rc != 0)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get install.ini path failed!");
|
|
|
- return (ErrorCodeEnum)rc;
|
|
|
- }
|
|
|
-
|
|
|
- if (ExistsFileA(tmp)) // 可能后续版本目录被删除
|
|
|
- {
|
|
|
- // 倒回状态
|
|
|
- CVersion lVer(latterVer.major, latterVer.minor, latterVer.revision, latterVer.build);
|
|
|
- inifile_write_str(tmp, (const char*)lVer.ToString(), "InstallState", "R");
|
|
|
-
|
|
|
- // 修改内存状态
|
|
|
- auto pLatterVerInfo = sp_cfg_find_version_info(cfg, &latterVer);
|
|
|
- if (pLatterVerInfo != NULL)
|
|
|
- pLatterVerInfo->install_state = Install_RollBack;
|
|
|
-
|
|
|
- // 修改对应安装包日志
|
|
|
- auto p = inifile_read_str(tmp, (const char*)lVer.ToString(), "InstallPack", "");
|
|
|
- CSimpleStringA strPackName = p;
|
|
|
- FREE(p);
|
|
|
- TOOLKIT_ASSERT(!strPackName.IsNullOrEmpty());
|
|
|
-
|
|
|
- auto &curVer = cfg->install_ini->install_version;
|
|
|
- WriteInstallLog(strPackName, CSimpleStringA::Format("Rollback to version: [%d.%d.%d.%d]",
|
|
|
- curVer.major, curVer.minor, curVer.revision, curVer.build));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 设置当前版本安装状态为活动
|
|
|
- char *pCurVersion = inifile_read_str(cfg->install_ini_path, "Main", "InstallVersion", "");
|
|
|
- inifile_write_str(cfg->install_ini_path, pCurVersion, "InstallState", "A");
|
|
|
- inifile_format_write(cfg->install_ini_path, pCurVersion, "SwitchOverDate", "0x%08X", y2k_time_now());
|
|
|
- auto pPackName = inifile_read_str(cfg->install_ini_path, pCurVersion, "InstallPack", "");
|
|
|
- CSimpleStringA strPackName = pPackName;
|
|
|
- FREE(pCurVersion);
|
|
|
- FREE(pPackName);
|
|
|
-
|
|
|
- // 修改安装包历史
|
|
|
- if (!strPackName.IsNullOrEmpty())
|
|
|
- WriteInstallLog(strPackName, "Set version state active");
|
|
|
-
|
|
|
- // 拷贝升级包到Upgraded目录
|
|
|
- const char *pPackFile = pVerInfo->install_pack;
|
|
|
- CSimpleStringA strDownloadPath, strUpgradedPath;
|
|
|
- GetPath("Downloads", strDownloadPath);
|
|
|
- GetPath("Upgraded", strUpgradedPath);
|
|
|
- CSimpleStringA strSourcePath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strDownloadPath, pPackFile);
|
|
|
- CSimpleStringA strDestPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUpgradedPath, pPackFile);
|
|
|
- CopyFileA(strSourcePath, strDestPath, FALSE);
|
|
|
-
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
ErrorCodeEnum SpEntityPrivilege::SetSysDebugLevel(const char *pszEntityName,DebugLevelEnum eDebugLevel,bool bPersist)
|
|
|
{
|
|
|
sp_env_t *env = sp_get_env();
|