forked from apex-hughin/CrimsonEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FtpTransferDialog.cpp
120 lines (93 loc) · 3.09 KB
/
FtpTransferDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// FtpTransferDialog.cpp : implementation file
//
#include "stdafx.h"
#include "cedtHeader.h"
#include "RemoteFile.h"
#include "FtpTransferDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BOOL CFtpTransferDialog::m_bDownload = TRUE;
CFtpAccount CFtpTransferDialog::m_clsFtpAccount;
CString CFtpTransferDialog::m_szRemoteFile;
CString CFtpTransferDialog::m_szLocalFile;
DWORD CFtpTransferDialog::m_dwFileSize;
BOOL CFtpTransferDialog::m_bTransferCanceledByUser = FALSE;
BOOL CFtpTransferDialog::m_bTransferCompleted = FALSE;
CFtpTransferDialog * CFtpTransferDialog::m_pActiveDialog = NULL;
CProgressCtrl * CFtpTransferDialog::m_pActiveProgressCtrl = NULL;
CWinThread * CFtpTransferDialog::m_pRunningWinThread = NULL;
/////////////////////////////////////////////////////////////////////////////
// CFtpTransferDialog dialog
CFtpTransferDialog::CFtpTransferDialog(BOOL bDownload, CFtpAccount & rAccount, LPCTSTR lpszRemoteFile, LPCTSTR lpszLocalFile, DWORD dwFileSize, CWnd* pParent /*=NULL*/)
: CDialog(CFtpTransferDialog::IDD, pParent)
{
m_bDownload = bDownload;
m_clsFtpAccount.CopyContents( rAccount );
m_szRemoteFile = lpszRemoteFile;
m_szLocalFile = lpszLocalFile;
m_dwFileSize = dwFileSize;
m_bTransferCanceledByUser = FALSE;
m_bTransferCompleted = FALSE;
m_pActiveDialog = NULL;
m_pActiveProgressCtrl = NULL;
m_pRunningWinThread = NULL;
//{{AFX_DATA_INIT(CFtpTransferDialog)
//}}AFX_DATA_INIT
}
void CFtpTransferDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFtpTransferDialog)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFtpTransferDialog, CDialog)
//{{AFX_MSG_MAP(CFtpTransferDialog)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFtpTransferDialog message handlers
BOOL CFtpTransferDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_bTransferCanceledByUser = FALSE;
m_bTransferCompleted = FALSE;
m_pActiveDialog = this;
m_pActiveProgressCtrl = (CProgressCtrl *)GetDlgItem(IDC_PROGRESS);
m_pActiveProgressCtrl->SetRange(0, 100);
m_pRunningWinThread = AfxBeginThread(TransferThreadMain, NULL);
return TRUE;
}
void CFtpTransferDialog::OnCancel()
{
m_bTransferCanceledByUser = TRUE;
CDialog::OnCancel();
}
void CFtpTransferDialog::OnDestroy()
{
m_pActiveDialog = NULL;
m_pActiveProgressCtrl = NULL;
CDialog::OnDestroy();
}
UINT CFtpTransferDialog::TransferThreadMain(LPVOID pParam)
{
if( m_bDownload ) {
m_bTransferCompleted = DownloadRemoteFile(m_clsFtpAccount, m_szRemoteFile, m_szLocalFile, TransferProgress);
} else {
m_bTransferCompleted = UploadLocalFile(m_clsFtpAccount, m_szLocalFile, m_szRemoteFile, TransferProgress);
}
// close dialog box
if( m_pActiveDialog ) m_pActiveDialog->PostMessage(WM_COMMAND, IDOK, 0L);
return 0;
}
BOOL CFtpTransferDialog::TransferProgress(UINT nTotalRead)
{
if( m_pActiveProgressCtrl ) {
if( m_dwFileSize > 0 ) m_pActiveProgressCtrl->SetPos( 100U * nTotalRead / m_dwFileSize );
else m_pActiveProgressCtrl->SetPos( 100 );
}
return ! m_bTransferCanceledByUser;
}