forked from svn2github/FDM
-
Notifications
You must be signed in to change notification settings - Fork 4
/
DlgDL.cpp
101 lines (78 loc) · 2.04 KB
/
DlgDL.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
/*
Free Download Manager Copyright (c) 2003-2016 FreeDownloadManager.ORG
*/
#include "stdafx.h"
#include "fdmapp.h"
#include "DlgDL.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CDlgDL::CDlgDL(CWnd* pParent )
: CDialog(CDlgDL::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgDL)
//}}AFX_DATA_INIT
m_bSucceeded = false;
m_bCancelled = false;
}
void CDlgDL::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgDL)
DDX_Control(pDX, IDC_PROGRESS, m_wndProgress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgDL, CDialog)
//{{AFX_MSG_MAP(CDlgDL)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CDlgDL::OnInitDialog()
{
CDialog::OnInitDialog();
m_dldr.CreateByUrl (m_strUrl, TRUE);
fsDownload_Properties *dp = m_dldr.GetDP ();
fsDownload_NetworkProperties *dnp = m_dldr.GetDNP ();
SAFE_DELETE_ARRAY (dp->pszFileName);
fsnew (dp->pszFileName, TCHAR, m_strFile.GetLength () + 1);
_tcscpy (dp->pszFileName, m_strFile);
dp->uMaxSections = 1;
dp->uMaxAttempts = 1;
dp->dwFlags |= DPF_DONTRESTARTIFNORESUME;
dp->enSCR = SCR_STOP;
dp->enAER = AER_REWRITE;
*dp->pszAdditionalExt = 0;
SAFE_DELETE_ARRAY (dnp->pszReferer);
fsnew (dnp->pszReferer, TCHAR, 1);
*dnp->pszReferer = 0;
m_dldr.StartDownloading ();
SetTimer (1, 200, NULL);
SetDlgItemText (IDC__MSG, m_strDlName);
SetWindowText (LS (L_PLEASEWAIT));
return TRUE;
}
void CDlgDL::OnTimer(UINT nIDEvent)
{
if (nIDEvent == 1)
{
if (m_dldr.IsRunning () == FALSE)
{
m_bSucceeded = m_dldr.IsDone () != FALSE;
EndDialog (IDOK);
return;
}
m_wndProgress.SetPos ((int)m_dldr.GetDownloader ()->GetPercentDone ());
}
CDialog::OnTimer(nIDEvent);
}
void CDlgDL::OnCancel()
{
m_dldr.StopDownloading ();
const int sleepVal = 10;
for (int i = 0; i < 7 * 1000 / sleepVal && m_dldr.IsRunning (); i += sleepVal)
Sleep (sleepVal);
m_bCancelled = true;
CDialog::OnCancel();
}