📄 export.cpp
字号:
#include "stdafx.h"
#include "export.h"
#include "../include/MyIniFile.h"
using namespace std;
using namespace Ice;
using namespace Patch;
BOOL GetAuthIPAddr(CHAR *strAuthIP)
{
IniFile ini;
CHAR szInst[MAX_PATH] = {0};
if(!GetSystemDirectoryA(szInst, MAX_PATH))
{
return FALSE;
}
strcat(szInst,"\\Product.ini");
if(!ini.open(szInst))
{
return FALSE;
}
string s = ini.GetProfileValue("[EditionMend]","Directory");
DWORD len = s.length();
if((0 == len) || (MAX_PATH < len))
{
return FALSE;
}
memset(szInst,0,strlen(szInst));
ini.close();
memcpy(szInst, s.c_str(), len);
szInst[len] = 0;
if('\\' != szInst[len - 1])
{
szInst[len++] = '\\';
szInst[len] = 0;
}
strcat(szInst,"\\Config.ini");
if (!ini.open(szInst))
{
return FALSE;
}
s = ini.GetProfileValue("[communicate]","AuthIPAddr");
len = s.length();
if ((0==len)||(MAX_PATH<len))
{
return FALSE;
}
ini.close();
memset(strAuthIP,0,strlen(strAuthIP));
memcpy(strAuthIP,s.c_str(),len);
return TRUE;
}
ICEPATCH_API void __stdcall Start()
{
Ice::CommunicatorPtr ic;
try
{
int argc = 0;
ic = Ice::initialize(argc, 0);
CHAR strAuthIP[128] = {0};
BOOL bRet = GetAuthIPAddr(strAuthIP);
if (bRet==FALSE)
{
return;
}
char s[256] = {0};
sprintf(s, "%s: tcp -h %s -p %s","PatchPro",strAuthIP,"11020");
Ice::ObjectPrx base = ic->stringToProxy(s);
UpdateServerPrx upDate = UpdateServerPrx::checkedCast(base);
if(!upDate)
{
throw "Invalid proxy";
}
g_UpdatePrx = upDate;
}
catch (...)
{
return ;
}
return ;
}
ICEPATCH_API BOOL __stdcall Init()
{
BOOL bRet = FALSE;
try
{
bRet = g_UpdatePrx->Init();
}
catch (...) {
Start();
return FALSE;
}
return bRet;
}
ICEPATCH_API BOOL __stdcall isUpdate(IN CHAR *curVersion)
{
BOOL bRet = FALSE;
try
{
bRet = g_UpdatePrx->isUpdate(curVersion);
}
catch (...)
{
Start();
return TRUE;
}
return bRet;
}
ICEPATCH_API BOOL __stdcall GetFileInfo(OUT CHAR *fileName,IN OUT LONGLONG *fileSize,
OUT CHAR *updateVersion,OUT CHAR *pFileHash,IN OUT int *iHashLen)
{
try
{
::Patch::ByteSeq pHashSeq;
::std::string strFileName;
::std::string strUpdateVersion;
g_UpdatePrx->GetFileInfo(strFileName,*fileSize,strUpdateVersion,pHashSeq);
int iLen = pHashSeq.size();
if (*iHashLen<iLen) {
SetLastError(ERROR_INSUFFICIENT_BUFFER);
*iHashLen = iLen;
return FALSE;
}
strcpy(fileName,strFileName.c_str());
strcpy(updateVersion,strUpdateVersion.c_str());
subvector sub;
sub.vectortobuf((BYTE *)pFileHash,iHashLen,pHashSeq);
}
catch (...)
{
Start();
return FALSE;
}
return TRUE;
}
ICEPATCH_API void __stdcall GetDataFromFile(IN int iFilePos,OUT BYTE *pBuf,OUT BYTE *hashValue,IN OUT int *iReadSize)
{
::Patch::ByteSeq pDataBuf;
::Patch::ByteSeq pHashBuf;
try
{
g_UpdatePrx->GetDataFromFile(iFilePos,pDataBuf,pHashBuf,*iReadSize);
subvector sub;
int bufLen;
sub.vectortobuf(pBuf,iReadSize,pDataBuf);
sub.vectortobuf(hashValue,&bufLen,pHashBuf);
}
catch (...)
{
Start();
return ;
}
return ;
}
ICEPATCH_API BOOL __stdcall shutdown()
{
BOOL bRet;
try
{
bRet = g_UpdatePrx->shutdown();
}
catch (...)
{
return FALSE;
}
return bRet;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -