Przeglądaj źródła

Z991239-5719 #comment 环境变量兼容

80374374 11 miesięcy temu
rodzic
commit
98f1e3bac7

+ 0 - 13
Framework/spbase/SpBase.cpp

@@ -506,19 +506,6 @@ static HMODULE LoadModuleLibrary(sp_mod_t *mod)
 	return LoadLibraryA(tmp);
 }
 
-/*It seems never been used anywhere.*/
-SPBASE_API HINSTANCE SpLoadLibrary(const char *file)
-{
-	sp_env_t *env = sp_get_env();
-	if (env) {
-		char tmp[MAX_PATH];
-		sprintf(tmp, "%s" SPLIT_SLASH_STR "%s", env->dir->dep_path, file);
-		return LoadLibraryA(tmp);
-	} else {
-		return NULL;
-	}
-}
-
 /*only sphost would invoke it.*/
 extern "C" SPBASE_API int __stdcall SpExit(const char* mod_name)
 {

+ 16 - 35
Framework/spbase/SpEntity.cpp

@@ -1354,33 +1354,6 @@ bool SpEntity::IsPackInstalled(const char *pPackName)
 	return false;
 }
 
-///*TODO(80374374@3/9/2023):  */
-const char *SpEntity::GetCenterSettingNameBySite()
-{
-#if defined(_MSC_VER)
-	return  "CenterSetting.ini";
-#else
-	CSystemStaticInfo info;
-	GetSystemStaticInfo(info);
-
-	if (info.strSite.IsNullOrEmpty()) {
-		return  "CenterSetting.ini";
-	}
-
-	if ((stricmp(info.strSite, "CMB.LIB") == 0)
-		|| (stricmp(info.strSite, "CMB.SSB") == 0)) {
-		return  "CenterSetting.LAN.ini";
-	} else if ((stricmp(info.strSite, "CMB.LSS") == 0)
-		|| (stricmp(info.strSite, "CMB.FLB") == 0)
-		|| (stricmp(info.strSite, "CMB.OSB") == 0)
-		|| (stricmp(info.strSite, "CMB.SMM") == 0)) {
-		return   "CenterSetting.DMZ.ini";
-	} else {
-		return  "CenterSetting.DMZ.ini";
-	}
-#endif //_MSC_VER
-}
-
 ErrorCodeEnum SpEntity::GetPath(const char *pszKey,CSimpleStringA &strPath)
 {
 	sp_env_t *env = sp_get_env();
@@ -1423,19 +1396,27 @@ ErrorCodeEnum SpEntity::GetPath(const char *pszKey,CSimpleStringA &strPath)
 		strPath = CSimpleStringA(env->cfg->root_ini->ref_uploadphoto_path);
 	} else if (_stricmp(pszKey, "UploadVideo") == 0) {
 		strPath = CSimpleStringA(env->cfg->root_ini->ref_uploadvideo_path);
-
-
-
 	} else if (_stricmp(pszKey, "Dbg") == 0) {
 		strPath = CSimpleStringA(env->dir->dbg_path);
 	} else if (_stricmp(pszKey, "Slv") == 0) {
 		strPath = CSimpleStringA(env->dir->slv_path);
-	} else if (_stricmp(pszKey, "Dep") == 0) {
+	}
+	else if (_stricmp(pszKey, "DepBak") == 0) {
 		strPath = CSimpleStringA(env->dir->dep_path);
-	} else if (_stricmp(pszKey, "Ad0") == 0) {
+	}
+	else if (_stricmp(pszKey, "Dep") == 0) {
+		if (env->dir->dep_ver_path == NULL) {
+			sp_dir_refresh_dep_path(env->dir);
+		}
+		if (env->dir->dep_ver_path == NULL) {
+			Error = Error_NotInit;
+		}
+		else {
+			strPath = CSimpleStringA(env->dir->dep_ver_path);
+		}
+	}
+	else if (_stricmp(pszKey, "Ad0") == 0) {
 		strPath = CSimpleStringA(env->dir->ad0_path);
-	//} else if (_stricmp(pszKey, "CenterSetting") == 0) {
-	//	strPath = CSimpleStringA(env->cfg->root_ini->ref_centersetting_path);
 	} else if (_stricmp(pszKey, "Dmp") == 0 || _stricmp(pszKey, "Dump") == 0) {
 		strPath = CSimpleStringA(env->dir->dmp_path);
 	} else if (_stricmp(pszKey, "RunInfo") == 0){
@@ -1450,7 +1431,7 @@ ErrorCodeEnum SpEntity::GetPath(const char *pszKey,CSimpleStringA &strPath)
 		// return centersetting name by current site
 		strPath = CSimpleStringA(env->dir->cfg_path);
 		strPath += SPLIT_SLASH_STR;
-		strPath += GetCenterSettingNameBySite();
+		strPath += "CenterSetting.ini";
 	} else if (_stricmp(pszKey, "rvc") == 0) {
 		strPath = CSimpleStringA(env->dir->rvc_path);
 	} else {

+ 0 - 1
Framework/spbase/SpEntity.h

@@ -162,7 +162,6 @@ protected:
 	ErrorCodeEnum AskShell(int call_type, iobuffer_t **req_pkt, iobuffer_t **ans_pkt);
 	ErrorCodeEnum PostInfoShell(int call_type, iobuffer_t **info_pkt);
 	ErrorCodeEnum AskEntityByRPC(const char* pszEntityName, int call_type, iobuffer_t **req_pkt, iobuffer_t **ans_pkt);
-	const char *GetCenterSettingNameBySite();
 	void SetEntityLastError(ErrorCodeEnum systemCode, DWORD dwUserCode, const char* lpcszMessage);
 
 private:

+ 1 - 1
Framework/spbase/SpEntityPrivilege.cpp

@@ -465,7 +465,7 @@ ErrorCodeEnum SpEntityPrivilege::UpdateActiveTxt(const char* strActiveFilePath,
 			{
 				if (WriteFile(hFile, toWriteVersionStr, strlen(toWriteVersionStr), &dwWrittenLen, NULL))
 				{
-					LOG_TRACE("rewrite active.txt success, strPrevVersion[%s]", toWriteVersionStr);
+					LOG_TRACE("rewrite active.txt success, version[%s]", toWriteVersionStr);
 				}
 				else
 				{

+ 1 - 0
Framework/spbase/sp_bcm.c

@@ -421,6 +421,7 @@ int sp_bcm_deamon_refresh(sp_bcm_daemon_t* daemon)
 
 	daemon_unlock(daemon);
 	*/
+	return 0;
 }
 
 int sp_bcm_daemon_create(sp_svc_t *svc, sp_bcm_daemon_t **p_daemon)

+ 29 - 107
Framework/spbase/sp_cfg.cpp

@@ -562,30 +562,41 @@ bool update_rootCfg(sp_cfg_root_ini_t* root, std::map <std::string, std::map<std
 	return true;
 }
 
-int sp_cfg_getVer(char *ver)
+SPBASE_API int sp_cfg_getVer(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 "active.txt", sp_get_env()->dir->root_ver_path);
-		std::ifstream iFile(strActiveFile.GetData());
-		if (!iFile.is_open()) {
-			LogError(Severity_Low, Error_Unexpect, 0, "open active.txt fail");
-			return Error_Unexpect;
+		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 active.txt, version[%s]", s_terminalVer.GetData());
 		}
+		else {
+			return result;
+		}
+	}
+	sprintf_s(ver, SP_MAX_VER_LEN, "%s", s_terminalVer.GetData());
+	return Error_Succeed;
+}
 
-		std::ostringstream buffer;
-		buffer << iFile.rdbuf();
-		std::string myString = buffer.str();
-		// 去除空格
-		myString.erase(std::remove(myString.begin(), myString.end(), ' '), myString.end());
-		// 去除换行符
-		myString.erase(std::remove(myString.begin(), myString.end(), '\r'), myString.end());
-		myString.erase(std::remove(myString.begin(), myString.end(), '\n'), myString.end());
-
-		s_terminalVer = myString.c_str();
-
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read active.txt, version[%s]", s_terminalVer.GetData());
+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;
+		}
 	}
 	sprintf_s(ver, SP_MAX_VER_LEN, "%s", s_terminalVer.GetData());
 	return Error_Succeed;
@@ -1892,60 +1903,6 @@ static inline int shell_ini__load_software_version(sp_cfg_shell_ini_t* shell, co
 	return rc;
 }
 
-static int sp_cfg_get_vertify_sign(sp_dir_t* dir, sp_cfg_root_ini_t* root)
-{
-	CSimpleStringA strCenterSettingFullPath;
-	strCenterSettingFullPath = dir->cfg_path;
-
-	strCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.ini";
-	CSimpleStringA oldCenterSettingFullPath = dir->cfg_path;
-
-	if (root->site == NULL || strlen(root->site) == 0) {
-		oldCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.ini";
-	} else if ((stricmp(root->site, "CMB.LIB") == 0)	// 行内大堂
-		|| (stricmp(root->site, "CMB.SSB") == 0))// 自助网点
-	{
-		oldCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.LAN.ini";
-	} else if ((stricmp(root->site, "CMB.LSS") == 0)	// 生活销售机
-		|| (stricmp(root->site, "CMB.FLB") == 0)		// 离行机器
-		|| (stricmp(root->site, "CMB.OSB") == 0)		// 外拓PAD
-		|| (stricmp(root->site, "CMB.SMM") == 0))		// 商户终端
-	{
-		oldCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.DMZ.ini";
-	} else {
-		oldCenterSettingFullPath += SPLIT_SLASH_STR "CenterSetting.DMZ.ini";
-	}
-
-
-	///*TODO(80374374@3/14/2023): 该操作目前仅在Win端支持,UOS还未做改造 */
-#if defined(_MSC_VER)
-	if (!ExistsFileA(strCenterSettingFullPath.GetData()) && ExistsFileA(oldCenterSettingFullPath.GetData())) {
-		//拷贝已经存在的centersetting去替换centersetting.ini
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__).setVtmCode(DWORD2Hex(ERR_SPSHELL_COPY_CEN))("since %s not exist, copy %s to replace it, result:%s",
-			strCenterSettingFullPath.GetData(), oldCenterSettingFullPath.GetData(),
-			CopyFileA(oldCenterSettingFullPath.GetData(), strCenterSettingFullPath.GetData(), TRUE) ? "success" : "failed");
-}
-#else
-	strCenterSettingFullPath = oldCenterSettingFullPath;
-#endif //_MSC_VER
-
-	//add (const char*) for fixing string print bug. Gifur
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("centersettings full path=%s!", (const char*)strCenterSettingFullPath);
-
-	//add by zl 20170717,从集中配置读取代码签名开关[VerifyCodeSign]
-	const int nVerifyCodeSign = inifile_read_int(strCenterSettingFullPath, "SpBase", "VerifyCodeSign", 0);
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get VerifyCodeSign=%d from [%s] ini", nVerifyCodeSign, strCenterSettingFullPath.GetData());
-	return nVerifyCodeSign > 0 ? 1 : 0;
-}
-#ifdef _WIN32
-CSimpleStringA getDefaultCenterSettingPath(sp_dir_t* dir)
-{
-	CSimpleStringA strCenterSettingFullPath;
-	strCenterSettingFullPath = dir->cfg_path;
-	strCenterSettingFullPath += "\\CenterSetting.ini";
-	return strCenterSettingFullPath;
-}
-#endif //_WIN32
 void init_shellVer(sp_dir_t* dir, CVersionInfo &shellVerInfo)
 {
 #ifdef _WIN32
@@ -2551,36 +2508,6 @@ static int generate_install_ini(sp_dir_t *dir)
 	return 0;
 }
 
-#ifdef _WIN32
-void copyOldCenterSetting(sp_dir_t* dir, sp_cfg_root_ini_t* root)
-{
-	CSimpleStringA strCenterSettingFullPath = getDefaultCenterSettingPath(dir);
-	CSimpleStringA oldCenterSettingFullPath = dir->cfg_path;
-
-
-	if ((stricmp(root->site, "CMB.LIB") == 0)	// 行内大堂
-		|| (stricmp(root->site, "CMB.SSB") == 0))// 自助网点
-		oldCenterSettingFullPath += "\\CenterSetting.LAN.ini";
-	else if ((stricmp(root->site, "CMB.LSS") == 0)	// 生活销售机
-		|| (stricmp(root->site, "CMB.FLB") == 0)		// 离行机器
-		|| (stricmp(root->site, "CMB.OSB") == 0)		// 外拓PAD
-		|| (stricmp(root->site, "CMB.SMM") == 0))		// 商户终端
-		oldCenterSettingFullPath += "\\CenterSetting.DMZ.ini";
-	else
-		oldCenterSettingFullPath += "\\CenterSetting.DMZ.ini";
-
-	if (!fileExist(strCenterSettingFullPath.GetData()) && fileExist(oldCenterSettingFullPath.GetData()))
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__).setVtmCode(DWORD2Hex(ERR_SPSHELL_COPY_CEN))("since %s not exist, copy %s to replace it, result:%s",
-			strCenterSettingFullPath.GetData(), oldCenterSettingFullPath.GetData(),
-			CopyFileA(oldCenterSettingFullPath.GetData(), strCenterSettingFullPath.GetData(), TRUE) ? "success" : "failed");//拷贝已经存在的centersetting去替换centersetting.ini
-
-
-	//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("strCenterSettingFullPath=%s!", strCenterSettingFullPath);
-}
-#endif
-
-
-
 int sp_cfg_create(sp_dir_t* dir, const sp_cfg_start_args_t* args, sp_cfg_t** p_cfg)
 {
 	sp_cfg_t *cfg;
@@ -2656,15 +2583,10 @@ int sp_cfg_create(sp_dir_t* dir, const sp_cfg_start_args_t* args, sp_cfg_t** p_c
 	shellvarPath = shell_var_path;
 
 	/*override*/
-	cfg->args->sign_verifity = sp_cfg_get_vertify_sign(dir, cfg->root_ini);
+	cfg->args->sign_verifity = 0;
 	if (cfg->args->sign_verifity) {
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("verify code sign required.");
 	}
-	/*
-#if defined(_MSC_VER)
-	copyOldCenterSetting(dir, cfg->root_ini);//解决集中配置存在旧配置问题
-#endif
-*/
 
 	SetTokenCallBack(shell_getHttpToken);
 	SetRestfulTokenCallBack(shell_getHttpToken);

+ 2 - 0
Framework/spbase/sp_cfg.h

@@ -261,7 +261,9 @@ SPBASE_API int sp_tryRefreshLogLevelFromCacheConfig();
 SPBASE_API void sp_cfg_setShellFirstStartTime(LARGE_TIME t_shellFirstStart);
 SPBASE_API void load_specialRunInfoInCentersetting(const char* fileName);
 SPBASE_API LARGE_TIME sp_cfg_getShellFirstStartTime();
+
 SPBASE_API int sp_cfg_getVer(char* ver);
+SPBASE_API int sp_cfg_getDepVer(char* ver);
 
 #define SP_MAX_VER_LEN		128
 #define SPSHELL_NAME		"SpShell"

+ 75 - 7
Framework/spbase/sp_dir.c

@@ -10,22 +10,26 @@ int sp_dir_create(sp_dir_t **p_dir)
 	sp_dir_t *dir;
 	int rc = Error_Unexpect;
 	char tmp[MAX_PATH];
-
+	char ver[SP_MAX_VER_LEN];
 	dir = shm_malloc(sizeof(sp_dir_t));
 	memset(dir, 0, sizeof(sp_dir_t));
 
 	//TODO(Gifur): duplicate path value set, which would makd memory leak
 	GetModuleFileNameA(NULL, tmp, MAX_PATH);
 	*strrchr(tmp, SPLIT_SLASH) = 0;
+	//C:/Run/version/1.2.3.4/bin
 	dir->bin_path = shm_strdup(tmp);
 	*strrchr(tmp, SPLIT_SLASH) = 0;
+	//C:/Run/version/1.2.3.4
 	dir->base_path = shm_strdup(tmp);
 	*strrchr(tmp, SPLIT_SLASH) = 0;
+	//C:/Run/version
 	dir->root_ver_path = shm_strdup(tmp);
 	*strrchr(tmp, SPLIT_SLASH) = 0;
+	//C:/Run
 	dir->root_path = shm_strdup(tmp);
 	*strrchr(tmp, SPLIT_SLASH) = 0;
-
+	//C:
 	dir->rvc_path = shm_strdup_printf("%s" SPLIT_SLASH_STR "rvc", tmp);
 
 	//TODO: duplicate
@@ -65,6 +69,22 @@ int sp_dir_create(sp_dir_t **p_dir)
 	if (!ExistsDirA(tmp))
 		CreateDirRecursiveA(tmp);
 
+	dir->dep_base_path = shm_strdup_printf("%s" SPLIT_SLASH_STR "dep", dir->root_path);
+	if (!ExistsDirA(dir->dep_base_path)) {
+		CreateDirRecursiveA(dir->dep_base_path);
+	}
+	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);
+	}
+	else {
+		//TODO:   [Gifur@20241014]
+		dir->dep_ver_path = NULL;
+	}
+
 	*p_dir = dir;
 	rc = 0;
 
@@ -102,6 +122,10 @@ void sp_dir_destroy(sp_dir_t* dir)
 			shm_free(dir->root_runinfo_path);
 		if (dir->root_ver_path)
 			shm_free(dir->root_ver_path);
+		if (dir->dep_base_path)
+			shm_free(dir->dep_base_path);
+		if (dir->dep_ver_path)
+			shm_free(dir->dep_ver_path);
 		shm_free(dir);
 	}
 }
@@ -223,11 +247,7 @@ static int __dir_get_path(char *base_dir, int flag, const char *cat_name, char *
 	else if (flag == SP_DIR_CENTER_SETTING_INI)
 	{
         strcpy(buf, base_dir);
-#if defined(_MSC_VER)
-        strcat(buf, SPLIT_SLASH_STR  "CenterSetting.ini");
-#else
-        strcat(buf, SPLIT_SLASH_STR  "CenterSetting.LAN.ini");
-#endif //_MSC_VER
+		strcat(buf, SPLIT_SLASH_STR  "CenterSetting.ini");
 	}
 	return rc;
 }
@@ -313,3 +333,51 @@ void sp_dir_get_cur_drive(char* path)
 	memcpy(path, drive, sizeof(drive));
 }
 
+int sp_dir_inner_get_content(const char* file, char* ver)
+{
+	FILE* pFile = NULL;
+	if (!ExistsFileA(file)) {
+		return Error_NotExist;
+	}
+	pFile = fopen(file, "rb+");
+	if (pFile != NULL)
+	{
+		char szTemp[256];
+		int i, n;
+		memset(szTemp, 0, sizeof(szTemp));
+		n = fread(szTemp, 1, 256, pFile);
+		fclose(pFile);
+		memset(ver, 0, SP_MAX_VER_LEN);
+		strncpy_s(ver, SP_MAX_VER_LEN, szTemp, _TRUNCATE);
+		//TODO:   [Gifur@20241014]
+		if (strlen(ver) == 0) {
+			return Error_Null;
+		}
+	}
+	else
+	{
+		return Error_IO;
+	}
+	return 0;
+}
+
+SPBASE_API int sp_dir_refresh_dep_path(sp_dir_t* dir)
+{
+	char tmp[MAX_PATH];
+	char ver[SP_MAX_VER_LEN];
+	int result = 0;
+	if (dir && dir->dep_base_path != NULL && strlen(dir->dep_base_path) > 0) {
+		memset(tmp, 0, sizeof(tmp));
+		sprintf(tmp, "%s" SPLIT_SLASH_STR ADAPTER_VERSION_FILE_NAME, dir->dep_base_path);
+		result = sp_dir_inner_get_content(tmp, ver);
+		if (result == 0) {
+			if (dir->dep_ver_path != NULL) {
+				shm_free(dir->dep_ver_path);
+			}
+			dir->dep_ver_path = shm_strdup_printf("%s" SPLIT_SLASH_STR "%s", dir->dep_base_path, ver);
+		}
+		return result;
+	}
+	return Error_InvalidState;
+}
+

+ 10 - 1
Framework/spbase/sp_dir.h

@@ -6,6 +6,12 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
+
+#define ADAPTER_VERSION_FILE_NAME "depver.txt"
+#ifndef SP_MAX_VER_LEN
+#define SP_MAX_VER_LEN		128
+#endif
+
 /*this path created rely on program executing path*/
 typedef struct sp_dir_t {
 	char *root_path; // c:\run
@@ -23,6 +29,8 @@ typedef struct sp_dir_t {
 	char *slv_path; // $(rvc_path)\slv, for silverlight debug
 	char *dmp_path; // $(rvc_path)\dmp, for dump
 	char *ad0_path; // $(rvc_path)\ad0, for AD screen silverlight
+	char *dep_ver_path; // Run\dep\0.0.0.1
+	char* dep_base_path; // Run\dep
 }sp_dir_t;
 
 /* always return zero.*/
@@ -49,7 +57,8 @@ SPBASE_API int sp_dir_get_path_new(sp_dir_t*, int flag, const char* cat_name, ch
 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);
 SPBASE_API int sp_dir_get_path(sp_dir_t*, int flag, const char* cat_name, char* buf, int len);
 SPBASE_API void sp_dir_get_cur_drive(char* path);
-
+int sp_dir_inner_get_content(const char* file, char* ver); //SP_MAX_VER_LEN
+SPBASE_API int sp_dir_refresh_dep_path(sp_dir_t* dir);
 
 #ifdef __cplusplus
 } // extern "C" {

+ 39 - 65
Framework/spbase/sp_env.c

@@ -18,99 +18,73 @@ void set_ld_library_path(sp_env_t* env)
 #else
     const char* name = "LD_LIBRARY_PATH";
 #endif //_MSC_VER
-	const char* RVC_DEP_PATH = "RVC_VENDOR_HOME";
 
 	int result;
 	char ld_value[1025] = {'\0'};
-	char dep_value[1025] = { '\0' };
+	char sub_dep_value[256] = { '\0' };
+	char dep_value[256] = { '\0' };
 	char new_ld_value[1025] = { '\0' };
 	char manu[16] = { '\0' };
 	char* pos;
 	size_t i = 0;
 	size_t size = 1024;
 
+	if (env->dir->dep_ver_path == NULL) {
+		DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "dep ver path is null, cannot set sub dep directory!");
+		return;
+	}
+	strcpy(dep_value, env->dir->dep_ver_path);
+
 	if (env->cfg->root_ini != NULL && env->cfg->root_ini->manufacturer != NULL)
 	{
 		strcpy(manu, env->cfg->root_ini->manufacturer);
 		if (strlen(manu) == 0) {
 			DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "not any config for manufacturer, cannot set sub dep directory!");
-			return;
 		}
-	}
-	
-	for (i = 0; i < strlen(manu); ++i) {
-		if (!isalpha(manu[i])) {
-			DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "not pure alpha: %s", manu);
-			return;
+		else {
+			for (i = 0; i < strlen(manu); ++i) {
+				if (!isalpha(manu[i])) {
+					DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "not pure alpha: %s", manu);
+					memset(manu, '\0', sizeof(manu));
+					break;
+				}
+				if ('A' <= manu[i] && manu[i] <= 'Z')
+					manu[i] = manu[i] + 32;
+			}
 		}
-        if ('A' <= manu[i] && manu[i] <= 'Z')
-			manu[i] = manu[i] + 32;
 	}
-    strcpy(dep_value, env->dir->dep_path);
-    strcat(dep_value, SPLIT_SLASH_STR);
-    strcat(dep_value, manu);
-
-	result = toolkit_getenv(name, ld_value, &size);
-    if (result != 0) {
-        DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "getenv %s failed: %s", name, toolkit_strerror(result));
-		if (result == TOOLKIT_ENOENT) {
-			strcpy(new_ld_value, env->dir->bin_path);
-			strcat(new_ld_value, ENV_SEP_STR);
-            strcat(new_ld_value, env->dir->dep_path);
-            strcat(new_ld_value, ENV_SEP_STR);
-			strcat(new_ld_value, dep_value);
-			toolkit_setenv(name, new_ld_value);
-		}
-        return;
-    }
-	if (strstr(ld_value, dep_value) != NULL) {
-		DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "has been set vendor, ld path:%s, dep_value:%s, manu:%s",
-			(ld_value == NULL ? "" : ld_value), (dep_value == NULL ? "" : dep_value), manu);
-		return;
+	if (strlen(manu) > 0) {
+		strcpy(sub_dep_value, env->dir->dep_ver_path);
+		strcat(sub_dep_value, SPLIT_SLASH_STR);
+		strcat(sub_dep_value, manu);
 	}
 
-	size = 1024;
-	memset(dep_value, '\0', sizeof(dep_value));
-
-    result = toolkit_getenv(RVC_DEP_PATH, dep_value, &size);
+	result = toolkit_getenv(name, ld_value, &size);
 	if (result != 0 && result != TOOLKIT_ENOENT) {
-		DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "getenv %s failed: %s", RVC_DEP_PATH, toolkit_strerror(result));
+		DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "getenv %s failed: %s", name, toolkit_strerror(result));
 		return;
 	}
-
-	//remove old vendor path
-	if (result == 0 && (pos = strstr(ld_value, dep_value)) != NULL) {
-		if (pos > ld_value && --pos && pos[0] == ENV_SEP_CHAR) {
-			pos[0] = '\0';
-			strcpy(new_ld_value, ld_value);
-			pos[0] = ENV_SEP_CHAR, pos++;
-			strcat(new_ld_value, pos + strlen(dep_value));
-		}
-		else if(pos == ld_value) {
-			strcpy(new_ld_value, pos + strlen(dep_value));
-		}
-
-	} else {
-		strcpy(new_ld_value, ld_value);
-	}
-	
-	strcpy(dep_value, env->dir->dep_path);
-    strcat(dep_value, SPLIT_SLASH_STR);
-    strcat(dep_value, manu);
-
-	if(new_ld_value[strlen(new_ld_value)-1] != ENV_SEP_CHAR)
+	DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "ld value:%s", ld_value);
+	strcpy(new_ld_value, ld_value);
+	pos = strstr(new_ld_value, dep_value);
+	if (pos == NULL || !(strlen(pos) > strlen(dep_value) && pos[strlen(dep_value)] == ENV_SEP_STR || strlen(pos) == strlen(dep_value))) {
 		strcat(new_ld_value, ENV_SEP_STR);
-	strcat(new_ld_value, dep_value);
-
-    result = toolkit_setenv(RVC_DEP_PATH, dep_value);
-	if (result != 0) {
-		DbgWithLinkForC(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM, "setenv failed: %s", toolkit_strerror(result));
+		strcat(new_ld_value, dep_value);
+	}
+	if (strlen(sub_dep_value) > 0) {
+		pos = strstr(new_ld_value, sub_dep_value);
+		if (pos == NULL || !(strlen(pos) > strlen(sub_dep_value) && pos[strlen(sub_dep_value)] == ENV_SEP_STR || strlen(pos) == strlen(sub_dep_value))) {
+			strcat(new_ld_value, ENV_SEP_STR);
+			strcat(new_ld_value, sub_dep_value);
+		}
 	}
-
 	result = toolkit_setenv(name, new_ld_value);
 	if (result != 0) {
 		DbgWithLinkForC(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM, "setenv failed: %s", toolkit_strerror(result));
 	}
+	else {
+		DbgWithLinkForC(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM, "new ld value:%s", new_ld_value);
+	}
 }
 
 void sp_set_env(sp_env_t *env)

+ 30 - 54
Framework/spshell/spshell.cpp

@@ -107,19 +107,18 @@ char* relate_processes_ex[] = { spshell_execute_name, sphost_execute_name, guard
 const int relate_processes_ex_count = 4;
 const int MAX_LEN = 256;
 
+
 //E:\Run\version\3.10.0.1\dep;E:\Run\version\3.10.0.1\bin;E:\Run\version\3.10.0.1\dev;E:\Run\version\3.10.0.1\imdep
-static bool IsSpPathType(const CSimpleStringA& value)
+static bool IsSpPathType(const CSimpleStringA& value, const char* key)
 {
-#if defined(RVC_OS_WIN)
-    const int leastLength = strlen("C:\\version\\1.0.0.0\\");
-#else
-    const int leastLength = strlen("Run/version/1.0.0.0/");
-#endif //RVC_OS_WIN
-
+	const int leastLength = strlen("Run//1.0.0.0/") + strlen(key);
     CSimpleStringA path(value.GetData());
     if (path.IsNullOrEmpty() || path.GetLength() < leastLength) return false;
-    const int sionPos = path.IndexOf("version");
-    const int verPos = sionPos + strlen("version" SPLIT_SLASH_STR);
+	for (int i = 0; i < path.GetLength(); ++i) {
+		if (path[i] >= 'A' && path[i] <= 'Z') path[i] = path[i] + ('a' - 'A');
+	}
+    const int sionPos = path.IndexOf(key);
+    const int verPos = sionPos + strlen(key) + strlen(SPLIT_SLASH_STR);
     if (sionPos < 0) return false;
     int suffixPos = -1, i;
     int dotCnt = 0;
@@ -128,15 +127,9 @@ static bool IsSpPathType(const CSimpleStringA& value)
         lastIsNum = !(path[i] == '.');
         if (!lastIsNum) dotCnt++;
     }
-
     if (i >= path.GetLength() || dotCnt != 3 || !lastIsNum)
         return false;
-
-
-    //if(path[i] == '\\' || path[i] == '//')
-
     return true;
-
 }
 
 static CSimpleStringA CutSpPathFromPathValue(const char* value, const char* prefix)
@@ -148,30 +141,32 @@ static CSimpleStringA CutSpPathFromPathValue(const char* value, const char* pref
         return path;
     }
     for (int i = 0; i < values.GetCount(); ++i) {
-        if (values[i].IsStartWith(prefix) || !IsSpPathType(values[i])) {
+        if (!values[i].IsStartWith(prefix) && !IsSpPathType(values[i], "version") &&! IsSpPathType(values[i], "dep")) {
             if (!result.IsNullOrEmpty()) result += ENV_SEP_STR;
             result += values[i];
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("toadd:%s", values[i].GetData());
         }
     }
-
-    if (!result.IsNullOrEmpty() && path[path.GetLength() - 1] == ENV_SEP_CHAR) {
-        result += ENV_SEP_STR;
-    }
-
+    //if (!result.IsNullOrEmpty() && path[path.GetLength() - 1] == ENV_SEP_CHAR) {
+    //    result += ENV_SEP_STR;
+    //}
     return result;
 }
 
-static void SetEnvPath()
+static void ResetEnvPath()
 {
 	char path[MAX_PATH];
 	char *buf;
 	DWORD size;
-	const char *var = "PATH";
-
+#if defined(_MSC_VER)
+	const char* var = "PATH";
+#else
+	const char* var = "LD_LIBRARY_PATH";
+#endif //_MSC_VER
 	// set current path
 	GetModuleFileNameA(NULL, path, MAX_PATH);
-	*strrchr(path, SPLIT_SLASH) = 0;
-	*strrchr(path, SPLIT_SLASH) = 0;
+	*strrchr(path, SPLIT_SLASH) = 0; //bin
+	*strrchr(path, SPLIT_SLASH) = 0; //1.2.3.4
 	SetCurrentDirectoryA(path);
 
 	size = GetEnvironmentVariableA(var, NULL, 0);
@@ -179,38 +174,17 @@ static void SetEnvPath()
 	size = GetEnvironmentVariableA(var, buf, size);
 
     CSimpleStringA newValue = CutSpPathFromPathValue(buf, path);
-    if (newValue.GetLength() < size) {
-        printf("before: %s,%d\n", buf, size);
-        strcpy(buf, newValue.GetData());
-        memset(buf + newValue.GetLength(), '\0', sizeof(char) * (size + MAX_PATH * 3 - newValue.GetLength()));
-        size = newValue.GetLength();
-        printf("after: %s,%d\n", buf, size);
-    }
+	memset(buf, 0, size + MAX_PATH * 3);
+	strcpy(buf, newValue.GetData());
+	size = newValue.GetLength();
 
-	strcpy(buf+size, ENV_SEP_STR);
-
-    // append dep sub dir to %PATH%
-    strcat(path, SPLIT_SLASH_STR "dep");
-	strcat(buf+size, path);
-
-	*strrchr(path, SPLIT_SLASH) = 0;
+    // append bin sub dir to %PATH%
 	strcat(path, SPLIT_SLASH_STR "bin");
-	strcat(buf+size, ENV_SEP_STR);
-	strcat(buf+size, path);
-	
-	*strrchr(path, SPLIT_SLASH) = 0;
-	strcat(path, SPLIT_SLASH_STR "dev");
-	strcat(buf+size, ENV_SEP_STR);
-	strcat(buf+size, path);
-
-	*strrchr(path, SPLIT_SLASH) = 0;
-	strcat(path, SPLIT_SLASH_STR "imdep");
-	strcat(buf + size, ENV_SEP_STR);
-	strcat(buf + size, path);
+	strcat(buf, ENV_SEP_STR);
+	strcat(buf, path);
 
 	SetEnvironmentVariableA(var, buf);
 	free(buf);
-
 	SetEnvironmentVariableA("ModuleName", "SpShell");
 }
 
@@ -1142,7 +1116,9 @@ int main(int argc, char** argv)
 		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("setlocale failed: %s", strerror(errno));
 	}
 #endif //RVC_OS_WIN
-	SetEnvPath();
+
+	ResetEnvPath();
+
 #ifdef RVC_OS_WIN
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Config working set......");
 	SetWorkingSet();//获取设置内存使用率,4G