📄 patch.cpp
字号:
GetFile(szTemp); // 拳老 拌加 罐扁 ^^;
}
}
else
{
// End Patch
if(m_HFileFtp != NULL)
{
InternetCloseHandle(m_HFileFtp);
m_HFileFtp = NULL;
}
m_bPatched = TRUE;
return 0l;
}
return 1l;
}
HRESULT CPatch::GetFile(char* nName)
{
static long CurrentSize = 0;
int BufferSize;
DWORD dwBytes;
HANDLE hFind;
char FileBuffer[4100];
hFind = NULL;
BufferSize = 4100;
ZeroMemory(FileBuffer, 4100);
if (InternetReadFile( m_HFileFtp, FileBuffer, (DWORD)BufferSize, &dwBytes) != FALSE)
{
m_AnAmount += dwBytes;
if ( (int)dwBytes != BufferSize )
{
BufferSize = (int)dwBytes;
WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwBytes, NULL);
m_PatchState = 2;
}
else
{
WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwBytes, NULL);
m_PatchState = 1;
}
}
else
{
m_PatchState = 2;
}
return 0L;
}
VOID CPatch::RenderSence(INT nLoopTime)
{
if ( FAILED(g_xMainWnd.Present()) )
{
g_xMainWnd.RestoreSurfaces();
}
}
VOID CPatch::DrawProgressImage(VOID)
{
long lSpace;
double dSpace;
int Height;
int Width;
RECT tRect;
HDC hdc;
HDC MemDC,MemDC2;
HBITMAP OldBitmap1;
HBITMAP OldBitmap2;
BITMAP bit;
PAINTSTRUCT PaintStruct;
BeginPaint(g_xMainWnd.GetSafehWnd(),&PaintStruct);
GetClientRect(g_xMainWnd.GetSafehWnd(),&tRect);
hdc = GetDC(g_xMainWnd.GetSafehWnd());
MemDC = CreateCompatibleDC(hdc);
MemDC2 = CreateCompatibleDC(hdc);
OldBitmap1 = (HBITMAP)SelectObject(MemDC, m_xBmp[0]);
OldBitmap2 = (HBITMAP)SelectObject(MemDC2, m_xBmp[1]);
GetObject(m_xBmp[0],sizeof(BITMAP), &bit);
Width = bit.bmWidth;
Height = bit.bmHeight;
dSpace = (Height / 100.0) * (100 - Progress(m_TheAmount, m_AnAmount % (m_TheAmount + 1)));
lSpace = (long)dSpace;
if(lSpace < 0) lSpace = 0;
BitBlt(MemDC, 0, lSpace, tRect.right, tRect.bottom, MemDC2, 0, lSpace, SRCCOPY);
BitBlt(hdc, 0, 0, tRect.right, tRect.bottom, MemDC, 0, 0, SRCCOPY);
SelectObject(MemDC, OldBitmap1);
SelectObject(MemDC2, OldBitmap2);
DeleteDC(MemDC);
DeleteDC(MemDC2);
EndPaint(g_xMainWnd.GetSafehWnd(), &PaintStruct);
InvalidateRect(g_xMainWnd.GetSafehWnd(), &tRect, FALSE);
}
VOID CPatch::InitPatch(VOID)
{
int Width,Height;
LONG Left,Top;
LONG tWidth,tHeight;
RECT rcWork;
DWORD dwFrameWidth;
DWORD dwFrameHeight;
DWORD dwMenuHeight;
FILE* HFile;
char szDirStr[MAX_PATH];
char szFileName[MAX_PATH];
char szTemp[MAX_PATH];
FileListHeader FLHeader;
m_ppFilesData = NULL;
m_bEndPatch = TRUE;
m_bPatched = FALSE;
m_PatchState = 0; // Start
Width = 479;
Height = 359;
dwMenuHeight = 0;
dwFrameHeight = 0;
dwFrameWidth = 0;
// 官帕拳搁狼 RECT甫 备茄促.
SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0);
// 泅力 汲沥等 Window狼 Rect甫 焊粮
tWidth =g_xMainWnd.m_rcWindow.right;
tHeight = g_xMainWnd.m_rcWindow.bottom;
// Window狼 (x,y)谅钎 掘扁
Left = (rcWork.right - Width) / 2;
Top = (rcWork.bottom - Height) / 2;
//Window狼 矫累 谅钎甫 汲沥
g_xMainWnd.m_rcWindow.left = Left + dwFrameWidth;
g_xMainWnd.m_rcWindow.top = Top + dwFrameHeight + dwMenuHeight;
// 官差霸瞪 window狼 Width客 Height
Width = Width + dwFrameWidth * 2;
Height = Height + dwFrameHeight * 2 + dwMenuHeight;
SetWindowPos(g_xMainWnd.GetSafehWnd(), HWND_TOP, Left, Top, Width, Height, NULL);
ShowWindow(g_xMainWnd.GetSafehWnd(), SW_SHOW);
g_xMainWnd.m_rcWindow.right = 800 + Left + dwFrameWidth;
g_xMainWnd.m_rcWindow.bottom = 600 + Top + dwFrameHeight + dwMenuHeight;
if(CheckPatchDate()) // Patch Date List Check
{
if(WillBePatch()) // Patch Data List Check
{
// 2 俺狼 Patch Check 啊 葛滴 己傍秦具父 啊瓷窍促.
m_bEndPatch = FALSE;
// 其摹啊 乐阑锭父, 捞固瘤甫 Convert 茄促.
ZeroMemory((BYTE*)&FLHeader,sizeof(FileListHeader));
HFile = NULL;
if((HFile =fopen(PATCH_LIST_FILE_LIST,"r"))==NULL)
{
m_bPatched = FALSE;
m_bEndPatch = TRUE;
fclose(HFile);
return;
};
fseek(HFile, 0, SEEK_SET);
fscanf(HFile, "%s",FLHeader.VersionDate);
fscanf(HFile, "%d",&m_FACount);
fscanf(HFile, "%ld",&m_TheAmount);
if(!jRegGetKey(_T(DEFAULT_REG_PATH), _T("setup path"), (LPBYTE)szDirStr))
{
ZeroMemory(szDirStr,MAX_PATH);
GetCurrentDirectory(MAX_PATH,szDirStr);
szDirStr[strlen(szDirStr)] = '\\';
szDirStr[strlen(szDirStr)] = NULL;
}
for ( INT nCnt = strlen(szDirStr); nCnt >= 0; nCnt--)
{
if ( szDirStr[nCnt] == '\\' )
{
szDirStr[nCnt+1] = NULL;
break;
}
}
// Update 且 Directory 甫 积己
strcat(szDirStr, "UpDate\\"); // Update Directory甫 积己
strcpy(m_UpdatePath, szDirStr); // Update Path甫 啊瘤绊 乐阑巴
CreateDirectory(szDirStr, NULL);
// Patch 沥焊甫 掘绰促.
m_ppFilesData = new UnCompressedFileNode* [m_FACount];
ZeroMemory(szFileName,MAX_PATH);
ZeroMemory(szTemp,MAX_PATH);
// 俺俺 拳老 沥焊 佬扁
for(int i = 0; i< m_FACount ;i ++)
{
m_ppFilesData[i] = new UnCompressedFileNode;
fscanf(HFile,"%s", m_ppFilesData[i]->szFileName);
fscanf(HFile,"%d", &m_ppFilesData[i]->lDirectory);
fscanf(HFile,"%s", m_ppFilesData[i]->szTargetFileName);
fscanf(HFile,"%d", &m_ppFilesData[i]->ActionMode);
fscanf(HFile,"%d", &m_ppFilesData[i]->Position);
fscanf(HFile,"%d", &m_ppFilesData[i]->lFileSize);
fscanf(HFile,"%d", &m_ppFilesData[i]->lCount);
}
fclose(HFile);
m_hLib = LoadLibrary("Pbmp.dll"); // Load Dll
if(m_hLib!=NULL)
{
m_xBmp[0] = LoadBitmap(m_hLib, MAKEINTRESOURCE(IDB_PATCH_BASE));
m_xBmp[1] = LoadBitmap(m_hLib, MAKEINTRESOURCE(IDB_PATCH_COVER));
FreeLibrary(m_hLib);
m_hLib = NULL;
}
else
{
m_xBmp[0] = NULL;
m_xBmp[1] = NULL;
}
}
}
}
BOOL CPatch::CheckPatchDate(VOID)
{
int CmpResult;
int BufferSize;
char ReadDate[9];
char LastUpdateDate[9];
char FileBuffer[4100];
DWORD dwReadLen;
DWORD dwErrNum;
FILE* HFile;
dwReadLen = 0;
BufferSize = 2048;
ZeroMemory(FileBuffer, 4100);
m_hFile = NULL;
m_hFile = CreateFile (PATCHED_LIST_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL);
if((dwErrNum=GetLastError())==ERROR_FILE_EXISTS)
{
// 拳老捞 粮犁窍搁 促矫 罐酒扼
DeleteFile(PATCHED_LIST_FILE);
m_hFile = CreateFile (PATCHED_LIST_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL);
}
m_HFileFtp = FtpOpenFile( m_HFtp, PATCHED_LIST_FILE, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
while(1) // 拳老 罐绰 何盒.
{
if (InternetReadFile( m_HFileFtp, FileBuffer, (DWORD)BufferSize, &dwReadLen) != FALSE)
{
if ( (int)dwReadLen != BufferSize )
{
BufferSize = (int)dwReadLen;
WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwReadLen, NULL);
break;
}
else
{
WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwReadLen, NULL);
}
}
else
{
break;
}
}
CloseHandle(m_hFile);
InternetCloseHandle(m_HFileFtp);
m_hFile = NULL;
m_HFileFtp = NULL;
m_PatchState = 0;
// Get Last Update Date From Reg
if(!jRegGetKey(_T(DEFAULT_REG_PATH), _T(PATCH_LAST_DATE), (LPBYTE)LastUpdateDate))
{
strcpy(LastUpdateDate,DEFAULT_LAST_PATCH_DATE); // Default Last Patch Date
}
if((HFile = fopen(PATCHED_LIST_FILE,"r")) == NULL) return FALSE;
fseek(HFile, 0L, SEEK_SET );
while(!feof( HFile ))
{
ZeroMemory(ReadDate, 9);
fread( ReadDate, sizeof( char ) * 9, 1, HFile );
// fscanf(HFile,"%8s",ReadDate);
// 佬菌栏聪鳖 厚背庆辑 贸府窍磊 ^^
ReadDate[8]=NULL;
CmpResult=strncmp(ReadDate, LastUpdateDate, 8);
if(CmpResult > 0)
{
// m_szPatchDate俊 秦寸 朝楼啊 乐澜.
fclose(HFile);
strcpy(m_szPatchDate, ReadDate);
return TRUE;
// Patch 罐酒具 窃
}
else
{
if(CmpResult == 0)
{
// Patch 罐阑 鞘夸 绝澜 促澜 朝楼 犬牢
continue;
}
else
{
// 泅力 啊瘤绊 乐绰巴捞 辑滚俊辑 瘤盔窍绰芭 焊促 弥辟 滚傈捞促 ぱ.ぱ?
// 促澜 朝楼 犬牢 ぱぱ;
continue;
}
}
}
return FALSE;
}
UnCompressedFileNode* CPatch::GetFileNode(int Pos)
{
return m_ppFilesData[Pos];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -