00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Network.h"
00026 #include "WizardSheet.h"
00027 #include "WizardConnectionPage.h"
00028 #include "UploadQueues.h"
00029 #include "Skin.h"
00030 #include "DlgHelp.h"
00031 #include "HostCache.h"
00032 #include "DiscoveryServices.h"
00033
00034 #ifdef _DEBUG
00035 #define new DEBUG_NEW
00036 #undef THIS_FILE
00037 static char THIS_FILE[] = __FILE__;
00038 #endif
00039
00040 IMPLEMENT_DYNCREATE(CWizardConnectionPage, CWizardPage)
00041
00042 BEGIN_MESSAGE_MAP(CWizardConnectionPage, CWizardPage)
00043
00044 ON_CBN_SELCHANGE(IDC_CONNECTION_TYPE, OnSelChangeConnectionType)
00045 ON_CBN_EDITCHANGE(IDC_CONNECTION_SPEED, OnEditChangeConnectionSpeed)
00046 ON_CBN_SELCHANGE(IDC_CONNECTION_SPEED, OnSelChangeConnectionSpeed)
00047 ON_CBN_SELCHANGE(IDC_CONNECTION_GROUP, OnSelChangeConnectionGroup)
00048
00049 END_MESSAGE_MAP()
00050
00051
00053
00054
00055 CWizardConnectionPage::CWizardConnectionPage() : CWizardPage(CWizardConnectionPage::IDD)
00056 {
00057
00058
00059 }
00060
00061 CWizardConnectionPage::~CWizardConnectionPage()
00062 {
00063 }
00064
00065 void CWizardConnectionPage::DoDataExchange(CDataExchange* pDX)
00066 {
00067 CPropertyPage::DoDataExchange(pDX);
00068
00069 DDX_Control(pDX, IDC_CONNECTION_LAN_SELECT, m_wndLanSelect);
00070 DDX_Control(pDX, IDC_CONNECTION_LAN_LABEL, m_wndLanLabel);
00071 DDX_Control(pDX, IDC_CONNECTION_HOME_SELECT, m_wndHomeSelect);
00072 DDX_Control(pDX, IDC_CONNECTION_HOME_LABEL, m_wndHomeLabel);
00073 DDX_Control(pDX, IDC_CONNECTION_GROUP, m_wndGroup);
00074 DDX_Control(pDX, IDC_CONNECTION_SPEED, m_wndSpeed);
00075 DDX_Control(pDX, IDC_CONNECTION_TYPE, m_wndType);
00076
00077 }
00078
00080
00081
00082 BOOL CWizardConnectionPage::OnInitDialog()
00083 {
00084 CPropertyPage::OnInitDialog();
00085
00086 Skin.Apply( _T("CWizardConnectionPage"), this );
00087
00088 m_wndGroup.SetCurSel( 0 );
00089
00090 m_wndType.SetItemData( 0, 0 );
00091 m_wndType.SetItemData( 1, 56 );
00092 m_wndType.SetItemData( 2, 128 );
00093 m_wndType.SetItemData( 3, 256);
00094 m_wndType.SetItemData( 4, 512);
00095 m_wndType.SetItemData( 5, 768);
00096 m_wndType.SetItemData( 6, 1536 );
00097 m_wndType.SetItemData( 7, 4096 );
00098 m_wndType.SetItemData( 8, 8192 );
00099 m_wndType.SetItemData( 9, 12288 );
00100 m_wndType.SetItemData(10, 24576 );
00101 m_wndType.SetItemData(11, 1550 );
00102 m_wndType.SetItemData(12, 1544 );
00103 m_wndType.SetItemData(13, 45000 );
00104 m_wndType.SetItemData(14, 100000 );
00105 m_wndType.SetItemData(15, 155000 );
00106
00107
00108 CString strSpeed;
00109 strSpeed.Format( _T(" %lu.0 kbps"), Settings.Connection.InSpeed );
00110 m_wndSpeed.SetWindowText( strSpeed );
00111
00112
00113
00114 return TRUE;
00115 }
00116
00117 BOOL CWizardConnectionPage::OnSetActive()
00118 {
00119 SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
00120 return CWizardPage::OnSetActive();
00121 }
00122
00123 void CWizardConnectionPage::OnSelChangeConnectionGroup()
00124 {
00125 int nGroup = m_wndGroup.GetCurSel();
00126
00127 m_wndHomeLabel.ShowWindow( nGroup == 1 ? SW_SHOW : SW_HIDE );
00128 m_wndHomeSelect.ShowWindow( nGroup == 1 ? SW_SHOW : SW_HIDE );
00129 m_wndLanLabel.ShowWindow( nGroup > 1 ? SW_SHOW : SW_HIDE );
00130 m_wndLanSelect.ShowWindow( nGroup > 1 ? SW_SHOW : SW_HIDE );
00131
00132 m_wndHomeSelect.SetCurSel( 2 );
00133 m_wndLanSelect.SetCurSel( nGroup == 2 ? 0 : 1 );
00134
00135 m_wndSpeed.SetWindowText( _T("") );
00136 m_wndSpeed.SetCurSel( -1 );
00137 m_wndSpeed.EnableWindow( FALSE );
00138 m_wndType.EnableWindow( TRUE );
00139 m_wndType.SetCurSel( nGroup == 1 ? 1 : 8 );
00140 }
00141
00142 void CWizardConnectionPage::OnSelChangeConnectionType()
00143 {
00144 m_wndSpeed.EnableWindow( m_wndType.GetCurSel() < 1 );
00145 if ( m_wndType.GetCurSel() > 0 ) m_wndSpeed.SetWindowText( _T("") );
00146 }
00147
00148 void CWizardConnectionPage::OnEditChangeConnectionSpeed()
00149 {
00150 CString strSpeed;
00151 m_wndSpeed.GetWindowText( strSpeed );
00152 m_wndType.EnableWindow( strSpeed.IsEmpty() );
00153 if ( strSpeed.GetLength() ) m_wndType.SetCurSel( -1 );
00154 }
00155
00156 void CWizardConnectionPage::OnSelChangeConnectionSpeed()
00157 {
00158 m_wndType.EnableWindow( m_wndSpeed.GetCurSel() < 1 );
00159 if ( m_wndSpeed.GetCurSel() > 0 ) m_wndType.SetCurSel( -1 );
00160 }
00161
00162 LRESULT CWizardConnectionPage::OnWizardNext()
00163 {
00164 if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) return 0;
00165
00166 int nGroup = m_wndGroup.GetCurSel();
00167
00168 if ( nGroup <= 0 )
00169 {
00170 CString strMessage;
00171 LoadString( strMessage, IDS_WIZARD_NEED_CONNECTION );
00172 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00173 return -1;
00174 }
00175 else if ( nGroup == 1 )
00176 {
00177 CString strFormat, strMessage;
00178
00179 switch ( m_wndHomeSelect.GetCurSel() )
00180 {
00181 case 0:
00182 Settings.Connection.FirewallStatus = CONNECTION_OPEN;
00183 if ( Settings.Connection.InPort == 6346 )
00184 Settings.Connection.InPort = Network.RandomPort();
00185 break;
00186 case 1:
00187 Settings.Connection.FirewallStatus = CONNECTION_OPEN;
00188
00189 LoadString( strFormat, IDS_WIZARD_PORT_FORWARD );
00190 strMessage.Format( strFormat, Settings.Connection.InPort );
00191 AfxMessageBox( strMessage, MB_ICONINFORMATION );
00192 break;
00193 case 2:
00194 Settings.Connection.FirewallStatus = CONNECTION_FIREWALLED;
00195 Settings.Connection.InPort = 6346;
00196 break;
00197 case 3:
00198 Settings.Connection.FirewallStatus = CONNECTION_AUTO;
00199 Settings.Connection.InPort = 6346;
00200 break;
00201 }
00202 }
00203 else
00204 {
00205 switch ( m_wndLanSelect.GetCurSel() )
00206 {
00207 case 0:
00208 Settings.Connection.FirewallStatus = CONNECTION_OPEN;
00209 if ( Settings.Connection.InPort == 6346 )
00210 Settings.Connection.InPort = Network.RandomPort();
00211 break;
00212 case 1:
00213 Settings.Connection.FirewallStatus = CONNECTION_FIREWALLED;
00214 Settings.Connection.InPort = 6346;
00215 break;
00216 case 2:
00217 Settings.Connection.FirewallStatus = CONNECTION_AUTO;
00218 Settings.Connection.InPort = 6346;
00219 break;
00220 }
00221 }
00222
00223 int nIndex = m_wndType.GetCurSel();
00224 int nSpeed = 0;
00225
00226 if ( nIndex > 0 )
00227 {
00228 nSpeed = m_wndType.GetItemData( nIndex );
00229 }
00230 else
00231 {
00232 CString strSpeed;
00233 m_wndSpeed.GetWindowText( strSpeed );
00234
00235 if ( _stscanf( strSpeed, _T("%lu"), &nSpeed ) != 1 || nSpeed <= 0 )
00236 {
00237 LoadString( strSpeed, IDS_WIZARD_NEED_SPEED );
00238 AfxMessageBox( strSpeed, MB_ICONEXCLAMATION );
00239 return -1;
00240 }
00241 }
00242
00243 Settings.Connection.InSpeed = nSpeed;
00244
00245 if( nSpeed <= 56 )
00246 Settings.Connection.OutSpeed = 32;
00247 else if( nSpeed <= 128 )
00248 Settings.Connection.OutSpeed = nSpeed;
00249 else if( nSpeed == 384 )
00250 Settings.Connection.OutSpeed = 128;
00251 else if( nSpeed <= 700 )
00252 Settings.Connection.OutSpeed = nSpeed / 4;
00253 else if( nSpeed < 1544 )
00254 Settings.Connection.OutSpeed = nSpeed / 6;
00255 else if( nSpeed == 1544 )
00256 Settings.Connection.OutSpeed = nSpeed;
00257 else if( nSpeed <= 4000 )
00258 Settings.Connection.OutSpeed = nSpeed / 2;
00259 else if( nSpeed <= 8192 )
00260 Settings.Connection.OutSpeed = nSpeed / 8;
00261 else if( nSpeed <= 12288 )
00262 Settings.Connection.OutSpeed = nSpeed / 10;
00263 else if( nSpeed <= 24576 )
00264 Settings.Connection.OutSpeed = nSpeed / 12;
00265 else
00266 Settings.Connection.OutSpeed = nSpeed;
00267
00268
00269 Settings.Bandwidth.Uploads = (DWORD)( Settings.Connection.OutSpeed * 0.9 );
00270 Settings.Bandwidth.Uploads >>= 3;
00271 Settings.Bandwidth.Uploads *= 1024;
00272
00273 if ( nSpeed > 750 )
00274 {
00275 Settings.Gnutella2.NumPeers = max( Settings.Gnutella2.NumPeers, 4 );
00276 }
00277
00278 Settings.eDonkey.MaxLinks = ( nSpeed < 100 || ! theApp.m_bNT ) ? 35 : 250;
00279
00280 if ( nSpeed > 2500 && theApp.m_bNT && ( !theApp.m_bLimitedConnections || Settings.General.IgnoreXPsp2 ) )
00281 {
00282 Settings.Downloads.MaxFiles = 32;
00283 Settings.Downloads.MaxTransfers = 200;
00284 Settings.Downloads.MaxFileTransfers = 32;
00285 Settings.Downloads.MaxConnectingSources = 32;
00286 Settings.Downloads.MaxFileSearches = 3;
00287
00288 Settings.Gnutella2.NumLeafs = 400;
00289 Settings.BitTorrent.DownloadTorrents = 4;
00290 }
00291 else if ( nSpeed > 768 && theApp.m_bNT )
00292 {
00293 Settings.Downloads.MaxFiles = 26;
00294 Settings.Downloads.MaxTransfers = 100;
00295 Settings.Downloads.MaxFileTransfers = 10;
00296 Settings.Downloads.MaxConnectingSources = 28;
00297 Settings.Downloads.MaxFileSearches = 2;
00298 }
00299 else if ( nSpeed > 256 && theApp.m_bNT )
00300 {
00301 Settings.Downloads.MaxFiles = 20;
00302 Settings.Downloads.MaxTransfers = 64;
00303 Settings.Downloads.MaxFileTransfers = 8;
00304 Settings.Downloads.MaxConnectingSources = 24;
00305 Settings.Downloads.MaxFileSearches = 1;
00306 Settings.Search.GeneralThrottle = 250;
00307 }
00308 else if ( nSpeed > 80 && theApp.m_bNT )
00309 {
00310 Settings.Downloads.MaxFiles = 14;
00311 Settings.Downloads.MaxTransfers = 32;
00312 Settings.Downloads.MaxFileTransfers = 6;
00313 Settings.Downloads.MaxConnectingSources = 20;
00314 Settings.Downloads.MaxFileSearches = 0;
00315 Settings.Search.GeneralThrottle = 250;
00316 }
00317 else
00318 {
00319 Settings.Downloads.MaxFiles = 8;
00320 Settings.Downloads.MaxTransfers = 24;
00321 Settings.Downloads.MaxFileTransfers = 4;
00322 Settings.Downloads.MaxConnectingSources = 16;
00323 Settings.Downloads.MaxFileSearches = 0;
00324 Settings.Downloads.SourcesWanted = 200;
00325 Settings.Search.GeneralThrottle = 300;
00326
00327 Settings.BitTorrent.DownloadTorrents = 1;
00328 }
00329
00330 UploadQueues.CreateDefault();
00331
00332 if ( ( theApp.m_bLimitedConnections ) && ( ! Settings.General.IgnoreXPsp2 ) )
00333 {
00334 theApp.Message( MSG_ERROR, _T("Warning - Windows XP Service Pack 2 detected. Performance may be reduced.") );
00335 Settings.Downloads.ConnectThrottle = max( Settings.Downloads.ConnectThrottle, DWORD(800) );
00336 Settings.Connection.ConnectThrottle = max( Settings.Connection.ConnectThrottle, DWORD(250) );
00337 Settings.Gnutella.ConnectFactor = min( Settings.Gnutella.ConnectFactor, DWORD(3) );
00338 Settings.Gnutella2.NumHubs = min( Settings.Gnutella2.NumHubs, 2 );
00339 Settings.Gnutella1.EnableAlways = FALSE;
00340 Settings.Gnutella1.EnableToday = FALSE;
00341 Settings.Downloads.MaxConnectingSources = 8;
00342 Settings.Connection.RequireForTransfers = TRUE;
00343 Settings.Connection.SlowConnect = TRUE;
00344
00345
00346
00347 CHelpDlg::Show( _T("GeneralHelp.XPsp2") );
00348 }
00349
00350
00351 if ( HostCache.Gnutella2.CountHosts() < 25 ) DiscoveryServices.QueryForHosts( PROTOCOL_G2 );
00352
00353
00354 if ( HostCache.eDonkey.CountHosts() < 8 ) HostCache.eDonkey.LoadDefaultED2KServers();
00355
00356 return 0;
00357 }
00358