📄 mhautopatchdlg.cpp
字号:
// MHAutoPatchDlg.cpp : implementation file
//
#include "stdafx.h"
#include <process.h>
#include "../4DyuchiGXGFunc/global.h"
#include "../4dyuchiGRX_common/IExecutive.h"
#include "MHAutoPatch.h"
#include "MHAutoPatchDlg.h"
#include "RainFTP_TypeDefine.h"
#include "MHAutoPatchDefines.h"
#include "StrClass.h"
#include "DirectoryName.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL g_bUsingEnginePack = TRUE;
BOOL bProcessing;
DWORD PackingProcess = 0;
BOOL bConnecting = FALSE;
DWORD dwFileSizeMax = 0;
char szOldestFile[256];
Connect_data cd;
Directory_data dd;
List_data ld_newversion;
List_data ld_zip;
File_data fd_newversion;
File_data fd_zip;
/////////////////////////////////////////////////////////////////////////////
// CMHAutoPatchDlg dialog
HWND CMHAutoPatchDlg::m_sHWnd = NULL;
CMHAutoPatchDlg::CMHAutoPatchDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMHAutoPatchDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMHAutoPatchDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bCanStart = FALSE;
m_hBmpMain = NULL;
m_hBmpTitle = NULL;
m_hBmpNBtn = NULL;
m_hBmpNBtnPress = NULL;
m_hBmpEBtn = NULL;
m_hBmpEBtnPress = NULL;
m_hBmpCB = NULL;
m_hBmpCBCheck = NULL;
m_bWindowModeChecked = FALSE;
}
void CMHAutoPatchDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMHAutoPatchDlg)
#ifdef _FOR_CLIENT_
DDX_Control(pDX, IDC_STC_MAINTITLE, m_picMain);
DDX_Control(pDX, IDC_TXT_HOMEPAGE, m_txtHomepage);
DDX_Control(pDX, IDC_TXT_REGIST, m_txtJoin);
DDX_Control(pDX, IDC_TXT_START, m_txtStart);
DDX_Control(pDX, IDC_TXT_BBS, m_txtBBS);
DDX_Control(pDX, IDC_PIC_TITLE, m_picTitle);
DDX_Control(pDX, IDOK, m_btnOK);
DDX_Control(pDX, IDC_REGIST, m_btnRegist);
DDX_Control(pDX, IDC_WINDOWMODE, m_btnWindowMode);
DDX_Control(pDX, IDC_HOMEPAGE, m_btnHomepage);
DDX_Control(pDX, IDC_BBS, m_btnBBS);
DDX_Control(pDX, IDC_STC_WINDOWMODE, m_stcWindowMode);
#endif
DDX_Control(pDX, IDCANCEL, m_btnCancel);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMHAutoPatchDlg, CDialog)
//{{AFX_MSG_MAP(CMHAutoPatchDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
#ifdef _FOR_CLIENT_
ON_WM_DRAWITEM()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_HOMEPAGE, OnHomepage)
ON_BN_CLICKED(IDC_REGIST, OnRegist)
ON_BN_CLICKED(IDC_BBS, OnBBS)
#endif
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMHAutoPatchDlg message handlers
BOOL CMHAutoPatchDlg::OnInitDialog()
{
// DeleteFile(g_szMHpatchFile);
#ifndef _MANUAL_PATCH_
DeleteFile("MHManualPatch.exe");
#endif
#ifdef _FOR_CLIENT_
DeleteFile("distributeserver.exe");
DeleteFile("agentserver.exe");
DeleteFile("mapserver.exe");
DeleteFile(".\\Sound\\BGM\\bg_nanju.MP3");
DeleteFile(".\\Sound\\BGM\\bg_gaebong.MP3");
DeleteFile(".\\Sound\\BGM\\bg_redwall.MP3");
#endif
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
m_nRetryCount = 0;
#ifdef _FOR_CLIENT_
SetWindowText( "DarkStoryOnline" );
int iX = GetSystemMetrics( SM_CXSCREEN );
int iY = GetSystemMetrics( SM_CYSCREEN );
int cx = 600;
int cy = 300;
SetWindowPos( NULL, ( iX - cx ) / 2, ( iY - cy ) / 2, cx, cy, SWP_NOZORDER );
m_BGMManager.CreateSound( m_hWnd );
//===============================
//controls' Setting & Positioning
//皋牢促捞倔肺弊 农扁 & 困摹
//橇肺弊饭胶官 农扁 & 困摹
//
SelectTitlePicture();
DWORD dwStyle = 0;
dwStyle = GetClassLong( m_btnOK.m_hWnd, GCL_STYLE );
dwStyle &= ~CS_DBLCLKS;
SetClassLong( m_btnOK.m_hWnd, GCL_STYLE, dwStyle );
dwStyle = GetClassLong( m_btnCancel.m_hWnd, GCL_STYLE );
dwStyle &= ~CS_DBLCLKS;
SetClassLong( m_btnCancel.m_hWnd, GCL_STYLE, dwStyle );
dwStyle = GetClassLong( m_btnRegist.m_hWnd, GCL_STYLE );
dwStyle &= ~CS_DBLCLKS;
SetClassLong( m_btnRegist.m_hWnd, GCL_STYLE, dwStyle );
dwStyle = GetClassLong( m_btnHomepage.m_hWnd, GCL_STYLE );
dwStyle &= ~CS_DBLCLKS;
SetClassLong( m_btnHomepage.m_hWnd, GCL_STYLE, dwStyle );
DWORD dwBStyle = m_btnWindowMode.GetButtonStyle();
dwBStyle |= BS_OWNERDRAW;
dwBStyle |= BS_CHECKBOX;
m_btnWindowMode.SetButtonStyle(dwBStyle);
int bottom = 300;
int right = 600;
bottom -= 20;
right -= 20;
m_btnCancel.SetWindowPos( NULL, right, bottom, 17, 17, SWP_NOZORDER );
right -= 95;
m_btnOK.SetWindowPos( NULL, right, bottom, 85, 17, SWP_NOZORDER );
#ifndef _FOR_CHINA_
m_txtStart.SetWindowText( "霸烙立加" ); //捞巴档 唱吝俊 颇老肺 哗绰霸 炒摆促..
#else
m_txtStart.SetLogFont( "宋体", 12, GB2312_CHARSET );
m_txtStart.SetWindowText( "进入游戏" );
#endif
m_txtStart.SetWindowPos( NULL, right + 11, bottom + 4, 85 - 20, 17 - 2, SWP_NOZORDER );
m_txtStart.SetFontColor( RGB( 100, 100, 100 ) );
#ifdef _FOR_CHINA_
right -= 90;
m_btnBBS.SetWindowPos( NULL, right, bottom, 85, 17, SWP_NOZORDER );
m_txtBBS.SetLogFont( "宋体", 12, GB2312_CHARSET );
m_txtBBS.SetWindowText( "登录论坛" );
m_txtBBS.SetWindowPos( NULL, right + 11, bottom + 4, 85 - 20, 17 - 2, SWP_NOZORDER );
m_btnBBS.ShowWindow( SW_SHOW );
m_txtBBS.ShowWindow( SW_SHOW );
#endif
right -= 90;
m_btnHomepage.SetWindowPos( NULL, right, bottom, 85, 17, SWP_NOZORDER );
#ifndef _FOR_CHINA_
m_txtHomepage.SetWindowText( "权其捞瘤" );
#else
m_txtHomepage.SetLogFont( "宋体", 12, GB2312_CHARSET );
m_txtHomepage.SetWindowText( "官方网站" );
#endif
m_txtHomepage.SetWindowPos( NULL, right + 11, bottom + 4, 85 - 20, 17 - 2, SWP_NOZORDER );
right -= 90;
m_btnRegist.SetWindowPos( NULL, right, bottom, 85, 17, SWP_NOZORDER );
#ifndef _FOR_CHINA_
m_txtJoin.SetWindowText( "雀盔啊涝" );
#else
m_txtJoin.SetLogFont( "宋体", 12, GB2312_CHARSET );
m_txtJoin.SetWindowText( "注册会员" );
#endif
m_txtJoin.SetWindowPos( NULL, right + 11, bottom + 4, 85 - 20, 17 - 5, SWP_NOZORDER );
#ifndef _FOR_CHINA_
right -= 90;
m_btnWindowMode.SetWindowPos( NULL, right, bottom, 17, 17, SWP_NOZORDER );
// m_stcWindowMode.SetFontColor( RGB( 220, 220, 0 ) );
m_stcWindowMode.SetWindowText( "芒葛靛" );
m_stcWindowMode.SetWindowPos( NULL, right+18, bottom+4, 60, 17, SWP_NOZORDER );
#endif
m_pHtmlViewNotice = new CHtmlViewNotice;
// m_pHtmlViewNotice->Create( NULL, NULL, WS_CHILD, CRect( 120, 187, 120+477, 189+85 ), this, 1 );
m_pHtmlViewNotice->Create( NULL, NULL, WS_CHILD, CRect( 120, 196, 120+477, 196+67 ), this, 1 );
// char curDir[MAX_PATH];
// char filepath[MAX_PATH];
// GetCurrentDirectory( MAX_PATH, curDir );
// wsprintf( filepath, "file:///%s\\ini\\test.html", curDir );
// m_pHtmlViewNotice->Navigate2( filepath );
#ifndef _FOR_CHINA_
m_pHtmlViewNotice->Navigate2( "http://www.darkstoryonline.com/main_pop/content.asp" );
#else
m_pHtmlViewNotice->Navigate2( "www.moxiang.com.cn/news/notice.asp" );
#endif
m_pProgressBar = new CSkinProgressBar;
m_pProgressBar->Create( WS_CHILD | WS_VISIBLE, CRect(122, 172, 581, 172+6), this, 2 );
m_pProgressBar->SetRange( 0, 255 );
m_pProgressBar->SetPos( 0 );
m_pProgressBar->SetStep( 8 );
m_pStatus = new CSkinStatic;
#ifndef _FOR_CHINA_
m_rcStatus.SetRect( 4, 167, 4+116, 167+15 );
m_pStatus->Create( "Checking Version", WS_CHILD | WS_VISIBLE | SS_CENTER, m_rcStatus, this, 3 );
m_pStatus->SetLogFont( "Arial", 11, DEFAULT_CHARSET );
#else
m_rcStatus.SetRect( 4, 169, 4+116, 169+15 );
m_pStatus->Create( "正在检查版本", WS_CHILD | WS_VISIBLE | SS_CENTER, m_rcStatus, this, 3 );
m_pStatus->SetLogFont( "宋体", 12, GB2312_CHARSET );
#endif
#else //_FOR_CLIENT_
SetWindowText( "DarkStoryOnline" );
int iX = GetSystemMetrics( SM_CXSCREEN );
int iY = GetSystemMetrics( SM_CYSCREEN );
RECT rt;
GetClientRect( &rt );
int cx = rt.right - rt.left;
int cy = rt.bottom - rt.top + GetSystemMetrics( SM_CYCAPTION );
SetWindowPos( NULL, ( iX - cx ) / 2, ( iY - cy ) / 2, cx, cy, SWP_NOZORDER );
SetStatusText( "Checking Version" );
CProgressCtrl* pPGCtrl = (CProgressCtrl*)GetDlgItem(IDC_PROGRESS_PATCH);
pPGCtrl->SetRange( 0, 255 );
pPGCtrl->SetPos( 0 );
pPGCtrl->SetStep( 8 );
#endif
//==================
// TODO: Add extra initialization here
m_sHWnd = m_hWnd;
//-------------
FILE* fp = fopen("../DeveloperWorking/_DONOTUSEENGINEPACK","r");
if(fp)
{
g_bUsingEnginePack = FALSE;
fclose(fp);
}
if(g_bUsingEnginePack)
Clear3DData();
LoadOption();
//烙矫!!!!!
#ifdef _MANUAL_PATCH_
FILE* fporn = fopen( g_szMHpatchFile, "r" );
if( fporn != NULL )
{
fclose( fporn );
Pack_N_Extract();
}
else
{
SetReadyToStart();
}
return TRUE;
#endif
//
//================
// Connect to FTP
//================
// FM_CONNECTED
cd.pvExcuteContext = (PVOID)FM_CONNECTED;
cd.bPassiveMode = TRUE;
lstrcpy( cd.szServerName, &g_FTPIp[g_nCurFTPNum*URL_LENGTH] );
cd.wServerPort = g_FTPPort[g_nCurFTPNum];
lstrcpy( cd.szUserName, g_FTPID );
lstrcpy( cd.szUserPassword, g_FTPPW);
iR = g_pFtp->Initialize( m_hWnd, WM_RAIN_FTP_NOTIFY, 1);
g_hSession = g_pFtp->CreateSession();
if( g_hSession == NULL )
{
QuitPatchDialog( TRUE );
return FALSE;
}
iR = g_pFtp->Connect( g_hSession, &cd);
bConnecting = TRUE;
m_bVersionChecking = FALSE;
//-------------
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMHAutoPatchDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMHAutoPatchDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMHAutoPatchDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
#ifdef _FOR_CLIENT_
if( m_pHtmlViewNotice )
{
m_pHtmlViewNotice->DestroyWindow();
delete m_pHtmlViewNotice;
m_pHtmlViewNotice = NULL;
}
if( m_pProgressBar )
{
m_pProgressBar->DestroyWindow();
delete m_pProgressBar;
m_pProgressBar = NULL;
}
if( m_pStatus )
{
m_pStatus->DestroyWindow();
delete m_pStatus;
m_pStatus = NULL;
}
m_BGMManager.StopBGM();
m_BGMManager.ReleaseSound();
#endif
CDialog::OnClose();
}
BOOL CMHAutoPatchDlg::Clear3DData()
{
char CurDir[MAX_PATH];
CStrClass datafolder = "3DData\\";
GetCurrentDirectory(MAX_PATH,CurDir);
BOOL bSD = SetCurrentDirectory("3ddata");
if(bSD == FALSE)
return TRUE;
CDirectoryName dirname(NULL,NULL);
dirname.LoadChild();
SetCurrentDirectory(CurDir);
dirname.SetPositionHead();
DWORD kind;
CStrClass filename;
CStrClass tname;
dirname.SetPositionHead();
while((kind=dirname.GetNextFileName(&filename)) != GETNEXTFILENAME_END)
{
if(kind != GETNEXTFILENAME_FILE)
continue;
if(filename == "")
continue;
tname = datafolder + filename;
BOOL rt = DeleteFile(tname);
}
dirname.SetPositionHead();
while((kind=dirname.GetNextFileName(&filename)) != GETNEXTFILENAME_END)
{
if(kind != GETNEXTFILENAME_DIRECTORY)
continue;
tname = datafolder + filename;
RemoveDirectory(tname);
}
RemoveDirectory(datafolder);
return TRUE;
}
LRESULT CMHAutoPatchDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch( message )
{
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 )
{
//----------------
//Error Check Code
// char temp[256];
// sprintf(temp,"CE_ERROR %u %d",*((DWORD*)pvdata),*((DWORD*)pvdata + 1));
// MessageBox( temp );
//----------------
if( *((DWORD*)pvdata + 1) != CE_SHUTDOWN_WININET )
return TRUE;
if( m_nRetryCount < g_nFTPCount*2 - 1 ) //犁矫档
{
cd.bPassiveMode = !cd.bPassiveMode; //passive mode 函版
if( m_nRetryCount % 2 == 1 ) //FTP 函版
{
++g_nCurFTPNum;
if( g_nCurFTPNum >= g_nFTPCount )
g_nCurFTPNum = 0;
lstrcpy( cd.szServerName, &g_FTPIp[g_nCurFTPNum*URL_LENGTH] );
cd.wServerPort = g_FTPPort[g_nCurFTPNum];
}
//----------------
//Error Check Code
// char temp[256];
// sprintf(temp,"Retry-%d : Passive-%d", m_nRetryCount+1, cd.bPassiveMode );
// MessageBox( temp );
//----------------
cd.pvExcuteContext = (PVOID)FM_CONNECTED;
iR = g_pFtp->Connect( g_hSession, &cd);
bConnecting = TRUE;
m_bVersionChecking = FALSE;
++m_nRetryCount;
return TRUE;
}
if( bConnecting == TRUE )
{
// Connect Fail
MessageBox( "Failed to Connect to Server", g_szMBErrCap, MB_OK );
QuitPatchDialog(TRUE);
return TRUE;
}
if( m_bVersionChecking )
{
MessageBox( "Now Uploading Patch Files. Try Again Later.", g_szMBErrCap );
QuitPatchDialog(TRUE);
return TRUE;
}
MessageBox( "Disconnected with Server", g_szMBErrCap, MB_OK );
QuitPatchDialog(TRUE);
return TRUE;
//------ checking error code ------------
// char temp[256];
// sprintf(temp,"CE_ERROR %u %d",*((DWORD*)pvdata),*((DWORD*)pvdata + 1));
// MessageBox( temp );
//---------------------------------------
//---------------------------------------
/*
if( *((DWORD*)pvdata + 1) != CE_SHUTDOWN_WININET )
return TRUE;
if( m_bVersionChecking )
{
MessageBox( "Now Uploading Patch Files. Try Again Later.", g_szMBErrCap );
QuitPatchDialog(TRUE);
return TRUE;
}
FILE* fporn = fopen( MH_VERSION_INFO_FILE, "r+" );
if(fporn == NULL)
{
MessageBox( "Failed to Open Version File", g_szMBErrCap, MB_OK );
QuitPatchDialog( TRUE );
return FALSE;
}
char Version[64];
fscanf( fporn, "%s", Version );
strcpy( Version+VERSION_HEADER_TEXT_LENGTH, "00000000" );
fseek( fporn, SEEK_SET, 0 );
fprintf( fporn, "%s", Version );
fclose(fporn);
wsprintf( MHFile, "%s.zip", Version ); //罐阑 zip颇老 背眉
cd.pvExcuteContext = (PVOID)FM_CONNECTED;
iR = g_pFtp->Connect( g_hSession, &cd);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -