Эх сурвалжийг харах

!2 accomplish the function GetHelpDetail

chenliangyu 1 жил өмнө
parent
commit
c06016c7ae

+ 10 - 0
Module/include/EventCode.h

@@ -694,6 +694,16 @@ ERROR_ACCESSAUTH_CONNECT_ACS_x}
 #define WARN_GUICONSOLE_BASICINFO_RUNINFO_FAILED		0x50820703
 //实体控制,打开日志失败,日志不存在
 #define WARN_GUICONSOLE_ENTITYCONTROL_LOG_NOTEXIST		0x50820801
+//实体控制,帮助-root配置打开失败
+#define WARN_GUICONSOLE_HELP_ROOT_FAILED			0x50820901
+//实体控制,帮助-center配置打开失败
+#define WARN_GUICONSOLE_HELP_CENTER_FAILED			0x50820902
+//实体控制,帮助-shell配置打开失败
+#define WARN_GUICONSOLE_HELP_SHELL_FAILED			0x50820903
+//实体控制,帮助-vtmerr配置打开失败
+#define WARN_GUICONSOLE_HELP_VTMERR_FAILED			0x50820904
+//实体控制,帮助--获取节点失败
+#define WARN_GUICONSOLE_HELP_GETSECTION_FAILED			0x50820905
 
 
 

+ 5 - 0
Module/mod_guiconsole/CMakeLists.txt

@@ -28,6 +28,7 @@ endif()
 set(${MODULE_PREFIX}_SRCS
 	mod_guiconsole.cpp
 	guiconsole_define.cpp
+	${ThirdPartyHeadRoot}/modp_b64/modp_b64.cc
 	)
 
 set(MOD_VERSION_STRING "0.0.1-dev1")
@@ -35,6 +36,10 @@ add_module_libraries(${MODULE_PREFIX} ${MODULE_NAME} ${MOD_VERSION_STRING})
 
 MESSAGE( STATUS "CONAN_INCLUDE_DIRS_JSONCPP = ${CONAN_INCLUDE_DIRS_JSONCPP}")
 
+target_include_directories(${MODULE_NAME} PRIVATE
+	${ThirdPartyHeadRoot}/modp_b64
+)
+
 target_link_directories(${MODULE_NAME} PRIVATE
 	${CONAN_LIB_DIRS_JSONCPP}
 	${CONAN_LIB_DIRS_BOOST}

+ 118 - 3
Module/mod_guiconsole/mod_guiconsole.cpp

@@ -4,6 +4,7 @@
 #include "GUIConsole_msg_g.h"
 #include <chrono>
 #include <fstream>
+#include "modp_b64.h"
 
 
 
@@ -26,6 +27,7 @@ void openProcess(std::string cmdline)
 #include <unistd.h>
 #include <cstdlib>
 #endif // RVC_OS_WIN
+#include <regex>
 
 
 
@@ -619,26 +621,139 @@ std::pair<DWORD, std::string> CGUIConsoleEntity::GetHelpInformationArr(SpReqAnsC
 	}
 	return std::pair<DWORD, std::string>(ErrorCodeEnum::Error_Succeed, "");
 }
