MonitorDetailWnd.cpp
资源名称:GGBT.rar [点击查看]
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:16k
源码类别:
P2P编程
开发平台:
Visual C++
- // MonitorDetailWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "testbt.h"
- #include "MonitorDetailWnd.h"
- #include "CategoryBarWnd.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define IDC_LIST_PEERS 56831
- #define IDC_LIST_INFOMATION 56832
- #define IDC_TREE_SUBFILES_MONITOR 56833
- #define IDC_EDIT_MSG 56834
- #define IDC_LIST_MSG 56834
- #define IDC_GRAPH_MSG 56835
- #define IDC_PEERINFO 56836
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorDetailWnd
- CMonitorDetailWnd::CMonitorDetailWnd()
- {
- m_pFileDBItem = 0;
- m_pCategoryBarWnd = 0;
- m_pSetupRegister = 0;
- m_bShowSubFiles = false;
- m_bShowInfomation = false;
- m_iCurImageID = -1;
- m_bShowFileDBLog = false;
- }
- CMonitorDetailWnd::~CMonitorDetailWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CMonitorDetailWnd, CWnd)
- //{{AFX_MSG_MAP(CMonitorDetailWnd)
- ON_WM_CREATE()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- ON_MESSAGE(WM_FILE_TORRENT_OPENED, OnFileTorrentOpened)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorDetailWnd message handlers
- void CMonitorDetailWnd::SetCateGoryBarWnd(CCategoryBarWnd* pCategoryBarWnd)
- {
- m_pCategoryBarWnd = pCategoryBarWnd;
- m_treeSubFiles.SetCateGoryBarWnd(pCategoryBarWnd);
- }
- BOOL CMonitorDetailWnd::CreateEx(CWnd *pParent, CRect rc, long lID, long lParam, CSetupRegister* pSetupRegister)
- {
- m_pSetupRegister = pSetupRegister;
- return Create(0, 0, WS_VISIBLE|WS_CHILD|WS_BORDER, rc, pParent, lID);
- }
- int CMonitorDetailWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- m_listPeers.CreateEx(this, CRect(0, 0, 100, 100), IDC_LIST_PEERS, 0, m_pSetupRegister, (CMonitorWnd*)GetParent());
- m_listInfomation.CreateEx(this, CRect(0, 0, 100, 100), IDC_LIST_INFOMATION, 0, m_pSetupRegister, (CMonitorWnd*)GetParent());
- m_listMsg.CreateEx(this, CRect(0, 0, 100, 100), IDC_LIST_MSG, 0, (CMonitorWnd*)GetParent());
- m_treeSubFiles.CreateEx(this, CRect(0, 0, 100, 100), IDC_TREE_SUBFILES_MONITOR, true, (CMonitorWnd*)GetParent());
- m_graphWnd.CreateEx(this, CRect(0, 0, 100, 100), IDC_GRAPH_MSG, 0, (CMonitorWnd*)GetParent());
- m_listPeers.m_PeerInfoWnd.CreateEx(this, CRect(0,0, 100, 100), &m_listPeers, IDC_PEERINFO, 0);
- /*
- m_listMsg.ShowWindow(false);
- m_listPeers.ShowWindow(false);
- m_listInfomation.ShowWindow(false);
- m_treeSubFiles.ShowWindow(false);
- m_graphWnd.ShowWindow(false);
- //*/
- m_listMsg.ShowWindow(false);
- m_listPeers.ShowWindow(false);
- m_treeSubFiles.ShowWindow(false);
- m_graphWnd.ShowWindow(false);
- m_listPeers.m_PeerInfoWnd.ShowWindow(false);
- return 0;
- }
- void CMonitorDetailWnd::OnSize(UINT nType, int cx, int cy)
- {
- CWnd::OnSize(nType, cx, cy);
- m_listMsg.MoveWindow(CRect(0, 0, cx, cy));
- m_listPeers.MoveWindow(CRect(0, 0, cx, cy));
- m_listInfomation.MoveWindow(CRect(0, 0, cx, cy));
- m_treeSubFiles.MoveWindow(CRect(0, 0, cx, cy));
- m_graphWnd.MoveWindow(CRect(0, 0, cx, cy));
- m_listPeers.m_PeerInfoWnd.MoveWindow(CRect(0, 0, cx, cy));
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorDetailWnd function
- void CMonitorDetailWnd::Monitor(CFileDBItem* pFileDBItem)
- {
- m_pFileDBItem = pFileDBItem;
- if (pFileDBItem)
- {
- m_treeSubFiles.Monitor(pFileDBItem->m_strTorrentFileName, pFileDBItem->m_strFileName, pFileDBItem);
- // m_treeSubFiles.Monitor(&m_fileTorrent, pFileDBItem->m_strFileName);
- }
- else
- m_treeSubFiles.Monitor();
- m_listInfomation.Monitor(pFileDBItem);
- m_listPeers.Monitor(pFileDBItem);
- m_listMsg.Monitor(pFileDBItem);
- m_graphWnd.Monitor(pFileDBItem);
- m_fileTorrent.Close();
- m_bShowSubFiles = false;
- m_bShowInfomation = false;
- m_iCurImageID = -1;
- }
- void CMonitorDetailWnd::OnFileTorrentOpened(long lParam, long lwParam)
- {
- if (m_fileTorrent.GetOpenIndex() != lParam)
- return;
- if (!m_fileTorrent.IsOpen())
- {
- assert(false);
- if (m_fileTorrent.IsBad())
- {
- string strBad = m_fileTorrent.GetBadMsg();
- }
- return;
- }
- if (m_iCurImageID == IID_SUBFILES)
- {
- m_bShowSubFiles = true;
- m_treeSubFiles.ShowSubFiles();
- }
- else if (m_iCurImageID == IID_INFOMATION)
- {
- m_listInfomation.ShowInfomation(true);
- }
- }
- void CMonitorDetailWnd::ShowNode(CTreeCursor& cursor, bool bRefreshInfo)
- {
- assert(cursor);
- int iImageID = cursor.GetImageID();
- if (bRefreshInfo)
- {
- m_listMsg.ShowWindow(iImageID == IID_PEER || iImageID == IID_LOG);
- m_listPeers.ShowWindow(iImageID == IID_ALL_PEERS);
- m_listInfomation.ShowWindow(iImageID == IID_INFOMATION);
- m_treeSubFiles.ShowWindow(iImageID == IID_SUBFILES);
- m_graphWnd.ShowWindow(iImageID == IID_RUN_GRAPH);
- m_listPeers.m_PeerInfoWnd.ShowWindow(false);
- }
- switch (iImageID)
- {
- case IID_SUBFILES:
- {
- /*
- if (m_pFileDBItem && !m_fileTorrent.IsOpen() && !m_fileTorrent.IsBad())
- {
- m_fileTorrent.OpenFileEx(m_pCategoryBarWnd->GetDBSavePath() +
- m_pFileDBItem->m_strTorrentFileName, string(), GetSafeHwnd());
- }
- else
- {
- //*/
- //*
- if (!m_bShowSubFiles)
- {
- m_bShowSubFiles = true;
- m_treeSubFiles.ShowSubFiles();
- }
- //*/
- // }
- }
- break;
- case IID_INFOMATION:
- {
- /*
- if (m_pFileDBItem && !m_fileTorrent.IsOpen() && !m_fileTorrent.IsBad())
- {
- m_fileTorrent.OpenFileEx(m_pCategoryBarWnd->GetDBSavePath() +
- m_pFileDBItem->m_strTorrentFileName, string(), GetSafeHwnd());
- }
- else
- {
- //*/
- m_listInfomation.ShowInfomation(bRefreshInfo);
- // }
- // if (m_iCurImageID != iImageID)
- // ShowInfomation();
- }
- break;
- case IID_ALL_PEERS:
- {
- /*
- m_listPeers.SetRedraw(false);
- ShowAllPeers(bRefreshInfo);
- m_listPeers.SetRedraw(true);
- //*/
- m_listPeers.ShowAllPeers(bRefreshInfo);
- }
- break;
- case IID_PEER:
- {
- // ShowPeer(cursor, bRefreshInfo);
- }
- break;
- case IID_LOG:
- {
- m_listMsg.ShowLogs(bRefreshInfo);
- // ShowLogs(bRefreshInfo);
- }
- break;
- case IID_RUN_GRAPH:
- {
- m_graphWnd.ShowGraph(bRefreshInfo);
- }
- break;
- default:
- assert(false);
- }
- m_iCurImageID = iImageID;
- }
- /*
- void CMonitorDetailWnd::ShowInfomation()
- {
- m_listInfomation.DeleteAllItems();
- if (!m_pFileDBItem)
- return;
- m_listInfomation.InsertItem(0, "保存文件名", eASTERISK);
- m_listInfomation.SetItemText(0, 1, m_pFileDBItem->m_strFileName.data());
- m_listInfomation.InsertItem(1, "torrent文件名", eASTERISK);
- m_listInfomation.SetItemText(1, 1, m_pFileDBItem->m_strTorrentFileName.data());
- m_listInfomation.InsertItem(2, "认证码(hash)", eASTERISK);
- m_listInfomation.SetItemText(2, 1, m_pFileDBItem->m_strHash.data());
- m_listInfomation.InsertItem(3, "文件大小", eASTERISK);
- m_listInfomation.SetItemText(3, 1, FormatSize(m_pFileDBItem->m_lFileSize).data());
- CTime tCreatedTime(m_pFileDBItem->m_tTime);
- m_listInfomation.InsertItem(4, "创建时间", eASTERISK);
- m_listInfomation.SetItemText(4, 1, tCreatedTime.Format("%Y-%m-%d %H:%M"));
- CString strText;
- m_listInfomation.InsertItem(5, "已完成", eASTERISK);
- strText.Format("%d%%", (long)((m_pFileDBItem->m_fComplete)*100));
- m_listInfomation.SetItemText(5, 1, strText);
- m_listInfomation.InsertItem(6, "", -1);
- long lRunParamInx = 7;
- m_listInfomation.InsertItem(lRunParamInx, "绑定端口:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 1, "最小下载者数:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 2, "最大下载者数:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 3, "显示间隔:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 4, "文件安置模式:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 5, "最大打开文件:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 6, "最大上传速度:", eASTERISK);
- m_listInfomation.InsertItem(lRunParamInx + 7, "最大上传连接:", eASTERISK);
- if (m_pFileDBItem && m_pFileDBItem->m_pDownload && m_pFileDBItem->m_pDownload->IsDownloading())
- {
- CString strText;
- long lPort = 0, lPeerMin = 0, lPeerMax = 0, lDisplayItval = 0, lAllocType = 0, lFileOpenMax =0;
- m_pFileDBItem->m_pDownload->GetRunParameter(lPort,lPeerMin, lPeerMax, lDisplayItval, lAllocType, lFileOpenMax);
- strText.Format("%d", lPort);
- m_listInfomation.SetItemText(lRunParamInx, 1, strText);
- strText.Format("%d", lPeerMin);
- m_listInfomation.SetItemText(lRunParamInx + 1, 1, strText);
- strText.Format("%d", lPeerMax);
- m_listInfomation.SetItemText(lRunParamInx + 2, 1, strText);
- strText.Format("%d微秒", lDisplayItval);
- m_listInfomation.SetItemText(lRunParamInx + 3, 1, strText);
- switch (lAllocType)
- {
- case CStorageWrapperEx::eAllocNormal:
- strText = "普通分配";
- break;
- case CStorageWrapperEx::eAllocSparse:
- strText = "特殊分配";
- break;
- case CStorageWrapperEx::eAllocPreAllocate:
- strText = "预分配";
- break;
- case CStorageWrapperEx::eAllocBackGound:
- strText = "后台分配";
- break;
- }
- m_listInfomation.SetItemText(lRunParamInx + 4, 1, strText);
- strText.Format("%d", lFileOpenMax);
- m_listInfomation.SetItemText(lRunParamInx + 5, 1, strText);
- strText.Format("%d(K)", m_pFileDBItem->m_lUploadSpeedMax);
- m_listInfomation.SetItemText(lRunParamInx + 6, 1, strText);
- strText.Format("%d", m_pFileDBItem->m_lUploadPeerMax);
- m_listInfomation.SetItemText(lRunParamInx + 7, 1, strText);
- }
- }
- void CMonitorDetailWnd::ShowRunStatics()
- {
- m_listInfomation.DeleteAllItems();
- if (!m_pFileDBItem || !m_pFileDBItem->m_pDownload || !m_pFileDBItem->m_pDownload->IsDownloading())
- return;
- CString strText;
- long lPort = 0, lPeerMin = 0, lPeerMax = 0, lDisplayItval = 0, lAllocType = 0, lFileOpenMax =0;
- m_pFileDBItem->m_pDownload->GetRunParameter(lPort,lPeerMin, lPeerMax, lDisplayItval, lAllocType, lFileOpenMax);
- m_listInfomation.InsertItem(0, "绑定端口:", eASTERISK);
- strText.Format("%d", lPort);
- m_listInfomation.SetItemText(0, 1, strText);
- m_listInfomation.InsertItem(1, "最小下载者数:", eASTERISK);
- strText.Format("%d", lPeerMin);
- m_listInfomation.SetItemText(1, 1, strText);
- m_listInfomation.InsertItem(2, "最大下载者数:", eASTERISK);
- strText.Format("%d", lPeerMax);
- m_listInfomation.SetItemText(2, 1, strText);
- m_listInfomation.InsertItem(3, "显示间隔:", eASTERISK);
- strText.Format("%d微秒", lDisplayItval);
- m_listInfomation.SetItemText(3, 1, strText);
- m_listInfomation.InsertItem(4, "文件安置模式:", eASTERISK);
- switch (lAllocType)
- {
- case CStorageWrapperEx::eAllocNormal:
- strText = "普通分配";
- break;
- case CStorageWrapperEx::eAllocSparse:
- strText = "特殊分配";
- break;
- case CStorageWrapperEx::eAllocPreAllocate:
- strText = "预分配";
- break;
- case CStorageWrapperEx::eAllocBackGound:
- strText = "后台分配";
- break;
- }
- m_listInfomation.SetItemText(4, 1, strText);
- m_listInfomation.InsertItem(5, "最大打开文件:", eASTERISK);
- strText.Format("%d", lFileOpenMax);
- m_listInfomation.SetItemText(5, 1, strText);
- m_listInfomation.InsertItem(6, "最大上传速度:", eASTERISK);
- strText.Format("%d(K)", m_pFileDBItem->m_lUploadSpeedMax);
- m_listInfomation.SetItemText(6, 1, strText);
- m_listInfomation.InsertItem(7, "最大上传连接:", eASTERISK);
- strText.Format("%d", m_pFileDBItem->m_lUploadPeerMax);
- m_listInfomation.SetItemText(7, 1, strText);
- }
- void CMonitorDetailWnd::ShowPeer(CTreeCursor& cursor, bool bRefreshInfo)
- {
- m_listMsg.DeleteAllItems();
- if (m_pFileDBItem && m_pFileDBItem->m_pDownload && m_pFileDBItem->m_pDownload->IsDownloading())
- {
- CAddrPort* pData = (CAddrPort*)cursor.GetData();
- m_listMsg.InsertItem(m_listMsg.GetItemCount(),
- m_pFileDBItem->m_pDownload->GetSocketMessage(pData->m_lAddr, pData->m_sPort).data());
- }
- else
- assert(false);
- }
- void CMonitorDetailWnd::ShowLogs(bool bRefreshInfo)
- {
- if (bRefreshInfo)
- {
- m_bShowFileDBLog = false;
- m_listMsg.DeleteAllItems();
- }
- if (m_pFileDBItem )
- {
- if (m_pFileDBItem->m_pDownload)
- {
- vector<string> vSystemMsg;
- m_pFileDBItem->m_pDownload->GetSystemMessage(vSystemMsg);
- int iStart = 0;
- if (!bRefreshInfo)
- {
- iStart = m_listMsg.GetItemCount();
- if (m_bShowFileDBLog)
- {
- assert(iStart > 0);
- iStart -= 1;
- }
- }
- for (int i=iStart; i<vSystemMsg.size(); i++)
- {
- m_listMsg.InsertItem(i, vSystemMsg[i].data());
- }
- }
- else
- {
- if (!bRefreshInfo)
- {
- int iCount = m_listMsg.GetItemCount();
- if (m_bShowFileDBLog)
- iCount -= 1;
- for (int i=0; i<iCount; i++)
- m_listMsg.DeleteItem(0);
- }
- }
- if (!m_pFileDBItem->m_strBad.empty())
- {
- m_bShowFileDBLog = true;
- if (bRefreshInfo)
- m_listMsg.InsertItem(m_listMsg.GetItemCount(), m_pFileDBItem->m_strBad.data());
- }
- }
- }
- void CMonitorDetailWnd::OnRclickListInfomation(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CListCtrl* pListCtrl = 0;
- if (m_listInfomation.IsWindowVisible())
- pListCtrl = &m_listInfomation;
- // else if (m_listPeers.IsWindowVisible())
- // pListCtrl = &m_listPeers;
- // else if (m_listMsg.IsWindowVisible())
- // pListCtrl = &m_listMsg;
- if (!pListCtrl) return;
- bool bcopy = false;
- if (pListCtrl->GetSelectedCount())
- bcopy = true;
- CMenu menu_bar;
- menu_bar.CreatePopupMenu();
- if (bcopy)
- menu_bar.AppendMenu(MF_STRING, ID_EDIT_COPY, "复制(&C)t");
- /*
- if (pListCtrl == &m_listPeers)
- {
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_PAUSE_PEERS, "暂停选中的连接(&P)t");
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_STOP_PEERS, "关闭选中的连接(&P)t");
- }
- //*/
- /*
- menu_bar.AppendMenu(MF_STRING, ID_MENUITEM_SELECT_ALL, "全选(&A)t");
- CPoint posMouse;
- GetCursorPos(&posMouse);
- menu_bar.TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON,posMouse.x,posMouse.y,this);
- }
- //*/
- /*
- void CMonitorDetailWnd::OnMenuitemCopy()
- {
- CListCtrl* pListCtrl = 0;
- if (m_listInfomation.IsWindowVisible())
- pListCtrl = &m_listInfomation;
- // else if (m_listPeers.IsWindowVisible())
- // pListCtrl = &m_listPeers;
- // else if (m_listMsg.IsWindowVisible())
- // pListCtrl = &m_listMsg;
- if (!pListCtrl) return;
- CString strSource;
- int nColumnCount = pListCtrl->GetHeaderCtrl()->GetItemCount();
- POSITION pos = pListCtrl->GetFirstSelectedItemPosition();
- while (pos)
- {
- int index = pListCtrl->GetNextSelectedItem(pos);
- for (int i=0; i<nColumnCount; i++)
- strSource += pListCtrl->GetItemText(index, i) + " ";
- strSource += "rn";
- }
- if (!CopyTextToClipboard(strSource))
- AfxMessageBox("复制失败");
- }
- void CMonitorDetailWnd::OnMenuitemSelectAll()
- {
- CListCtrl* pListCtrl = 0;
- if (m_listInfomation.IsWindowVisible())
- pListCtrl = &m_listInfomation;
- // else if (m_listPeers.IsWindowVisible())
- // pListCtrl = &m_listPeers;
- // else if (m_listMsg.IsWindowVisible())
- // pListCtrl = &m_listMsg;
- if (!pListCtrl) return;
- for (int i=0; i<pListCtrl->GetItemCount(); i++)
- pListCtrl->SetItemState(i, LVIS_SELECTED, LVIS_SELECTED);
- pListCtrl->SetFocus();
- }
- //*/
- /*
- void CMonitorDetailWnd::OnMenuItemPeers(UINT uID)
- {
- if (!m_pFileDBItem || !m_pFileDBItem->m_pDownload || !m_pFileDBItem->m_pDownload->IsDownloading())
- {
- assert(false);
- return;
- }
- switch (uID)
- {
- case ID_MENUITEM_PAUSE_PEERS:
- {
- // m_pFileDBItem->m_pDownload->PausePeer
- }
- break;
- case ID_MENUITEM_STOP_PEERS:
- {
- POSITION pos = m_listPeers.GetFirstSelectedItemPosition();
- while (pos)
- {
- int nItem = m_listPeers.GetNextSelectedItem(pos);
- CAddrPort* pData = (CAddrPort*)m_listPeers.GetItemData(nItem);
- if (!pData)
- {
- assert(false);
- return;
- }
- m_pFileDBItem->m_pDownload->ClosePeer(pData);
- }
- }
- break;
- default:
- assert(false);
- }
- }
- //*/