📄 ppgconnection.cpp
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@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 <math.h>
#include "emule.h"
#include "PPgConnection.h"
#include "wizard.h"
#include "Scheduler.h"
#include "OtherFunctions.h"
#include "emuledlg.h"
#include "Preferences.h"
#include "Opcodes.h"
#include "StatisticsDlg.h"
#include "Kademlia/Kademlia/Kademlia.h"
#include "HelpIDs.h"
#include "Statistics.h"
#include "Firewallopener.h"
#include "ListenSocket.h"
#include "ClientUDPSocket.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
IMPLEMENT_DYNAMIC(CPPgConnection, CPropertyPage)
CPPgConnection::CPPgConnection()
: CPropertyPage(CPPgConnection::IDD)
{
guardian=false;
}
CPPgConnection::~CPPgConnection()
{
}
void CPPgConnection::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CPPgConnection, CPropertyPage)
ON_BN_CLICKED(IDC_STARTTEST, OnStartPortTest)
ON_EN_CHANGE(IDC_DOWNLOAD_CAP, OnSettingsChange)
ON_BN_CLICKED(IDC_UDPDISABLE, OnEnChangeUDPDisable)
ON_EN_CHANGE(IDC_UDPPORT, OnEnChangeUDP)
ON_EN_CHANGE(IDC_UPLOAD_CAP, OnSettingsChange)
ON_EN_CHANGE(IDC_PORT, OnEnChangeTCP)
ON_EN_CHANGE(IDC_MAXCON, OnSettingsChange)
ON_EN_CHANGE(IDC_MAXSOURCEPERFILE, OnSettingsChange)
ON_BN_CLICKED(IDC_AUTOCONNECT, OnSettingsChange)
ON_BN_CLICKED(IDC_RECONN, OnSettingsChange)
ON_BN_CLICKED(IDC_WIZARD, OnBnClickedWizard)
ON_BN_CLICKED(IDC_NETWORK_ED2K, OnSettingsChange)
ON_BN_CLICKED(IDC_SHOWOVERHEAD, OnSettingsChange)
ON_BN_CLICKED(IDC_ULIMIT_LBL, OnLimiterChange)
ON_BN_CLICKED(IDC_DLIMIT_LBL, OnLimiterChange)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_NETWORK_KADEMLIA, OnSettingsChange)
ON_WM_HELPINFO()
ON_BN_CLICKED(IDC_OPENPORTS, OnBnClickedOpenports)
END_MESSAGE_MAP()
// CPPgConnection message handlers
void CPPgConnection::OnEnChangeTCP(){
OnEnChangePorts(true);
}
void CPPgConnection::OnEnChangeUDP(){
OnEnChangePorts(false);
}
void CPPgConnection::OnEnChangePorts(uint8 istcpport){
// ports unchanged?
CString buffer;
GetDlgItem(IDC_PORT)->GetWindowText(buffer);
uint16 tcp= _tstoi(buffer);
GetDlgItem(IDC_UDPPORT)->GetWindowText(buffer);
uint16 udp= _tstoi(buffer);
GetDlgItem(IDC_STARTTEST)->EnableWindow(
tcp==theApp.listensocket->GetConnectedPort() &&
udp==theApp.clientudp->GetConnectedPort()
);
if (istcpport==0)
OnEnChangeUDPDisable();
else if (istcpport==1)
OnSettingsChange();
}
void CPPgConnection::OnEnChangeUDPDisable(){
if (guardian) return;
uint16 tempVal=0;
CString strBuffer;
TCHAR buffer[510];
guardian=true;
SetModified();
GetDlgItem(IDC_UDPPORT)->EnableWindow(!IsDlgButtonChecked(IDC_UDPDISABLE));
if(GetDlgItem(IDC_UDPPORT)->GetWindowTextLength())
{
GetDlgItem(IDC_UDPPORT)->GetWindowText(buffer,20);
tempVal= _tstoi(buffer);
}
if (IsDlgButtonChecked(IDC_UDPDISABLE) || (!IsDlgButtonChecked(IDC_UDPDISABLE) && tempVal==0)){
tempVal= (_tstoi(buffer)) ? _tstoi(buffer)+10 : thePrefs.port+10;
if ( IsDlgButtonChecked(IDC_UDPDISABLE))
tempVal=0;
strBuffer.Format(_T("%d"), tempVal);
GetDlgItem(IDC_UDPPORT)->SetWindowText(strBuffer);
}
guardian=false;
}
BOOL CPPgConnection::OnInitDialog()
{
CPropertyPage::OnInitDialog();
InitWindowStyles(this);
LoadSettings();
Localize();
OnEnChangePorts(2);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPPgConnection::LoadSettings(void)
{
if(m_hWnd)
{
if( thePrefs.maxupload != 0 )
thePrefs.maxdownload =thePrefs.GetMaxDownload();
CString strBuffer;
strBuffer.Format(_T("%d"), thePrefs.udpport);
GetDlgItem(IDC_UDPPORT)->SetWindowText(strBuffer);
CheckDlgButton(IDC_UDPDISABLE,(thePrefs.udpport==0));
GetDlgItem(IDC_UDPPORT)->EnableWindow(thePrefs.udpport>0);
strBuffer.Format(_T("%d"), thePrefs.maxGraphDownloadRate);
GetDlgItem(IDC_DOWNLOAD_CAP)->SetWindowText(strBuffer);
((CSliderCtrl*)GetDlgItem(IDC_MAXDOWN_SLIDER))->SetRange(1, thePrefs.maxGraphDownloadRate);
strBuffer.Format(_T("%d"), thePrefs.maxGraphUploadRate);
GetDlgItem(IDC_UPLOAD_CAP)->SetWindowText(strBuffer);
((CSliderCtrl*)GetDlgItem(IDC_MAXUP_SLIDER))->SetRange(1, thePrefs.maxGraphUploadRate);
CheckDlgButton( IDC_DLIMIT_LBL, (thePrefs.maxdownload!=UNLIMITED) );
CheckDlgButton( IDC_ULIMIT_LBL, (thePrefs.maxupload!=UNLIMITED) );
((CSliderCtrl*)GetDlgItem(IDC_MAXDOWN_SLIDER))->SetPos(
(thePrefs.maxdownload!=UNLIMITED)?thePrefs.maxdownload:thePrefs.maxGraphDownloadRate
);
((CSliderCtrl*)GetDlgItem(IDC_MAXUP_SLIDER))->SetPos(
(thePrefs.maxupload!=UNLIMITED)?thePrefs.maxupload:thePrefs.maxGraphUploadRate
);
strBuffer.Format(_T("%d"), thePrefs.port);
GetDlgItem(IDC_PORT)->SetWindowText(strBuffer);
strBuffer.Format(_T("%d"), thePrefs.maxconnections);
GetDlgItem(IDC_MAXCON)->SetWindowText(strBuffer);
if(thePrefs.maxsourceperfile == 0xFFFF)
GetDlgItem(IDC_MAXSOURCEPERFILE)->SetWindowText(_T("0"));
else
{
strBuffer.Format(_T("%d"), thePrefs.maxsourceperfile);
GetDlgItem(IDC_MAXSOURCEPERFILE)->SetWindowText(strBuffer);
}
if (thePrefs.reconnect)
CheckDlgButton(IDC_RECONN,1);
else
CheckDlgButton(IDC_RECONN,0);
if (thePrefs.m_bshowoverhead)
CheckDlgButton(IDC_SHOWOVERHEAD,1);
else
CheckDlgButton(IDC_SHOWOVERHEAD,0);
if (thePrefs.autoconnect)
CheckDlgButton(IDC_AUTOCONNECT,1);
else
CheckDlgButton(IDC_AUTOCONNECT,0);
if (thePrefs.networkkademlia)
CheckDlgButton(IDC_NETWORK_KADEMLIA,1);
else
CheckDlgButton(IDC_NETWORK_KADEMLIA,0);
if (thePrefs.networked2k)
CheckDlgButton(IDC_NETWORK_ED2K,1);
else
CheckDlgButton(IDC_NETWORK_ED2K,0);
if (theApp.m_pFirewallOpener->DoesFWConnectionExist())
GetDlgItem(IDC_OPENPORTS)->EnableWindow(true);
else
GetDlgItem(IDC_OPENPORTS)->EnableWindow(false);
ShowLimitValues();
OnLimiterChange();
}
}
BOOL CPPgConnection::OnApply()
{
TCHAR buffer[510];
int lastmaxgu = thePrefs.maxGraphUploadRate;
int lastmaxgd = thePrefs.maxGraphDownloadRate;
bool bRestartApp = false;
if(GetDlgItem(IDC_DOWNLOAD_CAP)->GetWindowTextLength())
{
GetDlgItem(IDC_DOWNLOAD_CAP)->GetWindowText(buffer,20);
thePrefs.SetMaxGraphDownloadRate(_tstoi(buffer));
}
((CSliderCtrl*)GetDlgItem(IDC_MAXDOWN_SLIDER))->SetRange(1, thePrefs.GetMaxGraphDownloadRate(), TRUE);
if(GetDlgItem(IDC_UPLOAD_CAP)->GetWindowTextLength())
{
GetDlgItem(IDC_UPLOAD_CAP)->GetWindowText(buffer,20);
thePrefs.SetMaxGraphUploadRate(_tstoi(buffer));
}
((CSliderCtrl*)GetDlgItem(IDC_MAXUP_SLIDER))->SetRange(1, thePrefs.GetMaxGraphUploadRate(), TRUE);
if (IsDlgButtonChecked(IDC_ULIMIT_LBL)==FALSE)
thePrefs.SetMaxUpload(UNLIMITED);
else
thePrefs.SetMaxUpload(((CSliderCtrl*)GetDlgItem(IDC_MAXUP_SLIDER))->GetPos());
if( thePrefs.GetMaxGraphUploadRate() < thePrefs.GetMaxUpload() && thePrefs.GetMaxUpload()!=UNLIMITED )
thePrefs.SetMaxUpload(thePrefs.GetMaxGraphUploadRate()*.8);
if (thePrefs.GetMaxUpload()!=UNLIMITED)
((CSliderCtrl*)GetDlgItem(IDC_MAXUP_SLIDER))->SetPos(thePrefs.GetMaxUpload());
if (IsDlgButtonChecked(IDC_DLIMIT_LBL)==FALSE)
thePrefs.SetMaxDownload(UNLIMITED);
else
thePrefs.SetMaxDownload(((CSliderCtrl*)GetDlgItem(IDC_MAXDOWN_SLIDER))->GetPos());
if( thePrefs.GetMaxGraphDownloadRate() < thePrefs.GetMaxDownload() && thePrefs.GetMaxDownload()!=UNLIMITED )
thePrefs.SetMaxDownload(thePrefs.GetMaxGraphDownloadRate()*.8);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -