Patch.cpp
上传用户:cydong117
上传日期:2009-11-10
资源大小:638k
文件大小:17k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. // Patch.cpp: implementation of the CPatch class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Patch.h"
  6. #define PATCH_SECTION "PATCH_FTP"
  7. #define PATCH_VERSION "LastUpdate"
  8. #define PATCH_SETVER_NAME "FTPSerVerIP"
  9. #define PATCH_SERVER_PORT "FTPSerVerPort"
  10. #define PATCH_USER_ID "UserID"
  11. #define PATCH_USER_PASS "PassWord"
  12. #define IDB_PATCH_BASE                  109
  13. #define IDB_PATCH_COVER                 110
  14. #define DEFAULT_PATCH_SERVER "192.168.0.202" //"wemade.nefficient.co.kr"
  15. #define DEFAULT_PATCH_PORT INTERNET_DEFAULT_FTP_PORT
  16. #define DEFAULT_PATCH_UID "anonymous"
  17. #define DEFAULT_PATCH_PASS NULL
  18. #define DEFAULT_LAST_PATCH_DATE "20020120"
  19. #define DEFAULT_VERSION "20011219"
  20. #define DEFAULT_REG_PATH "SOFTWARE\WEMADE Entertainment\固福狼傈汲2ei"
  21. #define PATCH_INI_FILE_NAME "\Mir2Patch.ini"
  22. #define PATCHED_LIST_FILE "Patch.lst"
  23. #define PATCH_LIST_FILE_LIST "Mir2Patch.lst"
  24. #define PATCH_LAST_DATE "Last Patch Date"
  25. //////////////////////////////////////////////////////////////////////
  26. // Construction/Destruction
  27. //////////////////////////////////////////////////////////////////////
  28. CPatch::CPatch()
  29. {
  30. char m_szPatchServerIP[16];
  31. char FullPathFileName[MAX_PATH];
  32. m_TheAmount = 0;
  33. m_AnAmount = 0;
  34. m_PatchState = 0;
  35. m_HInet = NULL;
  36. m_HFileFtp = NULL;
  37. m_HFtp = NULL;
  38. GetCurrentDirectory(MAX_PATH,FullPathFileName);
  39.   strcat(FullPathFileName,PATCH_INI_FILE_NAME);
  40. m_Server_Port = DEFAULT_PATCH_PORT;
  41. GetPrivateProfileString(PATCH_SECTION,PATCH_SETVER_NAME,DEFAULT_PATCH_SERVER
  42. ,m_szPatchServerIP,16,FullPathFileName);
  43. m_Server_Port = GetPrivateProfileInt(PATCH_SECTION,PATCH_SERVER_PORT,m_Server_Port,FullPathFileName);
  44. GetPrivateProfileString(PATCH_SECTION,PATCH_USER_ID,DEFAULT_PATCH_UID
  45. ,m_UID,11,FullPathFileName);
  46. GetPrivateProfileString(PATCH_SECTION,PATCH_USER_PASS,DEFAULT_PATCH_PASS
  47. ,m_PASS,11,FullPathFileName);
  48. m_HInet = OpenInet("MIR2Patch");
  49. m_HFtp = ConnectInet(m_HInet,m_szPatchServerIP,m_Server_Port,m_UID,m_PASS);
  50. }
  51. CPatch::~CPatch()
  52. {
  53. for(int i = 0 ; i< m_FACount;i++)
  54. delete m_ppFilesData[i];
  55. if ( m_HFtp )
  56. {
  57. InternetCloseHandle(m_HFtp);
  58. m_HFtp = NULL;
  59. }
  60. if ( m_HInet)
  61. {
  62. InternetCloseHandle(m_HInet);
  63. m_HInet = NULL;
  64. }
  65. if(m_xBmp[0]!=NULL) DeleteObject(m_xBmp[0]);
  66. if(m_xBmp[1]!=NULL) DeleteObject(m_xBmp[1]);
  67. }
  68. short CPatch::Progress(long Total, long Current)
  69. {
  70. if( Total < Current ) return 0;
  71. return (short((Current * 100.0) / Total));
  72. }
  73. HINTERNET CPatch::OpenInet(char* name)
  74. {
  75. HINTERNET tHInet;
  76. tHInet = InternetOpen(name,INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
  77. if(tHInet == NULL)
  78. {
  79. // Error Handle
  80. }
  81. return tHInet;
  82. }
  83. HINTERNET CPatch::ConnectInet(HINTERNET hInet, char *sIP, WORD lPort, char *pID, char *pPass)
  84. {
  85. DWORD LenStr;
  86. DWORD dwErrorCode;
  87. char szErrorBuffer[512];
  88. HINTERNET thInet;
  89. thInet = InternetConnect( hInet,sIP,lPort,pID, pPass, INTERNET_SERVICE_FTP, INTERNET_FLAG_PASSIVE,0);
  90. if ( thInet == NULL )
  91. {
  92. LenStr =0;
  93. dwErrorCode =0;
  94. dwErrorCode = GetLastError();
  95. InternetGetLastResponseInfo(&dwErrorCode,szErrorBuffer,&LenStr);
  96. }
  97. return thInet;
  98. }
  99. BOOL CPatch::WillBePatch(VOID)
  100. {
  101. int CmpResult;
  102. int BufferSize;
  103. char Version[8];
  104. char szTemp[MAX_PATH];
  105. char FileBuffer[4100];
  106. DWORD dwReadLen;
  107. DWORD dwErrNum;
  108. FILE* HFile;
  109. FileListHeader FLHeader;
  110. BufferSize=0;
  111. dwReadLen = 0;
  112. BufferSize = 4100;
  113. ZeroMemory(FileBuffer,4100);
  114. m_hFile = NULL;
  115. m_hFile = CreateFile (PATCH_LIST_FILE_LIST, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  116. if((dwErrNum=GetLastError())==ERROR_FILE_EXISTS)
  117. {
  118. // 拳老捞 粮犁窍搁 促矫 罐酒扼
  119. DeleteFile(PATCH_LIST_FILE_LIST);
  120. m_hFile = CreateFile (PATCH_LIST_FILE_LIST, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  121. }
  122. // Make Update Directory from FTP
  123. m_szPatchDate[8] = '';
  124. strcpy(szTemp,m_szPatchDate);
  125. strcat(szTemp,"\");
  126. strcat(szTemp,PATCH_LIST_FILE_LIST);
  127. m_HFileFtp = FtpOpenFile( m_HFtp,szTemp, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
  128. while(1) // 拳老 罐绰 何盒.
  129. {
  130. if (InternetReadFile( m_HFileFtp, FileBuffer, (DWORD)BufferSize, &dwReadLen) != FALSE)
  131. {
  132. if ( (int)dwReadLen != BufferSize )
  133. {
  134. BufferSize = (int)dwReadLen;
  135. WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwReadLen, NULL);
  136. break;
  137. }
  138. else
  139. {
  140. WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwReadLen, NULL);
  141. }
  142. }
  143. else 
  144. {
  145. break;
  146. }
  147. }
  148. CloseHandle(m_hFile);
  149. InternetCloseHandle(m_HFileFtp);
  150. m_PatchState = 0;
  151. m_hFile = NULL;
  152. m_HFileFtp = NULL;
  153. if(!jRegGetKey(_T(DEFAULT_REG_PATH), _T(PATCH_LAST_DATE), (LPBYTE)Version))
  154. {
  155. strcpy(Version,DEFAULT_LAST_PATCH_DATE); // Default Last Patch Date
  156. }
  157. ZeroMemory(FLHeader.VersionDate,sizeof(FLHeader.VersionDate));
  158. if((HFile = fopen(PATCH_LIST_FILE_LIST,"r")) == NULL) return FALSE;
  159. fread(FLHeader.VersionDate,sizeof(char),sizeof(FLHeader.VersionDate),HFile);
  160. fclose(HFile);
  161. FLHeader.VersionDate[sizeof(FLHeader.VersionDate)] = NULL;
  162. CmpResult=strncmp(FLHeader.VersionDate, Version,8);
  163. if(CmpResult>0)
  164. {
  165. return TRUE;
  166. // Patch 罐酒具 窃
  167. }
  168. else
  169. {
  170. if(CmpResult==0)
  171. {
  172. // Patch 罐阑 鞘夸 绝澜
  173. return FALSE;
  174. }
  175. else
  176. {
  177. // 泅力 啊瘤绊 乐绰巴捞 辑滚俊辑 瘤盔窍绰芭 焊促 弥辟 滚傈捞促 ぱ.ぱ?
  178. return FALSE;
  179. }
  180. }
  181. }
  182. HRESULT CPatch::GetFtpFiles(VOID) // 咯扁俊辑 File List甫 盒籍秦辑 GetFile阑 拌加 倒妨临巴  return -1l : Error  0: End 1: Continue
  183. {
  184. static int Pos=0;
  185. char szTemp[MAX_PATH];
  186. char szDirStr[MAX_PATH];
  187. char szFileName[MAX_PATH];
  188. UnCompressedFileNode* FileNode;
  189. // 咯扁俊辑 Last Patch Date甫 掘绢具 茄促.
  190. if(m_bEndPatch != TRUE)
  191. {
  192. if(m_PatchState == 3)
  193. {
  194. m_bEndPatch = TRUE;
  195. return 0l;
  196. }
  197. else
  198. {
  199. if((m_PatchState == 2) || (m_PatchState == 0)) 
  200. {
  201. Pos ++;
  202. if(m_PatchState == 2)
  203. {
  204. if(m_hFile != NULL)   
  205. {
  206. CloseHandle(m_hFile);
  207. m_hFile = NULL;
  208. }
  209.    if(m_HFileFtp != NULL) 
  210. {
  211. InternetCloseHandle(m_HFileFtp);
  212. m_HFileFtp=NULL;
  213. }
  214. if(Pos > m_FACount)
  215. {
  216. m_PatchState = 0;
  217. m_bPatched   = TRUE;
  218. m_bEndPatch  = TRUE;
  219. return 0l;
  220. }
  221. }
  222. FileNode = GetFileNode(Pos - 1);
  223. ZeroMemory(szFileName, MAX_PATH);
  224. ZeroMemory(szTemp, MAX_PATH);
  225. DWORD dwErrNum;
  226. ZeroMemory(szDirStr, MAX_PATH);
  227. if(strcmp(FileNode->szFileName, "Mir2Patch.exe") == 0) // Patch 拳老 老 版快
  228. {
  229. DeleteFile(FileNode->szFileName);
  230. if(!jRegGetKey(_T(DEFAULT_REG_PATH), _T("setup path"), (LPBYTE)szDirStr))
  231. {
  232. ZeroMemory(szDirStr, MAX_PATH);
  233. GetCurrentDirectory(MAX_PATH, szDirStr);
  234. szDirStr[strlen(szDirStr)] ='\';
  235. szDirStr[strlen(szDirStr)] = NULL;
  236. }
  237. for ( INT nCnt = strlen(szDirStr); nCnt >= 0; nCnt--)
  238. {
  239. if ( szDirStr[nCnt] == '\' )
  240. {
  241. szDirStr[nCnt+1] = NULL;
  242. break;
  243. }
  244. }
  245. }
  246. else
  247. {
  248. strcpy(szDirStr, m_UpdatePath);
  249. }
  250. strcpy(szFileName, FileNode->szFileName);
  251. strcpy(szTemp, szDirStr);
  252. strcat(szTemp, szFileName);
  253. m_hFile = CreateFile (szTemp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  254. if((dwErrNum=GetLastError()) == ERROR_FILE_EXISTS)
  255. {
  256. // 拳老捞 捞固 粮犁 且 版快 弊 拳老狼 农扁甫 犬牢
  257. // 诀单捞飘 窍妨绰 拳老焊促 累篮 拳老狼 版快
  258. // 犁措肺 诀单捞飘 登瘤 臼篮 拳老 捞骨肺 促矫 诀单捞飘甫 罐绰促.
  259. m_hFile = CreateFile (szTemp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  260. DWORD High_FileSize;
  261. DWORD Low_FileSize;
  262. High_FileSize = 0;
  263. Low_FileSize = 0;
  264. Low_FileSize = GetFileSize(m_hFile, &High_FileSize);
  265. CloseHandle(m_hFile);
  266. m_hFile = NULL;
  267. if(Low_FileSize <= (DWORD)FileNode->lFileSize)
  268. {
  269. BOOL bResult = DeleteFile(szTemp);
  270. if (bResult)
  271. {
  272. // Success
  273. // MessageBox(NULL,"File Delete & ReCreate","Message",MB_OK); 
  274. m_hFile = CreateFile (szTemp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
  275. }
  276. else
  277. {
  278. // MessageBox(NULL,"File Delete Fail","Message",MB_OK); 
  279. // Fail 
  280. return -1l;
  281. }
  282. }
  283. }
  284. strcpy(szTemp, m_szPatchDate);
  285. strcat(szTemp, "\");
  286. strcat(szTemp, szFileName);
  287. m_HFileFtp = FtpOpenFile(m_HFtp, szTemp, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
  288. }
  289. else
  290. {
  291. FileNode = GetFileNode(Pos - 1);
  292. }
  293. strcpy(szTemp, m_szPatchDate);
  294. strcat(szTemp, "\");
  295. strcat(szTemp, szFileName);
  296. GetFile(szTemp); // 拳老 拌加 罐扁 ^^;
  297. }
  298. }
  299. else
  300. {
  301. // End Patch
  302. if(m_HFileFtp != NULL) 
  303. {
  304. InternetCloseHandle(m_HFileFtp);
  305. m_HFileFtp = NULL;
  306. }
  307. m_bPatched = TRUE;
  308. return 0l;
  309. }
  310. return 1l;
  311. }
  312. HRESULT CPatch::GetFile(char* nName)
  313. {
  314. static long CurrentSize = 0;
  315. int BufferSize;
  316. DWORD dwBytes;
  317. HANDLE hFind;
  318. char FileBuffer[4100];
  319. hFind = NULL;
  320. BufferSize = 4100;
  321. ZeroMemory(FileBuffer, 4100);
  322. if (InternetReadFile( m_HFileFtp, FileBuffer, (DWORD)BufferSize, &dwBytes) != FALSE)
  323. {
  324. m_AnAmount += dwBytes;
  325. if ( (int)dwBytes != BufferSize )
  326. {
  327. BufferSize = (int)dwBytes;
  328. WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwBytes, NULL);
  329. m_PatchState = 2;
  330. }
  331. else
  332. {
  333. WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwBytes, NULL);
  334. m_PatchState = 1;
  335. }
  336. }
  337. else
  338. {
  339. m_PatchState = 2;
  340. }
  341. return 0L;
  342. }
  343. VOID CPatch::RenderSence(INT nLoopTime)
  344. {
  345. if ( FAILED(g_xMainWnd.Present()) )
  346. {
  347. g_xMainWnd.RestoreSurfaces();
  348. }
  349. }
  350. VOID CPatch::DrawProgressImage(VOID)
  351. {
  352. long lSpace;
  353. double dSpace;
  354. int Height;
  355. int Width;
  356. RECT tRect;
  357. HDC hdc;
  358. HDC MemDC,MemDC2;
  359. HBITMAP OldBitmap1;
  360. HBITMAP OldBitmap2;
  361. BITMAP bit;
  362. PAINTSTRUCT PaintStruct;
  363. BeginPaint(g_xMainWnd.GetSafehWnd(),&PaintStruct);
  364. GetClientRect(g_xMainWnd.GetSafehWnd(),&tRect);
  365. hdc = GetDC(g_xMainWnd.GetSafehWnd());
  366. MemDC = CreateCompatibleDC(hdc);
  367. MemDC2 = CreateCompatibleDC(hdc);
  368. OldBitmap1 = (HBITMAP)SelectObject(MemDC, m_xBmp[0]);
  369. OldBitmap2 = (HBITMAP)SelectObject(MemDC2, m_xBmp[1]);
  370. GetObject(m_xBmp[0],sizeof(BITMAP), &bit);
  371. Width = bit.bmWidth;
  372. Height = bit.bmHeight;
  373. dSpace = (Height / 100.0) * (100 - Progress(m_TheAmount, m_AnAmount % (m_TheAmount + 1)));
  374. lSpace = (long)dSpace;
  375. if(lSpace < 0) lSpace = 0;
  376. BitBlt(MemDC, 0, lSpace, tRect.right, tRect.bottom, MemDC2, 0, lSpace, SRCCOPY);
  377. BitBlt(hdc, 0, 0, tRect.right, tRect.bottom, MemDC, 0, 0, SRCCOPY);
  378. SelectObject(MemDC, OldBitmap1);
  379. SelectObject(MemDC2, OldBitmap2);
  380. DeleteDC(MemDC);
  381. DeleteDC(MemDC2);
  382. EndPaint(g_xMainWnd.GetSafehWnd(), &PaintStruct);
  383. InvalidateRect(g_xMainWnd.GetSafehWnd(), &tRect, FALSE);
  384. }
  385. VOID CPatch::InitPatch(VOID)
  386. {
  387. int Width,Height;
  388. LONG Left,Top;
  389. LONG tWidth,tHeight;
  390. RECT rcWork;
  391.     DWORD dwFrameWidth;
  392.     DWORD dwFrameHeight;
  393. DWORD dwMenuHeight;
  394. FILE* HFile;
  395. char szDirStr[MAX_PATH];
  396. char szFileName[MAX_PATH];
  397. char szTemp[MAX_PATH];
  398. FileListHeader FLHeader;
  399. m_ppFilesData = NULL;
  400. m_bEndPatch = TRUE;
  401. m_bPatched = FALSE;
  402. m_PatchState = 0; // Start
  403. Width = 479;
  404. Height = 359;
  405. dwMenuHeight = 0;
  406. dwFrameHeight   = 0;
  407. dwFrameWidth    = 0;
  408. // 官帕拳搁狼 RECT甫 备茄促.
  409. SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWork, 0);
  410. // 泅力 汲沥等 Window狼 Rect甫 焊粮
  411. tWidth =g_xMainWnd.m_rcWindow.right;
  412. tHeight = g_xMainWnd.m_rcWindow.bottom;
  413. // Window狼 (x,y)谅钎 掘扁
  414. Left = (rcWork.right - Width) / 2;
  415. Top =  (rcWork.bottom - Height) / 2;
  416. //Window狼 矫累 谅钎甫 汲沥
  417. g_xMainWnd.m_rcWindow.left  = Left + dwFrameWidth;
  418. g_xMainWnd.m_rcWindow.top = Top + dwFrameHeight + dwMenuHeight;
  419. // 官差霸瞪 window狼 Width客 Height
  420. Width = Width + dwFrameWidth * 2;
  421. Height = Height + dwFrameHeight * 2 + dwMenuHeight;
  422. SetWindowPos(g_xMainWnd.GetSafehWnd(), HWND_TOP, Left, Top, Width, Height, NULL);
  423. ShowWindow(g_xMainWnd.GetSafehWnd(), SW_SHOW);
  424. g_xMainWnd.m_rcWindow.right = 800 + Left + dwFrameWidth;
  425. g_xMainWnd.m_rcWindow.bottom = 600 + Top + dwFrameHeight + dwMenuHeight;
  426. if(CheckPatchDate()) // Patch Date List Check
  427. {
  428. if(WillBePatch()) // Patch Data List Check
  429. {
  430. // 2 俺狼 Patch Check 啊 葛滴 己傍秦具父 啊瓷窍促.
  431. m_bEndPatch = FALSE;
  432. // 其摹啊 乐阑锭父, 捞固瘤甫 Convert 茄促.
  433. ZeroMemory((BYTE*)&FLHeader,sizeof(FileListHeader));
  434. HFile = NULL;
  435. if((HFile =fopen(PATCH_LIST_FILE_LIST,"r"))==NULL)
  436. {
  437. m_bPatched = FALSE;
  438. m_bEndPatch = TRUE;
  439. fclose(HFile);
  440. return;
  441. };
  442. fseek(HFile, 0, SEEK_SET);
  443. fscanf(HFile, "%s",FLHeader.VersionDate);
  444. fscanf(HFile, "%d",&m_FACount);
  445. fscanf(HFile, "%ld",&m_TheAmount);
  446. if(!jRegGetKey(_T(DEFAULT_REG_PATH), _T("setup path"), (LPBYTE)szDirStr))
  447. {
  448. ZeroMemory(szDirStr,MAX_PATH);
  449. GetCurrentDirectory(MAX_PATH,szDirStr);
  450. szDirStr[strlen(szDirStr)] = '\';
  451. szDirStr[strlen(szDirStr)] = NULL;
  452. }
  453. for ( INT nCnt = strlen(szDirStr); nCnt >= 0; nCnt--)
  454. {
  455. if ( szDirStr[nCnt] == '\' )
  456. {
  457. szDirStr[nCnt+1] = NULL;
  458. break;
  459. }
  460. }
  461. // Update 且 Directory 甫 积己 
  462. strcat(szDirStr, "UpDate\"); // Update Directory甫 积己
  463. strcpy(m_UpdatePath, szDirStr); // Update Path甫 啊瘤绊 乐阑巴 
  464. CreateDirectory(szDirStr, NULL);
  465. // Patch 沥焊甫 掘绰促.
  466. m_ppFilesData = new UnCompressedFileNode* [m_FACount];
  467. ZeroMemory(szFileName,MAX_PATH);
  468. ZeroMemory(szTemp,MAX_PATH);
  469. // 俺俺 拳老 沥焊 佬扁
  470. for(int i = 0; i< m_FACount ;i ++)
  471. {
  472. m_ppFilesData[i] = new UnCompressedFileNode;
  473. fscanf(HFile,"%s", m_ppFilesData[i]->szFileName);
  474. fscanf(HFile,"%d", &m_ppFilesData[i]->lDirectory);
  475. fscanf(HFile,"%s", m_ppFilesData[i]->szTargetFileName);
  476. fscanf(HFile,"%d", &m_ppFilesData[i]->ActionMode);
  477. fscanf(HFile,"%d", &m_ppFilesData[i]->Position);
  478. fscanf(HFile,"%d", &m_ppFilesData[i]->lFileSize);
  479. fscanf(HFile,"%d", &m_ppFilesData[i]->lCount);
  480. }
  481. fclose(HFile);
  482. m_hLib = LoadLibrary("Pbmp.dll"); // Load Dll
  483. if(m_hLib!=NULL)
  484. {
  485. m_xBmp[0] = LoadBitmap(m_hLib, MAKEINTRESOURCE(IDB_PATCH_BASE)); 
  486. m_xBmp[1] = LoadBitmap(m_hLib, MAKEINTRESOURCE(IDB_PATCH_COVER)); 
  487. FreeLibrary(m_hLib);
  488. m_hLib = NULL;
  489. }
  490. else
  491. {
  492. m_xBmp[0] = NULL;
  493. m_xBmp[1] = NULL;
  494. }
  495. }
  496. }
  497. }
  498. BOOL CPatch::CheckPatchDate(VOID)
  499. {
  500. int CmpResult;
  501. int BufferSize;
  502. char ReadDate[9];
  503. char LastUpdateDate[9];
  504. char FileBuffer[4100];
  505. DWORD dwReadLen;
  506. DWORD dwErrNum;
  507. FILE* HFile;
  508. dwReadLen = 0;
  509. BufferSize = 2048;
  510. ZeroMemory(FileBuffer, 4100);
  511. m_hFile = NULL;
  512. m_hFile = CreateFile (PATCHED_LIST_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL);
  513. if((dwErrNum=GetLastError())==ERROR_FILE_EXISTS)
  514. {
  515. // 拳老捞 粮犁窍搁 促矫 罐酒扼
  516. DeleteFile(PATCHED_LIST_FILE);
  517. m_hFile = CreateFile (PATCHED_LIST_FILE, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,NULL);
  518. }
  519. m_HFileFtp = FtpOpenFile( m_HFtp, PATCHED_LIST_FILE, GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
  520. while(1) // 拳老 罐绰 何盒.
  521. {
  522. if (InternetReadFile( m_HFileFtp, FileBuffer, (DWORD)BufferSize, &dwReadLen) != FALSE)
  523. {
  524. if ( (int)dwReadLen != BufferSize )
  525. {
  526. BufferSize = (int)dwReadLen;
  527. WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwReadLen, NULL);
  528. break;
  529. }
  530. else
  531. {
  532. WriteFile( m_hFile, FileBuffer, (DWORD)BufferSize, &dwReadLen, NULL);
  533. }
  534. }
  535. else 
  536. {
  537. break;
  538. }
  539. }
  540. CloseHandle(m_hFile);
  541. InternetCloseHandle(m_HFileFtp);
  542. m_hFile = NULL;
  543. m_HFileFtp = NULL;
  544. m_PatchState = 0;
  545. // Get Last Update Date From Reg
  546. if(!jRegGetKey(_T(DEFAULT_REG_PATH), _T(PATCH_LAST_DATE), (LPBYTE)LastUpdateDate))
  547. {
  548. strcpy(LastUpdateDate,DEFAULT_LAST_PATCH_DATE); // Default Last Patch Date
  549. }
  550. if((HFile = fopen(PATCHED_LIST_FILE,"r")) == NULL) return FALSE;
  551. fseek(HFile, 0L, SEEK_SET );
  552. while(!feof( HFile ))
  553. {
  554. ZeroMemory(ReadDate, 9);
  555. fread( ReadDate, sizeof( char ) * 9, 1, HFile );
  556. // fscanf(HFile,"%8s",ReadDate);
  557. // 佬菌栏聪鳖 厚背庆辑 贸府窍磊 ^^
  558. ReadDate[8]=NULL;
  559. CmpResult=strncmp(ReadDate, LastUpdateDate, 8);
  560. if(CmpResult > 0)
  561. {
  562. // m_szPatchDate俊 秦寸 朝楼啊 乐澜.
  563. fclose(HFile);
  564. strcpy(m_szPatchDate, ReadDate);
  565. return TRUE;
  566. // Patch 罐酒具 窃
  567. }
  568. else
  569. {
  570. if(CmpResult == 0)
  571. {
  572. // Patch 罐阑 鞘夸 绝澜 促澜 朝楼 犬牢
  573. continue;
  574. }
  575. else
  576. {
  577. // 泅力 啊瘤绊 乐绰巴捞 辑滚俊辑 瘤盔窍绰芭 焊促 弥辟 滚傈捞促 ぱ.ぱ?
  578. // 促澜 朝楼 犬牢 ぱぱ; 
  579. continue;
  580. }
  581. }
  582. }
  583. return FALSE;
  584. }
  585. UnCompressedFileNode* CPatch::GetFileNode(int Pos)
  586. {
  587. return m_ppFilesData[Pos];
  588. }