+#if(defined _WIN32 || defined _WIN64)
+std::string string_to_utf8(const std::string& str) {
+	int wcLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0);
+	if (wcLen > 0) {
+		wchar_t* pwBuf = new wchar_t[wcLen + 1];
+		if (pwBuf == NULL) {
+			return std::string();
+		}
+
+		memset(pwBuf, 0, sizeof(wchar_t) * (wcLen + 1));
+		wcLen = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, pwBuf, wcLen);
+		if (wcLen <= 0) {
+			delete[] pwBuf;
+			return std::string();
+		}
+
+		std::wstring modifyStr = pwBuf;
+
+
+		int ucLen = WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, NULL, 0, NULL, NULL);
+		//DbgEx("ucLen = %d", ucLen);
+		if (ucLen < 0) {
+			delete[] pwBuf;
+			return std::string();
+		}
+
+		char* pBuf = new char[ucLen + 1];
+		if (pBuf == NULL) {
+			delete[]pwBuf;
+			return std::string();
+		}
+		memset(pBuf, 0, sizeof(char) * (ucLen + 1));
+		ucLen = WideCharToMultiByte(CP_UTF8, 0, pwBuf, -1, pBuf, ucLen, NULL, NULL);
+		if (ucLen <= 0) {
+			delete[] pwBuf;
+			delete[] pBuf;
+			return std::string();
+		}
+
+		std::string retStr(pBuf);
+		//DbgEx("string_to_utf8 return: %s", retStr.c_str());
+
+		if (pwBuf) {
+			delete[] pwBuf;
+			pwBuf = NULL;
+		}
+		if (pBuf) {
+			delete[] pBuf;
+			pBuf = NULL;
+		}
+
+		return retStr;
+	}
+	return std::string();
+}
+#endif
+
+
 
 std::pair<DWORD, std::string> CGUIConsoleEntity::GetHelpDetail(SpReqAnsContext<GUIConsoleService_GetHelpDetail_Req, GUIConsoleService_GetHelpDetail_Ans>::Pointer ctx)
 {
 	CSimpleString tilte = ctx->Req.title;
+	CSmartPointer<IConfigInfo> spConfig;
+	
 	if (tilte.Compare("runcfg", true) == 0)
 	{
 		ctx->Ans.subtitle = "root配置";
-		ctx->Ans.detail = "root配置";
+		ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Root, spConfig);
+		if (!IS_SUCCEED(erroCode))
+			return std::pair<DWORD, std::string>(WARN_GUICONSOLE_HELP_ROOT_FAILED, "");
 	}
 	else if (tilte.Compare("centercfg", true) == 0)
 	{
 		ctx->Ans.subtitle = "集中配置";
-		ctx->Ans.detail = "集中配置";
+		ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
+		if (!IS_SUCCEED(erroCode))
+			return std::pair<DWORD, std::string>(WARN_GUICONSOLE_HELP_CENTER_FAILED, "");
 	}
 	else if (tilte.Compare("shellcfg", true) == 0)
 	{
 		ctx->Ans.subtitle = "shell配置";
-		ctx->Ans.detail = "shell配置";
+		ErrorCodeEnum erroCode = GetFunction()->OpenConfig(Config_Shell, spConfig);
+		if (!IS_SUCCEED(erroCode))
+			return std::pair<DWORD, std::string>(WARN_GUICONSOLE_HELP_SHELL_FAILED, "");
+	}
+
+	CAutoArray<CSimpleStringA> arrSections, arrKeys;
+
+	CSimpleStringA dstStr;
+	dstStr.Append("# ").Append(ctx->Ans.subtitle).Append("\n");
+	dstStr += "| moudle | name | value |\n";//table header
+	dstStr += "-----|------|-----\n";//sperate
+
+	if (Error_Succeed != spConfig->ReadAllSections(arrSections))
+	{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Read all sections failed.");
+		return std::pair<DWORD, std::string>(WARN_GUICONSOLE_HELP_GETSECTION_FAILED, "");
 	}
 
+	for (int i = 0; i < arrSections.GetCount(); ++i)
+	{
+		spConfig->ReadAllKeys(arrSections[i].GetData(), arrKeys);
+		for (int j = 0; j < arrKeys.GetCount(); ++j)
+		{
+			CSimpleStringA value, tmp;
+			spConfig->ReadConfigValue(arrSections[i].GetData(), arrKeys[j].GetData(), value);
+
+			tmp = CSimpleStringA::Format("{\"moudle\":\"%s\", \"name\":\"%s\", \"value\":\"%s\"}",
+				arrSections[i].GetData(), arrKeys[j].GetData(), value.GetData());
+			std::string result = value.GetData();
+			std::string::size_type pos = 0;
+			while ((pos = result.find("|", pos)) != std::string::npos) {
+				result.replace(pos, 1, "\\|");
+				pos += 2; // 跳过新插入的"\\"
+			}
+
+			dstStr.Append("| ").Append(arrSections[i]).Append(" | ").Append(arrKeys[j]).Append(" | ").Append(result.c_str()).Append(" |\n");
+		}
+	}
+#if(defined _WIN32 || defined _WIN64)
+	dstStr = string_to_utf8(dstStr.GetData()).c_str();
+#endif
+	int base64Len = modp_b64_encode_len(dstStr.GetLength());
+	char *base64Data = (char*)malloc(sizeof(char) * base64Len);
+	modp_b64_encode(base64Data, (const char*)dstStr.GetData(), dstStr.GetLength());
+
+
+	ctx->Ans.detail = base64Data;
+
+	if (base64Data)
+		free(base64Data);
+	
+
 	return std::pair<DWORD, std::string>(ErrorCodeEnum::Error_Succeed, "");
 }