DlgAdvancedPage.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:10k
源码类别:
P2P编程
开发平台:
Visual C++
- // DlgAdvancedPage.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "DlgAdvancedPage.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgAdvancedPage dialog
- CDlgAdvancedPage::CDlgAdvancedPage(CWnd* pParent /*=NULL*/)
- : CPropertyPage(CDlgAdvancedPage::IDD)
- {
- //{{AFX_DATA_INIT(CDlgAdvancedPage)
- m_strSendServerIP = _T("");
- m_strBindIP = _T("");
- //}}AFX_DATA_INIT
- m_lPeersMin = 0;
- m_lPeersMax = 0;
- m_lDisplayItval = 0;
- m_lAllocSpeed = 0;
- m_eAllocType = CStorageWrapperEx::eAllocNormal;
- m_lFileOpenMax = 0;
- m_bSuperSeed = false;
- m_pSetupRegister = 0;
- }
- void CDlgAdvancedPage::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgAdvancedPage)
- DDX_Control(pDX, IDC_BUTTON_RESET, m_btnReset);
- DDX_Control(pDX, IDC_GROUP_ADVSETUP, m_gpAdvSetup);
- DDX_Control(pDX, IDC_COMBO_FILE_LOCK, m_cbFileLock);
- DDX_Control(pDX, IDC_COMBO_EXTRA_CHECK, m_cbExtraCheck);
- DDX_Control(pDX, IDC_SPIN_ALLOC_SPEED, m_spinAllocSpeed);
- DDX_Control(pDX, IDC_COMBO_SEED_TYPE, m_cbSeedType);
- DDX_Control(pDX, IDC_COMBO_FILEOPEN_MAX, m_cbFileOpenMax);
- DDX_Control(pDX, IDC_COMBO_ALLOC_TYPE, m_cbAllocType);
- DDX_Control(pDX, IDC_SPIN_PEERS_MAX, m_spinPeersMax);
- DDX_Control(pDX, IDC_SPIN_DISPLAY_ITVAL, m_spinDisplayItval);
- DDX_Control(pDX, IDC_SPIN_PEERS_MIN, m_spinPeersMin);
- DDX_Text(pDX, IDC_EDIT_SEND_SERVER_IP, m_strSendServerIP);
- DDX_Text(pDX, IDC_EDIT_BIND_IP, m_strBindIP);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CDlgAdvancedPage, CPropertyPage)
- //{{AFX_MSG_MAP(CDlgAdvancedPage)
- ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgAdvancedPage message handlers
- BOOL CDlgAdvancedPage::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- // spins.
- m_spinPeersMin.SetBuddy(GetDlgItem(IDC_EDIT_PEERS_MIN));
- m_spinPeersMax.SetBuddy(GetDlgItem(IDC_EDIT_PEERS_MAX));
- m_spinDisplayItval.SetBuddy(GetDlgItem(IDC_EDIT_DISPLAY_ITVAL));
- m_spinAllocSpeed.SetBuddy(GetDlgItem(IDC_EDIT_ALLOC_SPEED));
- m_spinPeersMin.SetRange(10, 60);
- m_spinPeersMax.SetRange(10, 60);
- m_spinDisplayItval.SetRange(100, 10000);
- m_spinAllocSpeed.SetRange(1, 10);
- // CComboBox
- m_cbAllocType.AddString("普通分配");
- m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocNormal);
- m_cbAllocType.AddString("后台分配");
- m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocBackGound);
- m_cbAllocType.AddString("预分配");
- m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocPreAllocate);
- m_cbAllocType.AddString("特殊分配");
- m_cbAllocType.SetItemData(m_cbAllocType.GetCount()-1, CStorageWrapperEx::eAllocSparse);
- m_cbFileOpenMax.AddString("50");
- m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 50);
- m_cbFileOpenMax.AddString("100");
- m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 100);
- m_cbFileOpenMax.AddString("200");
- m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 200);
- m_cbFileOpenMax.AddString("无限制");
- m_cbFileOpenMax.SetItemData(m_cbFileOpenMax.GetCount()-1, 0);
- m_cbSeedType.AddString("普通");
- m_cbSeedType.SetItemData(m_cbSeedType.GetCount()-1, 0);
- m_cbSeedType.AddString("超级种子");
- m_cbSeedType.SetItemData(m_cbSeedType.GetCount()-1, 1);
- for (int i=0; i<CSetupRegister::eFileLockCount; i++)
- m_cbFileLock.AddString(CSetupRegister::m_strFileLock[i]);
- for (i=0; i<CSetupRegister::eExtraCheckCount; i++)
- m_cbExtraCheck.AddString(CSetupRegister::m_strExtraCheck[i]);
- //
- // Tool tip
- //
- m_Tooltip.Create(this);
- m_Tooltip.SetMaxTipWidth(200);
- m_Tooltip.Activate(TRUE);
- EnableToolTips();
- CRect rcItem;
- GetDlgItem(IDC_EDIT_SEND_SERVER_IP)->GetWindowRect(&rcItem);
- ScreenToClient(rcItem);
- //if (!m_Tooltip.AddTool(this, "你好", rcItem, IDC_EDIT_SEND_SERVER_IP))
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_PEERS_MIN), "当达到最小下载者数时,不再试图连接服务器,来获得新的客户端信息"))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_PEERS_MAX), "连接客户端数量的最大值,达到这个值后,系统不再新建与其他客户端的连接"))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_FILE_LOCK), "文件锁定选项防止数据在下载过程中被破坏."))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_EXTRA_CHECK), "该选项设定程序做额外的文件检查以便确定没有被破坏的文件,双倍检查可能耗用cpu资源,完全检查将减慢磁盘读写速度."))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_ALLOC_TYPE), "普通分配:将让文件大小随下载过程逐渐增长,这将有利于加快文件检查速度.rnrn后台分配:将在下载过程中分配空间.rnrn预分配:在下载前完成分配,这将有助于减少文件碎片.rnrn特殊分配:将先数据保存到一个地方直到下载完成移动数据"))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_ALLOC_SPEED), "安置速度是指在后台分配方式下,后台分配空间的速度"))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_FILEOPEN_MAX), "在同一时间打开文件的最大值,零表示无限制.注意这个选项有效时不能保证文件被锁定"))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_COMBO_SEED_TYPE), "超级种子能让你更有效地做一个大文件的种子."))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_DISPLAY_ITVAL), "更新显示时间的间隔.单位是千分之一秒,这个值设得太低将会拖慢你的系统和视频播放."))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_SEND_SERVER_IP), "报告给服务器的IP."))
- {
- ASSERT(FALSE);
- }
- if (!m_Tooltip.AddTool(GetDlgItem(IDC_EDIT_BIND_IP), "客户端绑定的IP,这个选项只有在你可以直接连接到多个IP时才有效,如果你不知道如何设置,请将留空."))
- {
- ASSERT(FALSE);
- }
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- bool CDlgAdvancedPage::Apply()
- {
- UpdateData();
- int lower=0, upper=0;
- m_lPeersMin = LOWORD(m_spinPeersMin.GetPos());
- m_lPeersMax = LOWORD(m_spinPeersMax.GetPos());
- m_lDisplayItval = LOWORD(m_spinDisplayItval.GetPos());
- m_lAllocSpeed = LOWORD(m_spinAllocSpeed.GetPos());
- m_spinPeersMin.GetRange(lower, upper);
- m_lPeersMin = max(lower, m_lPeersMin);
- m_lPeersMin = min(upper, m_lPeersMin);
- m_spinPeersMax.GetRange(lower, upper);
- m_lPeersMax = max(lower, m_lPeersMax);
- m_lPeersMax = min(upper, m_lPeersMax);
- if (m_lPeersMin >= m_lPeersMax)
- {
- m_spinPeersMin.GetRange(lower, upper);
- m_lPeersMin = lower;
- }
- m_spinDisplayItval.GetRange(lower, upper);
- m_lDisplayItval = max(lower, m_lDisplayItval);
- m_lDisplayItval = min(upper, m_lDisplayItval);
- m_spinAllocSpeed.GetRange(lower, upper);
- m_lAllocSpeed = max(lower, m_lAllocSpeed);
- m_lAllocSpeed = min(upper, m_lAllocSpeed);
- m_eAllocType = (CStorageWrapperEx::eAllocType)m_cbAllocType.GetItemData(m_cbAllocType.GetCurSel());
- m_lFileOpenMax = m_cbFileOpenMax.GetItemData(m_cbFileOpenMax.GetCurSel());
- m_bSuperSeed = m_cbSeedType.GetItemData(m_cbSeedType.GetCurSel()) > 0;
- return true;
- }
- void CDlgAdvancedPage::SetData(CSetupRegister *pSetupRegister)
- {
- m_pSetupRegister = pSetupRegister;
- m_lPeersMin = pSetupRegister->m_lPeersMin;
- m_lPeersMax = pSetupRegister->m_lPeersMax;
- m_lDisplayItval = pSetupRegister->m_lDisplayItval;
- m_lAllocSpeed = pSetupRegister->m_lAllocSpeed;
- m_eAllocType = pSetupRegister->m_eAllocType;
- m_lFileOpenMax = pSetupRegister->m_lFileOpenMax;
- m_bSuperSeed = pSetupRegister->m_bSuperSeed;
- m_spinPeersMin.SetPos(m_lPeersMin);
- m_spinPeersMax.SetPos(m_lPeersMax);
- m_spinDisplayItval.SetPos(m_lDisplayItval);
- m_spinAllocSpeed.SetPos(m_lAllocSpeed);
- m_cbAllocType.SetCurSel(0);
- for (int i=0; m_cbAllocType.GetCount(); i++)
- {
- if (m_cbAllocType.GetItemData(i) == m_eAllocType)
- {
- m_cbAllocType.SetCurSel(i);
- break;
- }
- }
- m_cbFileOpenMax.SetCurSel(0);
- for (i=0; m_cbFileOpenMax.GetCount(); i++)
- {
- if (m_cbFileOpenMax.GetItemData(i) == m_lFileOpenMax)
- {
- m_cbFileOpenMax.SetCurSel(i);
- break;
- }
- }
- m_cbSeedType.SetCurSel(0);
- for (i=0; m_cbSeedType.GetCount(); i++)
- {
- if (m_cbSeedType.GetItemData(i) == (long)m_bSuperSeed)
- {
- m_cbSeedType.SetCurSel(i);
- break;
- }
- }
- m_cbFileLock.SetCurSel(pSetupRegister->m_eFileLock);
- m_cbExtraCheck.SetCurSel(pSetupRegister->m_eExtraCheck);
- m_strBindIP = m_strSendServerIP = "";
- in_addr inaddress;
- if (pSetupRegister->m_lBindIP != INADDR_NONE )
- {
- inaddress.S_un.S_addr = pSetupRegister->m_lBindIP;
- m_strBindIP = inet_ntoa(inaddress);
- }
- if (pSetupRegister->m_lSendServerIP != INADDR_NONE)
- {
- inaddress.S_un.S_addr = pSetupRegister->m_lSendServerIP;
- m_strSendServerIP = inet_ntoa(inaddress);
- }
- UpdateData(false);
- }
- void CDlgAdvancedPage::GetData(CSetupRegister *pSetupRegister)
- {
- pSetupRegister->m_lPeersMin = m_lPeersMin;
- pSetupRegister->m_lPeersMax = m_lPeersMax ;
- pSetupRegister->m_lDisplayItval = m_lDisplayItval;
- pSetupRegister->m_lAllocSpeed = m_lAllocSpeed;
- pSetupRegister->m_eAllocType = m_eAllocType;
- pSetupRegister->m_lFileOpenMax = m_lFileOpenMax;
- pSetupRegister->m_bSuperSeed = m_bSuperSeed;
- pSetupRegister->m_eFileLock = (CSetupRegister::eFileLockType)m_cbFileLock.GetCurSel();
- pSetupRegister->m_eExtraCheck = (CSetupRegister::eExtraCheck)m_cbExtraCheck.GetCurSel();
- pSetupRegister->m_lBindIP = inet_addr(m_strBindIP);
- pSetupRegister->m_lSendServerIP = inet_addr(m_strSendServerIP);
- }
- void CDlgAdvancedPage::OnOK()
- {
- GetParent()->SendMessage(WM_COMMAND, IDOK, 0);
- CPropertyPage::OnOK();
- }
- void CDlgAdvancedPage::OnCancel()
- {
- GetParent()->SendMessage(WM_COMMAND, IDCANCEL, 0);
- CPropertyPage::OnCancel();
- }
- void CDlgAdvancedPage::OnButtonReset()
- {
- /*
- if (!m_pSetupRegister)
- {
- assert(false);
- return;
- }
- m_pSetupRegister->GetDefaultAdvaced();
- //*/
- CSetupRegister tempSetupRegister;
- SetData(&tempSetupRegister);
- }
- BOOL CDlgAdvancedPage::PreTranslateMessage(MSG* pMsg)
- {
- ASSERT(m_Tooltip.GetSafeHwnd());
- m_Tooltip.RelayEvent(pMsg);
- CWnd* pNext = GetNextDlgTabItem(0);
- if (pMsg->message == WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL) < 0 &&
- (pMsg->wParam == VK_TAB || pMsg->wParam == VK_PRIOR || pMsg->wParam == VK_NEXT))
- {
- }
- return CPropertyPage::PreTranslateMessage(pMsg);
- }