|
|
@@ -485,254 +485,6 @@ ErrorCodeEnum SpEntityPrivilege::UpdateActiveTxt(const char* strActiveFilePath,
|
|
|
return bSetSucc ? Error_Succeed : Error_Unexpect;
|
|
|
}
|
|
|
|
|
|
-// 创建新版本目录,拷贝当前版本bin、cfg、dep、mod、install.ini,并修改Shell.ini及install.ini中相关配置
|
|
|
-ErrorCodeEnum SpEntityPrivilege::CreateInstallNewVersion(CVersion NewSoftwareVersion,const char *pszPackageName, CSimpleStringA& strErrInfo)
|
|
|
-{
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- // 创建安装包日志文件
|
|
|
- WriteInstallLog(pszPackageName, CSimpleStringA::Format("Create new version: [%s], pack: [%s]",
|
|
|
- (const char*)NewSoftwareVersion.ToString(), (const char*)pszPackageName));
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Create new version: [%s], pack: [%s]", (const char*)NewSoftwareVersion.ToString(), (const char*)pszPackageName);
|
|
|
- CSimpleStringA strCurVerPath = env->dir->base_path;
|
|
|
- CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", env->dir->root_ver_path, (const char*)NewSoftwareVersion.ToString());
|
|
|
-
|
|
|
- auto &v = cfg->install_ini->install_version;
|
|
|
- CVersion curVersion(v.major, v.minor, v.revision, v.build);
|
|
|
- TOOLKIT_ASSERT(curVersion != NewSoftwareVersion);
|
|
|
-
|
|
|
- if (curVersion == NewSoftwareVersion)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Bug, 0, CSimpleStringA::Format("new ver [%s] equals current ver [%s]",
|
|
|
- (const char*)NewSoftwareVersion.ToString(), (const char*)curVersion.ToString()));
|
|
|
- strErrInfo = CSimpleStringA::Format("new ver [%s] equals current ver [%s]",
|
|
|
- (const char*)NewSoftwareVersion.ToString(), (const char*)curVersion.ToString());
|
|
|
- return Error_Bug;
|
|
|
- }
|
|
|
-
|
|
|
- if (ExistsDirA(strNewVerPath)) {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new version dir [%s] already exist, delete it %s", (const char*)strNewVerPath, RemoveDirRecursiveA(strNewVerPath) ? "success" : "fail");
|
|
|
- RemoveDirRecursiveA(strNewVerPath);
|
|
|
- }
|
|
|
-
|
|
|
- if (!CreateDirA(strNewVerPath, TRUE))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create new version dir fail: %d", GetLastError());
|
|
|
- strErrInfo = CSimpleStringA::Format("create new version dir fail: %d", GetLastError());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create new version dir succ");
|
|
|
- //增加错误信息字段,回传给上层应用
|
|
|
- CSimpleStringA strErrMsg = "";
|
|
|
- CSimpleStringA strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "bin", (const char*)strCurVerPath);
|
|
|
- CSimpleStringA strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "bin", (const char*)strNewVerPath);
|
|
|
- if (!RecursiveCopyDir(strSource, strDest, strErrMsg)) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy bin dir fail");
|
|
|
- strErrInfo = CSimpleStringA::Format("copy bin dir fail: %s", strErrMsg.GetData());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy bin dir succ");
|
|
|
-
|
|
|
- strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "cfg", (const char*)strCurVerPath);
|
|
|
- strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "cfg", (const char*)strNewVerPath);
|
|
|
- if (!RecursiveCopyDir(strSource, strDest, strErrMsg)) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy cfg dir fail");
|
|
|
- strErrInfo = CSimpleStringA::Format("copy cfg dir fail: %s", strErrMsg.GetData());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy cfg dir succ");
|
|
|
-
|
|
|
- strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "dep", (const char*)strCurVerPath);
|
|
|
- strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "dep", (const char*)strNewVerPath);
|
|
|
- if (!RecursiveCopyDir(strSource, strDest, strErrMsg)) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy dep dir fail");
|
|
|
- strErrInfo = CSimpleStringA::Format("copy dep dir fail: %s", strErrMsg.GetData());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy dep dir succ");
|
|
|
-
|
|
|
- strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "mod", (const char*)strCurVerPath);
|
|
|
- strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "mod", (const char*)strNewVerPath);
|
|
|
- if (!RecursiveCopyDir(strSource, strDest, strErrMsg)) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy mod dir fail");
|
|
|
- strErrInfo = CSimpleStringA::Format("copy mod dir fail: %s", strErrMsg.GetData());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy mod dir succ");
|
|
|
-
|
|
|
- strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "res", (const char*)strCurVerPath);
|
|
|
- strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "res", (const char*)strNewVerPath);
|
|
|
-
|
|
|
- // 检测res目录是否存在
|
|
|
- if (ExistsDirA(strSource))
|
|
|
- {
|
|
|
- if (!RecursiveCopyDir(strSource, strDest, strErrMsg)) {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy res dir fail");
|
|
|
- strErrInfo = CSimpleStringA::Format("copy res dir fail: %s", strErrMsg.GetData());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy res dir succ");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (!CreateDirA(strDest, TRUE))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create res dir fail");
|
|
|
- strErrInfo = "create res dir fail";
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create res dir succ");
|
|
|
- }
|
|
|
-
|
|
|
- strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "imdep", (const char*)strCurVerPath);
|
|
|
- strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "imdep", (const char*)strNewVerPath);
|
|
|
-
|
|
|
- // 检测imdep目录是否存在
|
|
|
- if (ExistsDirA(strSource))
|
|
|
- {
|
|
|
- if (!RecursiveCopyDir(strSource, strDest,strErrMsg))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy imdep dir fail");
|
|
|
- strErrInfo = CSimpleStringA::Format("copy imdep dir fail: %s", strErrMsg.GetData());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy imdep dir succ");
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (!CreateDirA(strDest, TRUE))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create imdep dir fail");
|
|
|
- strErrInfo = "create imdep dir fail";
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create imdep dir succ");
|
|
|
- }
|
|
|
-
|
|
|
- strSource = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "install.ini", (const char*)strCurVerPath);
|
|
|
- strDest = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "install.ini", (const char*)strNewVerPath);
|
|
|
- if (!CopyFileA(strSource, strDest, FALSE))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy install.ini fail: %d", GetLastError());
|
|
|
- strErrInfo = CSimpleStringA::Format("copy install.ini fail: %d", GetLastError());
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy install.ini succ");
|
|
|
-
|
|
|
- // 修改新Shell.ini
|
|
|
- CSimpleStringA strShellVarIni = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "shellVar.ini", (const char*)env->dir->root_runinfo_path);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("update SoftwareVersion to %s", strShellVarIni);
|
|
|
- int nRet = inifile_format_write((const char*)strShellVarIni, "Main", "SoftwareVersion", "%d.%d.%d", NewSoftwareVersion.GetMajor(),
|
|
|
- NewSoftwareVersion.GetMinor(), NewSoftwareVersion.GetRevision());
|
|
|
-
|
|
|
- //// 修改当前install.ini
|
|
|
- inifile_write_str(cfg->install_ini_path, "Main", "LatterInstallVersion", NewSoftwareVersion.ToString());
|
|
|
- inifile_write_str(cfg->install_ini_path, "Main", "LatterInstallPack", pszPackageName);
|
|
|
-
|
|
|
- //inifile_write_str(cfg->install_ini_path, CurVersion.ToString(), "InstallState", "U");
|
|
|
-
|
|
|
- // 修改新版本install.ini
|
|
|
- auto strNewInstallIni = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "install.ini", (const char*)strNewVerPath);
|
|
|
- TOOLKIT_ASSERT(ExistsFileA(strNewInstallIni));
|
|
|
-
|
|
|
- char szNow[16] = {};
|
|
|
- sprintf(szNow, "0x%08X", y2k_time_now());
|
|
|
-
|
|
|
- // 缓存前版本轻量包记录
|
|
|
- char *packs = inifile_read_str(strNewInstallIni, "Main", "LightPack", "");
|
|
|
-
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "InstallVersion", NewSoftwareVersion.ToString());
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "CreateDate", szNow);
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "LatterInstallVersion", "");
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "LightPack", "");
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "TotalRunCount", "1");
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "TodayRunCount", "1");
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, "Main", "CurrentTime", szNow);
|
|
|
-
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, NewSoftwareVersion.ToString(), "PreviousInstallVersion", curVersion.ToString());
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, NewSoftwareVersion.ToString(), "InstallPack", pszPackageName);
|
|
|
- nRet |= inifile_write_str(strNewInstallIni, NewSoftwareVersion.ToString(), "InstallState", "I"); // 正在安装
|
|
|
-
|
|
|
- // 去掉所有历史版本中轻量安装记录
|
|
|
- if (packs)
|
|
|
- {
|
|
|
- if (strlen(packs) >0)
|
|
|
- {
|
|
|
- char *p = NULL;
|
|
|
- while((p = strrchr(packs, ',')) != NULL)
|
|
|
- {
|
|
|
- *p = 0;
|
|
|
- WritePrivateProfileSectionA(p+1, NULL, strNewInstallIni);
|
|
|
- }
|
|
|
-
|
|
|
- WritePrivateProfileSectionA(packs, NULL, strNewInstallIni);
|
|
|
- }
|
|
|
-
|
|
|
- FREE(packs);
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("write version into install.ini done");
|
|
|
-
|
|
|
- // 修改内存配置项
|
|
|
- auto ver_info = (sp_cfg_version_info_t*)shm_malloc(sizeof(sp_cfg_version_info_t));
|
|
|
- memset(ver_info, 0, sizeof(sp_cfg_version_info_t));
|
|
|
- ver_info->version.major = NewSoftwareVersion.GetMajor();
|
|
|
- ver_info->version.minor = NewSoftwareVersion.GetMinor();
|
|
|
- ver_info->version.revision = NewSoftwareVersion.GetRevision();
|
|
|
- ver_info->version.build = NewSoftwareVersion.GetBuild();
|
|
|
- ver_info->previous_version.major = curVersion.GetMajor();
|
|
|
- ver_info->previous_version.minor = curVersion.GetMinor();
|
|
|
- ver_info->previous_version.revision = curVersion.GetRevision();
|
|
|
- ver_info->previous_version.build = curVersion.GetBuild();
|
|
|
- ver_info->install_pack = shm_strdup(pszPackageName);
|
|
|
- ver_info->install_state = Install_Pending;
|
|
|
- SHM_ARRAY_PUSH(cfg->install_ini->arr_version, sp_cfg_version_info_t*) = ver_info;
|
|
|
-
|
|
|
- cfg->install_ini->latter_install_version.major = NewSoftwareVersion.GetMajor();
|
|
|
- cfg->install_ini->latter_install_version.minor = NewSoftwareVersion.GetMinor();
|
|
|
- cfg->install_ini->latter_install_version.revision = NewSoftwareVersion.GetRevision();
|
|
|
- cfg->install_ini->latter_install_version.build = NewSoftwareVersion.GetBuild();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("write version into share mem done");
|
|
|
-
|
|
|
- return nRet == 0 ? Error_Succeed : Error_Unexpect;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum SpEntityPrivilege::GenerateNewInstallCfg() {
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Generate new install.ini to %s", cfg->install_ini_path);
|
|
|
-
|
|
|
- if (ExistsFile(cfg->install_ini_path))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("file exist, do not create, %s", cfg->install_ini_path);
|
|
|
- return Error_AlreadyExist;
|
|
|
- }
|
|
|
-
|
|
|
- char szVer[128];
|
|
|
- char szNow[128];
|
|
|
- y2k_time_t now;
|
|
|
- auto active_version = cfg->install_ini->install_version;
|
|
|
- auto szIniPath = cfg->install_ini_path;
|
|
|
- sprintf(szVer, "%d.%d.%d.%d", active_version.major, active_version.minor, active_version.revision, active_version.build);
|
|
|
- inifile_write_str(szIniPath, "Main", "InstallVersion", szVer);
|
|
|
- sprintf(szNow, "0x%08X", cfg->install_ini->install_time);
|
|
|
- inifile_write_str(szIniPath, "Main", "CreateDate", szNow);
|
|
|
- inifile_write_str(szIniPath, "Main", "LatterInstallVersion", "");
|
|
|
- inifile_write_str(szIniPath, "Main", "LightPack", "");
|
|
|
- inifile_write_str(szIniPath, "Main", "TotalRunCount", "0");
|
|
|
- inifile_write_str(szIniPath, "Main", "TodayRunCount", "0");
|
|
|
- inifile_write_str(szIniPath, "Main", "CurrentTime", szNow);
|
|
|
-
|
|
|
- inifile_write_str(szIniPath, szVer, "SwitchOverDate", szNow);
|
|
|
- inifile_write_str(szIniPath, szVer, "InstallPack", "");
|
|
|
- inifile_write_str(szIniPath, szVer, "InstallState", "A");
|
|
|
-
|
|
|
- return Error_Succeed;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
ErrorCodeEnum CopyFolder(CSimpleStringA strSourcePath, CSimpleStringA strDestPath)
|
|
|
{
|
|
|
if (strSourcePath.IsNullOrEmpty() || strDestPath.IsNullOrEmpty())
|
|
|
@@ -845,159 +597,6 @@ CSimpleStringA GetFileDirectory(const char *pszFullPath)
|
|
|
return CSimpleStringA(pszFullPath, i);
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum SpEntityPrivilege::BeginLightInstall(const char *pszPackageName)
|
|
|
-{
|
|
|
- // 创建安装包日志文件
|
|
|
- WriteInstallLog(pszPackageName, CSimpleStringA::Format("Begin install light pack: [%s]", pszPackageName));
|
|
|
-
|
|
|
- CSimpleStringA strAdPath;
|
|
|
- auto rc = GetPath("Ad", strAdPath);
|
|
|
- TOOLKIT_ASSERT(rc == Error_Succeed);
|
|
|
-
|
|
|
- CSimpleStringA strDownloadsPath;
|
|
|
- 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));
|
|
|
-
|
|
|
- char *p = inifile_read_str(strConfigPath, "Action", "ToCopy", "");
|
|
|
- CSimpleStringA strToCopy = p;
|
|
|
- FREE(p);
|
|
|
- //TOOLKIT_ASSERT(!strToCopy.IsNullOrEmpty());
|
|
|
- if (strToCopy.IsNullOrEmpty())
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Null, 0, "file to copy not define");
|
|
|
- return Error_Null;
|
|
|
- }
|
|
|
-
|
|
|
-#if defined(RVC_OS_LINUX)
|
|
|
- std::string strCopy = strToCopy.GetData();
|
|
|
- std::replace(strCopy.begin(), strCopy.end(), '\\', SPLIT_SLASH);
|
|
|
- strToCopy = strCopy.c_str();
|
|
|
-#endif //RVC_OS_LINUX
|
|
|
-
|
|
|
- auto list = strToCopy.Split(',');
|
|
|
- for(int i=0; i<list.GetCount(); i++)
|
|
|
- {
|
|
|
- auto &file = list[i];
|
|
|
- if (file.IsStartWith("Data" SPLIT_SLASH_STR))
|
|
|
- {
|
|
|
- // 通配符检测
|
|
|
- if (file.IndexOf("*") >0)
|
|
|
- {
|
|
|
- CSimpleStringA strSourcePath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUnzipPath, (const char*)GetFileDirectory(file));
|
|
|
-
|
|
|
- CSimpleStringA StrDirToCopy = GetFileDirectory(file).SubString(5, file.GetLength()-5);
|
|
|
- CSimpleStringA strDestPath = "";
|
|
|
- if (StrDirToCopy.IsNullOrEmpty())
|
|
|
- {
|
|
|
- strDestPath = strAdPath;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- strDestPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strAdPath, (const char*)GetFileDirectory(file).SubString(5, file.GetLength()-5));
|
|
|
- }
|
|
|
-
|
|
|
- rc = CopyFolder(strSourcePath, strDestPath);
|
|
|
- if (Error_Succeed != rc)
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("copy dir [%s] to dir [%s] fail", (const char*)strSourcePath, (const char*)strDestPath));
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- CSimpleStringA strSourcePath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUnzipPath, (const char*)file);
|
|
|
- CSimpleStringA strDestPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strAdPath, (const char*)file.SubString(5, file.GetLength()-5));
|
|
|
-
|
|
|
- if (ExistsFileA(strSourcePath))
|
|
|
- {
|
|
|
- // 先去除目标文件只读属性
|
|
|
- if (ExistsFileA(strDestPath))
|
|
|
- RemoveFileReadOnlyAttributeA(strDestPath);
|
|
|
-
|
|
|
- LOG_TRACE("copy file from [%s] to [%s]", (const char*)strSourcePath, (const char*)strDestPath);
|
|
|
- BOOL bRet = CopyFileA(strSourcePath, strDestPath, FALSE);
|
|
|
-
|
|
|
- // 去除只读属性
|
|
|
- if (bRet)
|
|
|
- RemoveFileReadOnlyAttributeA(strDestPath);
|
|
|
- else
|
|
|
- {
|
|
|
- // 覆盖失败,则生成.new副本
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy file [%s] to [%s] fail, now save as .new file", (const char*) strSourcePath, (const char*) strDestPath);
|
|
|
-
|
|
|
- strDestPath += ".new";
|
|
|
- bRet = CopyFileA(strSourcePath, strDestPath, FALSE);
|
|
|
- if (bRet)
|
|
|
- {
|
|
|
- RemoveFileReadOnlyAttributeA(strDestPath);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("copy [%s] as [%s] succeed", (const char*)strSourcePath, (const char*) strDestPath);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_Unexpect, 0, CSimpleStringA::Format("copy file [%s] as [%s] fail", (const char*) strSourcePath, (const char*) strDestPath));
|
|
|
- return Error_Block;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("file [%s] to copy not exists", (const char*)strSourcePath));
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NoPrivilege, 0, CSimpleStringA::Format("light pack [%s] has invalid copy item: [%s]",
|
|
|
- (const char*)pszPackageName, (const char*)file));
|
|
|
- return Error_NoPrivilege;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 登录到安装记录文件中
|
|
|
- sp_env_t *env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- CSimpleStringA strPackName = pszPackageName;
|
|
|
-
|
|
|
- CSimpleStringA strLightPacks = cfg->install_ini->light_packs;
|
|
|
- if (!strLightPacks.IsNullOrEmpty())
|
|
|
- strLightPacks += ",";
|
|
|
-
|
|
|
- strLightPacks += strPackName;
|
|
|
- inifile_write_str(cfg->install_ini_path, "Main", "LightPack", strLightPacks);
|
|
|
-
|
|
|
- shm_free(cfg->install_ini->light_packs);
|
|
|
- cfg->install_ini->light_packs = shm_strdup(strLightPacks);
|
|
|
-
|
|
|
- // 修改内存配置项
|
|
|
- sp_cfg_pack_info_t *pack_info = (sp_cfg_pack_info_t*)shm_malloc(sizeof(sp_cfg_pack_info_t));
|
|
|
- memset(pack_info, 0, sizeof(sp_cfg_pack_info_t));
|
|
|
- pack_info->name = shm_strdup(strPackName);
|
|
|
- pack_info->install_time = y2k_time_now();
|
|
|
- pack_info->state = Install_Installed;
|
|
|
- SHM_ARRAY_PUSH(cfg->install_ini->arr_light_pack, sp_cfg_pack_info_t*) = pack_info;
|
|
|
-
|
|
|
- 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 light pack [%s] succeed", (const char*)strPackName);
|
|
|
-
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
bool SpEntityPrivilege::IsWow64Process()
|
|
|
@@ -1209,143 +808,6 @@ ErrorCodeEnum SpEntityPrivilege::IsInstalledSysPack(const char *pszPackageName)
|
|
|
return Error_Unexpect;
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum SpEntityPrivilege::CopyFileToNewVersion(const char *pszRelativeFile, int nCopyMode)
|
|
|
-{
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- // 取到新版本安装包名称
|
|
|
- char *p = inifile_read_str(cfg->install_ini_path, "Main", "LatterInstallVersion", "");
|
|
|
- CSimpleStringA strNewVer = p;
|
|
|
- FREE(p);
|
|
|
- TOOLKIT_ASSERT(!strNewVer.IsNullOrEmpty());
|
|
|
-
|
|
|
- CSimpleStringA strNewInstallIni = CSimpleStringA::Format(
|
|
|
-#ifdef _WIN32
|
|
|
- "%s\\%s\\install.ini",
|
|
|
-#else
|
|
|
- "%s/%s/install.ini",
|
|
|
-#endif //_WIN32
|
|
|
- env->dir->root_ver_path, (const char*)strNewVer);
|
|
|
- TOOLKIT_ASSERT(ExistsFileA(strNewInstallIni));
|
|
|
-
|
|
|
- p = inifile_read_str(strNewInstallIni, strNewVer, "InstallPack", "");
|
|
|
- CSimpleStringA strPackName = p;
|
|
|
- FREE(p);
|
|
|
- TOOLKIT_ASSERT(!strPackName.IsNullOrEmpty());
|
|
|
-
|
|
|
- // 取得临时解压目录
|
|
|
- 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*)strPackName);
|
|
|
- if (strUnzipPath.IsEndWith(".zip") || strUnzipPath.IsEndWith(".cab"))
|
|
|
- strUnzipPath = strUnzipPath.SubString(0, strUnzipPath.GetLength()-4);
|
|
|
-
|
|
|
- CSimpleStringA strCopyPath = pszRelativeFile;
|
|
|
- CSimpleStringA strSourceFile;
|
|
|
- CSimpleStringA strDestFile;
|
|
|
-
|
|
|
- if (strCopyPath.IsStartWith("Data" SPLIT_SLASH_STR))
|
|
|
- {
|
|
|
- CSimpleStringA strAdPath;
|
|
|
- rc = GetPath("Ad", strAdPath);
|
|
|
- TOOLKIT_ASSERT(rc == Error_Succeed);
|
|
|
-
|
|
|
- strSourceFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUnzipPath, (const char*)strCopyPath);
|
|
|
- strDestFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strAdPath, (const char*)strCopyPath.SubString(5, strCopyPath.GetLength()-5));
|
|
|
- }
|
|
|
- else if (strCopyPath.IsStartWith("Run" SPLIT_SLASH_STR))
|
|
|
- {
|
|
|
- strSourceFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strUnzipPath, (const char*)strCopyPath);
|
|
|
- CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", env->dir->root_ver_path, (const char*)strNewVer);
|
|
|
- strDestFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s",(const char*) strNewVerPath, (const char*)strCopyPath.SubString(4, strCopyPath.GetLength()-4));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- WriteInstallLog(strPackName, CSimpleStringA::Format("Copy file: [%s], result: [0x%X]", pszRelativeFile, Error_NoPrivilege));
|
|
|
- LogError(Severity_Low, Error_NoPrivilege, 0, CSimpleStringA::Format("invalid copy item: [%s], must start with \"Data\" or \"Run\"", (const char*)pszRelativeFile));
|
|
|
- return Error_NoPrivilege;
|
|
|
- }
|
|
|
-
|
|
|
- //TOOLKIT_ASSERT(ExistsFileA(strSourceFile));
|
|
|
- if (!ExistsFileA(strSourceFile))
|
|
|
- {
|
|
|
- WriteInstallLog(strPackName, CSimpleStringA::Format("Copy file: [%s], result: [0x%X]", pszRelativeFile, Error_NotExist));
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("file [%s] to copy not exist", (const char*)strSourceFile));
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
-
|
|
|
-//#ifdef _DEBUG
|
|
|
-// bool bVerifySign = false;
|
|
|
-//#else
|
|
|
-// bool bVerifySign = true;
|
|
|
-//#endif
|
|
|
-//
|
|
|
-// if (bVerifySign && (strSourceFile.IsEndWith(".dll", true) || strSourceFile.IsEndWith(".exe", true)))
|
|
|
-// {
|
|
|
-// CSimpleStringA strErrMsg;
|
|
|
-// if (VerifySignature(strSourceFile, strErrMsg) != Error_Succeed)
|
|
|
-// {
|
|
|
-// WriteInstallLog(strPackName, CSimpleStringA::Format("file [%s] sign verify not pass: %s", pszRelativeFile, (const char*)strErrMsg));
|
|
|
-// LogError(Severity_Low, Error_FailVerify, 0, CSimpleStringA::Format("file [%s] sign verify not pass: %s", (const char*)strSourceFile, (const char*)strErrMsg));
|
|
|
-// return Error_FailVerify;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
- // check dest dir if exists
|
|
|
- auto strDestDir = GetFileDirectory(strDestFile);
|
|
|
- if (!ExistsDirA(strDestDir))
|
|
|
- CreateDirA(strDestDir, TRUE);
|
|
|
-
|
|
|
- BOOL bDestFileExists = ExistsFileA(strDestFile);
|
|
|
- if (bDestFileExists)
|
|
|
- RemoveFileReadOnlyAttributeA(strDestFile);
|
|
|
-
|
|
|
- BOOL bRet = TRUE;
|
|
|
-
|
|
|
- // 1(copy only exisit); 2(copy only not exist); 3(copy always); 4(no copy if exist)
|
|
|
- switch (nCopyMode)
|
|
|
- {
|
|
|
- case 1:
|
|
|
- {
|
|
|
- if (bDestFileExists)
|
|
|
- bRet= CopyFileA(strSourceFile, strDestFile, FALSE);
|
|
|
- else
|
|
|
- LOG_TRACE("ignore file [%s] copy for dest file not exists", pszRelativeFile);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- {
|
|
|
- if (!bDestFileExists)
|
|
|
- bRet= CopyFileA(strSourceFile, strDestFile, TRUE);
|
|
|
- else
|
|
|
- LOG_TRACE("ignore file [%s] copy for dest file exists", pszRelativeFile);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- bRet= CopyFileA(strSourceFile, strDestFile, FALSE);
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- {
|
|
|
- // 不发生拷贝,只进行判断
|
|
|
- if(bDestFileExists)
|
|
|
- LOG_TRACE("file [%s] exist", pszRelativeFile);
|
|
|
- else
|
|
|
- LOG_TRACE("file [%s] not exist", pszRelativeFile);
|
|
|
- }
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (bRet)
|
|
|
- RemoveFileReadOnlyAttributeA(strDestFile);
|
|
|
-
|
|
|
- rc = bRet ? Error_Succeed : Error_Unexpect;
|
|
|
- WriteInstallLog(strPackName, CSimpleStringA::Format("Copy file: [%s], result: [0x%X]", pszRelativeFile, rc));
|
|
|
- return rc;
|
|
|
-}
|
|
|
-
|
|
|
// File*A.*
|
|
|
bool SpEntityPrivilege::IsFileMatch(const char *pszFilter, const char *pszFileName)
|
|
|
{
|
|
|
@@ -1415,174 +877,6 @@ CSimpleStringA SpEntityPrivilege::GetFileDirectory(const char *pszFullPath)
|
|
|
return CSimpleStringA(pszFullPath, i);
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum SpEntityPrivilege::DeleteFileInNewVersion(const char *pszRelativeFile)
|
|
|
-{
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
-
|
|
|
- // 取到新版本安装包名称
|
|
|
- char *p =inifile_read_str(cfg->install_ini_path, "Main", "LatterInstallVersion", "");
|
|
|
- CSimpleStringA strNewVer = p;
|
|
|
- FREE(p);
|
|
|
-
|
|
|
- CSimpleStringA strNewInstallIni = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s" SPLIT_SLASH_STR "install.ini"
|
|
|
- , env->dir->root_ver_path, (const char*)strNewVer);
|
|
|
- TOOLKIT_ASSERT(ExistsFileA(strNewInstallIni));
|
|
|
-
|
|
|
- p = inifile_read_str(strNewInstallIni, strNewVer, "InstallPack", "");
|
|
|
- CSimpleStringA strPackName = p;
|
|
|
- FREE(p);
|
|
|
- TOOLKIT_ASSERT(!strPackName.IsNullOrEmpty());
|
|
|
-
|
|
|
- CSimpleStringA strDelFile = pszRelativeFile;
|
|
|
- CSimpleStringA strDestFile;
|
|
|
-
|
|
|
- if (strDelFile.IsStartWith("Data" SPLIT_SLASH_STR))
|
|
|
- {
|
|
|
- CSimpleStringA strAdPath;
|
|
|
- auto rc = GetPath("Ad", strAdPath);
|
|
|
- TOOLKIT_ASSERT(rc == Error_Succeed);
|
|
|
-
|
|
|
- strDestFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strAdPath, (const char*)strDelFile.SubString(5, strDelFile.GetLength()-5));
|
|
|
- }
|
|
|
- else if (strDelFile.IsStartWith("Run" SPLIT_SLASH_STR))
|
|
|
- {
|
|
|
- CSimpleStringA strNewVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", env->dir->root_ver_path, (const char*)strNewVer);
|
|
|
- TOOLKIT_ASSERT(ExistsDirA(strNewVerPath));
|
|
|
- strDestFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", (const char*)strNewVerPath, (const char*)strDelFile.SubString(4, strDelFile.GetLength()-4));
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- WriteInstallLog(strPackName, CSimpleStringA::Format("Delete file: [%s], result: [%d]", pszRelativeFile, Error_NoPrivilege));
|
|
|
- LogError(Severity_Low, Error_NoPrivilege, 0, CSimpleStringA::Format("invalid delete item: [%s], must start with \"Data\" or \"Run\"", (const char*)pszRelativeFile));
|
|
|
- return Error_NoPrivilege;
|
|
|
- }
|
|
|
-
|
|
|
- // 解析文件通配符*
|
|
|
- BOOL bRet = TRUE;
|
|
|
- int nIndex = strDestFile.IndexOf("*");
|
|
|
- if (nIndex > 0)
|
|
|
- {
|
|
|
- CSimpleStringA strFileFilter = _GetFileName(strDestFile);
|
|
|
- CSimpleStringA strDestDir = strDestFile.SubString(0, strDestFile.GetLength()-strFileFilter.GetLength()-1);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete wildchar file [%s] in dir [%s]", (const char*)strFileFilter, (const char*)strDestDir);
|
|
|
-
|
|
|
- // 删除所有匹配文件
|
|
|
- auto arr = fileutil_get_sub_files(strDestDir);
|
|
|
- if (arr != NULL)
|
|
|
- {
|
|
|
- for (int i = 0; i < arr->nelts; ++i)
|
|
|
- {
|
|
|
- char *file = ARRAY_IDX(arr, i, char*);
|
|
|
-
|
|
|
- if (IsFileMatch(strFileFilter, _GetFileName(file)))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete match file: [%s]", file);
|
|
|
- bRet &= RemoveFileA(file);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ignore not match file: [%s]", file);
|
|
|
- }
|
|
|
- }
|
|
|
- toolkit_array_free2(arr);
|
|
|
- }
|
|
|
-
|
|
|
- // xkm@20170302: 删除所有匹配子目录
|
|
|
- auto subdirs = fileutil_get_sub_dirs(strDestDir);
|
|
|
- if (subdirs != NULL)
|
|
|
- {
|
|
|
- for (int i = 0; i < subdirs->nelts; ++i)
|
|
|
- {
|
|
|
- const char *dir = ARRAY_IDX(subdirs, i, char*);
|
|
|
-
|
|
|
- if (IsFileMatch(strFileFilter, _GetFileName(dir)))
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete match dir: [%s]", dir);
|
|
|
- bRet &= RemoveDirRecursive(dir);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ignore not match dir: [%s]", dir);
|
|
|
- }
|
|
|
- }
|
|
|
- toolkit_array_free2(subdirs);
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- if (ExistsFileA(strDestFile))
|
|
|
- {
|
|
|
- bRet = DeleteFileA(strDestFile);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file [%s] result: %d", strDestFile, bRet);
|
|
|
- }
|
|
|
- else if (ExistsDirA(strDestFile))
|
|
|
- {
|
|
|
- bRet = RemoveDirRecursive(strDestFile);
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete dir [%s] result: %d", strDestFile, bRet);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("delete file [%s] fail, not exists", pszRelativeFile);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- auto rc = bRet ? Error_Succeed : Error_Unexpect;
|
|
|
- WriteInstallLog(strPackName, CSimpleStringA::Format("Delete file: [%s], result: [%d]", pszRelativeFile, rc));
|
|
|
- return rc;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum SpEntityPrivilege::RollBackToPreviousVersion()
|
|
|
-{
|
|
|
- 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);
|
|
|
-
|
|
|
- CInstallInfo info = {};
|
|
|
- auto rc = GetInstallInfo(curVersion, info);
|
|
|
- TOOLKIT_ASSERT(rc == Error_Succeed);
|
|
|
-
|
|
|
- if (!info.PreviousInstallVersion.IsValid())
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("current version [%s] has no previous version", (const char*)curVersion.ToString()));
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
-
|
|
|
- auto strPrevVersion = info.PreviousInstallVersion.ToString();
|
|
|
-
|
|
|
- // 检查对应文件夹是否存在
|
|
|
- CSimpleStringA strPreVerPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s", env->dir->root_ver_path, (const char*)strPrevVersion);
|
|
|
- if (!ExistsDirA(strPreVerPath))
|
|
|
- {
|
|
|
- LogError(Severity_Low, Error_NotExist, 0, CSimpleStringA::Format("previous version dir [%s] not exists", (const char*)strPreVerPath));
|
|
|
- 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, strPrevVersion, true);
|
|
|
- if (result == Error_Succeed) {
|
|
|
- LOG_TRACE("set rollback to previous version [%s] succeed", (const char*)strPrevVersion);
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
ErrorCodeEnum SpEntityPrivilege::RollBackToHistoryVersion(CVersion historyVersion)
|
|
|
{
|
|
|
auto env = sp_get_env();
|
|
|
@@ -1774,133 +1068,6 @@ ErrorCodeEnum SpEntityPrivilege::SetRunSucceed()
|
|
|
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
-
|
|
|
-ErrorCodeEnum SpEntityPrivilege::IsPackInstalled(const char *pszPackName, bool &bInstalled)
|
|
|
-{
|
|
|
- if (pszPackName == NULL)
|
|
|
- {
|
|
|
- bInstalled = false;
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
-
|
|
|
- // 先从内存查找
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
- bInstalled = sp_cfg_is_pack_installed(cfg, pszPackName) == 0;
|
|
|
-
|
|
|
- if (bInstalled)
|
|
|
- return Error_Succeed;
|
|
|
-
|
|
|
- // 再从安装文件目录查找
|
|
|
- CSimpleStringA strPath;
|
|
|
- GetPath("RunInfo", strPath);
|
|
|
-
|
|
|
- CSimpleStringA strInstallLog = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "InstallLog" SPLIT_SLASH_STR "%s.log", (const char*)strPath, pszPackName);
|
|
|
- bInstalled = ExistsFileA(strInstallLog) == TRUE;
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum SpEntityPrivilege::GetSystemStaticInfoForVersion(CVersion verSoftware,CSystemStaticInfo &Info)
|
|
|
-{
|
|
|
- auto env = sp_get_env();
|
|
|
- auto cfg = env->cfg;
|
|
|
- auto root_ini = cfg->root_ini;
|
|
|
- memset(&Info, 0, sizeof(Info));
|
|
|
- Info.strTerminalID = CSimpleStringA(root_ini->terminal_no);
|
|
|
- Info.strMachineType = CSimpleStringA(root_ini->machine_type);
|
|
|
- Info.MachineVersion = CVersion(root_ini->machine_version.major, root_ini->machine_version.minor, root_ini->machine_version.revision, root_ini->machine_version.build);
|
|
|
- Info.eScreen = (ScreenEnum)root_ini->screen;
|
|
|
- Info.strSite = root_ini->site;
|
|
|
- Info.strEnrolAddr = root_ini->enroll_address;
|
|
|
- Info.EnrolGPS = CSphereVector(root_ini->enroll_gps_x, root_ini->enroll_gps_y);
|
|
|
-
|
|
|
- CSimpleStringA strInstallIni = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s" SPLIT_SLASH_STR "install.ini", env->dir->root_ver_path, (const char*)verSoftware.ToString());
|
|
|
- if (ExistsFileA(strInstallIni))
|
|
|
- {
|
|
|
- int n1(0), n2(0), n3(0), n4(0);
|
|
|
- auto p = inifile_read_str(strInstallIni, "Main", "LatterInstallVersion", "");
|
|
|
- int n = sscanf(p, "%d.%d.%d.%d", &n1, &n2, &n3, &n4);
|
|
|
- toolkit_free(p);
|
|
|
- if (n == 4)
|
|
|
- Info.LatterInstallVersion = CVersion(n1, n2, n3, n4);
|
|
|
- else
|
|
|
- Info.LatterInstallVersion = CVersion(0, 0, 0, 0);
|
|
|
-
|
|
|
-
|
|
|
- //Info.LatterInstallPack = inifile_read_int(strInstallIni, "Main", "LatterInstallPack", 0);
|
|
|
- Info.nTotalRunCount = inifile_read_int(strInstallIni, "Main", "TotalRunCount", 0);
|
|
|
- Info.nTodayRunCount = inifile_read_int(strInstallIni, "Main", "TodayRunCount", 0);
|
|
|
- Info.tmCreateDate = CSmallDateTime(inifile_read_int(strInstallIni, "Main", "CreateDate", 0));
|
|
|
- Info.tmCurrentTime = CSmallDateTime(inifile_read_int(strInstallIni, "Main", "CurrentTime", 0));
|
|
|
-
|
|
|
- p = inifile_read_str(strInstallIni, "Main", "InstallVersion", "");
|
|
|
- n = sscanf(p, "%d.%d.%d.%d", &n1, &n2, &n3, &n4);
|
|
|
- toolkit_free(p);
|
|
|
-
|
|
|
- if (n != 4)
|
|
|
- return Error_Unexpect;
|
|
|
-
|
|
|
- Info.InstallVersion = CVersion(n1, n2, n3, n4);
|
|
|
- auto strInstallVersion = Info.InstallVersion.ToString();
|
|
|
-
|
|
|
- p = inifile_read_str(strInstallIni, strInstallVersion, "PreviousInstallVersion", "");
|
|
|
- n = sscanf(p, "%d.%d.%d.%d", &n1, &n2, &n3, &n4);
|
|
|
- toolkit_free(p);
|
|
|
-
|
|
|
- if (n == 4)
|
|
|
- Info.PreviousInstallVersion = CVersion(n1, n2, n3, n4);
|
|
|
- else
|
|
|
- Info.PreviousInstallVersion = CVersion(0, 0, 0, 0);
|
|
|
-
|
|
|
- Info.tmSwithOverDate = CSmallDateTime(inifile_read_int(strInstallIni, strInstallVersion, "SwitchOverDate", 0));
|
|
|
-
|
|
|
- p = inifile_read_str(strInstallIni, strInstallVersion, "InstallPack", "");
|
|
|
- Info.InstallPack = p;
|
|
|
- toolkit_free(p);
|
|
|
-
|
|
|
- Info.InstallState = (InstallStateEnum)read_ini_install_state(strInstallIni, strInstallVersion, "InstallState");
|
|
|
-
|
|
|
- // light pack
|
|
|
- p = inifile_read_str(strInstallIni, "Main", "LightPack", "");
|
|
|
- CSimpleStringA strLightPacks = p;
|
|
|
- toolkit_free(p);
|
|
|
-
|
|
|
- if (!strLightPacks.IsNullOrEmpty())
|
|
|
- {
|
|
|
- auto list = strLightPacks.Split(',');
|
|
|
- Info.LightPackInfos.Init(list.GetCount());
|
|
|
-
|
|
|
- for (int i = 0; i < list.GetCount(); ++i)
|
|
|
- {
|
|
|
- auto& strPackName = list[i];
|
|
|
- Info.LightPackInfos[i].strPackName = strPackName;
|
|
|
- Info.LightPackInfos[i].State = (InstallStateEnum)read_ini_install_state(strInstallIni, strPackName, "PackState");
|
|
|
- Info.LightPackInfos[i].tmInstalledDate = CSmallDateTime(inifile_read_int(strInstallIni, strPackName, "InstalledDate", 0));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- auto latterVer = cfg->install_ini->latter_install_version;
|
|
|
- Info.LatterInstallVersion = CVersion(latterVer.major, latterVer.minor, latterVer.revision, latterVer.build);
|
|
|
- Info.nTotalRunCount = cfg->install_ini->total_run_count;
|
|
|
- Info.tmCreateDate = CSmallDateTime(cfg->install_ini->current_startup_time);
|
|
|
- Info.tmCurrentTime = CSmallDateTime(cfg->install_ini->install_time);
|
|
|
- auto installver = cfg->install_ini->install_version;
|
|
|
- Info.InstallVersion = CVersion(installver.major, installver.minor, installver.revision, installver.build);
|
|
|
- Info.PreviousInstallVersion = CVersion(0, 0, 0, 0);
|
|
|
- Info.tmSwithOverDate = CSmallDateTime(cfg->install_ini->install_time);
|
|
|
- Info.InstallPack = "";
|
|
|
- Info.InstallState = Install_Active;
|
|
|
- Info.InstallPack = "";
|
|
|
- Info.LightPackInfos.Clear();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
ErrorCodeEnum SpEntityPrivilege::SetSysDebugLevel(const char *pszEntityName,DebugLevelEnum eDebugLevel,bool bPersist)
|
|
|
{
|
|
|
sp_env_t *env = sp_get_env();
|