HGVersion.h获取版本接口修改

This commit is contained in:
luoliangyi 2022-07-14 09:41:51 +08:00
parent 96cfb0f9b9
commit 0fc71bf09a
5 changed files with 95 additions and 35 deletions

View File

@ -11,5 +11,6 @@ HGVersion_PostCrashInfo
HGVersion_PostUserFeedback
HGVersion_GetVersionList
HGVersion_HttpDownload
HGVersion_ReleaseVersionList
HGVersion_GetCurrVersion
HGVersion_CompareVersion

View File

@ -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);

View File

@ -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);

View File

@ -15,6 +15,21 @@
#include <iphlpapi.h>
#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<HGVersionInfo>& versionList)
static HGResult GetVersionList(const std::string& appName, std::list<VersionInfoImpl> &versionList)
{
versionList.clear();
@ -668,23 +683,23 @@ static HGResult GetVersionList(const std::string& appName, std::list<HGVersionIn
cJSON* p2 = p->child;
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<HGVersionInfo> versionList;
std::list<VersionInfoImpl> versionList;
HGResult ret = ::GetVersionList(appName, versionList);
if (HGBASE_ERR_OK != ret)
{
return ret;
}
HGUInt count2 = 0;
std::list<HGVersionInfo>::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<VersionInfoImpl>::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)

View File

@ -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: