Ver código fonte

Z991239-5719 #comment 添加写入适配器版本号的接口

80374374 11 meses atrás
pai
commit
7e9a30f92b

+ 8 - 1
Framework/Common/SpBase.h

@@ -374,6 +374,7 @@ public:
 
 struct CInstallInfo
 {
+	CInstallInfo() :PreviousInstallVersion(), InstallVersion(), tmSwithOverDate(), InstallPack(true), InstallState(Install_Active){}
 	CVersion PreviousInstallVersion;
 	CVersion InstallVersion;
 	CSmallDateTime tmSwithOverDate;
@@ -1034,7 +1035,7 @@ struct IEntityFunction
 	*/
 	virtual ErrorCodeEnum GetRunningVersion(CSimpleString& ver) = 0;
 
-	/*Get current Dep version*/
+	/*Get current Dep version from txt directly*/
 	virtual ErrorCodeEnum GetRunningDepVersion(CSimpleString& ver) = 0;
 
 	virtual ErrorCodeEnum GetVTMErrMsg(DWORD dwUserCode, CSimpleStringA& strDescription, CSimpleStringA& strVTMCode) = 0;
@@ -1146,6 +1147,12 @@ struct IEntityFunctionPrivilege
 	virtual ErrorCodeEnum TryUpdateVTMERRMSG() = 0;
 	virtual ErrorCodeEnum GetVTMErrMsgArr(CAutoArray<CSimpleStringA>& strErrorCodeArr,
 		CAutoArray<CSimpleStringA>& strDescriptionArr, CAutoArray<CSimpleStringA>& strRemarkArr) = 0;
+
+	/*
+	* strVersion, the text to be written to depver.txt, which just like: 1.2.3.4
+	bRefresh, true: update the GetPath('Dep') synchronously	
+	*/
+	virtual ErrorCodeEnum RewriteDepVersion(const CSimpleStringA& strVersion, bool bRefresh) = 0;
 };
 
 /**

+ 1 - 0
Framework/Common/def.h

@@ -30,6 +30,7 @@
 #define SHELL_CMD_INFO_START_UPLOAD_LOG		11
 #define SHELL_CMD_INFO_STOP_UPLOAD_LOG		12
 #define SHELL_CMD_INFO_UPDATE_TOKEN			13
+#define SHELL_CMD_INFO_REFRESH_ENV			14
 
 #define ENTITY_CMD_REQ_QUERY_ENTITY_SESSIONS    100
 

+ 6 - 1
Framework/spbase/SpEntity.cpp

@@ -1257,7 +1257,6 @@ ErrorCodeEnum SpEntity::GetSystemStaticInfo(CSystemStaticInfo &Info)
 	int i;
 	sp_cfg_version_info_t *version_info;
 
-	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);
@@ -1294,6 +1293,9 @@ ErrorCodeEnum SpEntity::GetSystemStaticInfo(CSystemStaticInfo &Info)
 		Info.InstallPack = CSimpleStringA(version_info->install_pack);
 		Info.InstallState = (InstallStateEnum)version_info->install_state;
 	}
+	if (dir->dep_ver_path == NULL) {
+		sp_dir_refresh_dep_path(env->dir);
+	}
 	if (dir->dep_ver_path != NULL) {
 		Info.CurrDepVersion = CSimpleStringA(strrchr(dir->dep_ver_path, SPLIT_SLASH) + 1);
 	}
@@ -1373,6 +1375,9 @@ ErrorCodeEnum SpEntity::GetPath(const char *pszKey,CSimpleStringA &strPath)
 	} else if (_stricmp(pszKey, "Slv") == 0) {
 		strPath = CSimpleStringA(env->dir->slv_path);
 	}
+	else if (_stricmp(pszKey, "DepBase") == 0) {
+		strPath = CSimpleStringA(env->dir->dep_base_path);
+	}
 	else if (_stricmp(pszKey, "DepBak") == 0) {
 		strPath = CSimpleStringA(env->dir->dep_path);
 	}

+ 45 - 25
Framework/spbase/SpEntityPrivilege.cpp

@@ -329,30 +329,6 @@ ErrorCodeEnum SpEntityPrivilege::Reboot(RebootTriggerEnum eTriggerReason,RebootW
 	return Error;
 }
 
-bool SpEntityPrivilege::WriteInstallLog(const char *pszPackName, const char *pszLogText)
-{
-	auto env = sp_get_env();
-
-	// 创建安装包日志文件
-	CSimpleStringA strInstallLogDir = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "InstallLog", env->dir->root_runinfo_path);
-	if (!ExistsDirA(strInstallLogDir))
-		CreateDirA(strInstallLogDir, TRUE);
-
-	// 写安装包日志
-	CSimpleStringA strInstallLog = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s.log", (const char*)strInstallLogDir, pszPackName);
-	FILE *pInstallLog = fopen(strInstallLog, "a+");
-	if (pInstallLog == NULL)
-	{
-		LogError(Severity_Low, Error_Unexpect, 0,  CSimpleStringA::Format("open install log file [%s] to write fail", pszPackName));
-		return false;
-	}
-	
-	fprintf_s(pInstallLog, "[%s] %s\r\n",  (const char*)CSmallDateTime::GetNow().ToTimeString(), pszLogText);
-	fflush(pInstallLog);
-	fclose(pInstallLog);
-	return true;
-}
-
 bool SpEntityPrivilege::RecursiveCopyDir(const char *pszSourceDir, const char *pszDestDir, CSimpleStringA& strErrInfo)
 {
 	array_header_t *arr;
@@ -428,7 +404,7 @@ bool SpEntityPrivilege::RecursiveCopyDir(const char *pszSourceDir, const char *p
 	return true;
 }
 
-ErrorCodeEnum SpEntityPrivilege::UpdateActiveTxt(const char* strActiveFilePath, const char* toWriteVersionStr, bool toCheck)
+ErrorCodeEnum SpEntityPrivilege::UpdateVerTxt(const char* strActiveFilePath, const char* toWriteVersionStr, bool toCheck)
 {
 	HANDLE hFile = ::CreateFileA(strActiveFilePath, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
 	BOOL bSetSucc = FALSE;
@@ -999,6 +975,50 @@ ErrorCodeEnum SpEntityPrivilege::GetVTMErrMsgArr(CAutoArray<CSimpleStringA>& str
 }
 
 
+ErrorCodeEnum SpEntityPrivilege::RewriteDepVersion(const CSimpleStringA& strVersion, bool bRefresh)
+{
+	ErrorCodeEnum rc(Error_Succeed);
+	auto dir = sp_get_env()->dir;
+	auto cfg = sp_get_env()->cfg;
+	
+	if (dir == NULL)
+		return Error_Null;
+
+	if (strVersion.IsNullOrEmpty())
+		return Error_Param;
+
+	CSimpleStringA strOldVer(true);
+	rc = GetRunningDepVersion(strOldVer);
+	if (rc == Error_Succeed && !strOldVer.IsNullOrEmpty() && strOldVer.Compare(strVersion) == 0) {
+		return Error_AlreadyExist;
+	}
+
+	char path[MAX_PATH] = {'\0'};
+	rc = (ErrorCodeEnum)sp_dir_get_path(dir, SP_DIR_DEPVER_TXT, NULL, path, MAX_PATH);
+	if (rc != 0) {
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get dep ver txt failed!");
+		return rc;
+	}
+	else {
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("path:%s", path);
+	}
+
+	rc = UpdateVerTxt(path, strVersion, true);
+	if (rc == Error_Succeed && bRefresh) {
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to refresh...");
+		rc = (ErrorCodeEnum)sp_dir_refresh_dep_path(dir);
+		if (rc == Error_Succeed) {
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to send fresh post");
+			iobuffer_t* pkt = iobuffer_create(-1, -1);
+			rc = PostInfoShell(SHELL_CMD_INFO_REFRESH_ENV, &pkt);
+			if (pkt)
+				iobuffer_dec_ref(pkt);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("send fresh post return %s", SpStrError(rc));
+		}
+	}
+	return rc;
+}
+
 ErrorCodeEnum SpEntityPrivilege::TryUpdateToken(CSimpleString& oldToken, CSimpleString& newToken)
 {
 	char t_oldToken[MAX_PATH] = "", t_newToken[MAX_PATH] = "";

+ 5 - 4
Framework/spbase/SpEntityPrivilege.h

@@ -69,11 +69,14 @@ public:
 	virtual ErrorCodeEnum TryUpdateVTMERRMSG();
 	virtual ErrorCodeEnum GetVTMErrMsgArr(CAutoArray<CSimpleStringA>& strErrorCodeArr,
 		CAutoArray<CSimpleStringA>& strDescriptionArr, CAutoArray<CSimpleStringA> &strRemarkArr);
-		
+	
+	virtual ErrorCodeEnum RewriteDepVersion(const CSimpleStringA& strVersion, bool bRefresh);
+
 	// debug
 	virtual ErrorCodeEnum SetSysDebugLevel(const char *pszEntityName,DebugLevelEnum eDebugLevel,bool bPersist=false);
 
 	virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState);
+
 private:
 
 	void on_entity_create(int entity_id, int trigger_entity_id);
@@ -94,13 +97,11 @@ private:
 
 	bool IsFileMatch(const char *pszFilter, const char *pszFileName);
 	CSimpleStringA GetFileDirectory(const char *pszFullPath);
-	bool WriteInstallLog(const char *pszPackName, const char *pLogText);
-
 	bool IsWow64Process();
 	bool GetSysUpgradeResult(const char *pszResultLog, ErrorCodeEnum &eErrorCode, CSimpleStringA &strErrMsg);
 	bool RecursiveCopyDir(const char* pszSourceDir, const char* pszDestDir, CSimpleStringA& strErrInfo);
 
-	ErrorCodeEnum UpdateActiveTxt(const char* strActiveFilePath, const char* toWriteVersionStr, bool toCheck = false);
+	ErrorCodeEnum UpdateVerTxt(const char* strActiveFilePath, const char* toWriteVersionStr, bool toCheck = false);
 
 
 protected:

+ 20 - 14
Framework/spbase/sp_cfg.cpp

@@ -584,21 +584,27 @@ SPBASE_API int sp_cfg_getVer(char *ver)
 
 SPBASE_API int sp_cfg_getDepVer(char* ver)
 {
-	static CSimpleStringA s_terminalVer;
-	if (s_terminalVer.GetLength() == 0)//only init s_terminalVer one time
-	{
-		CSimpleStringA strActiveFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR ADAPTER_VERSION_FILE_NAME, sp_get_env()->dir->dep_base_path);
-		char version[SP_MAX_VER_LEN];
-		int result;
-		if ((result = sp_dir_inner_get_content(strActiveFile, version)) == 0) {
-			s_terminalVer = version;
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read dep version text, version[%s]", s_terminalVer.GetData());
-		}
-		else {
-			return result;
-		}
+	auto cfg = sp_get_env()->cfg;
+	auto dir = sp_get_env()->dir;
+	int rc = Error_Succeed;
+	if (cfg == NULL || dir == NULL || cfg->shell_ini == NULL || cfg->root_ini == NULL)
+		return Error_Null;
+
+	char path[MAX_PATH] = "";
+	rc = sp_dir_get_path(dir, SP_DIR_DEPVER_TXT, NULL, path, MAX_PATH);
+	if (rc != 0) {
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get depver.txt path failed!");
+		return rc;
 	}
-	sprintf_s(ver, SP_MAX_VER_LEN, "%s", s_terminalVer.GetData());
+	char version[SP_MAX_VER_LEN];
+	int result;
+	if ((result = sp_dir_inner_get_content(path, version)) == 0) {
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read dep version text, version[%s]", version);
+	}
+	else {
+		return result;
+	}
+	sprintf_s(ver, SP_MAX_VER_LEN, "%s", version);
 	return Error_Succeed;
 }
 

+ 14 - 2
Framework/spbase/sp_dir.c

@@ -75,8 +75,8 @@ int sp_dir_create(sp_dir_t **p_dir)
 	}
 	memset(tmp, 0, sizeof(tmp));
 	sprintf(tmp, "%s" SPLIT_SLASH_STR ADAPTER_VERSION_FILE_NAME, dir->dep_base_path);
+
 	memset(ver, 0, sizeof(ver));
-	
 	if (sp_dir_inner_get_content(tmp, ver) == 0) {
 		dir->dep_ver_path = shm_strdup_printf("%s" SPLIT_SLASH_STR "%s", dir->dep_base_path, ver);
 	}
@@ -165,10 +165,12 @@ static int __dir_get_path(char *base_dir, int flag, const char *cat_name, char *
 	else if (flag == SP_DIR_ENV_INI) {
 		needed += strlen("env.ini") + 10;
 	}
+	else if (flag == SP_DIR_DEPVER_TXT) {
+		needed += 12;
+	}
 	else {
 		rc = Error_Param;
 	}
-
 	if (buf) {
 		if (len && len < needed)
 			return Error_TooSmallBuffer;
@@ -249,6 +251,13 @@ static int __dir_get_path(char *base_dir, int flag, const char *cat_name, char *
         strcpy(buf, base_dir);
 		strcat(buf, SPLIT_SLASH_STR  "CenterSetting.ini");
 	}
+	else if (flag == SP_DIR_DEPVER_TXT) {
+		strcpy(buf, base_dir);
+		strcat(buf, SPLIT_SLASH_STR  ADAPTER_VERSION_FILE_NAME);
+	}
+	else {
+		rc = (int)Error_Param;
+	}
 	return rc;
 }
 
@@ -291,6 +300,9 @@ int sp_dir_get_path_new(sp_dir_t* dir, int flag, const char *cat_name, char *buf
 	case SP_DIR_ENTITY_DBG_LOG:
 		base_path = dir->dbg_path;
 		break;
+	case SP_DIR_DEPVER_TXT:
+		base_path = dir->dep_base_path;
+		break;
 	default:
 		return Error_Param;
 	}

+ 1 - 0
Framework/spbase/sp_dir.h

@@ -52,6 +52,7 @@ void sp_dir_destroy(sp_dir_t*);
 #define SP_DIR_ENTITY_DBG_LOG             12
 #define SP_DIR_RUNINFO_GLOBAL_INI    	13
 #define SP_DIR_ENV_INI					14
+#define SP_DIR_DEPVER_TXT				15
 
 SPBASE_API int sp_dir_get_path_new(sp_dir_t*, int flag, const char* cat_name, char* buf, int len, int mode);
 int sp_dir_get_path_version(sp_dir_t*, int major, int minor, int revision, int build, int flag, const char *mod_name, char *buf, int len, int mode);

+ 1 - 0
Framework/spbase/sp_env.c

@@ -57,6 +57,7 @@ void set_ld_library_path(sp_env_t* env)
 		strcpy(sub_dep_value, env->dir->dep_ver_path);
 		strcat(sub_dep_value, SPLIT_SLASH_STR);
 		strcat(sub_dep_value, manu);
+		toolkit_setenv("RVC_MANUFACTURER_NAME", manu);
 	}
 
 	result = toolkit_getenv(name, ld_value, &size);

+ 1 - 1
Framework/spshell/app.cpp

@@ -100,7 +100,7 @@ static void on_info(sp_rpc_server_t *server, int epid, int svc_id, int call_type
 		HANDLE_INFO(SHELL_CMD_INFO_TERMINALSTAGE_CHANGE, on_terminal_stage_change)
 		HANDLE_INFO(SHELL_CMD_INFO_START_UPLOAD_LOG, on_start_upload_log)
 		HANDLE_INFO(SHELL_CMD_INFO_UPDATE_TOKEN, on_start_update_token)
-		
+		HANDLE_INFO(SHELL_CMD_INFO_REFRESH_ENV, on_fresh_env)
 	END_INFO_MAP()
 }
 

+ 45 - 1
Framework/spshell/svc.cpp

@@ -24,6 +24,7 @@
 
 #include <winpr/library.h>
 #include <winpr/sysinfo.h>
+#include <winpr/environment.h>
 #include <iniutil.h>
 
 static void shutdown_app(void* arg)
@@ -593,9 +594,52 @@ void on_start_update_token(sp_rpc_server_t* server, int epid, int svc_id, int ca
 
 	toolkit_free(channelId);
 	toolkit_free(token);
-
 }
 
+void on_fresh_env(sp_rpc_server_t* server, int epid, int svc_id, int call_type, iobuffer_t** info_pkt)
+{
+	LOG_FUNCTION();
+	sp_env_t* env = sp_get_env();
+	char path[2049];
+	size_t size;
+#if defined(_MSC_VER)
+	const char* name = "PATH";
+#else
+	const char* name = "LD_LIBRARY_PATH";
+#endif //_MSC_VER
+	memset(path, '\0', sizeof(path));
+	size = 2048;
+	toolkit_getenv(name, path, &size);
+	CAutoArray<CSimpleStringA> values = CSimpleStringA(path).Split(ENV_SEP_CHAR);
+	CSimpleStringA strNewPath(true);
+	CSimpleStringA strPrefix(env->dir->dep_base_path);
+	for (int i = 0; i < values.GetCount(); ++i) {
+		if (!values[i].IsStartWith(strPrefix)) {
+			if (!strNewPath.IsNullOrEmpty()) strNewPath += ENV_SEP_STR;
+			strNewPath += values[i];
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("toadd:%s", values[i].GetData());
+		}
+	}
+	if (env->dir->dep_ver_path != NULL) {
+		if (!strNewPath.IsNullOrEmpty()) strNewPath += ENV_SEP_STR;
+		strNewPath += env->dir->dep_ver_path;
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("toadd1:%s", env->dir->dep_ver_path);
+	}
+	char vendorName[128];
+	size = 127;
+	memset(vendorName, '\0', sizeof(vendorName));
+	toolkit_getenv("RVC_MANUFACTURER_NAME", vendorName, &size);
+	if (strlen(vendorName) > 0) {
+		CSimpleStringA strSubDep(env->dir->dep_ver_path);
+		strSubDep += SPLIT_SLASH_STR;
+		strSubDep += vendorName;
+		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("toadd1:%s", strSubDep.GetData());
+		if (!strNewPath.IsNullOrEmpty()) strNewPath += ENV_SEP_STR;
+		strNewPath += strSubDep;
+	}
+	toolkit_setenv(name, strNewPath.GetData());
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("renew env:%s", strNewPath.GetData());
+}
 
 typedef struct
 {

+ 1 - 1
Framework/spshell/svc.h

@@ -71,7 +71,7 @@ void on_output_console_off(sp_rpc_server_t *server, int epid, int svc_id, int ca
 void on_terminal_stage_change(sp_rpc_server_t * server, int epid, int svc_id, int call_type, iobuffer_t * *info_pkt);
 void on_start_upload_log(sp_rpc_server_t * server, int epid, int svc_id, int call_type, iobuffer_t **info_pkt);
 void on_start_update_token(sp_rpc_server_t * server, int epid, int svc_id, int call_type, iobuffer_t * *info_pkt);
-
+void on_fresh_env(sp_rpc_server_t * server, int epid, int svc_id, int call_type, iobuffer_t * *info_pkt);
 
 //
 // req handlers