forked from SomeSupport/eMule
-
Notifications
You must be signed in to change notification settings - Fork 97
/
AddSourceDlg.cpp
198 lines (175 loc) · 5.51 KB
/
AddSourceDlg.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//this file is part of eMule
//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include "emule.h"
#include "AddSourceDlg.h"
#include "PartFile.h"
#include "OtherFunctions.h"
#include "UpDownClient.h"
#include "DownloadQueue.h"
#include <wininet.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// CAddSourceDlg dialog
IMPLEMENT_DYNAMIC(CAddSourceDlg, CDialog)
BEGIN_MESSAGE_MAP(CAddSourceDlg, CResizableDialog)
ON_BN_CLICKED(IDC_RSRC, OnBnClickedRadio1)
ON_BN_CLICKED(IDC_RURL, OnBnClickedRadio4)
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()
CAddSourceDlg::CAddSourceDlg(CWnd* pParent /*=NULL*/)
: CResizableDialog(CAddSourceDlg::IDD, pParent)
, m_nSourceType(0)
{
m_pFile = NULL;
}
CAddSourceDlg::~CAddSourceDlg()
{
}
void CAddSourceDlg::DoDataExchange(CDataExchange* pDX)
{
CResizableDialog::DoDataExchange(pDX);
DDX_Radio(pDX, IDC_RSRC, m_nSourceType);
}
void CAddSourceDlg::SetFile(CPartFile *pFile)
{
m_pFile = pFile;
}
BOOL CAddSourceDlg::OnInitDialog()
{
CResizableDialog::OnInitDialog();
InitWindowStyles(this);
AddAnchor(IDC_SOURCE_TYPE, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(IDC_EDIT10, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDOK, BOTTOM_RIGHT);
AddAnchor(IDC_BUTTON1, BOTTOM_RIGHT);
AddAnchor(IDCANCEL, BOTTOM_RIGHT);
if (m_pFile)
SetWindowText(m_pFile->GetFileName());
// localize
SetDlgItemText(IDC_BUTTON1,GetResString(IDS_ADD));
SetDlgItemText(IDCANCEL,GetResString(IDS_CANCEL));
SetDlgItemText(IDC_RSRC,GetResString(IDS_SOURCECLIENT));
SetDlgItemText(IDC_SOURCE_TYPE,GetResString(IDS_META_SRCTYPE));
SetDlgItemText(IDC_RURL,GetResString(IDS_SV_URL));
SetDlgItemText(IDC_UIP,GetResString(IDS_USERSIP));
SetDlgItemText(IDC_PORT,GetResString(IDS_PORT));
GetDlgItem(IDOK)->SetWindowText(GetResString(IDS_TREEOPTIONS_OK));
EnableSaveRestore(_T("AddSourceDlg"));
OnBnClickedRadio1();
return FALSE; // return FALSE, we changed the focus!
}
void CAddSourceDlg::OnBnClickedRadio1()
{
m_nSourceType = 0;
GetDlgItem(IDC_EDIT2)->EnableWindow(true);
GetDlgItem(IDC_EDIT3)->EnableWindow(true);
GetDlgItem(IDC_EDIT10)->EnableWindow(false);
GetDlgItem(IDC_EDIT2)->SetFocus();
}
void CAddSourceDlg::OnBnClickedRadio4()
{
m_nSourceType = 1;
GetDlgItem(IDC_EDIT2)->EnableWindow(false);
GetDlgItem(IDC_EDIT3)->EnableWindow(false);
GetDlgItem(IDC_EDIT10)->EnableWindow(true);
GetDlgItem(IDC_EDIT10)->SetFocus();
}
void CAddSourceDlg::OnBnClickedButton1()
{
if (!m_pFile)
return;
switch (m_nSourceType)
{
case 0:
{
CString sip;
GetDlgItem(IDC_EDIT2)->GetWindowText(sip);
if (sip.IsEmpty())
return;
// if the port is specified with the IP, ignore any possible specified port in the port control
uint16 port;
int iColon = sip.Find(_T(':'));
if (iColon != -1) {
port = (uint16)_tstoi(sip.Mid(iColon + 1));
sip = sip.Left(iColon);
}
else {
BOOL bTranslated = FALSE;
port = (uint16)GetDlgItemInt(IDC_EDIT3, &bTranslated, FALSE);
if (!bTranslated)
return;
}
uint32 ip;
if ((ip = inet_addr(CT2CA(sip))) == INADDR_NONE && _tcscmp(sip, _T("255.255.255.255")) != 0)
ip = 0;
if (IsGoodIPPort(ip, port))
{
CUpDownClient* toadd = new CUpDownClient(m_pFile, port, ntohl(ip), 0, 0);
toadd->SetSourceFrom(SF_PASSIVE);
theApp.downloadqueue->CheckAndAddSource(m_pFile, toadd);
}
break;
}
case 1:
{
CString strURL;
GetDlgItem(IDC_EDIT10)->GetWindowText(strURL);
if (!strURL.IsEmpty())
{
TCHAR szScheme[INTERNET_MAX_SCHEME_LENGTH];
TCHAR szHostName[INTERNET_MAX_HOST_NAME_LENGTH];
TCHAR szUrlPath[INTERNET_MAX_PATH_LENGTH];
TCHAR szUserName[INTERNET_MAX_USER_NAME_LENGTH];
TCHAR szPassword[INTERNET_MAX_PASSWORD_LENGTH];
TCHAR szExtraInfo[INTERNET_MAX_URL_LENGTH];
URL_COMPONENTS Url = {0};
Url.dwStructSize = sizeof(Url);
Url.lpszScheme = szScheme;
Url.dwSchemeLength = ARRSIZE(szScheme);
Url.lpszHostName = szHostName;
Url.dwHostNameLength = ARRSIZE(szHostName);
Url.lpszUserName = szUserName;
Url.dwUserNameLength = ARRSIZE(szUserName);
Url.lpszPassword = szPassword;
Url.dwPasswordLength = ARRSIZE(szPassword);
Url.lpszUrlPath = szUrlPath;
Url.dwUrlPathLength = ARRSIZE(szUrlPath);
Url.lpszExtraInfo = szExtraInfo;
Url.dwExtraInfoLength = ARRSIZE(szExtraInfo);
if (InternetCrackUrl(strURL, 0, 0, &Url) && Url.dwHostNameLength > 0 && Url.dwHostNameLength < INTERNET_MAX_HOST_NAME_LENGTH)
{
SUnresolvedHostname* hostname = new SUnresolvedHostname;
hostname->strURL = strURL;
hostname->strHostname = szHostName;
theApp.downloadqueue->AddToResolved(m_pFile, hostname);
delete hostname;
}
}
break;
}
}
}
void CAddSourceDlg::OnBnClickedOk()
{
OnBnClickedButton1();
OnOK();
}