📄 downloaddlg.cpp.svn-base
字号:
// DownloadDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DownloadDlg.h"
#include "NetInfoDlg.h"
#include "UpgradeDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDownloadDlg dialog
HANDLE CDownloadDlg::m_hEventKillDownloadThread = NULL;
HANDLE CDownloadDlg::m_hEventDownloadThreadKilled = NULL;
BOOL CALLBACK DownloadCallback(DWORD dwCode, DWORD dwProgress,
LPCTSTR lpszMsg, void *cookie)
{
HWND hMainWnd = (HWND)cookie;
if( PROG_PROGRESS == dwCode && ::IsWindow(hMainWnd) )
{
::SendMessage( hMainWnd, WM_USER_DOWNLOAD_PROGRESS, dwProgress, (LPARAM)lpszMsg );
}
else if( ::IsWindow(hMainWnd) )
{
::SendMessage( hMainWnd, WM_USER_DOWNLOAD_MESSAGE, dwCode, (LPARAM)lpszMsg );
}
// User wants to quit program
if(WAIT_OBJECT_0 == WaitForSingleObject(CDownloadDlg::m_hEventKillDownloadThread,0) )
{
::PostMessage( hMainWnd, WM_USER_DOWNLOAD_END, FALSE, 0 );
SetEvent(CDownloadDlg::m_hEventDownloadThreadKilled);
AfxEndThread( 0, TRUE );
return FALSE;
}
return TRUE;
}
UINT DownloadMain(LPVOID pParam)
{
LPDOWNLOAD_INFO pInfo=(LPDOWNLOAD_INFO)pParam;
int nCountDay = 0;
int nCountBase = 0;
int nCountXDR = 0;
int nCountMin5 = 0;
if( pInfo->bDay )
{
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_DAY );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_PROGRESS, 0, NULL );
CSPTime tmFrom( pInfo->tmDayFrom );
CSPTime tmTo( pInfo->tmDayTo );
tmFrom = CSPTime( tmFrom.GetYear(), tmFrom.GetMonth(), tmFrom.GetDay(), 0, 0, 0 );
tmTo = CSPTime( tmTo.GetYear(), tmTo.GetMonth(), tmTo.GetDay(), 23, 59, 59 );
nCountDay = pInfo->pNetDB->NetloadDayKLine( NULL, &tmFrom, &tmTo, DownloadCallback, pInfo->hMainWnd );
}
// User wants to quit program
if(WAIT_OBJECT_0 == WaitForSingleObject(CDownloadDlg::m_hEventKillDownloadThread,0) )
{
::PostMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_END, FALSE, 0 );
SetEvent(CDownloadDlg::m_hEventDownloadThreadKilled);
AfxEndThread( 0, TRUE );
return 0;
}
if( pInfo->bBase )
{
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_BASE );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_PROGRESS, 0, NULL );
nCountBase = pInfo->pNetDB->NetloadBasetable( NULL, NULL, NULL, DownloadCallback, pInfo->hMainWnd );
}
// User wants to quit program
if(WAIT_OBJECT_0 == WaitForSingleObject(CDownloadDlg::m_hEventKillDownloadThread,0) )
{
::PostMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_END, FALSE, 0 );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_PROGRESS, 0, NULL );
SetEvent(CDownloadDlg::m_hEventDownloadThreadKilled);
AfxEndThread( 0, TRUE );
return 0;
}
if( pInfo->bXDR )
{
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_XDR );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_PROGRESS, 0, NULL );
nCountXDR = pInfo->pNetDB->NetloadDRData( NULL, NULL, NULL, DownloadCallback, pInfo->hMainWnd );
}
// User wants to quit program
if(WAIT_OBJECT_0 == WaitForSingleObject(CDownloadDlg::m_hEventKillDownloadThread,0) )
{
::PostMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_END, FALSE, 0 );
SetEvent(CDownloadDlg::m_hEventDownloadThreadKilled);
AfxEndThread( 0, TRUE );
return 0;
}
if( pInfo->bMin5 )
{
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_MIN5 );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_PROGRESS, 0, NULL );
CSPTime tmFrom( pInfo->tmMin5From );
CSPTime tmTo( pInfo->tmMin5To );
tmFrom = CSPTime( tmFrom.GetYear(), tmFrom.GetMonth(), tmFrom.GetDay(), 0, 0, 0 );
tmTo = CSPTime( tmTo.GetYear(), tmTo.GetMonth(), tmTo.GetDay(), 23, 59, 59 );
nCountMin5 = pInfo->pNetDB->Netload5MinKLine( NULL, &tmFrom, &tmTo, DownloadCallback, pInfo->hMainWnd );
}
if( pInfo->bMin5 && nCountMin5 == 0 )
{
CString strNote;
strNote.LoadString( IDS_DLMIN5_NOTSUPPORT );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_END, TRUE, (LPARAM)strNote.GetBuffer(strNote.GetLength()+1) );
strNote.ReleaseBuffer();
}
else if( pInfo->bBase && nCountBase == 0 )
{
CString strNote;
strNote.LoadString( IDS_DLBASE_NOTSUPPORT );
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_END, TRUE, (LPARAM)strNote.GetBuffer(strNote.GetLength()+1) );
strNote.ReleaseBuffer();
}
else
{
::SendMessage( pInfo->hMainWnd, WM_USER_DOWNLOAD_END, TRUE, 0 );
}
AfxEndThread( 0, TRUE );
return 0;
}
CDownloadDlg::CDownloadDlg(CWnd* pParent /*=NULL*/)
: CXFDialog(CDownloadDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDownloadDlg)
m_tmDayFrom = 0;
m_tmDayTo = 0;
m_tmMin5From = 0;
m_tmMin5To = 0;
//}}AFX_DATA_INIT
m_pDownloadInfo = NULL;
m_bDBModified = FALSE;
CSPTime tmLatestOld = 0;
if( m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) )
m_netdb.GetTimeLocalRange( &tmLatestOld, NULL, NULL );
m_tmLatestOld = tmLatestOld.GetTime();
m_bInitDownloadTime = FALSE;
m_bAutoRun = FALSE;
m_bReportFinished = TRUE;
}
CDownloadDlg::~CDownloadDlg()
{
if( m_pDownloadInfo )
{
delete m_pDownloadInfo;
m_pDownloadInfo = NULL;
}
}
void CDownloadDlg::SetInitDownloadTime( CSPTime tmDLBegin, CSPTime tmDLEnd, BOOL bAutoRun )
{
m_bInitDownloadTime = TRUE;
m_tmDLBegin = tmDLBegin;
m_tmDLEnd = tmDLEnd;
m_bAutoRun = TRUE;
}
void CDownloadDlg::DoDataExchange(CDataExchange* pDX)
{
CXFDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDownloadDlg)
DDX_Control(pDX, IDC_STATIC_LATEST, m_staticLatest);
DDX_Control(pDX, IDC_STATIC_PROGRESS, m_staticProgress);
DDX_Control(pDX, IDC_CHECK_MIN5, m_btnCheckMin5);
DDX_Control(pDX, IDC_CHECK_REPORT, m_btnCheckReport);
DDX_Control(pDX, IDC_PROXY_SET, m_btnProxySet);
DDX_Control(pDX, IDCANCEL, m_btnCancel);
DDX_Control(pDX, IDC_STATIC_STATUS, m_staticStatus);
DDX_Control(pDX, IDOK, m_btnOK);
DDX_Control(pDX, IDC_STOP_REFRESH, m_btnStopRefresh);
DDX_Control(pDX, IDC_STOP, m_btnStop);
DDX_Control(pDX, IDC_REFRESH_SERVERS, m_btnRefreshServers);
DDX_Control(pDX, IDC_CHECK_XDR, m_btnCheckXDR);
DDX_Control(pDX, IDC_CHECK_DAY, m_btnCheckDay);
DDX_Control(pDX, IDC_CHECK_BASE, m_btnCheckBase);
DDX_Control(pDX, IDC_TIME_DAYTO, m_dtctrlDayTo);
DDX_Control(pDX, IDC_TIME_DAYFROM, m_dtctrlDayFrom);
DDX_Control(pDX, IDC_DL_PROGRESS, m_ctrlProgress);
DDX_Control(pDX, IDC_STATIC_REFRESH, m_staticRefreshServer);
DDX_Control(pDX, IDC_COMBO_SERVERS, m_comboServers);
DDX_DateTimeCtrl(pDX, IDC_TIME_DAYFROM, m_tmDayFrom);
DDX_DateTimeCtrl(pDX, IDC_TIME_DAYTO, m_tmDayTo);
DDX_DateTimeCtrl(pDX, IDC_TIME_MIN5FROM, m_tmMin5From);
DDX_DateTimeCtrl(pDX, IDC_TIME_MIN5TO, m_tmMin5To);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDownloadDlg, CXFDialog)
//{{AFX_MSG_MAP(CDownloadDlg)
ON_BN_CLICKED(IDC_REFRESH_SERVERS, OnRefreshServers)
ON_BN_CLICKED(IDC_STOP_REFRESH, OnStopRefresh)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_NOTIFY(NM_SETFOCUS, IDC_TIME_DAYFROM, OnSetfocusTimeDay)
ON_BN_CLICKED(IDC_PROXY_SET, OnProxySet)
ON_NOTIFY(NM_SETFOCUS, IDC_TIME_DAYTO, OnSetfocusTimeDay)
ON_NOTIFY(NM_SETFOCUS, IDC_TIME_MIN5FROM, OnSetfocusTimeMin5)
ON_NOTIFY(NM_SETFOCUS, IDC_TIME_MIN5TO, OnSetfocusTimeMin5)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_USER_DOWNLOAD_MESSAGE, OnDownloadMessage)
ON_MESSAGE(WM_USER_DOWNLOAD_PROGRESS, OnDownloadProgress)
ON_MESSAGE(WM_USER_DOWNLOAD_END, OnDownloadEnd)
ON_MESSAGE(WM_APP_STKRECEIVER_DATA, OnStkReceiverData)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDownloadDlg message handlers
BOOL CDownloadDlg::OnInitDialog()
{
CXFDialog::OnInitDialog();
// TODO: Add extra initialization here
m_staticRefreshServer.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_HIDEWINDOW);
m_staticStatus.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_HIDEWINDOW);
m_ctrlProgress.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_HIDEWINDOW);
m_btnStopRefresh.EnableWindow( FALSE );
m_btnStop.EnableWindow( FALSE );
InitComboServers();
m_ctrlProgress.SetRange( 0, STKLIB_MAX_PROGRESS );
m_ctrlProgress.SetPos( 0 );
m_btnCheckReport.SetCheck( AfxGetStkReceiver().NetEngineIsWorking() );
m_btnCheckReport.EnableWindow( AfxGetStkReceiver().NetEngineIsWorking() );
m_btnCheckDay.SetCheck( TRUE );
// Set Time
CSPTime tmCurrent = CSPTime::GetCurrentTime();
if( tmCurrent.GetHour() < 15 )
tmCurrent -= CSPTimeSpan(1,0,0,0);
if( tmCurrent.GetMonth() == 1 && tmCurrent.GetDay() == 1 )
tmCurrent -= CSPTimeSpan(1,0,0,0);
if( tmCurrent.GetMonth() == 5 && tmCurrent.GetDay() == 1 )
tmCurrent -= CSPTimeSpan(1,0,0,0);
if( tmCurrent.GetMonth() == 10 && tmCurrent.GetDay() == 1 )
tmCurrent -= CSPTimeSpan(1,0,0,0);
if( tmCurrent.GetDayOfWeek() == 1 )
tmCurrent -= CSPTimeSpan(2,0,0,0);
if( tmCurrent.GetDayOfWeek() == 7 )
tmCurrent -= CSPTimeSpan(1,0,0,0);
m_tmDayFrom = m_netdb.GetTimeInitial().GetTime();
m_tmDayTo = tmCurrent;
m_tmMin5From = m_tmMin5To = tmCurrent;
CSPTime tmLatest;
if( m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB )
&& m_netdb.GetTimeLocalRange( &tmLatest, NULL, NULL ) )
{
CString strTimeLatest = (LPCTSTR)AfxGetTimeString( tmLatest.GetTime(), "%Y-%m-%d", TRUE ); //tmLatest.Format( "%Y-%m-%d,%A" );
m_staticLatest.SetWindowText( strTimeLatest );
m_tmDayFrom = CSPTime(tmLatest.GetTime()) + CSPTimeSpan(1,0,0,0 );
if( m_tmDayFrom.GetMonth() == 1 && m_tmDayFrom.GetDay() == 1 )
m_tmDayFrom += CSPTimeSpan(1,0,0,0);
if( m_tmDayFrom.GetMonth() == 5 && m_tmDayFrom.GetDay() == 1 )
m_tmDayFrom += CSPTimeSpan(1,0,0,0);
if( m_tmDayFrom.GetMonth() == 10 && m_tmDayFrom.GetDay() == 1 )
m_tmDayFrom += CSPTimeSpan(1,0,0,0);
if( m_tmDayFrom.GetDayOfWeek() == 1 )
m_tmDayFrom += CSPTimeSpan(1,0,0,0);
if( m_tmDayFrom.GetDayOfWeek() == 7 )
m_tmDayFrom += CSPTimeSpan(2,0,0,0);
if( m_tmDayFrom > m_tmDayTo )
m_tmDayTo = m_tmDayFrom;
}
// Initial Download
if( m_bInitDownloadTime )
{
m_tmDayFrom = m_tmDLBegin;
m_tmDayTo = m_tmDLEnd;
}
UpdateData( FALSE );
if( m_bAutoRun )
{
UpdateWindow( );
ShowWindow( SW_SHOW );
OnOK( );
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDownloadDlg::InitComboServers( )
{
for( int i=m_comboServers.GetCount()-1; i>=0; i-- )
m_comboServers.DeleteString(i);
CString strMain = AfxGetProfile().GetMainServer();
m_comboServers.AddString( strMain );
CSPStringArray & astr = AfxGetProfile().GetDownloadServers();
for( int i=0; i<astr.GetSize(); i++ )
{
if( 0 != strMain.CompareNoCase((LPCTSTR)astr.ElementAt(i)) )
m_comboServers.AddString( (LPCTSTR)astr.ElementAt(i) );
}
m_comboServers.SelectString( 0, AfxGetProfile().GetDefaultServer() );
}
BOOL CDownloadDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CXFDialog::PreTranslateMessage(pMsg);
}
void CDownloadDlg::OnOK()
{
UpdateData( );
// clear error pac msg
m_astrErrorPac.RemoveAll();
// disable and enble buttons
m_btnOK.EnableWindow( FALSE );
m_btnCancel.EnableWindow( FALSE );
m_btnProxySet.EnableWindow( FALSE );
m_btnRefreshServers.EnableWindow( FALSE );
m_btnStop.EnableWindow( TRUE );
BOOL bOK = TRUE;
// Set Message
SendMessage( WM_USER_DOWNLOAD_MESSAGE, PROG_NEWGROUP, IDS_DLMSG_CONNECTING );
m_staticStatus.SetWindowPos( NULL, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_SHOWWINDOW);
MSG msg;
while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE) )
AfxGetApp()->PumpMessage();
// set server info
if( bOK && !m_netdb.SetRootPath( AfxGetProfile().GetSelfDBPath(), IStStore::dbtypeSelfDB ) )
{
AfxMessageBox( IDS_ROOTPATH_ERROR, MB_OK | MB_ICONINFORMATION );
bOK = FALSE;
}
CString strServer;
m_comboServers.GetWindowText( strServer );
CDownloadServer server;
if( !server.FromString( strServer ) )
{
AfxMessageBox( IDS_NOSERVER_DEFINED, MB_OK | MB_ICONINFORMATION );
bOK = FALSE;
}
AfxGetProfile().SetDefaultServer( strServer );
if( bOK && !m_netdb.SetServer( server.m_strAddress, server.m_nPort ) )
{
AfxMessageBox( IDS_NOSERVER_DEFINED, MB_OK | MB_ICONINFORMATION );
bOK = FALSE;
}
// set access type
if( bOK && !m_netdb.SetAccessType( AfxGetQSProfile().GetAccessType(), AfxGetQSProfile().GetProxyType(),
AfxGetQSProfile().GetProxyAddress(), AfxGetQSProfile().GetProxyPort(),
AfxGetQSProfile().GetProxyUser(), AfxGetQSProfile().GetProxyPasswd() ) )
{
AfxMessageBox( IDS_NOSERVER_DEFINED, MB_OK | MB_ICONINFORMATION );
bOK = FALSE;
}
// login
if( bOK && !m_netdb.Login( AfxGetSView().GetS(), AfxGetSView().GetU(),
NULL, AfxGetProfile().GetVersion() ) )
{
char szErr[1024];
if( m_netdb.GetLastErrorMessage(szErr,1023) )
AfxMessageBox( szErr, MB_OK | MB_ICONINFORMATION );
else
AfxMessageBox( IDS_LOGIN_FAILED, MB_OK | MB_ICONINFORMATION );
bOK = FALSE;
}
// load package info
if( bOK && ! m_netdb.NetloadPackageInfo( NULL, NULL ) )
{
char szErr[1024];
if( m_netdb.GetLastErrorMessage(szErr,1023) )
AfxMessageBox( szErr, MB_OK | MB_ICONINFORMATION );
else
AfxMessageBox( IDS_DOWNLOAD_FAILED, MB_OK | MB_ICONINFORMATION );
bOK = FALSE;
}
if( bOK )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -