浏览代码

Z991239-1017 #comment fea 联调通过大部分功能,解决路径问题

陈良瑜80374463 4 年之前
父节点
当前提交
e84b258d2a

+ 81 - 104
Module/mod_RomoteController/RemoteControllerCnn.cpp

@@ -14,6 +14,7 @@
 #include "base64.h"
 #include "digital_conv.h"
 #include <fstream>
+#include "path.h"
 
 
 
@@ -46,7 +47,7 @@ namespace fs = boost::filesystem;
 #define generateFilesize(fileHandle, filePath)	long long nFileSize = fs::file_size(filePath.GetData())
 #include "zip.h"
 #include <stdlib.h>
-#include "../mod_upload/XZipZilb.h"
+#include "XZipZilb.h"
 #define ZeroMemory(object, size) memset(object, 0, size)
 #define WritePrivateProfileStringA(a, b, c, d) Base_writeIni(std::string(a), std::string(b), std::string(c), std::string(d))
 
@@ -356,7 +357,8 @@ ErrorCodeEnum CRemoteControllerCnn::HandleDelRunInfoLogReq(const CSmartPointer<I
 	CSimpleString runInfoPath;
 	pFunc->GetPath("RunInfo", runInfoPath);
 
-	CSimpleString delFilePaht = runInfoPath + "\\runcfg\\" + strLogName + ".ini";
+	CSimpleString delFilePaht = runInfoPath;
+	delFilePaht.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR).Append(strLogName).Append(".ini");
 	Dbg("curTaskId:%d ,try to delete %s, strLogName = %s", req.TaskID, delFilePaht, strLogName);
 
 
@@ -389,7 +391,8 @@ ErrorCodeEnum CRemoteControllerCnn::HandleTest(const CSmartPointer<IPackage> &pR
 	CSimpleString runInfoPath;
 	pFunc->GetPath("RunInfo", runInfoPath);
 
-	CSimpleString delFilePaht = runInfoPath + "\\runcfg\\" + "MediaController" + ".ini";
+	CSimpleString delFilePaht = runInfoPath;
+	delFilePaht.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR).Append("MediaController").Append(".ini");
 	Dbg("try to delete %s", delFilePaht);
 
 	if (Base_Exist(delFilePaht.GetData()))
@@ -693,14 +696,14 @@ ErrorCodeEnum CRemoteControllerCnn::HandleEditConfigReq(const CSmartPointer<IPac
 			auto rc = pFunc->GetPath("HardwareCfg", strCfgPath);
 			assert(rc == Error_Succeed);
 
-			strCfgPath += "\\Root.ini";
+			strCfgPath.Append(SPLIT_SLASH_STR).Append("Root.ini");
 		}
 		else
 		{
 			auto rc = pFunc->GetPath("Cfg", strCfgPath);
 			assert(rc == Error_Succeed);
 
-			strCfgPath += CSimpleStringA::Format("\\%s.ini", (const char*)strEntityName);
+			strCfgPath.Append(SPLIT_SLASH_STR).Append((const char*)strEntityName).Append(".ini");
 		}
 
 		char cEditType = pReq[i].EditType;
@@ -709,7 +712,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleEditConfigReq(const CSmartPointer<IPac
 		if (cEditType == 'A' || cEditType == 'U')
 			WritePrivateProfileStringA(pReq[i].Section, pReq[i].Key, pReq[i].Value, strCfgPath.GetData());
 		else if (cEditType == 'D')
-			WritePrivateProfileStringA(pReq[i].Section, pReq[i].Key, NULL, strCfgPath.GetData());
+			WritePrivateProfileStringA(pReq[i].Section, pReq[i].Key, "", strCfgPath.GetData());
 	}
 
 	delete[] pBuf;	
@@ -728,7 +731,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewEntityConfigReq(const CSmartPointe
 	int nLen = pRecvPkg->GetStructLen("ViewCfgR");
 	if (nLen <=0)
 	{
-		pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewCfgR] fail");
+		pReplyPkg->SetErrMsg(Error_Param, 0, "get struct [ViewCfgR] fail"); 
 		SendPackage(pReplyPkg);
 		return Error_Param;
 	}
