From 0fc71bf09ae9d3af5f6c1ad8f29dc23b06ec9f3c Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Thu, 14 Jul 2022 09:41:51 +0800 Subject: [PATCH] =?UTF-8?q?HGVersion.h=E8=8E=B7=E5=8F=96=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/windows/HGVersion/HGVersion.def | 1 + modules/version/HGVersion.cpp | 9 ++- modules/version/HGVersion.h | 16 ++-- modules/version/HGVersionImpl.cpp | 101 +++++++++++++++++++------- modules/version/HGVersionImpl.hpp | 3 +- 5 files changed, 95 insertions(+), 35 deletions(-) diff --git a/build/windows/HGVersion/HGVersion.def b/build/windows/HGVersion/HGVersion.def index 9d0ce958..b40b9671 100644 --- a/build/windows/HGVersion/HGVersion.def +++ b/build/windows/HGVersion/HGVersion.def @@ -11,5 +11,6 @@ HGVersion_PostCrashInfo HGVersion_PostUserFeedback HGVersion_GetVersionList HGVersion_HttpDownload +HGVersion_ReleaseVersionList HGVersion_GetCurrVersion HGVersion_CompareVersion \ No newline at end of file diff --git a/modules/version/HGVersion.cpp b/modules/version/HGVersion.cpp index 21546d7b..75d8523c 100644 --- a/modules/version/HGVersion.cpp +++ b/modules/version/HGVersion.cpp @@ -84,7 +84,7 @@ HGResult HGAPI HGVersion_PostUserFeedback(HGVersionMgr mgr, const HGChar* appNam return versionMgrImpl->PostUserFeedback(appName, desc, feedback, contact); } -HGResult HGAPI HGVersion_GetVersionList(HGVersionMgr mgr, const HGChar* appName, HGVersionInfo* info, HGUInt maxLen, HGUInt* count) +HGResult HGAPI HGVersion_GetVersionList(HGVersionMgr mgr, const HGChar* appName, HGVersionInfo** info, HGUInt* count) { if (NULL == mgr) { @@ -92,7 +92,7 @@ HGResult HGAPI HGVersion_GetVersionList(HGVersionMgr mgr, const HGChar* appName, } HGVersionMgrImpl* versionMgrImpl = (HGVersionMgrImpl*)mgr; - return versionMgrImpl->GetVersionList(appName, info, maxLen, count); + return versionMgrImpl->GetVersionList(appName, info, count); } HGResult HGAPI HGVersion_HttpDownload(HGVersionMgr mgr, const HGChar* url, const HGChar* saveFilePath, HGHttpDownloadFunc func, HGPointer param) @@ -106,6 +106,11 @@ HGResult HGAPI HGVersion_HttpDownload(HGVersionMgr mgr, const HGChar* url, const return versionMgrImpl->HttpDownload(url, saveFilePath, func, param); } +HGResult HGAPI HGVersion_ReleaseVersionList(HGVersionInfo* info, HGUInt count) +{ + return HGVersionMgrImpl::ReleaseVersionList(info, count); +} + HGResult HGAPI HGVersion_GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen) { return HGVersionMgrImpl::GetCurrVersion(appName, version, maxLen); diff --git a/modules/version/HGVersion.h b/modules/version/HGVersion.h index f9a51726..b519995a 100644 --- a/modules/version/HGVersion.h +++ b/modules/version/HGVersion.h @@ -18,12 +18,12 @@ typedef struct typedef struct { - HGChar version[64]; /* 版本号 */ - HGChar desc[1024]; /* 版本描述 */ - HGChar bugInfo[1024]; /* BUG描述 */ - HGChar url[256]; /* 安装包URL */ - HGULonglong size; /* 安装包大小 */ - HGChar md5[64]; /* 安装包MD5 */ + HGChar *version; /* 版本号 */ + HGChar *desc; /* 版本描述 */ + HGChar *bugInfo; /* BUG描述 */ + HGChar *url; /* 安装包URL */ + HGULonglong size; /* 安装包大小 */ + HGChar *md5; /* 安装包MD5 */ }HGVersionInfo; /* HTTP下载回调, 如果需要停止下载返回非0, 否则返回0 @@ -44,10 +44,12 @@ HGEXPORT HGResult HGAPI HGVersion_PostCrashInfo(HGVersionMgr mgr, const HGChar* HGEXPORT HGResult HGAPI HGVersion_PostUserFeedback(HGVersionMgr mgr, const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact); -HGEXPORT HGResult HGAPI HGVersion_GetVersionList(HGVersionMgr mgr, const HGChar* appName, HGVersionInfo *info, HGUInt maxLen, HGUInt *count); +HGEXPORT HGResult HGAPI HGVersion_GetVersionList(HGVersionMgr mgr, const HGChar* appName, HGVersionInfo **info, HGUInt *count); HGEXPORT HGResult HGAPI HGVersion_HttpDownload(HGVersionMgr mgr, const HGChar *url, const HGChar *saveFilePath, HGHttpDownloadFunc func, HGPointer param); +HGEXPORT HGResult HGAPI HGVersion_ReleaseVersionList(HGVersionInfo* info, HGUInt count); + HGEXPORT HGResult HGAPI HGVersion_GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen); HGEXPORT HGResult HGAPI HGVersion_CompareVersion(const HGChar* version1, const HGChar* version2, HGInt* result); diff --git a/modules/version/HGVersionImpl.cpp b/modules/version/HGVersionImpl.cpp index e2bade83..29cae9ed 100644 --- a/modules/version/HGVersionImpl.cpp +++ b/modules/version/HGVersionImpl.cpp @@ -15,6 +15,21 @@ #include #endif +struct VersionInfoImpl +{ + VersionInfoImpl() + { + size = 0; + } + + std::string version; + std::string desc; + std::string bugInfo; + std::string url; + unsigned long long size; + std::string md5; +}; + static size_t write_data(void* ptr, size_t size, size_t nmemb, void* stream) { std::string data((const char*)ptr, (size_t)size * nmemb); @@ -614,7 +629,7 @@ static HGResult PostUserFeedback(const std::string& appName, const std::string& return PostInfo(4, appName, desc, "", "", feedback, contact); } -static HGResult GetVersionList(const std::string& appName, std::list& versionList) +static HGResult GetVersionList(const std::string& appName, std::list &versionList) { versionList.clear(); @@ -668,23 +683,23 @@ static HGResult GetVersionList(const std::string& appName, std::listchild; while (NULL != p2) { - HGVersionInfo version; + VersionInfoImpl version; cJSON* p3 = p2->child; while (NULL != p3) { if (0 == strcmp(p3->string, "full") && p3->type == cJSON_String) - strcpy(version.url, p3->valuestring); + version.url = p3->valuestring; else if (0 == strcmp(p3->string, "size") && p3->type == cJSON_String) version.size = atoll(p3->valuestring); else if (0 == strcmp(p3->string, "desc") && p3->type == cJSON_String) - strcpy(version.desc, p3->valuestring); + version.desc = p3->valuestring; else if (0 == strcmp(p3->string, "bug") && p3->type == cJSON_String) - strcpy(version.bugInfo, p3->valuestring); + version.bugInfo = p3->valuestring; else if (0 == strcmp(p3->string, "md5") && p3->type == cJSON_String) - strcpy(version.md5, p3->valuestring); + version.md5 = p3->valuestring; else if (0 == strcmp(p3->string, "v") && p3->type == cJSON_String) - strcpy(version.version, p3->valuestring); + version.version = p3->valuestring; p3 = p3->next; } @@ -818,38 +833,49 @@ HGResult HGVersionMgrImpl::PostUserFeedback(const HGChar* appName, const HGChar* return ::PostUserFeedback(appName, desc, feedback, contact); } -HGResult HGVersionMgrImpl::GetVersionList(const HGChar* appName, HGVersionInfo* info, HGUInt maxLen, HGUInt* count) +HGResult HGVersionMgrImpl::GetVersionList(const HGChar* appName, HGVersionInfo** info, HGUInt* count) { - if (NULL == info || 0 == maxLen || NULL == count) + if (NULL == info || NULL == count) { return HGBASE_ERR_INVALIDARG; } - std::list versionList; + std::list versionList; HGResult ret = ::GetVersionList(appName, versionList); if (HGBASE_ERR_OK != ret) { return ret; } - HGUInt count2 = 0; - std::list::const_iterator iter; - for (iter = versionList.begin(); iter != versionList.end(); ++iter) + if (versionList.empty()) { - strcpy(info[count2].version, (*iter).version); - strcpy(info[count2].desc, (*iter).desc); - strcpy(info[count2].bugInfo, (*iter).bugInfo); - strcpy(info[count2].url, (*iter).url); - info[count2].size = (*iter).size; - strcpy(info[count2].md5, (*iter).md5); - - ++count2; - if (count2 >= maxLen) - { - break; - } + return HGBASE_ERR_FAIL; } + HGUInt count2 = (HGUInt)versionList.size(); + HGVersionInfo *info2 = new HGVersionInfo[count2]; + + HGUInt index = 0; + std::list::const_iterator iter; + for (iter = versionList.begin(); iter != versionList.end(); ++iter) + { + const VersionInfoImpl& ver = *iter; + info2[index].version = new HGChar[ver.version.size() + 1]; + strcpy(info2[index].version, ver.version.c_str()); + info2[index].desc = new HGChar[ver.desc.size() + 1]; + strcpy(info2[index].desc, ver.desc.c_str()); + info2[index].bugInfo = new HGChar[ver.bugInfo.size() + 1]; + strcpy(info2[index].bugInfo, ver.bugInfo.c_str()); + info2[index].url = new HGChar[ver.url.size() + 1]; + strcpy(info2[index].url, ver.url.c_str()); + info2[index].size = ver.size; + info2[index].md5 = new HGChar[ver.md5.size() + 1]; + strcpy(info2[index].md5, ver.md5.c_str()); + + ++index; + } + + *info = info2; *count = count2; return HGBASE_ERR_OK; } @@ -859,6 +885,31 @@ HGResult HGVersionMgrImpl::HttpDownload(const HGChar* url, const HGChar* saveFil return ::HttpDownload(url, saveFilePath, func, param); } +HGResult HGVersionMgrImpl::ReleaseVersionList(HGVersionInfo* info, HGUInt count) +{ + if (NULL == info || 0 == count) + { + return HGBASE_ERR_INVALIDARG; + } + + for (HGUInt i = 0; i < count; ++i) + { + delete[] info[i].version; + info[i].version = NULL; + delete[] info[i].desc; + info[i].desc = NULL; + delete[] info[i].bugInfo; + info[i].bugInfo = NULL; + delete[] info[i].url; + info[i].url = NULL; + delete[] info[i].md5; + info[i].md5 = NULL; + } + + delete[] info; + return HGBASE_ERR_OK; +} + HGResult HGVersionMgrImpl::GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen) { if (NULL == version || 0 == maxLen) diff --git a/modules/version/HGVersionImpl.hpp b/modules/version/HGVersionImpl.hpp index a7802de0..e29767f7 100644 --- a/modules/version/HGVersionImpl.hpp +++ b/modules/version/HGVersionImpl.hpp @@ -15,8 +15,9 @@ public: HGResult PostUninstallInfo(const HGChar* appName, const HGChar* desc); HGResult PostCrashInfo(const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr); HGResult PostUserFeedback(const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact); - HGResult GetVersionList(const HGChar* appName, HGVersionInfo* info, HGUInt maxLen, HGUInt* count); + HGResult GetVersionList(const HGChar* appName, HGVersionInfo** info, HGUInt* count); HGResult HttpDownload(const HGChar* url, const HGChar* saveFilePath, HGHttpDownloadFunc func, HGPointer param); + static HGResult ReleaseVersionList(HGVersionInfo *info, HGUInt count); static HGResult GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen); private: