code_app/app/scanner/VersionDll.cpp

251 lines
5.9 KiB
C++

#include "VersionDll.h"
#include "base/HGDef.h"
#include "base/HGInc.h"
VersionDll::VersionDll()
{
m_dll = NULL;
m_funcCreateMgr = NULL;
m_funcDestroyMgr = NULL;
m_funcGetServerConfig = NULL;
m_funcGetVersionList = NULL;
m_funcPostCrashInfo = NULL;
m_funcPostUserFeedback = NULL;
m_funcHttpDownload = NULL;
m_funcReleaseVersionList = NULL;
m_funcGetCurrVersion = NULL;
m_funcCompareVersion = NULL;
Load();
}
VersionDll::~VersionDll()
{
Free();
}
HGResult VersionDll::Load()
{
if (NULL != m_dll)
{
return HGBASE_ERR_FAIL;
}
HGBase_CreateDll("HGVersion.dll", &m_dll);
if (NULL == m_dll)
{
return HGBASE_ERR_FAIL;
}
bool ok = true;
do
{
HGBase_GetDllProcAddress(m_dll, "HGVersion_CreateMgr", (HGPointer *)&m_funcCreateMgr);
if (NULL == m_funcCreateMgr)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_DestroyMgr", (HGPointer *)&m_funcDestroyMgr);
if (NULL == m_funcCreateMgr)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_GetServerConfig", (HGPointer *)&m_funcGetServerConfig);
if (NULL == m_funcGetServerConfig)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_PostCrashInfo", (HGPointer *)&m_funcPostCrashInfo);
if (NULL == m_funcPostCrashInfo)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_PostUserFeedback", (HGPointer *)&m_funcPostUserFeedback);
if (NULL == m_funcPostUserFeedback)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_GetVersionList", (HGPointer *)&m_funcGetVersionList);
if (NULL == m_funcGetVersionList)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_HttpDownload", (HGPointer *)&m_funcHttpDownload);
if (NULL == m_funcHttpDownload)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_ReleaseVersionList", (HGPointer *)&m_funcReleaseVersionList);
if (NULL == m_funcReleaseVersionList)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_GetCurrVersion", (HGPointer *)&m_funcGetCurrVersion);
if (NULL == m_funcGetCurrVersion)
{
ok = false;
break;
}
HGBase_GetDllProcAddress(m_dll, "HGVersion_CompareVersion", (HGPointer *)&m_funcCompareVersion);
if (NULL == m_funcCompareVersion)
{
ok = false;
break;
}
}while (0);
if (!ok)
{
m_funcCreateMgr = NULL;
m_funcDestroyMgr = NULL;
m_funcGetServerConfig = NULL;
m_funcGetVersionList = NULL;
m_funcPostCrashInfo = NULL;
m_funcPostUserFeedback = NULL;
m_funcHttpDownload = NULL;
m_funcReleaseVersionList = NULL;
m_funcGetCurrVersion = NULL;
m_funcCompareVersion = NULL;
HGBase_DestroyDll(m_dll);
m_dll = NULL;
return HGBASE_ERR_FAIL;
}
return HGBASE_ERR_OK;
}
HGResult VersionDll::Free()
{
if (NULL == m_dll)
{
return HGBASE_ERR_FAIL;
}
HGBase_DestroyDll(m_dll);
m_dll = NULL;
}
HGBool VersionDll::IsValid()
{
return (NULL != m_dll);
}
HGResult VersionDll::CreateMgr(HGVersionMgr *mgr)
{
if (NULL == m_funcCreateMgr)
{
return HGBASE_ERR_FAIL;
}
return m_funcCreateMgr(mgr);
}
HGResult VersionDll::DestroyMgr(HGVersionMgr mgr)
{
if (NULL == m_funcDestroyMgr)
{
return HGBASE_ERR_FAIL;
}
return m_funcDestroyMgr(mgr);
}
HGResult VersionDll::GetServerConfig(HGVersionMgr mgr, HGServerConfig *config)
{
if (NULL == m_funcGetServerConfig)
{
return HGBASE_ERR_FAIL;
}
return m_funcGetServerConfig(mgr, config);
}
HGResult VersionDll::GetVersionList(HGVersionMgr mgr, const HGChar* appName, HGVersionInfo **info, HGUInt *count)
{
if (NULL == m_funcGetVersionList)
{
return HGBASE_ERR_FAIL;
}
return m_funcGetVersionList(mgr, appName, info, count);
}
HGResult VersionDll::HttpDownload(HGVersionMgr mgr, const HGChar *url, const HGChar *saveFilePath, HGHttpDownloadFunc func, HGPointer param)
{
if (NULL == m_funcHttpDownload)
{
return HGBASE_ERR_FAIL;
}
return m_funcHttpDownload(mgr, url, saveFilePath, func, param);
}
HGResult VersionDll::ReleaseVersionList(HGVersionInfo* info, HGUInt count)
{
if (NULL == m_funcReleaseVersionList)
{
return HGBASE_ERR_FAIL;
}
return m_funcReleaseVersionList(info, count);
}
HGResult VersionDll::GetCurrVersion(const HGChar* appName, HGChar* version, HGUInt maxLen)
{
if (NULL == m_funcGetCurrVersion)
{
return HGBASE_ERR_FAIL;
}
return m_funcGetCurrVersion(appName, version, maxLen);
}
HGResult VersionDll::CompareVersion(const HGChar* version1, const HGChar* version2, HGInt* result)
{
if (NULL == m_funcCompareVersion)
{
return HGBASE_ERR_FAIL;
}
return m_funcCompareVersion(version1, version2, result);
}
HGResult VersionDll::PostCrashInfo(HGVersionMgr mgr, const HGChar* appName, const HGChar* desc, const HGChar* crashFilePath, const HGChar* exceptionAddr)
{
if (NULL == m_funcPostCrashInfo)
{
return HGBASE_ERR_FAIL;
}
return m_funcPostCrashInfo(mgr, appName, desc, crashFilePath, exceptionAddr);
}
HGResult VersionDll::PostUserFeedback(HGVersionMgr mgr, const HGChar* appName, const HGChar* desc, const HGChar* feedback, const HGChar* contact)
{
if (NULL == m_funcPostUserFeedback)
{
return HGBASE_ERR_FAIL;
}
return m_funcPostUserFeedback(mgr, appName, desc, feedback, contact);
}