@@ -747,15 +750,13 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewEntityConfigReq(const CSmartPointe
 	{
 		auto rc = pFunc->GetPath("HardwareCfg", strCfgPath);
 		assert(rc == Error_Succeed);
-
-		strCfgPath += "\\Root.ini";
+		strCfgPath.Append(SPLIT_SLASH_STR).Append("Root.ini");
 	}
 	else
 	{
 		auto rc = pFunc->GetPath("Cfg", strCfgPath);
 		assert(rc == Error_Succeed);
-
-		strCfgPath += CSimpleStringA::Format("\\%s.ini", (const char*)strEntityName);
+		strCfgPath.Append(SPLIT_SLASH_STR).Append((const char*)strEntityName).Append(".ini");
 	}
 	
 	if (!Base_Exist(strCfgPath.GetData()))
@@ -828,20 +829,20 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewDebugLogReq(const CSmartPointer<IP
 	{
 		auto rc = pFunc->GetPath("Dbg", strLogPath);
 		assert(rc == Error_Succeed);
-		strLogPath += CSimpleStringA::Format("\\SpShell\\%s.log", (const char*)strViewDate);
+		strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
 	}
 	else if (iequals(strEntityName.GetData(), "Silverlight"))
 	{
 		auto rc = pFunc->GetPath("Slv", strLogPath);
 		assert(rc == Error_Succeed);
-		strLogPath += CSimpleStringA::Format("\\%s.log", (const char*)strViewDate);
+		strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
 	}
 	else if (iequals(strEntityName.GetData(), "DualActive")|| iequals(strEntityName.GetData(), "SpHost")
 		|| iequals(strEntityName.GetData(), "SysInit") || iequals(strEntityName.GetData(), "SpBase") || iequals(strEntityName.GetData(), "guardian"))
 	{
 		auto rc = pFunc->GetPath("Dbg", strLogPath);
 		assert(rc == Error_Succeed);
-		strLogPath += CSimpleStringA::Format("\\%s\\%s.log", (const char*)strEntityName, (const char*)strViewDate);
+		strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strEntityName).Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
 	}
 	else
 	{
@@ -857,7 +858,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewDebugLogReq(const CSmartPointer<IP
 
 		rc = pFunc->GetPath("Dbg", strLogPath);
 		assert(rc == Error_Succeed);
-		strLogPath += CSimpleStringA::Format("\\%s\\%s.log", (const char*)info.strSpFileName, (const char*)strViewDate);
+		strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strViewDate).Append(".log");
 	}
 
 	if (!Base_Exist(strLogPath.GetData()))
@@ -888,9 +889,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewDebugLogReq(const CSmartPointer<IP
 	generateFilesize(file, strLogPath);
 
 	if (nStartPos >0 && nStartPos < nFileSize)
-	{
 		_fseeki64(file, nStartPos, SEEK_SET);
-	}
 	else
 		nStartPos = 0;
 	
@@ -921,11 +920,8 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewDebugLogReq(const CSmartPointer<IP
 	BOOL bRet = TRUE;
 	do
 	{
-		//Dbg("ftell: %d", ftell(file));
 		nReadLen = fread(pLogData+nHasRead, 1, nMaxBytes-nHasRead, file);
 		
-		//Dbg("ftell: %d", ftell(file));
-
 		if (nReadLen >0)
 			nHasRead += nReadLen;
 	}
@@ -1011,15 +1007,11 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadEventLogReq(const CSmartPointer<
 			Dbg("evtName:%d, evtLevel:%d, duration:%d, startTime:%d, endTime:%d, cusEvtFileName:%s,evtSrcEventName:%s, reversed1:%d, reversed2:%s, startPos:%d, MaxRet:%d, UploadFile:%s", 
 				req.evtName, req.evtLevel, req.duration, req.startTime, req.endTime,
 				req.cusEvtFileName, req.evtSrcEventName, req.reversed1, req.reversed2, req.StartPos, req.MaxRetBytes, req.UploadFile);
-// 			Dbg("evtName:%d, evtLevel:%d, duration:%d, startTime:%d, endTime:%d, cusEvtFileName:%s,evtSrcEventName:%s, reversed1:%d, reversed2:%s", 
-// 				rvcReq.evtName, rvcReq.evtLevel, rvcReq.duration, rvcReq.startTime, rvcReq.endTime,
-// 				rvcReq.cusEvtFileName.GetData(), rvcReq.evtSrcEventName.GetData(), rvcReq.reversed1, rvcReq.reversed2.GetData());
 			rc = pClient->ExtractEventLog(rvcReq, rvcAns, 60000 * 5);
 			Dbg("entries:%d, information:%s, evtLogFileName:%s", rvcAns.entries, rvcAns.information.GetData(), rvcAns.evtLogFileName.GetData());
 			pClient->GetFunction()->CloseSession();
 
 		}
-		pClient->SafeDelete();
 
 		if (rc != Error_Succeed)
 		{
@@ -1037,8 +1029,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadEventLogReq(const CSmartPointer<
 			strZipFileName = CSimpleStringA::Format("%s_event_%s_%02X_%02X.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName, rvcAns.entries,
 				req.evtLevel + req.duration + req.startTime + req.endTime);
 			pFunc->GetPath("Temp", strZipPath);
-			strZipPath += "\\";
-			strZipPath += strZipFileName;
+			strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
 
 			strLogPath = rvcAns.evtLogFileName;
 
@@ -1076,8 +1067,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadEventLogReq(const CSmartPointer<
 		strZipFileName = req.UploadFile;
 
 		pFunc->GetPath("Temp", strZipPath);
-		strZipPath += "\\";
-		strZipPath += strZipFileName;
+		strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
 	}
 
 	if (!Base_Exist(strZipPath.GetData()))
@@ -1279,7 +1269,6 @@ ErrorCodeEnum CRemoteControllerCnn::HandleOperateDiskReq(const CSmartPointer<IPa
 		pClient->GetFunction()->CloseSession();
 		
 	}
-	pClient->SafeDelete();
 
 	if (rc != Error_Succeed)
 	{
@@ -1292,10 +1281,8 @@ ErrorCodeEnum CRemoteControllerCnn::HandleOperateDiskReq(const CSmartPointer<IPa
 
 		//添加首层目录信息
 		RvcOperateDiskRet1 ret1(req.TaskID, rvcAns.result, rvcAns.header, rvcAns.attachment1);
-		//pReplyPkg->AddStruct("OprDkA1", false, false, (BYTE*)&ret1, sizeof(RvcOperateDiskRet1));
 		RvcOperateDiskRet2 current(rvcAns.attachment2, rvcAns.fileSize, rvcAns.ftCreate, rvcAns.ftModified,
 			rvcAns.ftAccess, rvcAns.fileAttribute, rvcAns.forbidAttribute, rvcAns.reversed1, rvcAns.reversed2);
-		//Dbg("1:0%d, %d, %s, %d", ret1.TaskID, ret1.result, ret1.header, ret1.attachment1);
 		//添加目录具体文件信息
 		pRet2 = new RvcOperateDiskRet2[rvcAns.count + 1];
 		ZeroMemory(pRet2, sizeof(RvcOperateDiskRet2) * (rvcAns.count + 1));
@@ -1330,18 +1317,16 @@ ErrorCodeEnum CRemoteControllerCnn::HandleOperateDiskReq(const CSmartPointer<IPa
 		ZeroMemory(pBuf, nRetLen);
 		RvcOperateDiskJsonRet *pRet = (RvcOperateDiskJsonRet*)pBuf;
 		pRet->TaskID = req.TaskID;
-// 		pRet->jsonLength = strlen(slimJsonStr);
-// 		memcpy(pRet->jsonData, slimJsonStr, pRet->jsonLength);
 
 		auto pFunc = m_pEntity->GetFunction();
 		CSimpleStringA jsonFileName, tempDir, zipJsonName;
 		pFunc->GetPath("Temp", tempDir);
-		jsonFileName = tempDir + "\\transfer.txt";
-		zipJsonName = tempDir + "\\zipJson.zip";
+		jsonFileName.Append(tempDir).Append(SPLIT_SLASH_STR).Append("transfer.txt");
+		zipJsonName.Append(tempDir).Append(SPLIT_SLASH_STR).Append("zipJson.zip");
 		ofstream jsonFile(jsonFileName.GetData());
 		if (jsonFile.is_open())
 		{
-			Dbg("%d", pRet->jsonLength);
+			Dbg("jsonLength:%d", pRet->jsonLength);
 			jsonFile << slimJsonStr << endl;
 			jsonFile.close();
 		}
@@ -1886,7 +1871,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleGetVersionReq(const CSmartPointer<IPac
 	auto rc = m_pEntity->GetFunction()->GetPath("RootVer", strPath);
 	if (rc == Error_Succeed)
 	{
-		strPath += "\\active.txt";
+		strPath.Append(SPLIT_SLASH_STR).Append("active.txt");
 		FILE *pFile = fopen(strPath, "r");
 		if (pFile != NULL)
 		{
@@ -1939,7 +1924,8 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewRunCfgReq(const CSmartPointer<IPac
 	CSimpleStringA strCfgPath;
 	assert(Error_Succeed == pFunc->GetPath("RunInfo", strCfgPath));
 
-	strCfgPath += CSimpleStringA::Format("\\runcfg\\%s", (const char*)strConfigName);
+
+	strCfgPath.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR).Append(strConfigName);
 
 	if (!Base_Exist(strCfgPath.GetData()))
 	{
@@ -1995,7 +1981,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewInstallLogReq(const CSmartPointer<
 	auto rc = m_pEntity->GetFunction()->GetPath("RunInfo", strLogPath);
 	assert(rc == Error_Succeed);
 
-	strLogPath += CSimpleStringA::Format("\\InstallLog\\%s", (const char*)strLogFile);
+	strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)strLogFile);
 
 	if (!Base_Exist(strLogPath.GetData()))
 	{
@@ -2082,7 +2068,7 @@ ErrorCodeEnum CRemoteControllerCnn::ZipFile(LPCTSTR lpszZipArchive, LPCTSTR lpsz
 	Base_CopyFile(lpszSrcFile, strCopyFile.GetData());
 
 	// use only the file name for zip file entry
-	TCHAR * cp = (TCHAR *)strrchr(lpszSrcFile, '\\');
+	TCHAR * cp = (TCHAR *)strrchr(lpszSrcFile, SPLIT_SLASH);
 	if (cp == NULL)
 		cp = (TCHAR *)lpszSrcFile;
 	else
@@ -2102,7 +2088,7 @@ ErrorCodeEnum CRemoteControllerCnn::ZipFile(LPCTSTR lpszZipArchive, LPCTSTR lpsz
 		CloseZip(hz);
 		if (zr == ZR_OK)
 #else
-		auto zr = AddFileToZip(hz, getPathName(strCopyFile.GetData()).c_str(), strCopyFile.GetData());
+		auto zr = AddFileToZip(hz, cp, strCopyFile.GetData());
 		zipClose(hz, NULL);
 		if (zr)
 #endif
@@ -2176,11 +2162,11 @@ ErrorCodeEnum CRemoteControllerCnn::BatchZipFiles(LPCTSTR lpszZipArchive, const
 
 		// use only the file name for zip file entry
 		CSimpleStringA strTmp = strSrcFile;
-		const TCHAR * cp = strrchr(strTmp, '\\');
+		const TCHAR * cp = strrchr(strTmp, SPLIT_SLASH);
 		if (cp != NULL)
 		{
 			*((char*)cp) = '_';
-			cp = (TCHAR *)strrchr(strTmp, '\\');
+			cp = (TCHAR *)strrchr(strTmp, SPLIT_SLASH);
 		}
 
 		if (cp != NULL)
@@ -2192,8 +2178,7 @@ ErrorCodeEnum CRemoteControllerCnn::BatchZipFiles(LPCTSTR lpszZipArchive, const
 		ZRESULT zr = ZipAdd(hz, cp, (void*)(const char*)strCopyFile, 0, ZIP_FILENAME);
 		CloseZip(hz);
 #else
-		auto zr = AddFileToZip(hz, getPathName(strCopyFile.GetData()).c_str(), strCopyFile.GetData());
-		zipClose(hz, NULL);
+		auto zr = AddFileToZip(hz, cp, strCopyFile.GetData());
 #endif
 
 		// delete .bak file 
@@ -2223,7 +2208,7 @@ ErrorCodeEnum CRemoteControllerCnn::BatchZipFiles(LPCTSTR lpszZipArchive, const
 	{
 		Base_DeleteFile(lpszZipArchive);
 	}
-
+	zipClose(hz, NULL);
 	return bResult ? Error_Succeed : Error_Unexpect;
 }
 
@@ -2269,14 +2254,14 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogByDateReq(const CSmartPointer
 			strZipFileName = CSimpleStringA::Format("%s_slv_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
 		
 			pFunc->GetPath("Slv", strLogPath);
-			strLogPath += CSimpleStringA::Format("\\%s.log", (const char*)strTodayLogName);
+			strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 		}
 		else if (strReqLogName.IsEndWith(".zip", true))	// 安装包日志
 		{
 			strZipFileName = CSimpleStringA::Format("%s_pkg_%s", (const char*)sysInfo.strTerminalID, (const char*)strReqLogName);
 
 			pFunc->GetPath("RunInfo", strLogPath);
-			strLogPath += CSimpleStringA::Format("\\InstallLog\\%s.log", (const char*)strReqLogName);
+			strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)strReqLogName).Append(".log");
 		}
 		else
 		{
@@ -2286,17 +2271,17 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogByDateReq(const CSmartPointer
 
 			pFunc->GetPath("Dbg", strLogPath);
 			if (strReqLogName.Compare("Shell", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SpShell\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("DualActive", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\DualActive\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("guardian", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\guardian\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("SpHost", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SpHost\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("SysInit", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SysInit\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("SpBase", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SpBase\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else
 			{
 				CEntityStaticInfo info = {};
@@ -2309,13 +2294,12 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogByDateReq(const CSmartPointer
 					return Error_NotExist;
 				}
 
-				strLogPath += CSimpleStringA::Format("\\%s\\%s.log", (const char*)info.strSpFileName, (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			}
 		}
 
 		pFunc->GetPath("Temp", strZipPath);
-		strZipPath += "\\";
-		strZipPath += strZipFileName;
+		strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
 		
 		if (!Base_Exist(strLogPath.GetData()))
 		{
@@ -2339,8 +2323,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogByDateReq(const CSmartPointer
 		strZipFileName = req.UploadFile;
 		
 		pFunc->GetPath("Temp", strZipPath);
-		strZipPath += "\\";
-		strZipPath += strZipFileName;
+		strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
 	}
 			
 	if (!Base_Exist(strZipPath.GetData()))
@@ -2483,7 +2466,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 			strZipFileName = CSimpleStringA::Format("%s_slv_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
 		
 			pFunc->GetPath("Slv", strLogPath);
-			strLogPath += CSimpleStringA::Format("\\%s.log", (const char*)strTodayLogName);
+			strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			
 		}
 		else if (strReqLogName.Compare("AllDbg", true) == 0)
@@ -2491,7 +2474,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 			strZipFileName = CSimpleStringA::Format("%s_AllDbg_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
 			pFunc->GetPath("Dbg", strLogPath);
 			pFunc->GetPath("Temp", strZipPath);
-			strZipPath += CSimpleStringA::Format("\\%s", (const char*)strZipFileName);
+			strZipPath.Append(SPLIT_SLASH_STR).Append((const char*)strZipFileName);
 			try
 			{
 				std::pair<bool, std::string> result = MyZip::ZipDir(strZipPath.GetData(), strLogPath.GetData());
@@ -2515,12 +2498,12 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 		{
 			strZipFileName = CSimpleStringA::Format("%s_runInformation_%s.zip", (const char*)sysInfo.strTerminalID, (const char*)strTodayLogName);
 			pFunc->GetPath("Temp", strZipPath);
-			strZipPath += CSimpleStringA::Format("\\%s", (const char*)strZipFileName);
+			strZipPath.Append(SPLIT_SLASH_STR).Append((const char*)strZipFileName);
 			vector<std::string> zipArr;
 			pFunc->GetPath("RunInfo", strLogPath);
 			zipArr.push_back(strLogPath.GetData());
 			pFunc->GetPath("HardwareCfg", strLogPath);
-			strLogPath = strLogPath + "\\root.ini";
+			strLogPath.Append(SPLIT_SLASH_STR).Append("root.ini");
 			zipArr.push_back(strLogPath.GetData());
 			Dbg("%s,%s,%s", zipArr[0].c_str(), zipArr[1].c_str(), strZipPath);
 
@@ -2540,7 +2523,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 			strZipFileName = CSimpleStringA::Format("%s_pkg_%s", (const char*)sysInfo.strTerminalID, (const char*)strReqLogName);
 
 			pFunc->GetPath("RunInfo", strLogPath);
-			strLogPath += CSimpleStringA::Format("\\InstallLog\\%s.log", (const char*)strReqLogName);
+			strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)strReqLogName).Append(".log");
 		}
 		else
 		{
@@ -2550,17 +2533,17 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 
 			pFunc->GetPath("Dbg", strLogPath);
 			if (strReqLogName.Compare("Shell", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SpShell\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("DualActive", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\DualActive\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("guardian", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\guardian\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("SpHost", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SpHost\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("SysInit", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SysInit\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else if (strReqLogName.Compare("SpBase", true) == 0)
-				strLogPath += CSimpleStringA::Format("\\SpBase\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			else
 			{
 				CEntityStaticInfo info = {};
@@ -2572,14 +2555,12 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 					SendPackage(pReplyPkg);
 					return Error_NotExist;
 				}
-
-				strLogPath += CSimpleStringA::Format("\\%s\\%s.log", (const char*)info.strSpFileName, (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			}
 		}
 
 		pFunc->GetPath("Temp", strZipPath);
-		strZipPath += "\\";
-		strZipPath += strZipFileName;
+		strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
 		
 		if (!Base_Exist(strLogPath.GetData()))
 		{
@@ -2603,8 +2584,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleUploadLogReq(const CSmartPointer<IPack
 		strZipFileName = req.UploadFile;
 		
 		pFunc->GetPath("Temp", strZipPath);
-		strZipPath += "\\";
-		strZipPath += strZipFileName;
+		strZipPath.Append(SPLIT_SLASH_STR).Append(strZipFileName);
 	}
 			
 	if (!Base_Exist(strZipPath.GetData()))
@@ -2745,10 +2725,10 @@ ErrorCodeEnum CRemoteControllerCnn::HandleViewEntityStateExReq(const CSmartPoint
 		CSimpleStringA strEntCfgDir;
 		CSimpleStringA strRunCfgDir;
 		pFunc->GetPath("Cfg", strEntCfgDir);
-		strEntCfgDir += "\\";
+		strEntCfgDir.Append(SPLIT_SLASH_STR);
 
 		pFunc->GetPath("RunInfo", strRunCfgDir);
-		strRunCfgDir += "\\runcfg\\";
+		strRunCfgDir.Append(SPLIT_SLASH_STR).Append("runcfg").Append(SPLIT_SLASH_STR);
 
 		for (int i = 0; i<nCount - 8; i++)
 		{
@@ -2851,7 +2831,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsByDateReq(const CSmartP
 	CSimpleStringA strZipPath;
 	auto pFunc = m_pEntity->GetFunction();
 	pFunc->GetPath("Temp", strZipPath);
-	strZipPath += "\\";
+	strZipPath.Append(SPLIT_SLASH_STR);
 	CSimpleStringA strZipFileName = req.ZipFileName;
 	strZipPath += strZipFileName;
 
@@ -2871,31 +2851,31 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsByDateReq(const CSmartP
 			if (arrFiles[i].Compare("Silverlight", true) == 0)	// slv日志
 			{				
 				pFunc->GetPath("Slv", strLogPath);
-				strLogPath += CSimpleStringA::Format("\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			}
 			else if (arrFiles[i].IsEndWith(".zip", true))	// 安装包日志
 			{
 				pFunc->GetPath("RunInfo", strLogPath);
-				strLogPath += CSimpleStringA::Format("\\InstallLog\\%s.log", (const char*)arrFiles[i]);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)arrFiles[i]).Append(".log");
 			}
 			else
 			{
 				// 实体Dbg日志
 				pFunc->GetPath("Dbg", strLogPath);
 				if (arrFiles[i].Compare("Shell", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SpShell\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("DualActive", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\DualActive\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("guardian", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\guardian\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("SpHost", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SpHost\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("SysInit", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SysInit\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("SpBase", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SpBase\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("Root", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\Root\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("Root").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else
 				{
 					CEntityStaticInfo info = {};
@@ -2908,16 +2888,13 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsByDateReq(const CSmartP
 						return Error_NotExist;
 					}
 
-					strLogPath += CSimpleStringA::Format("\\%s\\%s.log", (const char*)info.strSpFileName, (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				}
 			}
 
 			if (!Base_Exist(strLogPath.GetData()))
 			{
 				Dbg("log [%s] not exist", (const char*)strLogPath);
-				//pReplyPkg->SetErrMsg(Error_NotExist, 0, CSimpleStringA::Format("日志文件[%s]不存在", (const char*)strLogPath));
-				//SendPackage(pReplyPkg);
-				//return Error_NotExist;
 				continue;
 			}
 
@@ -2931,7 +2908,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsByDateReq(const CSmartP
 			return Error_NotExist;
 		}
 
-		Dbg("strZipPath:%s", strZipPath);
+		Dbg("strZipPath:%s", strZipPath.GetData());
 		// 生成ZIP
 		auto rc = BatchZipFiles(strZipPath, listSrcFiles);
 		if (rc != Error_Succeed)
@@ -3074,7 +3051,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsReq(const CSmartPointer
 	CSimpleStringA strZipPath;
 	auto pFunc = m_pEntity->GetFunction();
 	pFunc->GetPath("Temp", strZipPath);
-	strZipPath += "\\";
+	strZipPath.Append(SPLIT_SLASH_STR);
 	CSimpleStringA strZipFileName = req.ZipFileName;
 	strZipPath += strZipFileName;
 
@@ -3094,31 +3071,31 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsReq(const CSmartPointer
 			if (arrFiles[i].Compare("Silverlight", true) == 0)	// slv日志
 			{				
 				pFunc->GetPath("Slv", strLogPath);
-				strLogPath += CSimpleStringA::Format("\\%s.log", (const char*)strTodayLogName);
+				strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 			}
 			else if (arrFiles[i].IsEndWith(".zip", true))	// 安装包日志
 			{
 				pFunc->GetPath("RunInfo", strLogPath);
-				strLogPath += CSimpleStringA::Format("\\InstallLog\\%s.log", (const char*)arrFiles[i]);
+				strLogPath.Append(SPLIT_SLASH_STR).Append("InstallLog").Append(SPLIT_SLASH_STR).Append((const char*)arrFiles[i]).Append(".log");
 			}
 			else
 			{
 				// 实体Dbg日志
 				pFunc->GetPath("Dbg", strLogPath);
 				if (arrFiles[i].Compare("Shell", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SpShell\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SpShell").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("DualActive", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\DualActive\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("DualActive").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("guardian", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\guardian\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("guardian").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("SpHost", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SpHost\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SpHost").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("SysInit", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SysInit\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SysInit").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("SpBase", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\SpBase\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("SpBase").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else if (arrFiles[i].Compare("Root", true) == 0)
-					strLogPath += CSimpleStringA::Format("\\Root\\%s.log", (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append("Root").Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				else
 				{
 					CEntityStaticInfo info = {};
@@ -3131,7 +3108,7 @@ ErrorCodeEnum CRemoteControllerCnn::HandleBatchUploadLogsReq(const CSmartPointer
 						return Error_NotExist;
 					}
 
-					strLogPath += CSimpleStringA::Format("\\%s\\%s.log", (const char*)info.strSpFileName, (const char*)strTodayLogName);
+					strLogPath.Append(SPLIT_SLASH_STR).Append((const char*)info.strSpFileName).Append(SPLIT_SLASH_STR).Append((const char*)strTodayLogName).Append(".log");
 				}
 			}
 

+ 153 - 0
Module/mod_RomoteController/XZipZilb.cpp

@@ -0,0 +1,153 @@
+#include "XZipZilb.h"
+#include "libtoolkit/path.h"
+#include "fileutil.h"
+
+
+bool CreateZipFromFile(string srcFileName, string zipFileName)
+{
+	if (srcFileName.empty() || srcFileName.length() == 0 ||
+		zipFileName.empty() || zipFileName.length() == 0) {
+		//Dbg("压缩文件参数为空:");
+		Dbg("XZipZilb zip param is null");
+		return false;
+	}
+	int pos = srcFileName.find_last_of(SPLIT_SLASH);
+
+	if (pos < 0) {
+		//Dbg("文件路径不对:%s",srcFileName.c_str());
+		Dbg("XZipZilb srcFileName path format is error:%s", srcFileName.c_str());
+		return false;
+	}
+	string strName(srcFileName.substr(pos + 1));
+	// does zip source file exist?
+	//if (ExistsFileA(zipFileName)) {
+	//	remove(zipFileName.c_str();
+	//}
+
+	zipFile newZipFile = zipOpen(zipFileName.c_str(), APPEND_STATUS_CREATE); //创建zip文件
+	if (newZipFile == NULL)
+	{
+		//Dbg("无法创建zip文件!");
+		Dbg("XZipZilb can't create zip file: %s", zipFileName.c_str());
+		return false;
+	}
+	//压缩文件
+	if (!AddFileToZip(newZipFile, strName.c_str(), srcFileName.c_str()))
+	{
+		//Dbg("压缩失败: %s",zipFileName.c_str());
+		Dbg("XZipZilb zip fail: %s", zipFileName.c_str());
+		zipClose(newZipFile, NULL); 
+		if (ExistsFileA(zipFileName.c_str())) {
+			if (remove(zipFileName.c_str()) != 0) {
+				//Dbg("删除临时压缩文件失败");
+				Dbg("XZipZilb delete temp zip file is error");
+			}
+		}
+		return false;
+	}
+	//释放文件
+	zipClose(newZipFile, NULL); 
+	//Dbg("压缩成功: %s", zipFileName.c_str());
+	Dbg("XZipZilb zip succ: %s", zipFileName.c_str());
+	return true;
+	
+}
+
+bool AddFileToZip(zipFile zf, const char* fileNameInZip, const char* srcFile)
+{
+	//Dbg("fileNameInZip %s : %s", fileNameInZip, srcFile);
+	FILE* srcfp = NULL;
+
+	//初始化写入zip的文件信息(后期写入文件修改日期等信息)
+	zip_fileinfo zi;
+	zi.tmz_date.tm_sec = zi.tmz_date.tm_min = zi.tmz_date.tm_hour =
+		zi.tmz_date.tm_mday = zi.tmz_date.tm_mon = zi.tmz_date.tm_year = 0;
+	zi.dosDate = 0;
+	zi.internal_fa = 0;
+	zi.external_fa = 0;
+
+	//如果srcFile为空,加入空目录
+	char new_file_name[256];
+	memset(new_file_name, 0, sizeof(new_file_name));
+	strcat(new_file_name, fileNameInZip);
+	if (srcFile == NULL)
+	{
+		strcat(new_file_name, SPLIT_SLASH_STR);
+	}
+
+	//在zip文件中创建新文件或文件夹
+	int ret = zipOpenNewFileInZip(zf, new_file_name, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);
+	if (ret != ZIP_OK)
+	{
+		if (srcFile != NULL) {
+			//Dbg("在zip文件中创建新文件失败: %s", srcFile);
+			Dbg("XZipZilb create file in zip fail: %s", srcFile);
+		}
+		else {
+			//Dbg("在zip文件中创建新目录失败: %s", new_file_name);
+			Dbg("XZipZilb create dir in zip fail: %s", new_file_name);
+		}
+		return false;
+	}
+
+	if (srcFile != NULL)
+	{
+		//打开源文件
+		srcfp = fopen(srcFile, "rb+");
+		if (srcfp == NULL)
+		{
+			//Dbg("打开要往zip压缩的文件失败: %s", srcFile);
+			Dbg("XZipZilb open src file to zip is fail: %s", srcFile);
+			zipCloseFileInZip(zf); //关闭zip中的新文件
+			return false;
+		}
+
+		int fileLen = (int)GetFileLen(srcfp);
+		//读入源文件并写入zip文件
+		char buf[16 * 1024];
+		int numBytes = 0;
+		int sumWrite = 0;
+		while (!feof(srcfp) && !ferror(srcfp))
+		{
+			numBytes = fread(buf, 1, sizeof(buf), srcfp);
+			int ret = zipWriteInFileInZip(zf, buf, numBytes);
+			if (ret != ZIP_OK) {
+				Dbg("文件写入zip压缩包失败1: %s", srcFile);
+				fclose(srcfp);
+				zipCloseFileInZip(zf);
+				return false;//写文件失败
+			}
+			sumWrite += numBytes;
+		}
+
+
+		if (sumWrite != fileLen) {
+			//Dbg("文件写入zip压缩包失败,总长度不一致: %s", srcFile);
+			Dbg("XZipZilb write to zip file is error ,sumWrite is not equal to fileLen, %s", srcFile);
+			fclose(srcfp);
+			zipCloseFileInZip(zf);
+			return false;//写文件失败
+		}
+		//关闭源文件
+		fclose(srcfp);
+	}
+
+	//关闭zip文件
+	zipCloseFileInZip(zf);
+	return true;
+
+}
+
+long GetFileLen(FILE* _file)
+{
+	long curPosit = ftell(_file), fileLen;
+	fseek(_file, 0, SEEK_END);
+	fileLen = ftell(_file);
+	fseek(_file, curPosit, SEEK_SET);
+	return fileLen;
+}
+
+
+
+
+

+ 31 - 0
Module/mod_RomoteController/XZipZilb.h

@@ -0,0 +1,31 @@
+#ifndef RVC_MOD_UPLOAD_XZIP_ZLIB_H_
+#define RVC_MOD_UPLOAD_XZIP_ZLIB_H_
+
+#include "SpBase.h"
+
+#ifdef RVC_OS_WIN
+
+#define ZLIB_WINAPI //win32 必须使用的宏
+
+#endif 
+
+
+
+#include "zip.h"
+#include "unzip.h"
+#include <iostream>
+#include <stdio.h>
+#include <string>
+
+using namespace std;
+
+bool CreateZipFromFile(string srcFileName, string zipFileName);
+
+bool AddFileToZip(zipFile zf, const char* fileNameInZip, const char* srcFile);
+//获取文件长度 完成
+long GetFileLen(FILE* _file);
+
+
+
+
+#endif //RVC_MOD_UPLOAD_XZIP_ZLIB_H_