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); m_ctlMaxDown.SetRange(1, thePrefs.maxGraphDownloadRate); SetRateSliderTicks(m_ctlMaxDown); if (thePrefs.maxGraphUploadRate != UNLIMITED) strBuffer.Format(_T("%d"), thePrefs.maxGraphUploadRate); else strBuffer = _T("0"); GetDlgItem(IDC_UPLOAD_CAP)->SetWindowText(strBuffer); m_ctlMaxUp.SetRange(1, thePrefs.GetMaxGraphUploadRate(true)); SetRateSliderTicks(m_ctlMaxUp); CheckDlgButton( IDC_DLIMIT_LBL, (thePrefs.maxdownload != UNLIMITED)); CheckDlgButton( IDC_ULIMIT_LBL, (thePrefs.maxupload != UNLIMITED)); m_ctlMaxDown.SetPos((thePrefs.maxdownload != UNLIMITED) ? thePrefs.maxdownload : thePrefs.maxGraphDownloadRate); m_ctlMaxUp.SetPos((thePrefs.maxupload != UNLIMITED) ? thePrefs.maxupload : thePrefs.GetMaxGraphUploadRate(true)); 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.GetNetworkKademlia()) CheckDlgButton(IDC_NETWORK_KADEMLIA, 1); else CheckDlgButton(IDC_NETWORK_KADEMLIA, 0); GetDlgItem(IDC_NETWORK_KADEMLIA)->EnableWindow(thePrefs.GetUDPPort() > 0); if (thePrefs.networked2k) CheckDlgButton(IDC_NETWORK_ED2K, 1); else CheckDlgButton(IDC_NETWORK_ED2K, 0); // don't try on XP SP2 or higher, not needed there anymore if (thePrefs.GetWindowsVersion() == _WINVER_XP_ && IsRunningXPSP2() == 0 && theApp.m_pFirewallOpener->DoesFWConnectionExist()) GetDlgItem(IDC_OPENPORTS)->ShowWindow(SW_SHOW); else GetDlgItem(IDC_OPENPORTS)->ShowWindow(SW_HIDE); if (thePrefs.GetWindowsVersion() != _WINVER_95_ && thePrefs.GetWindowsVersion() != _WINVER_98_ && thePrefs.GetWindowsVersion() != _WINVER_NT4_) GetDlgItem(IDC_PREF_UPNPONSTART)->EnableWindow(true); else GetDlgItem(IDC_PREF_UPNPONSTART)->EnableWindow(false); if (thePrefs.IsUPnPEnabled()) CheckDlgButton(IDC_PREF_UPNPONSTART, 1); else CheckDlgButton(IDC_PREF_UPNPONSTART, 0); 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)); } m_ctlMaxDown.SetRange(1, thePrefs.GetMaxGraphDownloadRate(), TRUE); SetRateSliderTicks(m_ctlMaxDown); if (GetDlgItem(IDC_UPLOAD_CAP)->GetWindowTextLength()) { GetDlgItem(IDC_UPLOAD_CAP)->GetWindowText(buffer, 20); thePrefs.SetMaxGraphUploadRate(_tstoi(buffer)); } m_ctlMaxUp.SetRange(1, thePrefs.GetMaxGraphUploadRate(true), TRUE); SetRateSliderTicks(m_ctlMaxUp); { uint16 ulSpeed; if (!IsDlgButtonChecked(IDC_ULIMIT_LBL)) ulSpeed = UNLIMITED; else ulSpeed = (uint16)m_ctlMaxUp.GetPos(); if (thePrefs.GetMaxGraphUploadRate(true) < ulSpeed && ulSpeed != UNLIMITED) ulSpeed = (uint16)(thePrefs.GetMaxGraphUploadRate(true) * 0.8); if(ulSpeed > thePrefs.GetMaxUpload()) { // make USS go up to higher ul limit faster theApp.lastCommonRouteFinder->InitiateFastReactionPeriod(); } thePrefs.SetMaxUpload(ulSpeed); } if (thePrefs.GetMaxUpload() != UNLIMITED) m_ctlMaxUp.SetPos(thePrefs.GetMaxUpload()); if (!IsDlgButtonChecked(IDC_DLIMIT_LBL)) thePrefs.SetMaxDownload(UNLIMITED); else thePrefs.SetMaxDownload(m_ctlMaxDown.GetPos()); if (thePrefs.GetMaxGraphDownloadRate() < thePrefs.GetMaxDownload() && thePrefs.GetMaxDownload() != UNLIMITED) thePrefs.SetMaxDownload((uint16)(thePrefs.GetMaxGraphDownloadRate() * 0.8)); if (thePrefs.GetMaxDownload() != UNLIMITED) m_ctlMaxDown.SetPos(thePrefs.GetMaxDownload()); if (GetDlgItem(IDC_PORT)->GetWindowTextLength()) { GetDlgItem(IDC_PORT)->GetWindowText(buffer, 20); uint16 nNewPort = ((uint16)_tstoi(buffer)) ? (uint16)_tstoi(buffer) : (uint16)thePrefs.port; if (nNewPort != thePrefs.port){ thePrefs.port = nNewPort; if (theApp.IsPortchangeAllowed()) theApp.listensocket->Rebind(); else bRestartApp = true; } } if (GetDlgItem(IDC_MAXSOURCEPERFILE)->GetWindowTextLength()) { GetDlgItem(IDC_MAXSOURCEPERFILE)->GetWindowText(buffer, 20); thePrefs.maxsourceperfile = (_tstoi(buffer)) ? _tstoi(buffer) : 1; } if (GetDlgItem(IDC_UDPPORT)->GetWindowTextLength()) { GetDlgItem(IDC_UDPPORT)->GetWindowText(buffer, 20); uint16 nNewPort = ((uint16)_tstoi(buffer) && !IsDlgButtonChecked(IDC_UDPDISABLE)) ? (uint16)_tstoi(buffer) : (uint16)0; if (nNewPort != thePrefs.udpport){ thePrefs.udpport = nNewPort; if (theApp.IsPortchangeAllowed()) theApp.clientudp->Rebind(); else bRestartApp = true; } } if (IsDlgButtonChecked(IDC_SHOWOVERHEAD)){ if (!thePrefs.m_bshowoverhead){ // reset overhead data counters before starting to meassure! theStats.ResetDownDatarateOverhead(); theStats.ResetUpDatarateOverhead(); } thePrefs.m_bshowoverhead = true; } else{ if (thePrefs.m_bshowoverhead){ // free memory used by overhead computations theStats.ResetDownDatarateOverhead(); theStats.ResetUpDatarateOverhead(); } thePrefs.m_bshowoverhead = false; } if (IsDlgButtonChecked(IDC_NETWORK_KADEMLIA)) thePrefs.SetNetworkKademlia(true); else thePrefs.SetNetworkKademlia(false); if (IsDlgButtonChecked(IDC_NETWORK_ED2K)) thePrefs.SetNetworkED2K(true); else thePrefs.SetNetworkED2K(false); GetDlgItem(IDC_UDPPORT)->EnableWindow(!IsDlgButtonChecked(IDC_UDPDISABLE)); thePrefs.autoconnect = IsDlgButtonChecked(IDC_AUTOCONNECT)!=0; thePrefs.reconnect = IsDlgButtonChecked(IDC_RECONN)!=0; if (lastmaxgu != thePrefs.maxGraphUploadRate) theApp.emuledlg->statisticswnd->SetARange(false, thePrefs.GetMaxGraphUploadRate(true)); if (lastmaxgd!=thePrefs.maxGraphDownloadRate) theApp.emuledlg->statisticswnd->SetARange(true, thePrefs.maxGraphDownloadRate); UINT tempcon = thePrefs.maxconnections; if (GetDlgItem(IDC_MAXCON)->GetWindowTextLength()) { GetDlgItem(IDC_MAXCON)->GetWindowText(buffer, 20); tempcon = (_tstoi(buffer)) ? _tstoi(buffer) : CPreferences::GetRecommendedMaxConnections(); } if (tempcon > (unsigned)::GetMaxWindowsTCPConnections()) { CString strMessage; strMessage.Format(GetResString(IDS_PW_WARNING), GetResString(IDS_PW_MAXC), ::GetMaxWindowsTCPConnections()); int iResult = AfxMessageBox(strMessage, MB_ICONWARNING | MB_YESNO); if (iResult != IDYES) { //TODO: set focus to max connection? strMessage.Format(_T("%d"), thePrefs.maxconnections); GetDlgItem(IDC_MAXCON)->SetWindowText(strMessage); tempcon = ::GetMaxWindowsTCPConnections(); } } thePrefs.maxconnections = tempcon; if (IsDlgButtonChecked(IDC_PREF_UPNPONSTART) != 0){ if (!thePrefs.IsUPnPEnabled()){ thePrefs.m_bEnableUPnP = true; theApp.emuledlg->StartUPnP(); } } else thePrefs.m_bEnableUPnP = false; #ifdef Scheduler theApp.scheduler->SaveOriginals(); #endif SetModified(FALSE); LoadSettings(); theApp.emuledlg->ShowConnectionState(); if (bRestartApp) AfxMessageBox(GetResString(IDS_NOPORTCHANGEPOSSIBLE)); OnEnChangePorts(2); return CPropertyPage::OnApply(); }
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); m_ctlMaxDown.SetRange(1, thePrefs.maxGraphDownloadRate); SetRateSliderTicks(m_ctlMaxDown); strBuffer.Format(_T("%d"), thePrefs.maxGraphUploadRate); GetDlgItem(IDC_UPLOAD_CAP)->SetWindowText(strBuffer); m_ctlMaxUp.SetRange(1, thePrefs.maxGraphUploadRate); SetRateSliderTicks(m_ctlMaxUp); CheckDlgButton( IDC_DLIMIT_LBL, (thePrefs.maxdownload != UNLIMITED)); CheckDlgButton( IDC_ULIMIT_LBL, (thePrefs.maxupload != UNLIMITED)); m_ctlMaxDown.SetPos((thePrefs.maxdownload != UNLIMITED) ? thePrefs.maxdownload : thePrefs.maxGraphDownloadRate); m_ctlMaxUp.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(); } }