⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autopatchdlg.cpp

📁 墨香最新私服
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// AutoPatchDlg.cpp : implementation file
//

#include "stdafx.h"
#include "corumautopatch.h"
#include "AutoPatchDlg.h"

#include "CorumAutopatch.h"
#include <commctrl.h>
#include "DirectoryName.h"
#include <process.h>
#include "ServerGroupSelectDlg.h"

#include "../4dyuchiGRX_common/IRenderer.h"
#include "../4DyuchiGXGFunc/global.h"
#include "../4dyuchiGRX_common/IExecutive.h"
#include "../4dyuchiGRX_myself97_util/MouseLib.h"

WIN32_FIND_DATA*		pwfd				= NULL;
int						iR;
HMODULE					g_hDllModule		= NULL;
IRainFTP*				g_pFtp				= NULL;
//////////////////////////////////////////////////
//
Connect_data		cd;
Directory_data		dd;
List_data			ld_newversion;
List_data			ld_zip;
File_data			fd_newversion;
File_data			fd_zip;


I4DyuchiGXExecutive* g_pExecutive = NULL;
HANDLE					g_hSession			= NULL;
HMODULE        g_hExecutiveHandle = NULL;
BOOL bProcessing;
DWORD PackingProcess = 0;
BOOL bConnecting = FALSE;
DWORD dwFileSizeMax = 0;


char g_FTPID[256] = {0,};
char g_FTPPW[256] = {0,};

char newverFilename[256];


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAutoPatchDlg dialog


CAutoPatchDlg::CAutoPatchDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAutoPatchDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAutoPatchDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CAutoPatchDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAutoPatchDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAutoPatchDlg, CDialog)
	//{{AFX_MSG_MAP(CAutoPatchDlg)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAutoPatchDlg message handlers



HWND g_HDlgFTP_DownLoader = NULL;

BOOL g_bUsingEnginePack = TRUE;

HWND		hPro_DN;
HWND		hPro_EX;
HWND		hWnd;

DWORD		dwContext;
DWORD		dwCompletion;
BOOL		bReturn;
DWORD		dwReturn;

static DWORD			dwSession;

int		iX,iY;
RECT	rcDlg;

//	PROGRESS BAR
DWORD		dwProLv;
//	Cancel, Exit 滚瓢.
static BOOL	bExit = FALSE;
//	Remained Time Status
static DWORD dwRtStatus = 0;
//	滚傈 佬绢辑 崔肺弊俊 嘛阑锭..
char szVersion[MAX_PATH];

char g_FTPIp[128];
WORD g_FTPPort;
char g_ExecutableFileName[MAX_PATH];

#define FTP_INFO_FILE "FTPInfo.mfi"
char	g_szOldestFile[256];

void Pack3DData(void* p);

BOOL SaveFileList();

INT_PTR CALLBACK Autopatch(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{	
	switch (message)
	{
	case WM_INITDIALOG:
		{
			OnInitDialog(hDlg, message, wParam, lParam);
		}
		return TRUE;

	case WM_CLOSE:
		{
//			if( m_pHtmlViewNotice )
//			{
//				delete m_pHtmlViewNotice;
//				m_pHtmlViewNotice = NULL;
//			}
		}
		break;
		
	case WM_RAIN_FTP_NOTIFY:
		{
			int			iR;
			
			HANDLE		hSession;
			PVOID		pvdata;
			hSession = g_pFtp->GetCompletionHandle();
			if( hSession == NULL )
				return TRUE;

			iR = g_pFtp->GetCompletionResult( hSession, &pvdata);
			_ASSERTE( iR == 0 );



			if( *((DWORD*)pvdata + 1) > CE_ERROR )
			{
				if( bConnecting == TRUE )
				{
					//	Connect Fail
					MessageBox_Error( "Fail to connect to Server.");
					
					bExit = TRUE;
					SetDlgItemText( hDlg, IDC_B_CANCEL, "Exit");
					Update_AS( hDlg, g_sz_Initial);
					//
					//	Connect 滚瓢 劝己拳.
					hWnd = GetDlgItem( hDlg, IDC_B_CONNECT );
					EnableWindow( hWnd, TRUE);
				}

				return TRUE;
			}

			switch( *((DWORD*)pvdata) )
			{
			case FM_CONNECTED:
				{
					OnConnected(hDlg, message, wParam, lParam, pvdata);
				}
				return TRUE;
			case FM_GET_CURRENT_DIRECTORY:
				{
					OnGetCurrentDirectory(hDlg, message, wParam, lParam, pvdata);
				}
				return TRUE;
				
			case FM_GETFILELIST:
				{
					OnGetFileList(hDlg, message, wParam, lParam, pvdata);
				}
				return TRUE;
				
			case FM_CONFIRM:
				{
					OnConfirm(hDlg, message, wParam, lParam, pvdata);
				}
				return TRUE;
				
			case FM_DOWNLOAD:
				{
					OnDownLoad(hDlg, message, wParam, lParam, pvdata);
				}
				return TRUE;
			}
		}
		break;
			
	case WM_RUNPROGRAM:
		{
			OnRunProgram(hDlg, message, wParam, lParam);
		}
		return TRUE;
		
	case WM_COMMAND:
		{
			//	Cancel, Exit 滚瓢.
			if ( LOWORD(wParam) == IDC_B_CANCEL )
			{
				if( bExit )
				{
					//	橇肺弊伐 辆丰.
					EndDialog( hDlg, 1);
					return TRUE;
				}
				
				Update_AS( hDlg, NULL );
				
				//
				//	Cancel, Exit 滚瓢 技飘.
				bExit = TRUE;
				SetDlgItemText( hDlg, IDC_B_CANCEL, "Exit");
				
				
				dwSession++;
				g_pFtp->Shutdown(g_hSession);
				
				//
				Update_AS( hDlg, g_sz_Initial);
				
				UpdateDialog_DownLoad( hDlg, FALSE);
				
				//
				//	Connect 滚瓢 劝己拳.
				hWnd = GetDlgItem( hDlg, IDC_B_CONNECT ); 
				EnableWindow( hWnd, TRUE);
				
				//	EndDialog( hDlg, 1);
				return TRUE;
			}
			return TRUE;
		}
		
		
	}	//	SWITCH END
	
    return FALSE;
}

BOOL GetFtpInfoFile( char* filename )
{
	FILE* fp = fopen(filename,"r");
	if(fp == NULL)
		return FALSE;

	fscanf(fp,"%s %d %s",&g_FTPIp,&g_FTPPort,&g_ExecutableFileName);

	fclose(fp);
	return TRUE;
}

//
//
BOOL Initialize_Ftp()
{
	HRESULT	hr;

	FILE* fp = fopen("FTPAccount.ini","r");
	if(fp)
	{
		fscanf(fp,"%s",g_FTPID);
		fscanf(fp,"%s",g_FTPPW);
		fclose(fp);
	}
	else
	{
		sprintf(g_FTPID,FTP_USERID);
		sprintf(g_FTPPW,FTP_PASSWORD);	
	}

	
	if( GetFtpInfoFile( FTP_INFO_FILE ) == FALSE)
	{
		MessageBox_Error( "Fail To Load FTPInfo File .");

		return FALSE;
	}

	//	
	DllGetClassObject_RainFTP pfLoader;

	g_hDllModule = LoadLibrary( "RainFTP.dll");
	if( g_hDllModule == NULL )
	{
		MessageBox_Info( "Fail to Load - RainFTP.dll");
		return FALSE;
	}
	
	pfLoader = (DllGetClassObject_RainFTP) GetProcAddress( g_hDllModule, "DllGetClassObject");
	hr = (*pfLoader)( CLSID_RainFTP, IID_RainFTP, (void**)&g_pFtp);
	if ( FAILED(hr) )
	{
		MessageBox_Info( "No Matching CLSID or IID.");
		return FALSE;
	}

	return TRUE;
}

void UnInitialize_Ftp()
{
	if( g_pFtp )
	{
		if( g_hSession)
			g_pFtp->CloseSession( g_hSession);

		g_pFtp->Release();
		g_pFtp = NULL;
	}

	FreeLibrary( g_hDllModule);
	
	if( g_pExecutive )
	{
		g_pExecutive->Release();
		g_pExecutive = NULL;
	}
	if( g_hExecutiveHandle )
	{
		FreeLibrary(g_hExecutiveHandle);
	}	
	delete [] pwfd;
}
//

//	滚傈 颇老 佬扁 窃荐.
BOOL GetVersionInfoFile( char* lpszVerInfoFile, char* lpszVerInfo)
{
	HANDLE	hFile;
	DWORD	dwBytesRead;
	DWORD	dwReturn;
	
	hFile = CreateFile( lpszVerInfoFile,
		GENERIC_READ,
		0,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		NULL );
	
	if( hFile == INVALID_HANDLE_VALUE )
	{
		MessageBox_Error( "Can not open Version File");
		return FALSE;
	}
	
	dwReturn = ReadFile( hFile,
		lpszVerInfo,
		VERSION_TOTAL_LENGTH,
		&dwBytesRead,
		NULL );
	
	if( !dwReturn || dwBytesRead < VERSION_TOTAL_LENGTH )
	{
		MessageBox_Error( "Version File is incorrect.");
		return FALSE;
	}
	
	CloseHandle( hFile );
	
	memcpy( lpszVerInfo + VERSION_TOTAL_LENGTH, ".zip", 4);
	
	return TRUE;
}


BOOL UpdateVersionInfoFile( char* lpszOldVerInfoFile, char* lpszNewVerInfoFile)
{
	HANDLE			hFind;
	WIN32_FIND_DATA wfd;
	BOOL			bReturn;
	
	hFind = FindFirstFile( lpszNewVerInfoFile, &wfd);
	if( hFind == INVALID_HANDLE_VALUE )
		return FALSE;
	
	bReturn = DeleteFile( lpszOldVerInfoFile);
	if( !bReturn )
	{
		MessageBox(NULL,"Failed To Delete VersionFile",0,0);
		return FALSE;
	}
	
	bReturn = MoveFile( lpszNewVerInfoFile, lpszOldVerInfoFile); // for win2000 later ==> , MOVEFILE_REPLACE_EXISTING);
	if( !bReturn )
	{
		MessageBox(NULL,"Failed To Rename VersionFile",0,0);
		return FALSE;
	}
	
	return TRUE;
}


BOOL Extract_DownloadFile( HWND hDlg, char* lpFileName)
{
	HWND	hPro_EX;
	DWORD	dwi;
	int		iMax;
	bool	bReturn;
	
	DWORD	dwProLv;
	
	g_pZip->Open( g_szCorumpatchFile, CZipArchive::zipOpen);
	iMax = g_pZip->GetCount();
	bReturn = TRUE;
	
	
	//
	//
	hPro_EX = GetDlgItem( hDlg, IDC_PROGRESS_EX);
	SendMessage( hPro_EX, PBM_SETPOS, 0, 0);
	SetDlgItemInt( hDlg, IDC_STATIC_EX1, 1, FALSE );
	SetDlgItemInt( hDlg, IDC_STATIC_EX3, iMax, FALSE );
	
	//
	//	拘绵 促捞倔肺弊 能飘费 焊捞扁.
	UpdateDialog_Extract( hDlg);
	
	
	CZipFileHeader head;
	for ( dwi = 0; (int)dwi < iMax; dwi++)
	{
		if( g_pZip->GetFileInfo( head, dwi)  == false )
		{
			bReturn = FALSE;
			break;
		}
		CZipString filename = head.GetFileName();
		SetFileAttributes(filename,FILE_ATTRIBUTE_NORMAL);
		
		if( g_pZip->ExtractFile( dwi, NULL ) == false )
		{
			bReturn = FALSE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -