PageRenderTime 668ms CodeModel.GetById 6ms app.highlight 617ms RepoModel.GetById 1ms app.codeStats 2ms

/srchybrid/StatisticsDlg.cpp

https://github.com/acat/emule
C++ | 3498 lines | 2949 code | 277 blank | 272 comment | 646 complexity | d574d37a32225f8da8c164e512d36778 MD5 | raw file
   1//this file is part of eMule
   2//Copyright (C)2002-2008 Merkur ( strEmail.Format("%s@%s", "devteam", "emule-project.net") / http://www.emule-project.net )
   3//
   4//This program is free software; you can redistribute it and/or
   5//modify it under the terms of the GNU General Public License
   6//as published by the Free Software Foundation; either
   7//version 2 of the License, or (at your option) any later version.
   8//
   9//This program is distributed in the hope that it will be useful,
  10//but WITHOUT ANY WARRANTY; without even the implied warranty of
  11//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12//GNU General Public License for more details.
  13//
  14//You should have received a copy of the GNU General Public License
  15//along with this program; if not, write to the Free Software
  16//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17#include "stdafx.h"
  18#include "emule.h"
  19#include "StatisticsDlg.h"
  20#include "UploadQueue.h"
  21#include "Statistics.h"
  22#include "emuledlg.h"
  23#include "OtherFunctions.h"
  24#include "WebServer.h"
  25#include "DownloadQueue.h"
  26#include "ClientList.h"
  27#include "Preferences.h"
  28#include "ListenSocket.h"
  29#include "ServerList.h"
  30#include "SharedFileList.h"
  31#include "UpDownClient.h"
  32#include "UserMsgs.h"
  33#include "HelpIDs.h"
  34#include "Kademlia/Kademlia/kademlia.h"
  35#include "Kademlia/Kademlia/Prefs.h"
  36#include "kademlia/kademlia/UDPFirewallTester.h"
  37
  38
  39#ifdef _DEBUG
  40#define new DEBUG_NEW
  41#undef THIS_FILE
  42static char THIS_FILE[] = __FILE__;
  43#endif
  44
  45#ifdef _DEBUG
  46extern _CRT_ALLOC_HOOK g_pfnPrevCrtAllocHook;
  47#endif
  48
  49
  50// CStatisticsDlg dialog
  51
  52IMPLEMENT_DYNAMIC(CStatisticsDlg, CDialog)
  53
  54BEGIN_MESSAGE_MAP(CStatisticsDlg, CResizableDialog)
  55	ON_WM_SHOWWINDOW()
  56	ON_WM_SIZE()
  57	ON_BN_CLICKED(IDC_BNMENU, OnMenuButtonClicked)	
  58	ON_WM_SYSCOLORCHANGE()
  59	ON_WM_CTLCOLOR()
  60	ON_STN_DBLCLK(IDC_SCOPE_D, OnStnDblclickScopeD)
  61	ON_STN_DBLCLK(IDC_SCOPE_U, OnStnDblclickScopeU)
  62	ON_STN_DBLCLK(IDC_STATSSCOPE, OnStnDblclickStatsscope)
  63	ON_MESSAGE(UM_OSCOPEPOSITION, OnOscopePositionMsg)
  64	ON_WM_HELPINFO()
  65END_MESSAGE_MAP()
  66
  67CStatisticsDlg::CStatisticsDlg(CWnd* pParent /*=NULL*/)
  68	: CResizableDialog(CStatisticsDlg::IDD, pParent)
  69	, m_DownloadOMeter(3)
  70	, m_Statistics(4)
  71	, m_UploadOMeter(5)
  72
  73{
  74	m_oldcx=0;
  75	m_oldcy=0;
  76	m_TimeToolTips = NULL;
  77}
  78
  79CStatisticsDlg::~CStatisticsDlg()
  80{
  81	delete m_TimeToolTips;
  82
  83#ifdef _DEBUG
  84	POSITION pos = blockFiles.GetStartPosition();
  85	while (pos != NULL) 
  86	{
  87		const unsigned char* fileName;
  88		HTREEITEM* pTag;
  89		blockFiles.GetNextAssoc(pos, fileName, pTag);
  90		delete pTag;
  91	}
  92#endif
  93}
  94
  95void CStatisticsDlg::DoDataExchange(CDataExchange* pDX)
  96{
  97	CResizableDialog::DoDataExchange(pDX);
  98	DDX_Control(pDX, IDC_STATTREE, stattree);
  99}
 100
 101void CStatisticsDlg::OnSysColorChange()
 102{
 103	CResizableDialog::OnSysColorChange();
 104	SetAllIcons();
 105}
 106
 107void CStatisticsDlg::SetAllIcons()
 108{
 109	InitWindowStyles(this);
 110
 111	CImageList iml;
 112	iml.Create(16, 16, theApp.m_iDfltImageListColorFlags | ILC_MASK, 0, 1);
 113	iml.Add(CTempIconLoader(_T("StatsGeneric")));			// Dots & Arrow (Default icon for stats)
 114	iml.Add(CTempIconLoader(_T("TransferUpDown")));			// Transfer
 115	iml.Add(CTempIconLoader(_T("Connection")));				// Connection
 116	iml.Add(CTempIconLoader(_T("StatsClients")));			// Clients
 117	iml.Add(CTempIconLoader(_T("Server")));					// Server
 118	iml.Add(CTempIconLoader(_T("SharedFiles")));			// Shared Files
 119	iml.Add(CTempIconLoader(_T("Upload")));					// Transfer > Upload
 120	iml.Add(CTempIconLoader(_T("Download")));				// Transfer > Download
 121	iml.Add(CTempIconLoader(_T("StatsDetail")));			// Session Sections
 122	iml.Add(CTempIconLoader(_T("StatsCumulative")));		// Cumulative Sections
 123	iml.Add(CTempIconLoader(_T("StatsRecords")));			// Records
 124	iml.Add(CTempIconLoader(_T("TransferUpDown")));			// Connection > General
 125	iml.Add(CTempIconLoader(_T("StatsTime")));				// Time Section
 126	iml.Add(CTempIconLoader(_T("StatsProjected")));			// Time > Averages and Projections
 127	iml.Add(CTempIconLoader(_T("StatsDay")));				// Time > Averages and Projections > Daily
 128	iml.Add(CTempIconLoader(_T("StatsMonth")));				// Time > Averages and Projections > Monthly
 129	iml.Add(CTempIconLoader(_T("StatsYear")));				// Time > Averages and Projections > Yearly
 130	iml.Add(CTempIconLoader(_T("HardDisk")));				// Diskspace
 131	stattree.SetImageList(&iml, TVSIL_NORMAL);
 132	imagelistStatTree.DeleteImageList();
 133	imagelistStatTree.Attach(iml.Detach());
 134
 135	COLORREF crBk = GetSysColor(COLOR_WINDOW);
 136	COLORREF crFg = GetSysColor(COLOR_WINDOWTEXT);
 137
 138	theApp.LoadSkinColorAlt(_T("StatisticsTvBk"), _T("DefLvBk"), crBk);
 139	theApp.LoadSkinColorAlt(_T("StatisticsTvFg"), _T("DefLvFg"), crFg);
 140
 141	stattree.SetBkColor(crBk);
 142	stattree.SetTextColor(crFg);
 143	// can't use 'TVM_SETLINECOLOR' because the color may not match that one used in "StatsGeneric" item image.
 144	//stattree.SendMessage(TVM_SETLINECOLOR, 0, (LPARAM)crFg);
 145}
 146
 147BOOL CStatisticsDlg::OnInitDialog()
 148{
 149	CResizableDialog::OnInitDialog();
 150	EnableWindow(FALSE);
 151	SetAllIcons();
 152	m_bTreepaneHidden=false;
 153
 154	if (theApp.m_fontSymbol.m_hObject)
 155	{
 156		GetDlgItem(IDC_BNMENU)->SetFont(&theApp.m_fontSymbol);
 157		GetDlgItem(IDC_BNMENU)->SetWindowText(_T("6")); // show a down-arrow
 158	}
 159
 160	// Win98: Explicitly set to Unicode to receive Unicode notifications.
 161	stattree.SendMessage(CCM_SETUNICODEFORMAT, TRUE);
 162	if (thePrefs.GetUseSystemFontForMainControls())
 163		stattree.SendMessage(WM_SETFONT, NULL, FALSE);
 164	CreateMyTree();
 165
 166	// Setup download-scope
 167	CRect rcDown;
 168	GetDlgItem(IDC_SCOPE_D)->GetWindowRect(rcDown);
 169	GetDlgItem(IDC_SCOPE_D)->DestroyWindow();
 170	ScreenToClient(rcDown);
 171	m_DownloadOMeter.Create(WS_VISIBLE | WS_CHILD, rcDown, this, IDC_SCOPE_D);
 172	SetARange(true, thePrefs.GetMaxGraphDownloadRate());
 173	m_DownloadOMeter.SetYUnits(GetResString(IDS_KBYTESPERSEC));
 174	
 175	// Setup upload-scope
 176	CRect rcUp;
 177	GetDlgItem(IDC_SCOPE_U)->GetWindowRect(rcUp);
 178	GetDlgItem(IDC_SCOPE_U)->DestroyWindow();
 179	ScreenToClient(rcUp);
 180	// compensate rounding errors due to dialog units, make each of the 3 panes with same height
 181	rcUp.top = rcDown.bottom + 4;
 182	rcUp.bottom = rcUp.top + rcDown.Height();
 183	m_UploadOMeter.Create(WS_VISIBLE | WS_CHILD, rcUp, this, IDC_SCOPE_U);
 184	SetARange(false, thePrefs.GetMaxGraphUploadRate(true));
 185	m_UploadOMeter.SetYUnits(GetResString(IDS_KBYTESPERSEC));
 186	
 187	// Setup additional graph-scope
 188	CRect rcConn;
 189	GetDlgItem(IDC_STATSSCOPE)->GetWindowRect(rcConn);
 190	GetDlgItem(IDC_STATSSCOPE)->DestroyWindow();
 191	ScreenToClient(rcConn);
 192	// compensate rounding errors due to dialog units, make each of the 3 panes with same height
 193	rcConn.top = rcUp.bottom + 4;
 194	rcConn.bottom = rcConn.top + rcDown.Height();
 195	m_Statistics.Create(WS_VISIBLE | WS_CHILD, rcConn, this, IDC_STATSSCOPE);
 196	m_Statistics.SetRanges(0, thePrefs.GetStatsMax());
 197	m_Statistics.autofitYscale = false;
 198	// Set the trend ratio of the Active Connections trend in the Connection Statistics scope.
 199	m_Statistics.SetTrendRatio(0, thePrefs.GetStatsConnectionsGraphRatio());
 200
 201	m_Statistics.SetYUnits(_T(""));
 202	m_Statistics.SetXUnits(GetResString(IDS_TIME));
 203
 204	RepaintMeters();
 205	m_Statistics.SetBackgroundColor(thePrefs.GetStatsColor(0)) ;
 206	m_Statistics.SetGridColor(thePrefs.GetStatsColor(1)) ;
 207	
 208	m_DownloadOMeter.InvalidateCtrl();
 209	m_UploadOMeter.InvalidateCtrl();
 210	m_Statistics.InvalidateCtrl();
 211
 212	if (thePrefs.GetStatsInterval()==0) 
 213		GetDlgItem(IDC_STATTREE)->EnableWindow(false);
 214
 215	UpdateData(FALSE);
 216
 217	EnableWindow( TRUE );
 218
 219	m_ilastMaxConnReached = 0;
 220	CRect rcW,rcSpl,rcTree,rcStat;
 221	
 222	GetWindowRect(rcW);
 223	ScreenToClient(rcW);
 224
 225	GetDlgItem(IDC_STATTREE)->GetWindowRect(rcTree);
 226	ScreenToClient(rcTree);
 227	m_DownloadOMeter.GetWindowRect(rcDown);
 228	ScreenToClient(rcDown);
 229	m_UploadOMeter.GetWindowRect(rcUp);
 230	ScreenToClient(rcUp);
 231	m_Statistics.GetWindowRect(rcStat);
 232	ScreenToClient(rcStat);
 233		
 234	//vertical splitter
 235	rcSpl.left = rcTree.right;
 236	rcSpl.right = rcSpl.left + 4;
 237	rcSpl.top = rcW.top + 2;
 238	rcSpl.bottom = rcW.bottom - 5;
 239	m_wndSplitterstat.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER_STAT);
 240	int PosStatVinitX = rcSpl.left;
 241	int PosStatVnewX = thePrefs.GetSplitterbarPositionStat()*rcW.Width()/100;
 242	int maxX = rcW.right-13;
 243	int minX = rcW.left+8;
 244	if (thePrefs.GetSplitterbarPositionStat() > 90)
 245		PosStatVnewX = maxX;
 246	else if (thePrefs.GetSplitterbarPositionStat() < 10)
 247		PosStatVnewX = minX;
 248	rcSpl.left = PosStatVnewX;
 249	rcSpl.right = PosStatVnewX + 4;
 250	m_wndSplitterstat.MoveWindow(rcSpl);
 251
 252	//HR splitter
 253	rcSpl.left = rcDown.left;
 254	rcSpl.right = rcDown.right;
 255	rcSpl.top = rcDown.bottom;
 256	rcSpl.bottom = rcSpl.top + 4;
 257	m_wndSplitterstat_HR.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER_STAT_HR);
 258	int PosStatVinitZ = rcSpl.top;
 259	int PosStatVnewZ = thePrefs.GetSplitterbarPositionStat_HR()*rcW.Height()/100;
 260	int maxZ = rcW.bottom-14;
 261	int minZ = 0;
 262	if (thePrefs.GetSplitterbarPositionStat_HR() > 90) 
 263		PosStatVnewZ = maxZ;
 264	else if (thePrefs.GetSplitterbarPositionStat_HR() < 10)
 265		PosStatVnewZ = minZ;
 266	rcSpl.top = PosStatVnewZ;
 267	rcSpl.bottom = PosStatVnewZ+4;
 268	m_wndSplitterstat_HR.MoveWindow(rcSpl);
 269
 270	//HL splitter
 271	rcSpl.left = rcUp.left;
 272	rcSpl.right = rcUp.right;
 273	rcSpl.top = rcUp.bottom;
 274	rcSpl.bottom = rcSpl.top + 4;
 275	m_wndSplitterstat_HL.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER_STAT_HL);
 276	int PosStatVinitY = rcSpl.top;
 277	int PosStatVnewY = thePrefs.GetSplitterbarPositionStat_HL()*rcW.Height()/100;
 278	int maxY = rcW.bottom-9;
 279	int minY = 10;
 280	if (thePrefs.GetSplitterbarPositionStat_HL() > 90)
 281		PosStatVnewY = maxY;
 282	else if (thePrefs.GetSplitterbarPositionStat_HL() < 10)
 283		PosStatVnewY = minY;
 284	rcSpl.top = PosStatVnewY;
 285	rcSpl.bottom = PosStatVnewY+4;
 286	m_wndSplitterstat_HL.MoveWindow(rcSpl);
 287
 288	DoResize_V(PosStatVnewX - PosStatVinitX);
 289	DoResize_HL(PosStatVnewY - PosStatVinitY);
 290	DoResize_HR(PosStatVnewZ - PosStatVinitZ);
 291
 292	Localize();
 293	ShowStatistics(true);
 294	
 295	m_TimeToolTips = new CToolTipCtrl();
 296	m_TimeToolTips->Create(this);
 297	m_TimeToolTips->AddTool(GetDlgItem(IDC_SCOPE_D), _T(""), NULL, 0);
 298	m_TimeToolTips->AddTool(GetDlgItem(IDC_SCOPE_U), _T(""), NULL, 0);
 299	m_TimeToolTips->AddTool(GetDlgItem(IDC_STATSSCOPE),	_T(""), NULL, 0);
 300	// Any Autopop-Time which is specified higher than ~30 sec. will get reset to 5 sec.
 301	m_TimeToolTips->SetDelayTime(TTDT_AUTOPOP, 30000);
 302	m_TimeToolTips->SetDelayTime(TTDT_INITIAL, 30000);
 303	m_TimeToolTips->SetDelayTime(TTDT_RESHOW,  30000);
 304	EnableToolTips(TRUE);
 305
 306	return true;
 307}
 308
 309void CStatisticsDlg::initCSize()
 310{
 311	UINT x = thePrefs.GetSplitterbarPositionStat();
 312	UINT y = thePrefs.GetSplitterbarPositionStat_HL();
 313	UINT z = thePrefs.GetSplitterbarPositionStat_HR();
 314	if (x > 90)
 315		x = 100;
 316	else if (x < 10)
 317		x = 0;
 318	if (y > 90)
 319		y = 100;
 320	else if (y < 10)
 321		y = 0;
 322	if (z > 90)
 323		z = 100;
 324	else if (z < 10)
 325		z = 0;
 326
 327	RemoveAnchor(IDC_BNMENU);
 328	AddAnchor(IDC_BNMENU,CSize(0,0));
 329
 330	//StatTitle
 331	RemoveAnchor(IDC_STATIC_LASTRESET);
 332	AddAnchor(IDC_STATIC_LASTRESET,CSize(0,0),CSize(x,0));
 333	//stattree
 334	RemoveAnchor(stattree);
 335	AddAnchor(stattree,CSize(0,0),CSize(x,100));
 336
 337	//graph
 338	RemoveAnchor(m_DownloadOMeter);
 339	AddAnchor(m_DownloadOMeter,CSize(x,0),CSize(100,z));
 340
 341	RemoveAnchor(m_UploadOMeter);
 342	AddAnchor(m_UploadOMeter,CSize(x,z),CSize(100,y));
 343
 344	RemoveAnchor(m_Statistics);
 345	AddAnchor(m_Statistics,CSize(x,y),CSize(100,100));
 346	
 347	//set range
 348	CRect rcW;
 349	GetWindowRect(rcW);
 350	ScreenToClient(rcW);
 351
 352	CRect rcHR,rcHL;
 353	m_wndSplitterstat_HR.GetWindowRect(rcHR);
 354	m_wndSplitterstat_HL.GetWindowRect(rcHL);
 355	ScreenToClient(rcHR);
 356	ScreenToClient(rcHL);
 357
 358	m_wndSplitterstat.SetRange(rcW.left+11, rcW.right-11);
 359	m_wndSplitterstat_HL.SetRange(rcHR.bottom+5, rcW.bottom-7);
 360	m_wndSplitterstat_HR.SetRange(rcW.top+3, rcHL.top-5);
 361}
 362
 363
 364void CStatisticsDlg::DoResize_HL(int delta)
 365{
 366	if(!delta)
 367		return;
 368	m_DownloadOMeter.InvalidateCtrl(true);
 369	CSplitterControl::ChangeHeight(&m_UploadOMeter, delta , CW_TOPALIGN);
 370	CSplitterControl::ChangeHeight(&m_Statistics, -delta, CW_BOTTOMALIGN);
 371
 372	CRect rcW;
 373 
 374	GetWindowRect(rcW);
 375	ScreenToClient(rcW);
 376
 377	CRect rcspl;
 378
 379	m_UploadOMeter.GetWindowRect(rcspl);
 380	ScreenToClient(rcspl);
 381	thePrefs.SetSplitterbarPositionStat_HL(rcspl.bottom*100/rcW.Height());
 382
 383	initCSize();
 384
 385	ShowInterval();
 386	Invalidate();
 387	UpdateWindow();
 388}
 389
 390void CStatisticsDlg::DoResize_HR(int delta)
 391{
 392	if(!delta)
 393		return;
 394	CSplitterControl::ChangeHeight(&m_DownloadOMeter, delta , CW_TOPALIGN);
 395	CSplitterControl::ChangeHeight(&m_UploadOMeter, -delta, CW_BOTTOMALIGN);
 396	m_Statistics.InvalidateCtrl(true);
 397	CRect rcW;
 398 
 399	GetWindowRect(rcW);
 400	ScreenToClient(rcW);
 401
 402	CRect rcspl;
 403
 404	m_DownloadOMeter.GetWindowRect(rcspl);
 405	ScreenToClient(rcspl);
 406	thePrefs.SetSplitterbarPositionStat_HR(rcspl.bottom*100/rcW.Height());
 407
 408	initCSize();
 409
 410	ShowInterval();
 411	Invalidate();
 412	UpdateWindow();
 413}
 414
 415void CStatisticsDlg::DoResize_V(int delta)
 416{
 417	if(!delta)
 418		return;
 419	CSplitterControl::ChangeWidth(GetDlgItem(IDC_STATIC_LASTRESET), delta);
 420	CSplitterControl::ChangeWidth(&stattree, delta);
 421	CSplitterControl::ChangeWidth(&m_DownloadOMeter, -delta, CW_RIGHTALIGN);
 422	CSplitterControl::ChangeWidth(&m_UploadOMeter, -delta, CW_RIGHTALIGN);
 423	CSplitterControl::ChangeWidth(&m_Statistics, -delta, CW_RIGHTALIGN);
 424
 425	CRect rcW;
 426 
 427	GetWindowRect(rcW);
 428	ScreenToClient(rcW);
 429
 430	CRect rcspl;
 431
 432	GetDlgItem(IDC_STATTREE)->GetWindowRect(rcspl);
 433	ScreenToClient(rcspl);
 434	thePrefs.SetSplitterbarPositionStat(rcspl.right*100/rcW.Width());
 435
 436	if (rcspl.left==rcspl.right) {
 437		GetDlgItem(IDC_STATTREE)->ShowWindow(SW_HIDE);
 438		GetDlgItem(IDC_BNMENU)->ShowWindow(SW_HIDE);
 439		GetDlgItem(IDC_STATIC_LASTRESET)->ShowWindow(SW_HIDE);
 440		m_bTreepaneHidden=true;
 441	} else if (m_bTreepaneHidden) {
 442		m_bTreepaneHidden=false;
 443		GetDlgItem(IDC_STATTREE)->ShowWindow(SW_SHOW);
 444		GetDlgItem(IDC_BNMENU)->ShowWindow(SW_SHOW);
 445		GetDlgItem(IDC_STATIC_LASTRESET)->ShowWindow(SW_SHOW);
 446	}
 447
 448	initCSize();
 449
 450	ShowInterval();
 451	Invalidate();
 452	UpdateWindow();
 453}
 454
 455LRESULT CStatisticsDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
 456{
 457	switch (message) 
 458	{
 459		case WM_PAINT:
 460			if (m_wndSplitterstat) 
 461			{
 462				CRect rctree,rcSpl,rcW;
 463				GetWindowRect(rcW);
 464				ScreenToClient(rcW);
 465
 466				GetDlgItem(IDC_STATTREE)->GetWindowRect(rctree);
 467				ScreenToClient(rctree);
 468				
 469				if (rcW.Width()>0) 
 470				{
 471					rcSpl.left = rctree.right;
 472					rcSpl.right = rcSpl.left + 4;
 473					rcSpl.top = rcW.top + 2;
 474					rcSpl.bottom = rcW.bottom - 5;
 475					m_wndSplitterstat.MoveWindow(rcSpl,true);
 476				}
 477			}
 478			if (m_wndSplitterstat_HL) 
 479			{
 480				CRect rcUp,rcSpl,rcW;
 481				CWnd* pWnd;
 482
 483				GetWindowRect(rcW);
 484				ScreenToClient(rcW);
 485
 486				pWnd = &m_UploadOMeter;
 487				pWnd->GetWindowRect(rcUp);
 488
 489				ScreenToClient(rcUp);
 490
 491				if (rcW.Height()>0) 
 492				{
 493					rcSpl.left = rcUp.left;
 494					rcSpl.right = rcUp.right;
 495					rcSpl.top = rcUp.bottom;
 496					rcSpl.bottom = rcUp.bottom + 4;
 497					m_wndSplitterstat_HL.MoveWindow(rcSpl,true);
 498				}
 499			}
 500			if (m_wndSplitterstat_HR) 
 501			{
 502				CRect rcDown,rcSpl,rcW;
 503				CWnd* pWnd;
 504
 505				GetWindowRect(rcW);
 506				ScreenToClient(rcW);
 507
 508				pWnd = &m_DownloadOMeter;
 509				pWnd->GetWindowRect(rcDown);
 510				ScreenToClient(rcDown);
 511
 512				if (rcW.Height()>0) 
 513				{
 514					rcSpl.left = rcDown.left;
 515					rcSpl.right = rcDown.right;
 516					rcSpl.top = rcDown.bottom;
 517					rcSpl.bottom = rcDown.bottom + 4;
 518					m_wndSplitterstat_HR.MoveWindow(rcSpl,true);
 519				}
 520			}
 521			break;
 522		case WM_NOTIFY:
 523			if (wParam == IDC_SPLITTER_STAT)
 524			{ 
 525				SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
 526				DoResize_V(pHdr->delta);
 527			}
 528			else if (wParam == IDC_SPLITTER_STAT_HL)
 529			{ 
 530				SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
 531				DoResize_HL(pHdr->delta);
 532			}
 533			else if (wParam == IDC_SPLITTER_STAT_HR)
 534			{ 
 535				SPC_NMHDR* pHdr = (SPC_NMHDR*) lParam;
 536				DoResize_HR(pHdr->delta);
 537			}
 538			break;
 539		case WM_WINDOWPOSCHANGED: 
 540		{
 541			CRect rcW;
 542			GetWindowRect(rcW);
 543			ScreenToClient(rcW);
 544			if (m_wndSplitterstat && rcW.Width()>0) Invalidate();
 545			if (m_wndSplitterstat_HL && rcW.Height()>0) Invalidate();
 546			if (m_wndSplitterstat_HR && rcW.Height()>0) Invalidate();
 547			break;
 548		}
 549		case WM_SIZE:
 550		{
 551			//set range
 552			if (m_wndSplitterstat)
 553			{
 554				CRect rcW;
 555				GetWindowRect(rcW);
 556				ScreenToClient(rcW);
 557				if (rcW.Width()>0)
 558				{
 559					CRect rcSpl;
 560					CRect rcTree,rcDown;
 561					stattree.GetWindowRect(rcTree);
 562					m_DownloadOMeter.GetWindowRect(rcDown);
 563					ScreenToClient(rcTree);
 564					ScreenToClient(rcDown);
 565					long splitposstat=thePrefs.GetSplitterbarPositionStat()*rcW.Width()/100;
 566					rcSpl.left = splitposstat; 
 567					rcSpl.right = rcSpl.left + 4; 
 568					rcSpl.top = rcW.top + 2; 
 569					rcSpl.bottom = rcW.bottom - 5;
 570	   				m_wndSplitterstat.MoveWindow(rcSpl,true);
 571					m_wndSplitterstat.SetRange(rcW.left+11, rcW.right-11);
 572				}
 573			}
 574			if (m_wndSplitterstat_HR)
 575			{
 576				CRect rcW;
 577				GetWindowRect(rcW);
 578				ScreenToClient(rcW);
 579				if (rcW.Width()>0)
 580				{
 581					CRect rcSpl;
 582					CRect rcDown;
 583					m_DownloadOMeter.GetWindowRect(rcDown);
 584					ScreenToClient(rcDown);
 585					long splitposstat=thePrefs.GetSplitterbarPositionStat()*rcW.Width()/100;
 586					long splitposstat_HR=thePrefs.GetSplitterbarPositionStat_HR()*rcW.Height()/100;
 587					long splitposstat_HL=thePrefs.GetSplitterbarPositionStat_HL()*rcW.Height()/100;
 588					rcSpl.left = splitposstat + 7;
 589					rcSpl.right = rcW.right - 14; 
 590					rcSpl.top = splitposstat_HR; 
 591					rcSpl.bottom = rcSpl.top + 4;
 592					m_wndSplitterstat_HR.MoveWindow(rcSpl,true);
 593					m_wndSplitterstat_HR.SetRange(rcW.top+3, splitposstat_HL-4);
 594				}
 595			}
 596			if (m_wndSplitterstat_HL)
 597			{
 598				CRect rcW;
 599				GetWindowRect(rcW);
 600				ScreenToClient(rcW);
 601				if (rcW.Width()>0)
 602				{
 603					CRect rcSpl;
 604					CRect rcStat;
 605					m_Statistics.GetWindowRect(rcStat);
 606					ScreenToClient(rcStat);
 607					long splitposstat=thePrefs.GetSplitterbarPositionStat()*rcW.Width()/100;
 608					long splitposstat_HR=thePrefs.GetSplitterbarPositionStat_HR()*rcW.Height()/100;
 609					long splitposstat_HL=thePrefs.GetSplitterbarPositionStat_HL()*rcW.Height()/100;
 610					rcSpl.left = splitposstat + 7; 
 611					rcSpl.right = rcW.right - 14; 
 612					rcSpl.top = splitposstat_HL; 
 613					rcSpl.bottom = rcSpl.top + 4;
 614					m_wndSplitterstat_HL.MoveWindow(rcSpl,true);
 615					m_wndSplitterstat_HL.SetRange(splitposstat_HR+14, rcW.bottom-7);
 616				}
 617			}
 618			break;
 619		}
 620	}
 621	return CResizableDialog::DefWindowProc(message, wParam, lParam);
 622}
 623
 624void CStatisticsDlg::RepaintMeters() 
 625{
 626	CString Buffer;
 627	m_DownloadOMeter.SetBackgroundColor(thePrefs.GetStatsColor(0));	// Background
 628	m_DownloadOMeter.SetGridColor(thePrefs.GetStatsColor(1));		// Grid
 629	m_DownloadOMeter.SetPlotColor(thePrefs.GetStatsColor(4), 0);	// Download session
 630	m_DownloadOMeter.SetPlotColor(thePrefs.GetStatsColor(3), 1);	// Download average
 631	m_DownloadOMeter.SetPlotColor(thePrefs.GetStatsColor(2), 2);	// Download current
 632	m_DownloadOMeter.SetBarsPlot(thePrefs.GetFillGraphs(), 2);
 633
 634	m_UploadOMeter.SetBackgroundColor(thePrefs.GetStatsColor(0));
 635	m_UploadOMeter.SetGridColor(thePrefs.GetStatsColor(1));			// Grid
 636	m_UploadOMeter.SetPlotColor(thePrefs.GetStatsColor(7), 0);		// Upload session
 637	m_UploadOMeter.SetPlotColor(thePrefs.GetStatsColor(6), 1);		// Upload average
 638	m_UploadOMeter.SetPlotColor(thePrefs.GetStatsColor(5), 2);		// Upload current
 639	m_UploadOMeter.SetPlotColor(thePrefs.GetStatsColor(14), 3);		// Upload current (excl. overhead)
 640	m_UploadOMeter.SetPlotColor(thePrefs.GetStatsColor(13), 4);		// Upload friend slots
 641	m_UploadOMeter.SetBarsPlot(thePrefs.GetFillGraphs(), 2);
 642
 643	m_Statistics.SetBackgroundColor(thePrefs.GetStatsColor(0));
 644	m_Statistics.SetGridColor(thePrefs.GetStatsColor(1));
 645	m_Statistics.SetPlotColor(thePrefs.GetStatsColor(8), 0);	// Active Connections
 646	m_Statistics.SetPlotColor(thePrefs.GetStatsColor(10), 1);	// Active Uploads
 647	m_Statistics.SetPlotColor(thePrefs.GetStatsColor(9), 2);	// Total Uploads
 648	m_Statistics.SetPlotColor(thePrefs.GetStatsColor(12), 3);	// Active Downloads
 649	m_Statistics.SetBarsPlot(thePrefs.GetFillGraphs(), 0);
 650
 651	m_DownloadOMeter.SetYUnits(GetResString(IDS_ST_DOWNLOAD));
 652	m_DownloadOMeter.SetLegendLabel(GetResString(IDS_ST_SESSION), 0);			// Download session
 653	Buffer.Format(_T(" (%u %s)"), thePrefs.GetStatsAverageMinutes(), GetResString(IDS_MINS));
 654	m_DownloadOMeter.SetLegendLabel(GetResString(IDS_AVG) + Buffer, 1);			// Download average
 655	m_DownloadOMeter.SetLegendLabel(GetResString(IDS_ST_CURRENT), 2);			// Download current
 656
 657	m_UploadOMeter.SetYUnits(GetResString(IDS_ST_UPLOAD));
 658	m_UploadOMeter.SetLegendLabel(GetResString(IDS_ST_SESSION), 0);				// Upload session
 659	Buffer.Format(_T(" (%u %s)"), thePrefs.GetStatsAverageMinutes(), GetResString(IDS_MINS));
 660	m_UploadOMeter.SetLegendLabel(GetResString(IDS_AVG) + Buffer, 1);			// Upload average
 661	m_UploadOMeter.SetLegendLabel(GetResString(IDS_ST_ULCURRENT), 2);			// Upload current
 662	m_UploadOMeter.SetLegendLabel(GetResString(IDS_ST_ULSLOTSNOOVERHEAD), 3);	// Upload current (excl. overhead)
 663	m_UploadOMeter.SetLegendLabel(GetResString(IDS_ST_ULFRIEND), 4);			// Upload friend slots
 664
 665	m_Statistics.SetYUnits(GetResString(IDS_FSTAT_CONNECTION));
 666	Buffer.Format(_T("%s (1:%u)"), GetResString(IDS_ST_ACTIVEC), thePrefs.GetStatsConnectionsGraphRatio());
 667	m_Statistics.SetLegendLabel(Buffer, 0);										// Active Connections
 668	m_Statistics.SetLegendLabel(GetResString(IDS_ST_ACTIVEU_ZZ), 1);			// Active Uploads
 669	m_Statistics.SetLegendLabel(GetResString(IDS_SP_TOTALUL), 2);				// Total Uploads
 670	m_Statistics.SetLegendLabel(GetResString(IDS_ST_ACTIVED), 3);				// Active Downloads
 671}
 672
 673void CStatisticsDlg::SetCurrentRate(float uploadrate, float downloadrate)
 674{
 675	if (!theApp.emuledlg->IsRunning())
 676		return;
 677
 678	// Download
 679	double m_dPlotDataDown[3];
 680	m_dPlotDataDown[0] = theStats.GetAvgDownloadRate(AVG_SESSION);
 681	m_dPlotDataDown[1] = theStats.GetAvgDownloadRate(AVG_TIME);
 682	m_dPlotDataDown[2] = downloadrate;
 683	m_DownloadOMeter.AppendPoints(m_dPlotDataDown);
 684
 685	// Upload
 686	double m_dPlotDataUp[5];
 687	m_dPlotDataUp[0] = theStats.GetAvgUploadRate(AVG_SESSION);
 688	m_dPlotDataUp[1] = theStats.GetAvgUploadRate(AVG_TIME);
 689	// current rate to network (standardPackets + controlPackets)
 690	m_dPlotDataUp[2] = uploadrate;
 691	// current rate (excl. overhead)
 692	m_dPlotDataUp[3] = uploadrate - (float)theStats.GetUpDatarateOverhead() / 1024;
 693	// current rate to friends
 694	m_dPlotDataUp[4] = uploadrate - (float)theApp.uploadqueue->GetToNetworkDatarate() / 1024;
 695	m_UploadOMeter.AppendPoints(m_dPlotDataUp);
 696
 697	// Connections
 698	CDownloadQueue::SDownloadStats myStats;
 699	theApp.downloadqueue->GetDownloadSourcesStats(myStats);
 700	m_dPlotDataMore[0] = theApp.listensocket->GetActiveConnections();
 701	m_dPlotDataMore[1] = theApp.uploadqueue->GetActiveUploadsCount();
 702	m_dPlotDataMore[2] = theApp.uploadqueue->GetUploadQueueLength();
 703	m_dPlotDataMore[3] = myStats.a[1];
 704	m_Statistics.AppendPoints(m_dPlotDataMore);
 705
 706	// Websever
 707	UpDown updown;
 708	updown.upload = uploadrate;
 709	updown.download = downloadrate;
 710	updown.connections = theApp.listensocket->GetActiveConnections();
 711	theApp.webserver->AddStatsLine(updown);
 712}
 713
 714
 715void CStatisticsDlg::ShowStatistics(bool forceUpdate) 
 716{
 717	stattree.SetRedraw(false);
 718	CString	cbuffer;
 719	// Set Tree Values
 720
 721	// TRANSFER SECTION
 722	// If a section is not expanded, don't waste CPU cycles updating it.
 723	if (forceUpdate || stattree.IsExpanded(h_transfer)) 
 724	{
 725		uint32	statGoodSessions =				0;
 726		uint32	statBadSessions =				0;
 727		double	percentSessions =				0;
 728		// Transfer Ratios
 729		if ( theStats.sessionReceivedBytes>0 && theStats.sessionSentBytes>0 ) 
 730		{
 731			// Session
 732			if (theStats.sessionReceivedBytes<theStats.sessionSentBytes) 
 733			{
 734				cbuffer.Format(_T("%s %.2f : 1"),GetResString(IDS_STATS_SRATIO),(float)theStats.sessionSentBytes/theStats.sessionReceivedBytes);
 735				stattree.SetItemText(trans[0], cbuffer);
 736			} 
 737			else 
 738			{
 739				cbuffer.Format(_T("%s 1 : %.2f"),GetResString(IDS_STATS_SRATIO),(float)theStats.sessionReceivedBytes/theStats.sessionSentBytes);
 740				stattree.SetItemText(trans[0], cbuffer);
 741			}
 742		}
 743		else 
 744		{
 745			cbuffer.Format(_T("%s %s"), GetResString(IDS_STATS_SRATIO), GetResString(IDS_FSTAT_WAITING)); // Localize
 746			stattree.SetItemText(trans[0], cbuffer);
 747		}
 748
 749		if ( theStats.sessionReceivedBytes>0 && theStats.sessionSentBytes>0) 
 750		{
 751			// Session
 752			if (theStats.sessionSentBytes > theStats.sessionSentBytesToFriend && theStats.sessionReceivedBytes<theStats.sessionSentBytes-theStats.sessionSentBytesToFriend) 
 753			{
 754				cbuffer.Format(_T("%s %.2f : 1"),GetResString(IDS_STATS_FRATIO),(float)(theStats.sessionSentBytes-theStats.sessionSentBytesToFriend)/theStats.sessionReceivedBytes);
 755				stattree.SetItemText(trans[1], cbuffer);
 756			} 
 757			else 
 758			{
 759				cbuffer.Format(_T("%s 1 : %.2f"),GetResString(IDS_STATS_FRATIO),(float)theStats.sessionReceivedBytes/(theStats.sessionSentBytes-theStats.sessionSentBytesToFriend));
 760				stattree.SetItemText(trans[1], cbuffer);
 761			}
 762		}
 763		else 
 764		{
 765			cbuffer.Format(_T("%s %s"), GetResString(IDS_STATS_FRATIO), GetResString(IDS_FSTAT_WAITING)); // Localize
 766			stattree.SetItemText(trans[1], cbuffer);
 767		}
 768
 769		if ( (thePrefs.GetTotalDownloaded()>0 && thePrefs.GetTotalUploaded()>0) || (theStats.sessionReceivedBytes>0 && theStats.sessionSentBytes>0) ) 
 770		{
 771			// Cumulative
 772			if ((theStats.sessionReceivedBytes+thePrefs.GetTotalDownloaded())<(theStats.sessionSentBytes+thePrefs.GetTotalUploaded())) 
 773			{
 774				cbuffer.Format(_T("%s %.2f : 1"),GetResString(IDS_STATS_CRATIO),(float)(theStats.sessionSentBytes+thePrefs.GetTotalUploaded())/(theStats.sessionReceivedBytes+thePrefs.GetTotalDownloaded()));
 775				stattree.SetItemText(trans[2], cbuffer);
 776			} 
 777			else 
 778			{
 779				cbuffer.Format(_T("%s 1 : %.2f"),GetResString(IDS_STATS_CRATIO),(float)(theStats.sessionReceivedBytes+thePrefs.GetTotalDownloaded())/(theStats.sessionSentBytes+thePrefs.GetTotalUploaded()));
 780				stattree.SetItemText(trans[2], cbuffer);
 781			}
 782		}
 783		else 
 784		{
 785			cbuffer.Format(_T("%s %s"), GetResString(IDS_STATS_CRATIO), GetResString(IDS_FSTAT_WAITING)); // Localize
 786			stattree.SetItemText(trans[2], cbuffer);
 787		}
 788		// TRANSFER -> DOWNLOADS SECTION
 789		if (forceUpdate || stattree.IsExpanded(h_download)) 
 790		{
 791			uint64	DownOHTotal = 0;
 792			uint64	DownOHTotalPackets = 0;
 793			CDownloadQueue::SDownloadStats myStats;
 794			theApp.downloadqueue->GetDownloadSourcesStats(myStats);
 795			// TRANSFER -> DOWNLOADS -> SESSION SECTION
 796			if (forceUpdate || stattree.IsExpanded(h_down_session)) 
 797			{
 798				// Downloaded Data
 799				cbuffer.Format( GetResString( IDS_STATS_DDATA ) , CastItoXBytes( theStats.sessionReceivedBytes, false, false ) );
 800				stattree.SetItemText( down_S[0] , cbuffer );
 801				if (forceUpdate || stattree.IsExpanded(down_S[0])) 
 802				{
 803					// Downloaded Data By Client
 804					if (forceUpdate || stattree.IsExpanded(hdown_scb)) 
 805					{
 806						int i = 0;
 807						uint64 DownDataTotal =		thePrefs.GetDownSessionClientData();
 808						uint64 DownDataClient =		thePrefs.GetDownData_EMULE();
 809						double percentClientTransferred = 0;
 810						if ( DownDataTotal!=0 && DownDataClient!=0 )
 811							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 812						cbuffer.Format( _T("eMule: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ) , percentClientTransferred);
 813						stattree.SetItemText( down_scb[i] , cbuffer );
 814						i++;
 815
 816						DownDataClient = thePrefs.GetDownData_EDONKEYHYBRID();
 817						if ( DownDataTotal!=0 && DownDataClient!=0 )
 818							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 819						else
 820							percentClientTransferred = 0;
 821						cbuffer.Format( _T("eD Hybrid: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ) , percentClientTransferred );
 822						stattree.SetItemText( down_scb[i] , cbuffer );
 823						i++;
 824
 825						DownDataClient = thePrefs.GetDownData_EDONKEY();
 826						if ( DownDataTotal!=0 && DownDataClient!=0 )
 827							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 828						else
 829							percentClientTransferred = 0;
 830						cbuffer.Format( _T("eDonkey: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
 831						stattree.SetItemText( down_scb[i] , cbuffer );
 832						i++;
 833
 834						DownDataClient = thePrefs.GetDownData_AMULE();
 835						if ( DownDataTotal!=0 && DownDataClient!=0 )
 836							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 837						else
 838							percentClientTransferred = 0;
 839						cbuffer.Format( _T("aMule: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
 840						stattree.SetItemText( down_scb[i] , cbuffer );
 841						i++;
 842
 843						DownDataClient = thePrefs.GetDownData_MLDONKEY();
 844						if ( DownDataTotal!=0 && DownDataClient!=0 )
 845							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 846						else
 847							percentClientTransferred = 0;
 848						cbuffer.Format( _T("MLdonkey: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
 849						stattree.SetItemText( down_scb[i] , cbuffer );
 850						i++;
 851
 852						DownDataClient = thePrefs.GetDownData_SHAREAZA();
 853						if ( DownDataTotal!=0 && DownDataClient!=0 )
 854							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 855						else
 856							percentClientTransferred = 0;
 857						cbuffer.Format( _T("Shareaza: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
 858						stattree.SetItemText( down_scb[i] , cbuffer );
 859						i++;
 860
 861						DownDataClient = thePrefs.GetDownData_EMULECOMPAT();
 862						if ( DownDataTotal!=0 && DownDataClient!=0 )
 863							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 864						else
 865							percentClientTransferred = 0;
 866						cbuffer.Format( _T("eM Compat: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
 867						stattree.SetItemText( down_scb[i] , cbuffer );
 868						i++;
 869
 870						DownDataClient = thePrefs.GetDownData_URL();
 871						if ( DownDataTotal!=0 && DownDataClient!=0 )
 872							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
 873						else
 874							percentClientTransferred = 0;
 875						cbuffer.Format( _T("URL: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
 876						stattree.SetItemText( down_scb[i] , cbuffer );
 877						i++;
 878					}
 879					// Downloaded Data By Port
 880					if (forceUpdate || stattree.IsExpanded(hdown_spb)) 
 881					{
 882						int i = 0;
 883						uint64	PortDataDefault =	thePrefs.GetDownDataPort_4662();
 884						uint64	PortDataOther =		thePrefs.GetDownDataPort_OTHER();
 885						uint64	PortDataPeerCache =	thePrefs.GetDownDataPort_PeerCache();
 886						uint64	PortDataTotal =		thePrefs.GetDownSessionDataPort();
 887						double	percentPortTransferred = 0;
 888
 889						if ( PortDataTotal!=0 && PortDataDefault!=0 )
 890							percentPortTransferred = (double) 100 * PortDataDefault / PortDataTotal;
 891						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTDEF) , CastItoXBytes( PortDataDefault, false, false ) , percentPortTransferred);
 892						stattree.SetItemText( down_spb[i] , cbuffer );
 893						i++;
 894
 895						if ( PortDataTotal!=0 && PortDataOther!=0 )
 896							percentPortTransferred = (double) 100 * PortDataOther / PortDataTotal;
 897						else
 898							percentPortTransferred = 0;
 899						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataOther, false, false ) , percentPortTransferred);
 900						stattree.SetItemText( down_spb[i] , cbuffer );
 901						i++;
 902
 903						if ( PortDataTotal!=0 && PortDataPeerCache!=0 )
 904							percentPortTransferred = (double) 100 * PortDataPeerCache / PortDataTotal;
 905						else
 906							percentPortTransferred = 0;
 907						cbuffer.Format( _T("%s: %s (%1.1f%%)") , thePrefs.GetPeerCacheShow() ? _T("PeerCache") : GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataPeerCache, false, false ) , percentPortTransferred);
 908						stattree.SetItemText( down_spb[i] , cbuffer );
 909						i++;
 910					}
 911				}
 912				// Completed Downloads
 913				cbuffer.Format( _T("%s: %u") , GetResString( IDS_STATS_COMPDL ) , thePrefs.GetDownSessionCompletedFiles() );
 914				stattree.SetItemText( down_S[1] , cbuffer );
 915				// Active Downloads
 916				cbuffer.Format( GetResString( IDS_STATS_ACTDL ) , myStats.a[1] );
 917				stattree.SetItemText( down_S[2] , cbuffer );
 918				// Found Sources
 919				cbuffer.Format( GetResString( IDS_STATS_FOUNDSRC ) , myStats.a[0] );
 920				stattree.SetItemText( down_S[3] , cbuffer );
 921				if (forceUpdate || stattree.IsExpanded(down_S[3])) 
 922				{ 
 923					int i = 0;
 924					// Sources By Status
 925					cbuffer.Format( _T("%s: %u") , GetResString( IDS_ONQUEUE ) , myStats.a[2] );
 926					stattree.SetItemText( down_sources[i] , cbuffer );
 927					i++;
 928					cbuffer.Format( _T("%s: %u") , GetResString( IDS_QUEUEFULL ) , myStats.a[3] );
 929					stattree.SetItemText( down_sources[i] , cbuffer );
 930					i++;
 931					cbuffer.Format( _T("%s: %u") , GetResString( IDS_NONEEDEDPARTS ) , myStats.a[4] );
 932					stattree.SetItemText( down_sources[i] , cbuffer );
 933					i++;
 934					cbuffer.Format( _T("%s: %u") , GetResString( IDS_ASKING ) , myStats.a[5] );
 935					stattree.SetItemText( down_sources[i] , cbuffer );
 936					i++;
 937					cbuffer.Format( _T("%s: %u") , GetResString( IDS_RECHASHSET ) , myStats.a[6] );
 938					stattree.SetItemText( down_sources[i] , cbuffer );
 939					i++;
 940					cbuffer.Format( _T("%s: %u") , GetResString( IDS_CONNECTING ) , myStats.a[7] );
 941					stattree.SetItemText( down_sources[i] , cbuffer );
 942					i++;
 943					cbuffer.Format( _T("%s: %u") , GetResString(IDS_CONNVIASERVER) , myStats.a[8] );
 944					stattree.SetItemText( down_sources[i] , cbuffer );
 945					i++;
 946					cbuffer.Format( _T("%s: %u") , GetResString(IDS_TOOMANYCONNS) , myStats.a[9] );
 947					stattree.SetItemText( down_sources[i] , cbuffer );
 948					i++;
 949					cbuffer.Format( _T("%s: %u") , GetResString(IDS_NOCONNECTLOW2LOW) , myStats.a[10] );
 950					stattree.SetItemText( down_sources[i] , cbuffer );
 951					i++;
 952					cbuffer.Format( _T("%s: %u") , GetResString(IDS_STATS_PROBLEMATIC) , myStats.a[12] );
 953					stattree.SetItemText( down_sources[i] , cbuffer );
 954					i++;
 955					cbuffer.Format( _T("%s: %u") , GetResString(IDS_BANNED) , myStats.a[13] );
 956					stattree.SetItemText( down_sources[i] , cbuffer );
 957					i++;
 958					cbuffer.Format( _T("%s: %u") , GetResString(IDS_ASKED4ANOTHERFILE) , myStats.a[15] );
 959					stattree.SetItemText( down_sources[i] , cbuffer );
 960					i++;
 961					cbuffer.Format( _T("%s: %u") , GetResString(IDS_UNKNOWN) , myStats.a[11] );
 962					stattree.SetItemText( down_sources[i] , cbuffer );
 963					i++;
 964
 965					// where from? (3)
 966					cbuffer.Format( _T("%s: %u") , GetResString( IDS_VIAED2KSQ ) , myStats.a[16] );
 967					stattree.SetItemText( down_sources[i] , cbuffer );
 968					i++;
 969					cbuffer.Format( _T("%s: %u") , GetResString( IDS_VIAKAD ) , myStats.a[17] );
 970					stattree.SetItemText( down_sources[i] , cbuffer );
 971					i++;
 972					cbuffer.Format( _T("%s: %u") , GetResString( IDS_VIASE ) , myStats.a[18] );
 973					stattree.SetItemText( down_sources[i] , cbuffer );
 974					i++;
 975					cbuffer.Format( _T("%s: %u") , GetResString( IDS_VIAPASSIVE ) , myStats.a[14] );
 976					stattree.SetItemText( down_sources[i] , cbuffer );
 977					i++;
 978					cbuffer.Format( _T("eD2K: %u (%.1f%%)") , myStats.a[19], myStats.a[0] ? (myStats.a[19] * 100.0 / myStats.a[0]) : 0.0 );
 979					stattree.SetItemText( down_sources[i] , cbuffer );
 980					i++;
 981					cbuffer.Format( _T("Kad: %u (%.1f%%)") , myStats.a[20], myStats.a[0] ? (myStats.a[20] * 100.0 / myStats.a[0]) : 0.0 );
 982					stattree.SetItemText( down_sources[i] , cbuffer );
 983					i++;
 984					cbuffer.Format( _T("eD2K/Kad: %u (%.1f%%)") , myStats.a[21], myStats.a[0] ? (myStats.a[21] * 100.0 / myStats.a[0]) : 0.0 );
 985					stattree.SetItemText( down_sources[i] , cbuffer );
 986					i++;
 987
 988					cbuffer.Format(_T("%s: %s, %s: %s (%.1f%%)"), GetResString(IDS_UDPREASKS), CastItoIShort(theApp.downloadqueue->GetUDPFileReasks()), GetResString(IDS_UFAILED), CastItoIShort(theApp.downloadqueue->GetFailedUDPFileReasks()), theApp.downloadqueue->GetUDPFileReasks() ? (theApp.downloadqueue->GetFailedUDPFileReasks() * 100.0 / theApp.downloadqueue->GetUDPFileReasks()) : 0.0 );
 989					stattree.SetItemText( down_sources[i] , cbuffer );
 990					i++;
 991
 992					cbuffer.Format(_T("%s: %s (%s + %s)"), GetResString(IDS_DEADSOURCES), CastItoIShort(theApp.clientlist->m_globDeadSourceList.GetDeadSourcesCount() + myStats.a[22]), CastItoIShort(theApp.clientlist->m_globDeadSourceList.GetDeadSourcesCount()), CastItoIShort((UINT)myStats.a[22]));
 993					stattree.SetItemText( down_sources[i] , cbuffer );
 994					i++;
 995				}
 996				// Set Download Sessions
 997				statGoodSessions =	thePrefs.GetDownS_SuccessfulSessions() + myStats.a[1]; // Add Active Downloads
 998				statBadSessions =	thePrefs.GetDownS_FailedSessions();
 999				cbuffer.Format( _T("%s: %u") , GetResString(IDS_STATS_DLSES) , statGoodSessions + statBadSessions );
1000				stattree.SetItemText( down_S[4] , cbuffer );
1001				if (forceUpdate || stattree.IsExpanded(down_S[4])) 
1002				{
1003					// Set Successful Download Sessions and Average Downloaded Per Session
1004					percentSessions = 0;
1005					if (statGoodSessions > 0) 
1006					{
1007						percentSessions = (double) 100 * statGoodSessions / (statGoodSessions + statBadSessions);
1008						cbuffer.Format( _T("%s: %s") , GetResString(IDS_STATS_AVGDATADLSES) , CastItoXBytes( theStats.sessionReceivedBytes / statGoodSessions, false, false ) ); 
1009					}
1010					else 
1011						cbuffer.Format( _T("%s: %s") , GetResString(IDS_STATS_AVGDATADLSES) , CastItoXBytes((uint32)0, false, false) );
1012					stattree.SetItemText( down_ssessions[2] , cbuffer ); // Set Avg DL/Session
1013					cbuffer.Format( _T("%s: %u (%1.1f%%)") , GetResString(IDS_STATS_SDLSES) , statGoodSessions , percentSessions );
1014					stattree.SetItemText( down_ssessions[0] , cbuffer ); // Set Succ Sessions
1015					// Set Failed Download Sessions (Avoid Division)
1016					if (percentSessions != 0 && statBadSessions > 0) 
1017						percentSessions = 100 - percentSessions; // There were some good sessions and bad ones...
1018					else if (percentSessions == 0 && statBadSessions > 0) 
1019						percentSessions = 100; // There were bad sessions and no good ones, must be 100%
1020					else 
1021						percentSessions = 0; // No sessions at all, or no bad ones.
1022					cbuffer.Format( _T("%s: %u (%1.1f%%)") , GetResString(IDS_STATS_FDLSES) , statBadSessions , percentSessions );
1023					stattree.SetItemText( down_ssessions[1] , cbuffer );
1024					// Set Average Download Time
1025					cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_AVGDLTIME), CastSecondsToLngHM(thePrefs.GetDownS_AvgTime()));
1026					stattree.SetItemText( down_ssessions[3] , cbuffer );
1027				}
1028				// Set Gain Due To Compression
1029				cbuffer.Format(GetResString(IDS_STATS_GAINCOMP) + _T(" (%.1f%%)"), CastItoXBytes(thePrefs.GetSesSavedFromCompression(), false, false), theStats.sessionReceivedBytes!=0 ? (thePrefs.GetSesSavedFromCompression() * 100.0 / theStats.sessionReceivedBytes) : 0.0);
1030				stattree.SetItemText( down_S[5] , cbuffer );
1031				// Set Lost Due To Corruption
1032				cbuffer.Format(GetResString(IDS_STATS_LOSTCORRUPT) + _T(" (%.1f%%)"), CastItoXBytes(thePrefs.GetSesLostFromCorruption(), false, false), theStats.sessionReceivedBytes!=0 ? (thePrefs.GetSesLostFromCorruption() * 100.0 / theStats.sessionReceivedBytes) : 0.0);
1033				stattree.SetItemText( down_S[6] , cbuffer );
1034				// Set Parts Saved Due To ICH
1035				cbuffer.Format(GetResString(IDS_STATS_ICHSAVED), thePrefs.GetSesPartsSavedByICH());
1036				stattree.SetItemText( down_S[7] , cbuffer );
1037
1038				// Calculate downline OH totals
1039				DownOHTotal =	theStats.GetDownDataOverheadFileRequest() + 
1040								theStats.GetDownDataOverheadSourceExchange() + 
1041								theStats.GetDownDataOverheadServer() + 
1042								theStats.GetDownDataOverheadKad() + 
1043								theStats.GetDownDataOverheadOther();
1044				DownOHTotalPackets = 
1045								theStats.GetDownDataOverheadFileRequestPackets() + 
1046								theStats.GetDownDataOverheadSourceExchangePackets() + 
1047								theStats.GetDownDataOverheadServerPackets() + 
1048								theStats.GetDownDataOverheadKadPackets() + 
1049								theStats.GetDownDataOverheadOtherPackets();
1050
1051				// Downline Overhead
1052				cbuffer.Format( GetResString( IDS_TOVERHEAD ) , CastItoXBytes( DownOHTotal, false, false ) , CastItoIShort( DownOHTotalPackets ) );
1053				stattree.SetItemText( hdown_soh , cbuffer );
1054				if (forceUpdate || stattree.IsExpanded(hdown_soh)) 
1055				{
1056					int i = 0;
1057					// Set down session file req OH
1058					cbuffer.Format( GetResString( IDS_FROVERHEAD ) , CastItoXBytes( theStats.GetDownDataOverheadFileRequest(), false, false ) , CastItoIShort( theStats.GetDownDataOverheadFileRequestPackets() ) );
1059					stattree.SetItemText( down_soh[i] , cbuffer );
1060					i++;
1061					// Set down session source exch OH
1062					cbuffer.Format( GetResString( IDS_SSOVERHEAD ) , CastItoXBytes( theStats.GetDownDataOverheadSourceExchange(), false, false ), CastItoIShort( theStats.GetDownDataOverheadSourceExchangePackets() ) );
1063					stattree.SetItemText( down_soh[i] , cbuffer );
1064					i++;
1065					// Set down session server OH
1066					cbuffer.Format(GetResString(IDS_SOVERHEAD),
1067								   CastItoXBytes(theStats.GetDownDataOverheadServer(), false, false), 
1068								   CastItoIShort(theStats.GetDownDataOverheadServerPackets()));
1069					stattree.SetItemText( down_soh[i] , cbuffer );
1070					i++;
1071					// Set down session Kad OH
1072					cbuffer.Format(GetResString(IDS_KADOVERHEAD),
1073								   CastItoXBytes(theStats.GetDownDataOverheadKad(), false, false), 
1074								   CastItoIShort(theStats.GetDownDataOverheadKadPackets()));
1075					stattree.SetItemText( down_soh[i] , cbuffer );
1076					i++;
1077				}
1078			}
1079			// TRANSFER -> DOWNLOADS -> CUMULATIVE SECTION
1080			if (forceUpdate || stattree.IsExpanded(h_down_total)) 
1081			{
1082				// Downloaded Data
1083				uint64 ullCumReceived = theStats.sessionReceivedBytes + thePrefs.GetTotalDownloaded();
1084				cbuffer.Format(GetResString(IDS_STATS_DDATA), CastItoXBytes(ullCumReceived, false, false));
1085				stattree.SetItemText(down_T[0], cbuffer);
1086				if (forceUpdate || stattree.IsExpanded(down_T[0])) 
1087				{
1088					// Downloaded Data By Client
1089					if (forceUpdate || stattree.IsExpanded(hdown_tcb)) 
1090					{
1091						int i = 0;
1092						uint64 DownDataTotal =		thePrefs.GetDownTotalClientData();
1093						uint64 DownDataClient =		thePrefs.GetCumDownData_EMULE();
1094						double percentClientTransferred = 0;
1095						if ( DownDataTotal!=0 && DownDataClient!=0 )
1096							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1097						cbuffer.Format( _T("eMule: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ) , percentClientTransferred);
1098						stattree.SetItemText( down_tcb[i] , cbuffer );
1099						i++;
1100
1101						DownDataClient = thePrefs.GetCumDownData_EDONKEYHYBRID();
1102						if ( DownDataTotal!=0 && DownDataClient!=0 )
1103							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1104						else
1105							percentClientTransferred = 0;
1106						cbuffer.Format( _T("eD Hybrid: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ) , percentClientTransferred );
1107						stattree.SetItemText( down_tcb[i] , cbuffer );
1108						i++;
1109
1110						DownDataClient = thePrefs.GetCumDownData_EDONKEY();
1111						if ( DownDataTotal!=0 && DownDataClient!=0 )
1112							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1113						else
1114							percentClientTransferred = 0;
1115						cbuffer.Format( _T("eDonkey: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
1116						stattree.SetItemText( down_tcb[i] , cbuffer );
1117						i++;
1118
1119						DownDataClient = thePrefs.GetCumDownData_AMULE();
1120						if ( DownDataTotal!=0 && DownDataClient!=0 )
1121							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1122						else
1123							percentClientTransferred = 0;
1124						cbuffer.Format( _T("aMule: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
1125						stattree.SetItemText( down_tcb[i] , cbuffer );
1126						i++;
1127
1128						DownDataClient = thePrefs.GetCumDownData_MLDONKEY();
1129						if ( DownDataTotal!=0 && DownDataClient!=0 )
1130							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1131						else
1132							percentClientTransferred = 0;
1133						cbuffer.Format( _T("MLdonkey: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
1134						stattree.SetItemText( down_tcb[i] , cbuffer );
1135						i++;
1136
1137						DownDataClient = thePrefs.GetCumDownData_SHAREAZA();
1138						if ( DownDataTotal!=0 && DownDataClient!=0 )
1139							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1140						else
1141							percentClientTransferred = 0;
1142						cbuffer.Format( _T("Shareaza: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
1143						stattree.SetItemText( down_tcb[i] , cbuffer );
1144						i++;
1145
1146						DownDataClient = thePrefs.GetCumDownData_EMULECOMPAT();
1147						if ( DownDataTotal!=0 && DownDataClient!=0 )
1148							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1149						else
1150							percentClientTransferred = 0;
1151						cbuffer.Format( _T("eM Compat: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
1152						stattree.SetItemText( down_tcb[i] , cbuffer );
1153						i++;
1154
1155						DownDataClient = thePrefs.GetCumDownData_URL();
1156						if ( DownDataTotal!=0 && DownDataClient!=0 )
1157							percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
1158						else
1159							percentClientTransferred = 0;
1160						cbuffer.Format( _T("URL: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
1161						stattree.SetItemText( down_tcb[i] , cbuffer );
1162						i++;
1163					}
1164					// Downloaded Data By Port
1165					if (forceUpdate || stattree.IsExpanded(hdown_tpb)) 
1166					{
1167						int i = 0;
1168						uint64	PortDataDefault =	thePrefs.GetCumDownDataPort_4662();
1169						uint64	PortDataOther =		thePrefs.GetCumDownDataPort_OTHER();
1170						uint64	PortDataPeerCache =	thePrefs.GetCumDownDataPort_PeerCache();
1171						uint64	PortDataTotal =		thePrefs.GetDownTotalPortData();
1172						double	percentPortTransferred = 0;
1173
1174						if ( PortDataTotal!=0 && PortDataDefault!=0 )
1175							percentPortTransferred = (double) 100 * PortDataDefault / PortDataTotal;
1176						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTDEF) , CastItoXBytes( PortDataDefault, false, false ) , percentPortTransferred);
1177						stattree.SetItemText( down_tpb[i] , cbuffer );
1178						i++;
1179
1180						if ( PortDataTotal!=0 && PortDataOther!=0 )
1181							percentPortTransferred = (double) 100 * PortDataOther / PortDataTotal;
1182						else
1183							percentPortTransferred = 0;
1184						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataOther, false, false ) , percentPortTransferred);
1185						stattree.SetItemText( down_tpb[i] , cbuffer );
1186						i++;
1187
1188						if ( PortDataTotal!=0 && PortDataPeerCache!=0 )
1189							percentPortTransferred = (double) 100 * PortDataPeerCache / PortDataTotal;
1190						else
1191							percentPortTransferred = 0;
1192						cbuffer.Format( _T("%s: %s (%1.1f%%)") , thePrefs.GetPeerCacheShow() ? _T("PeerCache") : GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataPeerCache, false, false ) , percentPortTransferred);
1193						stattree.SetItemText( down_tpb[i] , cbuffer );
1194						i++;
1195					}
1196				}
1197				// Set Cum Completed Downloads
1198				cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_COMPDL), thePrefs.GetDownCompletedFiles() );
1199				stattree.SetItemText(down_T[1], cbuffer);
1200				// Set Cum Download Sessions
1201				statGoodSessions = thePrefs.GetDownC_SuccessfulSessions() + myStats.a[1]; // Need to reset these from the session section.  Declared up there.
1202				statBadSessions = thePrefs.GetDownC_FailedSessions(); // ^^^^^^^^^^^^^^
1203				cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_DLSES), statGoodSessions+statBadSessions );
1204				stattree.SetItemText(down_T[2], cbuffer);
1205				if (forceUpdate || stattree.IsExpanded(down_T[2])) 
1206				{
1207					// Set Cum Successful Download Sessions & Cum Average Download Per Sessions (Save an if-else statement)
1208					if (statGoodSessions > 0) 
1209					{
1210						percentSessions = (double) 100 * statGoodSessions / (statGoodSessions + statBadSessions);
1211						cbuffer.Format( _T("%s: %s") , GetResString(IDS_STATS_AVGDATADLSES), CastItoXBytes(ullCumReceived / statGoodSessions, false, false));
1212					}
1213					else 
1214					{
1215						percentSessions = 0;
1216						cbuffer.Format( _T("%s: %s") , GetResString(IDS_STATS_AVGDATADLSES) , CastItoXBytes((uint32)0, false, false) );
1217					}
1218					stattree.SetItemText( down_tsessions[2] , cbuffer ); // Set Avg DL/Session
1219					cbuffer.Format( _T("%s: %u (%1.1f%%)"), GetResString(IDS_STATS_SDLSES) , statGoodSessions , percentSessions );
1220					stattree.SetItemText( down_tsessions[0] , cbuffer ); // Set Successful Sessions
1221					// Set Cum Failed Download Sessions
1222					if (percentSessions != 0 && statBadSessions > 0) 
1223						percentSessions = 100 - percentSessions; // There were some good sessions and bad ones...
1224					else if (percentSessions == 0 && statBadSessions > 0) 
1225						percentSessions = 100; // There were bad sessions and no good ones, must be 100%
1226					else 
1227						percentSessions = 0; // No sessions at all, or no bad ones.
1228					cbuffer.Format( _T("%s: %u (%1.1f%%)") , GetResString(IDS_STATS_FDLSES) , statBadSessions , percentSessions);
1229					stattree.SetItemText( down_tsessions[1] , cbuffer );
1230					// Set Cumulative Average Download Time
1231					uint32 avgDownTime = thePrefs.GetDownS_AvgTime();
1232					if (thePrefs.GetDownC_AvgTime()<=0) 
1233						thePrefs.SetDownCAvgTime(avgDownTime);
1234					avgDownTime = (uint32) (avgDownTime+thePrefs.GetDownC_AvgTime())/2;
1235					cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_AVGDLTIME), CastSecondsToLngHM(avgDownTime));
1236					stattree.SetItemText(down_tsessions[3], cbuffer);
1237				}
1238				// Set Cumulative Gained Due To Compression
1239				uint64 ullCumCompressed = thePrefs.GetSesSavedFromCompression() + thePrefs.GetCumSavedFromCompression();
1240				cbuffer.Format(GetResString(IDS_STATS_GAINCOMP) + _T(" (%.1f%%)"), CastItoXBytes(ullCumCompressed, false, false), ullCumReceived!=0 ? (ullCumCompressed * 100.0 / ullCumReceived) : 0.0);
1241				stattree.SetItemText( down_T[3] , cbuffer );
1242				// Set Cumulative Lost Due To Corruption
1243				uint64 ullCumCorrupted = thePrefs.GetSesLostFromCorruption() + thePrefs.GetCumLostFromCorruption();
1244				cbuffer.Format(GetResString(IDS_STATS_LOSTCORRUPT) + _T(" (%.1f%%)"), CastItoXBytes(ullCumCorrupted, false, false), ullCumReceived!=0 ? (ullCumCorrupted * 100.0 / ullCumReceived) : 0.0);
1245				stattree.SetItemText( down_T[4] , cbuffer );
1246				// Set Cumulative Saved Due To ICH
1247				cbuffer.Format(GetResString(IDS_STATS_ICHSAVED), thePrefs.GetSesPartsSavedByICH() + thePrefs.GetCumPartsSavedByICH());
1248				stattree.SetItemText( down_T[5] , cbuffer );
1249
1250				if (DownOHTotal == 0 || DownOHTotalPackets == 0) 
1251				{
1252					DownOHTotal =	theStats.GetDownDataOverheadFileRequest() + 
1253									theStats.GetDownDataOverheadSourceExchange() + 
1254									theStats.GetDownDataOverheadServer() + 
1255									theStats.GetDownDataOverheadKad() + 
1256									theStats.GetDownDataOverheadOther();
1257					DownOHTotalPackets = 
1258									theStats.GetDownDataOverheadFileRequestPackets() + 
1259									theStats.GetDownDataOverheadSourceExchangePackets() + 
1260									theStats.GetDownDataOverheadServerPackets() + 
1261									theStats.GetDownDataOverheadKadPackets() + 
1262									theStats.GetDownDataOverheadOtherPackets();
1263				}
1264				// Total Overhead
1265				cbuffer.Format(GetResString(IDS_TOVERHEAD),CastItoXBytes(DownOHTotal + thePrefs.GetDownOverheadTotal(), false, false), CastItoIShort(DownOHTotalPackets + thePrefs.GetDownOverheadTotalPackets()));
1266				stattree.SetItemText(hdown_toh, cbuffer);
1267				if (forceUpdate || stattree.IsExpanded(hdown_toh)) 
1268				{
1269					int i = 0;
1270					// File Request Overhead
1271					cbuffer.Format(GetResString(IDS_FROVERHEAD), CastItoXBytes( theStats.GetDownDataOverheadFileRequest() + thePrefs.GetDownOverheadFileReq(), false, false), CastItoIShort(theStats.GetDownDataOverheadFileRequestPackets() + thePrefs.GetDownOverheadFileReqPackets()));
1272					stattree.SetItemText(down_toh[i], cbuffer);
1273					i++;
1274					// Source Exchange Overhead
1275					cbuffer.Format(GetResString(IDS_SSOVERHEAD), CastItoXBytes( theStats.GetDownDataOverheadSourceExchange()+thePrefs.GetDownOverheadSrcEx(), false, false), CastItoIShort(theStats.GetDownDataOverheadSourceExchangePackets()+thePrefs.GetDownOverheadSrcExPackets()));
1276					stattree.SetItemText(down_toh[i], cbuffer);
1277					i++;
1278					// Server Overhead
1279					cbuffer.Format(GetResString(IDS_SOVERHEAD), 
1280								   CastItoXBytes(theStats.GetDownDataOverheadServer() + 
1281												 thePrefs.GetDownOverheadServer(), false, false), 
1282								   CastItoIShort(theStats.GetDownDataOverheadServerPackets() +
1283												 thePrefs.GetDownOverheadServerPackets()));
1284					stattree.SetItemText(down_toh[i], cbuffer);
1285					i++;
1286					// Kad Overhead
1287					cbuffer.Format(GetResString(IDS_KADOVERHEAD), 
1288								   CastItoXBytes(theStats.GetDownDataOverheadKad() + 
1289												 thePrefs.GetDownOverheadKad(), false, false), 
1290								   CastItoIShort(theStats.GetDownDataOverheadKadPackets() +
1291												 thePrefs.GetDownOverheadKadPackets()));
1292					stattree.SetItemText(down_toh[i], cbuffer);
1293					i++;
1294				}
1295			} // - End Transfer -> Downloads -> Cumulative Section
1296		} // - End Transfer -> Downloads Section
1297		// TRANSFER-> UPLOADS SECTION
1298		if (forceUpdate || stattree.IsExpanded(h_upload)) 
1299		{
1300			uint64 UpOHTotal =			0;
1301			uint64 UpOHTotalPackets =	0;
1302			// TRANSFER -> UPLOADS -> SESSION SECTION
1303			if (forceUpdate || stattree.IsExpanded(h_up_session)) 
1304			{
1305				// Uploaded Data
1306				cbuffer.Format(GetResString(IDS_STATS_UDATA),CastItoXBytes(theStats.sessionSentBytes, false, false));
1307				stattree.SetItemText(up_S[0], cbuffer);
1308				if (forceUpdate || stattree.IsExpanded(up_S[0])) 
1309				{
1310					// Uploaded Data By Client
1311					if (forceUpdate || stattree.IsExpanded(hup_scb)) 
1312					{
1313						int i = 0;
1314						uint64 UpDataTotal =		thePrefs.GetUpSessionClientData();
1315						uint64 UpDataClient =		thePrefs.GetUpData_EMULE();
1316						double percentClientTransferred = 0;
1317						if ( UpDataTotal!=0 && UpDataClient!=0 )
1318							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1319						cbuffer.Format( _T("eMule: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ) , percentClientTransferred);
1320						stattree.SetItemText( up_scb[i] , cbuffer );
1321						i++;
1322
1323						UpDataClient = thePrefs.GetUpData_EDONKEYHYBRID();
1324						if ( UpDataTotal!=0 && UpDataClient!=0 )
1325							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1326						else
1327							percentClientTransferred = 0;
1328						cbuffer.Format( _T("eD Hybrid: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ) , percentClientTransferred );
1329						stattree.SetItemText( up_scb[i] , cbuffer );
1330						i++;
1331
1332						UpDataClient = thePrefs.GetUpData_EDONKEY();
1333						if ( UpDataTotal!=0 && UpDataClient!=0 )
1334							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1335						else
1336							percentClientTransferred = 0;
1337						cbuffer.Format( _T("eDonkey: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1338						stattree.SetItemText( up_scb[i] , cbuffer );
1339						i++;
1340
1341						UpDataClient = thePrefs.GetUpData_AMULE();
1342						if ( UpDataTotal!=0 && UpDataClient!=0 )
1343							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1344						else
1345							percentClientTransferred = 0;
1346						cbuffer.Format( _T("aMule: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1347						stattree.SetItemText( up_scb[i] , cbuffer );
1348						i++;
1349
1350						UpDataClient = thePrefs.GetUpData_MLDONKEY();
1351						if ( UpDataTotal!=0 && UpDataClient!=0 )
1352							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1353						else
1354							percentClientTransferred = 0;
1355						cbuffer.Format( _T("MLdonkey: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1356						stattree.SetItemText( up_scb[i] , cbuffer );
1357						i++;
1358
1359						UpDataClient = thePrefs.GetUpData_SHAREAZA();
1360						if ( UpDataTotal!=0 && UpDataClient!=0 )
1361							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1362						else
1363							percentClientTransferred = 0;
1364						cbuffer.Format( _T("Shareaza: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1365						stattree.SetItemText( up_scb[i] , cbuffer );
1366						i++;
1367
1368						UpDataClient = thePrefs.GetUpData_EMULECOMPAT();
1369						if ( UpDataTotal!=0 && UpDataClient!=0 )
1370							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1371						else
1372							percentClientTransferred = 0;
1373						cbuffer.Format( _T("eM Compat: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1374						stattree.SetItemText( up_scb[i] , cbuffer );
1375						i++;
1376					}
1377					// Uploaded Data By Port
1378					if (forceUpdate || stattree.IsExpanded(hup_spb)) 
1379					{
1380						int i = 0;
1381						uint64	PortDataDefault =	thePrefs.GetUpDataPort_4662();
1382						uint64	PortDataOther =		thePrefs.GetUpDataPort_OTHER();
1383						uint64	PortDataPeerCache =	thePrefs.GetUpDataPort_PeerCache();
1384						uint64	PortDataTotal =		thePrefs.GetUpSessionPortData();
1385						double	percentPortTransferred = 0;
1386
1387						if ( PortDataTotal!=0 && PortDataDefault!=0 )
1388							percentPortTransferred = (double) 100 * PortDataDefault / PortDataTotal;
1389						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTDEF) , CastItoXBytes( PortDataDefault, false, false ) , percentPortTransferred);
1390						stattree.SetItemText( up_spb[i] , cbuffer );
1391						i++;
1392
1393						if ( PortDataTotal!=0 && PortDataOther!=0 )
1394							percentPortTransferred = (double) 100 * PortDataOther / PortDataTotal;
1395						else
1396							percentPortTransferred = 0;
1397						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataOther, false, false ) , percentPortTransferred);
1398						stattree.SetItemText( up_spb[i] , cbuffer );
1399						i++;
1400
1401						if ( PortDataTotal!=0 && PortDataPeerCache!=0 )
1402							percentPortTransferred = (double) 100 * PortDataPeerCache / PortDataTotal;
1403						else
1404							percentPortTransferred = 0;
1405						cbuffer.Format( _T("%s: %s (%1.1f%%)") , thePrefs.GetPeerCacheShow() ? _T("PeerCache") : GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataPeerCache, false, false ) , percentPortTransferred);
1406						stattree.SetItemText( up_spb[i] , cbuffer );
1407						i++;
1408					}
1409					// Uploaded Data By Source
1410					if (forceUpdate || stattree.IsExpanded(hup_ssb)) 
1411					{
1412						int i = 0;
1413						uint64	DataSourceFile =	thePrefs.GetUpData_File();
1414						uint64	DataSourcePF =		thePrefs.GetUpData_Partfile();
1415						uint64	DataSourceTotal =		thePrefs.GetUpSessionDataFile();
1416						double	percentFileTransferred = 0;
1417
1418						if ( DataSourceTotal!=0 && DataSourceFile!=0 )
1419							percentFileTransferred = (double) 100 * DataSourceFile / DataSourceTotal;
1420						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_DSFILE) , CastItoXBytes( DataSourceFile, false, false ) , percentFileTransferred);
1421						stattree.SetItemText( up_ssb[i] , cbuffer );
1422						i++;
1423
1424						if ( DataSourceTotal!=0 && DataSourcePF!=0 )
1425							percentFileTransferred = (double) 100 * DataSourcePF / DataSourceTotal;
1426						else
1427							percentFileTransferred = 0;
1428						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_DSPF) , CastItoXBytes( DataSourcePF, false, false ) , percentFileTransferred);
1429						stattree.SetItemText( up_ssb[i] , cbuffer );
1430						i++;
1431					}
1432				}
1433
1434                // Amount of data uploaded to friends
1435				cbuffer.Format(GetResString(IDS_STATS_UDATA_FRIENDS),CastItoXBytes(theStats.sessionSentBytesToFriend, false, false));
1436				stattree.SetItemText(up_S[1], cbuffer);
1437
1438				// Set fully Active Uploads
1439				cbuffer.Format(GetResString(IDS_STATS_ACTUL_ZZ),theApp.uploadqueue->GetActiveUploadsCount()); //theApp.uploadqueue->GetUploadQueueLength()
1440				stattree.SetItemText(up_S[2], cbuffer);
1441
1442                // Set Set Total Uploads                
1443				cbuffer.Format(GetResString(IDS_STATS_TOTALUL),theApp.uploadqueue->GetUploadQueueLength());
1444				stattree.SetItemText(up_S[3], cbuffer);
1445
1446				// Set Queue Length
1447				cbuffer.Format(GetResString(IDS_STATS_WAITINGUSERS),theApp.uploadqueue->GetWaitingUserCount());
1448				stattree.SetItemText(up_S[4], cbuffer);
1449
1450				// Set Upload Sessions
1451				statGoodSessions = theApp.uploadqueue->GetSuccessfullUpCount() + theApp.uploadqueue->GetUploadQueueLength();
1452				statBadSessions = theApp.uploadqueue->GetFailedUpCount();
1453				cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_ULSES), statGoodSessions + statBadSessions);
1454				stattree.SetItemText(up_S[5], cbuffer);
1455				if (forceUpdate || stattree.IsExpanded(up_S[5])) 
1456				{
1457					// Set Successful Upload Sessions & Average Uploaded Per Session
1458					if (statGoodSessions>0) 
1459					{ // Blackholes are when God divided by 0
1460						percentSessions = (double) 100*statGoodSessions/(statGoodSessions+statBadSessions);
1461						cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_AVGDATAULSES), CastItoXBytes( theStats.sessionSentBytes / statGoodSessions, false, false) ); 
1462					}
1463					else 
1464					{
1465						percentSessions = 0;
1466						cbuffer.Format( _T("%s: %s") , GetResString(IDS_STATS_AVGDATAULSES) , GetResString(IDS_FSTAT_WAITING) );
1467					}
1468					stattree.SetItemText(up_ssessions[2], cbuffer);
1469					cbuffer.Format(GetResString(IDS_STATS_SUCCUPCOUNT),statGoodSessions,percentSessions);
1470					stattree.SetItemText(up_ssessions[0], cbuffer);
1471					// Set Failed Upload Sessions
1472					if (percentSessions != 0 && statBadSessions > 0) 
1473						percentSessions = 100 - percentSessions; // There were some good sessions and bad ones...
1474					else if (percentSessions == 0 && statBadSessions > 0) 
1475						percentSessions = 100; // There were bad sessions and no good ones, must be 100%
1476					else 
1477						percentSessions = 0; // No sessions at all, or no bad ones.
1478					cbuffer.Format(GetResString(IDS_STATS_FAILUPCOUNT),statBadSessions,percentSessions);
1479					stattree.SetItemText(up_ssessions[1], cbuffer);
1480					// Set Avg Upload time
1481					//DWORD running=theApp.uploadqueue->GetAverageUpTime();
1482					cbuffer.Format(GetResString(IDS_STATS_AVEUPTIME),CastSecondsToLngHM(theApp.uploadqueue->GetAverageUpTime()));
1483					stattree.SetItemText(up_ssessions[3], cbuffer);
1484				}
1485				// Calculate Upline OH Totals
1486				UpOHTotal = theStats.GetUpDataOverheadFileRequest() + 
1487							theStats.GetUpDataOverheadSourceExchange() + 
1488							theStats.GetUpDataOverheadServer() + 
1489							theStats.GetUpDataOverheadKad() + 
1490							theStats.GetUpDataOverheadOther();
1491				UpOHTotalPackets = theStats.GetUpDataOverheadFileRequestPackets() + 
1492							theStats.GetUpDataOverheadSourceExchangePackets() + 
1493							theStats.GetUpDataOverheadServerPackets() + 
1494							theStats.GetUpDataOverheadKadPackets() + 
1495							theStats.GetUpDataOverheadOtherPackets();
1496				// Total Upline Overhead
1497				cbuffer.Format(GetResString(IDS_TOVERHEAD), CastItoXBytes( UpOHTotal, false, false ), CastItoIShort(UpOHTotalPackets));
1498				stattree.SetItemText(hup_soh, cbuffer);
1499				if (forceUpdate || stattree.IsExpanded(hup_soh)) 
1500				{
1501					int i = 0;
1502					// File Request Overhead
1503					cbuffer.Format(GetResString(IDS_FROVERHEAD), CastItoXBytes( theStats.GetUpDataOverheadFileRequest(), false, false ), CastItoIShort(theStats.GetUpDataOverheadFileRequestPackets()));
1504					stattree.SetItemText(up_soh[i], cbuffer);
1505					i++;
1506					// Source Exchanged Overhead
1507					cbuffer.Format(GetResString(IDS_SSOVERHEAD), CastItoXBytes( theStats.GetUpDataOverheadSourceExchange(), false, false ), CastItoIShort(theStats.GetUpDataOverheadSourceExchangePackets()));
1508					stattree.SetItemText(up_soh[i], cbuffer);
1509					i++;
1510					// Server Overhead
1511					cbuffer.Format(GetResString(IDS_SOVERHEAD), 
1512								   CastItoXBytes(theStats.GetUpDataOverheadServer(), false, false), 
1513								   CastItoIShort(theStats.GetUpDataOverheadServerPackets()));
1514					stattree.SetItemText(up_soh[i], cbuffer);
1515					i++;
1516					// Kad Overhead
1517					cbuffer.Format(GetResString(IDS_KADOVERHEAD), 
1518								   CastItoXBytes(theStats.GetUpDataOverheadKad(), false, false), 
1519								   CastItoIShort(theStats.GetUpDataOverheadKadPackets()));
1520					stattree.SetItemText(up_soh[i], cbuffer);
1521					i++;
1522				}
1523			} // - End Transfer -> Uploads -> Session Section
1524			// TRANSFER -> UPLOADS -> CUMULATIVE SECTION
1525			if (forceUpdate || stattree.IsExpanded(h_up_total)) 
1526			{
1527				// Uploaded Data
1528				cbuffer.Format(GetResString(IDS_STATS_UDATA),CastItoXBytes( theStats.sessionSentBytes+thePrefs.GetTotalUploaded(), false, false));
1529				stattree.SetItemText(up_T[0],cbuffer);
1530				if (forceUpdate || stattree.IsExpanded(up_T[0])) 
1531				{
1532					// Uploaded Data By Client
1533					if (forceUpdate || stattree.IsExpanded(hup_tcb)) 
1534					{
1535						int i = 0;
1536						uint64 UpDataTotal =		thePrefs.GetUpTotalClientData();
1537						uint64 UpDataClient =		thePrefs.GetCumUpData_EMULE();
1538						double percentClientTransferred = 0;
1539						if ( UpDataTotal!=0 && UpDataClient!=0 )
1540							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1541						cbuffer.Format( _T("eMule: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ) , percentClientTransferred);
1542						stattree.SetItemText( up_tcb[i] , cbuffer );
1543						i++;
1544
1545						UpDataClient = thePrefs.GetCumUpData_EDONKEYHYBRID();
1546						if ( UpDataTotal!=0 && UpDataClient!=0 )
1547							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1548						else
1549							percentClientTransferred = 0;
1550						cbuffer.Format( _T("eD Hybrid: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ) , percentClientTransferred );
1551						stattree.SetItemText( up_tcb[i] , cbuffer );
1552						i++;
1553
1554						UpDataClient = thePrefs.GetCumUpData_EDONKEY();
1555						if ( UpDataTotal!=0 && UpDataClient!=0 )
1556							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1557						else
1558							percentClientTransferred = 0;
1559						cbuffer.Format( _T("eDonkey: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1560						stattree.SetItemText( up_tcb[i] , cbuffer );
1561						i++;
1562
1563						UpDataClient = thePrefs.GetCumUpData_AMULE();
1564						if ( UpDataTotal!=0 && UpDataClient!=0 )
1565							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1566						else
1567							percentClientTransferred = 0;
1568						cbuffer.Format( _T("aMule: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1569						stattree.SetItemText( up_tcb[i] , cbuffer );
1570						i++;
1571
1572						UpDataClient = thePrefs.GetCumUpData_MLDONKEY();
1573						if ( UpDataTotal!=0 && UpDataClient!=0 )
1574							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1575						else
1576							percentClientTransferred = 0;
1577						cbuffer.Format( _T("MLdonkey: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1578						stattree.SetItemText( up_tcb[i] , cbuffer );
1579						i++;
1580
1581						UpDataClient = thePrefs.GetCumUpData_SHAREAZA();
1582						if ( UpDataTotal!=0 && UpDataClient!=0 )
1583							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1584						else
1585							percentClientTransferred = 0;
1586						cbuffer.Format( _T("Shareaza: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1587						stattree.SetItemText( up_tcb[i] , cbuffer );
1588						i++;
1589
1590						UpDataClient = thePrefs.GetCumUpData_EMULECOMPAT();
1591						if ( UpDataTotal!=0 && UpDataClient!=0 )
1592							percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
1593						else
1594							percentClientTransferred = 0;
1595						cbuffer.Format( _T("eM Compat: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
1596						stattree.SetItemText( up_tcb[i] , cbuffer );
1597						i++;
1598					}
1599					// Uploaded Data By Port
1600					if (forceUpdate || stattree.IsExpanded(hup_tpb)) 
1601					{
1602						int i = 0;
1603						uint64	PortDataDefault =	thePrefs.GetCumUpDataPort_4662();
1604						uint64	PortDataOther =		thePrefs.GetCumUpDataPort_OTHER();
1605						uint64	PortDataPeerCache =	thePrefs.GetCumUpDataPort_PeerCache();
1606						uint64	PortDataTotal =		thePrefs.GetUpTotalPortData();
1607						double	percentPortTransferred = 0;
1608
1609						if ( PortDataTotal!=0 && PortDataDefault!=0 )
1610							percentPortTransferred = (double) 100 * PortDataDefault / PortDataTotal;
1611						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTDEF) , CastItoXBytes( PortDataDefault, false, false ) , percentPortTransferred);
1612						stattree.SetItemText( up_tpb[i] , cbuffer );
1613						i++;
1614
1615						if ( PortDataTotal!=0 && PortDataOther!=0 )
1616							percentPortTransferred = (double) 100 * PortDataOther / PortDataTotal;
1617						else
1618							percentPortTransferred = 0;
1619						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataOther, false, false ) , percentPortTransferred);
1620						stattree.SetItemText( up_tpb[i] , cbuffer );
1621						i++;
1622
1623						if ( PortDataTotal!=0 && PortDataPeerCache!=0 )
1624							percentPortTransferred = (double) 100 * PortDataPeerCache / PortDataTotal;
1625						else
1626							percentPortTransferred = 0;
1627						cbuffer.Format( _T("%s: %s (%1.1f%%)") , thePrefs.GetPeerCacheShow() ? _T("PeerCache") : GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataPeerCache, false, false ) , percentPortTransferred);
1628						stattree.SetItemText( up_tpb[i] , cbuffer );
1629						i++;
1630					}
1631					// Uploaded Data By Source
1632					if (forceUpdate || stattree.IsExpanded(hup_tsb)) 
1633					{
1634						int i = 0;
1635						uint64	DataSourceFile =	thePrefs.GetCumUpData_File();
1636						uint64	DataSourcePF =		thePrefs.GetCumUpData_Partfile();
1637						uint64	DataSourceTotal =	thePrefs.GetUpTotalDataFile();
1638						double	percentFileTransferred = 0;
1639
1640						if ( DataSourceTotal!=0 && DataSourceFile!=0 )
1641							percentFileTransferred = (double) 100 * DataSourceFile / DataSourceTotal;
1642						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_DSFILE) , CastItoXBytes( DataSourceFile, false, false ) , percentFileTransferred);
1643						stattree.SetItemText( up_tsb[i] , cbuffer );
1644						i++;
1645
1646						if ( DataSourceTotal!=0 && DataSourcePF!=0 )
1647							percentFileTransferred = (double) 100 * DataSourcePF / DataSourceTotal;
1648						else
1649							percentFileTransferred = 0;
1650						cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_DSPF) , CastItoXBytes( DataSourcePF, false, false ) , percentFileTransferred);
1651						stattree.SetItemText( up_tsb[i] , cbuffer );
1652						i++;
1653					}
1654				}
1655				// Upload Sessions
1656				statGoodSessions = theApp.uploadqueue->GetSuccessfullUpCount() + thePrefs.GetUpSuccessfulSessions() + theApp.uploadqueue->GetUploadQueueLength();
1657				statBadSessions = theApp.uploadqueue->GetFailedUpCount() + thePrefs.GetUpFailedSessions();
1658				cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_ULSES), statGoodSessions + statBadSessions);
1659				stattree.SetItemText(up_T[1], cbuffer);
1660				if (forceUpdate || stattree.IsExpanded(up_T[1])) 
1661				{
1662					// Set Successful Upload Sessions & Average Uploaded Per Session
1663					if (statGoodSessions>0) 
1664					{ // Blackholes are when God divided by 0
1665						percentSessions = (double) 100*statGoodSessions/(statGoodSessions+statBadSessions);
1666						cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_AVGDATAULSES), CastItoXBytes((theStats.sessionSentBytes + thePrefs.GetTotalUploaded()) / statGoodSessions, false, false) ); 
1667					}
1668					else 
1669					{
1670						percentSessions = 0;
1671						cbuffer.Format( _T("%s: %s") , GetResString(IDS_STATS_AVGDATAULSES) , GetResString(IDS_FSTAT_WAITING) ); 
1672					}
1673					stattree.SetItemText(up_tsessions[2], cbuffer);
1674					cbuffer.Format(GetResString(IDS_STATS_SUCCUPCOUNT),statGoodSessions,percentSessions);
1675					stattree.SetItemText(up_tsessions[0], cbuffer);
1676					// Set Failed Upload Sessions
1677					if (percentSessions != 0 && statBadSessions > 0) 
1678						percentSessions = 100 - percentSessions; // There were some good sessions and bad ones...
1679					else if (percentSessions == 0 && statBadSessions > 0) 
1680						percentSessions = 100; // There were bad sessions and no good ones, must be 100%
1681					else 
1682						percentSessions = 0; // No sessions at all, or no bad ones.
1683					cbuffer.Format(GetResString(IDS_STATS_FAILUPCOUNT),statBadSessions,percentSessions);
1684					stattree.SetItemText(up_tsessions[1], cbuffer);
1685					// Set Avg Upload time
1686					uint32 avguptime = theApp.uploadqueue->GetAverageUpTime();
1687					if (thePrefs.GetUpAvgTime()<=0) 
1688						thePrefs.SetUpAvgTime(avguptime);
1689					avguptime = (uint32) (avguptime+thePrefs.GetUpAvgTime())/2;
1690					cbuffer.Format(GetResString(IDS_STATS_AVEUPTIME),CastSecondsToLngHM(avguptime));
1691					stattree.SetItemText(up_tsessions[3], cbuffer);
1692				}
1693
1694				if (UpOHTotal == 0 || UpOHTotalPackets == 0) 
1695				{
1696					// Calculate Upline OH Totals
1697					UpOHTotal = theStats.GetUpDataOverheadFileRequest() + 
1698								theStats.GetUpDataOverheadSourceExchange() + 
1699								theStats.GetUpDataOverheadServer() + 
1700								theStats.GetUpDataOverheadKad() + 
1701								theStats.GetUpDataOverheadOther();
1702					UpOHTotalPackets = theStats.GetUpDataOverheadFileRequestPackets() + 
1703								theStats.GetUpDataOverheadSourceExchangePackets() + 
1704								theStats.GetUpDataOverheadServerPackets() + 
1705								theStats.GetUpDataOverheadKadPackets() + 
1706								theStats.GetUpDataOverheadOtherPackets();
1707				}
1708				// Set Cumulative Total Overhead
1709				cbuffer.Format(GetResString(IDS_TOVERHEAD),CastItoXBytes(UpOHTotal + thePrefs.GetUpOverheadTotal(), false, false), CastItoIShort(UpOHTotalPackets + thePrefs.GetUpOverheadTotalPackets()));
1710				stattree.SetItemText(hup_toh, cbuffer);
1711				if (forceUpdate || stattree.IsExpanded(hup_toh)) 
1712				{
1713					int i = 0;
1714					// Set up total file req OH
1715					cbuffer.Format(GetResString(IDS_FROVERHEAD), CastItoXBytes( theStats.GetUpDataOverheadFileRequest() + thePrefs.GetUpOverheadFileReq(), false, false), CastItoIShort(theStats.GetUpDataOverheadFileRequestPackets() + thePrefs.GetUpOverheadFileReqPackets()));
1716					stattree.SetItemText(up_toh[i], cbuffer);
1717					i++;
1718					// Set up total source exch OH
1719					cbuffer.Format(GetResString(IDS_SSOVERHEAD), CastItoXBytes( theStats.GetUpDataOverheadSourceExchange()+thePrefs.GetUpOverheadSrcEx(), false, false), CastItoIShort(theStats.GetUpDataOverheadSourceExchangePackets()+thePrefs.GetUpOverheadSrcExPackets()));
1720					stattree.SetItemText(up_toh[i], cbuffer);
1721					i++;
1722					// Set up total server OH
1723					cbuffer.Format(GetResString(IDS_SOVERHEAD), 
1724								   CastItoXBytes(theStats.GetUpDataOverheadServer()
1725												 + thePrefs.GetUpOverheadServer(), false, false), 
1726								   CastItoIShort(theStats.GetUpDataOverheadServerPackets()
1727												 + thePrefs.GetUpOverheadServerPackets()));
1728					stattree.SetItemText(up_toh[i], cbuffer);
1729					i++;
1730					// Set up total Kad OH
1731					cbuffer.Format(GetResString(IDS_KADOVERHEAD), 
1732								   CastItoXBytes(theStats.GetUpDataOverheadKad() + 
1733											     thePrefs.GetUpOverheadKad(), false, false), 
1734								   CastItoIShort(theStats.GetUpDataOverheadKadPackets() + 
1735												 thePrefs.GetUpOverheadKadPackets()));
1736					stattree.SetItemText(up_toh[i], cbuffer);
1737					i++;
1738				}
1739			} // - End Transfer -> Uploads -> Cumulative Section
1740		} // - End Transfer -> Uploads Section
1741	} // - END TRANSFER SECTION
1742
1743
1744	// CONNECTION SECTION
1745	if (forceUpdate || stattree.IsExpanded(h_connection)) 
1746	{		
1747		// CONNECTION -> SESSION SECTION
1748		if (forceUpdate || stattree.IsExpanded(h_conn_session)) 
1749		{			
1750			// CONNECTION -> SESSION -> GENERAL SECTION
1751			if (forceUpdate || stattree.IsExpanded(hconn_sg)) 
1752			{
1753				int i = 0;
1754				// Server Reconnects
1755				if (theStats.reconnects>0) 
1756					cbuffer.Format(GetResString(IDS_STATS_RECONNECTS),theStats.reconnects-1);
1757				else 
1758					cbuffer.Format(GetResString(IDS_STATS_RECONNECTS),0);
1759				stattree.SetItemText(conn_sg[i], cbuffer);
1760				i++;
1761				// Active Connections
1762				cbuffer.Format(_T("%s: %i (%s:%u | %s:%u | %s:%u)"),GetResString(IDS_SF_ACTIVECON),theApp.listensocket->GetActiveConnections(), GetResString(IDS_HALF), theApp.listensocket->GetTotalHalfCon(), GetResString(IDS_CONCOMPL) ,theApp.listensocket->GetTotalComp(), GetResString(IDS_STATS_PRTOTHER) ,theApp.listensocket->GetActiveConnections() - theApp.listensocket->GetTotalHalfCon() - theApp.listensocket->GetTotalComp());
1763				stattree.SetItemText(conn_sg[i], cbuffer);
1764				i++;
1765				// Average Connections
1766				cbuffer.Format(_T("%s: %i"),GetResString(IDS_SF_AVGCON),(int)theApp.listensocket->GetAverageConnections());
1767				stattree.SetItemText(conn_sg[i], cbuffer);
1768				i++;
1769				// Peak Connections
1770				cbuffer.Format(_T("%s: %i"),GetResString(IDS_SF_PEAKCON),theApp.listensocket->GetPeakConnections());
1771				stattree.SetItemText(conn_sg[i], cbuffer);
1772				i++;
1773				// Connect Limit Reached
1774				uint32 m_itemp = theApp.listensocket->GetMaxConnectionReached();
1775				if( m_itemp != m_ilastMaxConnReached )
1776				{
1777					cbuffer.Format(_T("%s: %i : %s"), GetResString(IDS_SF_MAXCONLIMITREACHED), m_itemp, CTime::GetCurrentTime().Format(_T("%c")));
1778					stattree.SetItemText(conn_sg[i], cbuffer);
1779					m_ilastMaxConnReached = m_itemp;
1780				}
1781				else if( m_itemp == 0 )
1782				{
1783					cbuffer.Format(_T("%s: %i"),GetResString(IDS_SF_MAXCONLIMITREACHED),m_itemp);
1784					stattree.SetItemText(conn_sg[i], cbuffer);
1785				}
1786				i++;
1787			} // - End Connection -> Session -> General Section
1788			// CONNECTION -> SESSION -> UPLOADS SECTION
1789			if (forceUpdate || stattree.IsExpanded(hconn_su)) 
1790			{
1791				int i = 0;
1792				// Upload Rate
1793				cbuffer.Format(_T("%s: %s"), GetResString(IDS_ST_UPLOAD),CastItoXBytes(theStats.rateUp, true, true));
1794				stattree.SetItemText(conn_su[i], cbuffer);
1795				i++;
1796				// Average Upload Rate
1797				cbuffer.Format(GetResString(IDS_STATS_AVGUL),CastItoXBytes(theStats.GetAvgUploadRate(AVG_SESSION), true, true));
1798				stattree.SetItemText(conn_su[i], cbuffer);
1799				i++;
1800				// Max Upload Rate
1801				cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_MAXUL), CastItoXBytes(theStats.maxUp, true, true));
1802				stattree.SetItemText(conn_su[i], cbuffer);
1803				i++;
1804				// Max Average Upload Rate
1805				float myAverageUpRate = theStats.GetAvgUploadRate(AVG_SESSION);
1806				if (myAverageUpRate>theStats.maxUpavg)
1807					theStats.maxUpavg = myAverageUpRate;
1808				cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_MAXAVGUL), CastItoXBytes(theStats.maxUpavg, true, true));
1809				stattree.SetItemText(conn_su[i], cbuffer); 
1810				i++;
1811			} // - End Connection -> Session -> Uploads Section
1812			// CONNECTION -> SESSION -> DOWNLOADShead SECTION
1813			if (forceUpdate || stattree.IsExpanded(hconn_sd)) 
1814			{
1815				int i = 0;
1816				// Download Rate
1817				cbuffer.Format(_T("%s: %s"), GetResString(IDS_ST_DOWNLOAD), CastItoXBytes(theStats.rateDown, true, true));
1818				stattree.SetItemText(conn_sd[i], cbuffer); 
1819				i++;
1820				// Average Download Rate
1821				cbuffer.Format(GetResString(IDS_STATS_AVGDL),CastItoXBytes(theStats.GetAvgDownloadRate(AVG_SESSION), true, true));	
1822				stattree.SetItemText(conn_sd[i], cbuffer); 
1823				i++;
1824				// Max Download Rate
1825				cbuffer.Format(GetResString(IDS_STATS_MAXDL),CastItoXBytes(theStats.maxDown, true, true));
1826				stattree.SetItemText(conn_sd[i], cbuffer); 
1827				i++;
1828				// Max Average Download Rate
1829				float myAverageDownRate = theStats.GetAvgDownloadRate(AVG_SESSION);
1830				if (myAverageDownRate>theStats.maxDownavg) 
1831					theStats.maxDownavg = myAverageDownRate;
1832				cbuffer.Format(GetResString(IDS_STATS_MAXAVGDL), CastItoXBytes(theStats.maxDownavg, true, true));	
1833				stattree.SetItemText(conn_sd[i], cbuffer);
1834				i++;
1835			} // - End Connection -> Session -> Downloads Section		
1836		} // - End Connection -> Session Section
1837		// CONNECTION -> CUMULATIVE SECTION
1838		if (forceUpdate || stattree.IsExpanded(h_conn_total)) 
1839		{			
1840			// CONNECTION -> CUMULATIVE -> GENERAL SECTION
1841			if (forceUpdate || stattree.IsExpanded(hconn_tg)) 
1842			{
1843				int i = 0;
1844				// Server Reconnects
1845				if(theStats.reconnects>0)
1846					cbuffer.Format(GetResString(IDS_STATS_RECONNECTS),theStats.reconnects - 1 + thePrefs.GetConnNumReconnects());
1847				else
1848					cbuffer.Format(GetResString(IDS_STATS_RECONNECTS),thePrefs.GetConnNumReconnects());
1849				stattree.SetItemText(conn_tg[i], cbuffer);
1850				i++;
1851				// Average Connections
1852				cbuffer.Format(_T("%s: %i"), GetResString(IDS_SF_AVGCON), (int) (theApp.listensocket->GetActiveConnections() + thePrefs.GetConnAvgConnections()) / 2 );
1853				stattree.SetItemText(conn_tg[i], cbuffer);
1854				i++;
1855				// Peak Connections
1856				cbuffer.Format(_T("%s: %i"), GetResString(IDS_SF_PEAKCON), thePrefs.GetConnPeakConnections());
1857				stattree.SetItemText(conn_tg[i], cbuffer);
1858				i++;
1859				// Connection Limit Reached
1860				cbuffer.Format(_T("%s: %i"), GetResString(IDS_SF_MAXCONLIMITREACHED), theApp.listensocket->GetMaxConnectionReached() + thePrefs.GetConnMaxConnLimitReached());
1861				stattree.SetItemText(conn_tg[i], cbuffer);
1862				i++;
1863			} // - End Connection -> Cumulative -> General Section
1864			// CONNECTION -> CUMULATIVE -> UPLOADS SECTION
1865			if (forceUpdate || stattree.IsExpanded(hconn_tu)) 
1866			{
1867				int i = 0;
1868				// Average Upload Rate
1869				cbuffer.Format(GetResString(IDS_STATS_AVGUL),CastItoXBytes(theStats.cumUpavg, true, true));
1870				stattree.SetItemText(conn_tu[i], cbuffer);
1871				i++;
1872				// Max Upload Rate
1873				cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_MAXUL), CastItoXBytes(theStats.maxcumUp, true, true));
1874				stattree.SetItemText(conn_tu[i], cbuffer);
1875				i++;
1876				// Max Average Upload Rate
1877				cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_MAXAVGUL), CastItoXBytes(theStats.maxcumUpavg, true, true));
1878				stattree.SetItemText(conn_tu[i], cbuffer);
1879				i++;
1880			} // - End Connection -> Cumulative -> Uploads Section
1881			// CONNECTION -> CUMULATIVE -> DOWNLOADS SECTION
1882			if (forceUpdate || stattree.IsExpanded(hconn_td)) 
1883			{
1884				int i = 0;
1885				// Average Download Rate
1886				cbuffer.Format(GetResString(IDS_STATS_AVGDL), CastItoXBytes(theStats.cumDownavg, true, true));
1887				stattree.SetItemText(conn_td[i], cbuffer);
1888				i++;
1889				// Max Download Rate
1890				cbuffer.Format(GetResString(IDS_STATS_MAXDL), CastItoXBytes(theStats.maxcumDown, true, true));
1891				stattree.SetItemText(conn_td[i], cbuffer);
1892				i++;
1893				// Max Average Download Rate
1894				cbuffer.Format(GetResString(IDS_STATS_MAXAVGDL), CastItoXBytes(theStats.maxcumDownavg, true, true));
1895				stattree.SetItemText(conn_td[i], cbuffer);
1896				i++;
1897			} // - End Connection -> Cumulative -> Downloads Section
1898		} // - End Connection -> Cumulative Section
1899	} // - END CONNECTION SECTION
1900
1901
1902	// TIME STATISTICS SECTION
1903	if (forceUpdate || stattree.IsExpanded(h_time)) 
1904	{
1905		// Statistics Last Reset
1906		cbuffer.Format(GetResString(IDS_STATS_LASTRESETSTATIC), thePrefs.GetStatsLastResetStr(false));
1907        stattree.SetItemText(tvitime[0], cbuffer);
1908		// Time Since Last Reset
1909		time_t timeDiff;
1910		if (thePrefs.GetStatsLastResetLng()) 
1911		{
1912			time_t timeNow;
1913			time(&timeNow);
1914			timeDiff = timeNow - thePrefs.GetStatsLastResetLng(); // In seconds
1915			cbuffer.Format(GetResString(IDS_STATS_TIMESINCERESET), CastSecondsToLngHM(timeDiff));
1916		}
1917		else 
1918		{
1919			timeDiff = 0;
1920			cbuffer.Format(GetResString(IDS_STATS_TIMESINCERESET), GetResString(IDS_UNKNOWN));
1921		}
1922		stattree.SetItemText(tvitime[1], cbuffer);
1923		// TIME STATISTICS -> SESSION SECTION
1924		if (forceUpdate || stattree.IsExpanded(htime_s)) 
1925		{
1926			int i = 0;
1927			// Run Time
1928			time_t sessionRunTime = (GetTickCount() - theStats.starttime) / 1000;
1929			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_RUNTIME), CastSecondsToLngHM(sessionRunTime));
1930			stattree.SetItemText(tvitime_s[i], cbuffer);
1931			i++;
1932			if (!sessionRunTime) 
1933				sessionRunTime = 1;
1934			// Transfer Time
1935			cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_TRANSTIME), CastSecondsToLngHM(theStats.GetTransferTime()), (double) (100 *  theStats.GetTransferTime() ) / sessionRunTime);
1936			stattree.SetItemText(tvitime_s[i], cbuffer);
1937			if (forceUpdate || stattree.IsExpanded(tvitime_s[i])) 
1938			{
1939				int x = 0;
1940				// Upload Time
1941				cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_UPTIME), CastSecondsToLngHM(theStats.GetUploadTime()), (double) (100 * theStats.GetUploadTime()) / sessionRunTime);
1942				stattree.SetItemText(tvitime_st[x], cbuffer);
1943				x++;
1944				// Download Time
1945				cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_DOWNTIME), CastSecondsToLngHM(theStats.GetDownloadTime()), (double) (100 * theStats.GetDownloadTime()) / sessionRunTime);
1946				stattree.SetItemText(tvitime_st[x], cbuffer);
1947				x++;
1948			}
1949			i++;
1950			// Current Server Duration				
1951			cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_CURRSRVDUR), CastSecondsToLngHM(theStats.time_thisServerDuration), (double) (100 * theStats.time_thisServerDuration) / sessionRunTime);
1952			stattree.SetItemText(tvitime_s[i], cbuffer);
1953			i++;
1954			// Total Server Duration
1955			cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_TOTALSRVDUR), CastSecondsToLngHM(theStats.GetServerDuration()), (double) (100 * theStats.GetServerDuration()) / sessionRunTime);
1956			stattree.SetItemText(tvitime_s[i], cbuffer);
1957			i++;
1958		}
1959		// TIME STATISTICS -> CUMULATIVE SECTION
1960		if (forceUpdate || stattree.IsExpanded(htime_t)) 
1961		{
1962			int i = 0;
1963			// Run Time
1964			time_t totalRunTime = ((GetTickCount() - theStats.starttime)/1000) + thePrefs.GetConnRunTime();
1965			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_RUNTIME), CastSecondsToLngHM(totalRunTime));
1966			stattree.SetItemText(tvitime_t[i], cbuffer);
1967			i++;
1968			if (!totalRunTime) 
1969				totalRunTime = 1;
1970			// Transfer Time
1971			cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_TRANSTIME), CastSecondsToLngHM(theStats.GetTransferTime() + thePrefs.GetConnTransferTime()), (double) (100 * (theStats.GetTransferTime() + thePrefs.GetConnTransferTime())) / totalRunTime);
1972			stattree.SetItemText(tvitime_t[i], cbuffer);
1973			if (forceUpdate || stattree.IsExpanded(tvitime_t[i])) 
1974			{
1975				int x = 0;
1976				// Upload Time
1977				cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_UPTIME), CastSecondsToLngHM(theStats.GetUploadTime() + thePrefs.GetConnUploadTime()), (double) (100 * (theStats.GetUploadTime() + thePrefs.GetConnUploadTime())) / totalRunTime);
1978				stattree.SetItemText(tvitime_tt[x], cbuffer);
1979				x++;;
1980				// Download Time
1981				cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_DOWNTIME), CastSecondsToLngHM(theStats.GetDownloadTime() + thePrefs.GetConnDownloadTime()), (double) (100 * (theStats.GetDownloadTime() + thePrefs.GetConnDownloadTime())) / totalRunTime);
1982				stattree.SetItemText(tvitime_tt[x], cbuffer);
1983				x++;
1984			} 
1985			i++;
1986			// Total Server Duration
1987			cbuffer.Format(_T("%s: %s (%1.1f%%)"), GetResString(IDS_STATS_TOTALSRVDUR), CastSecondsToLngHM(theStats.GetServerDuration() + thePrefs.GetConnServerDuration()), (double) (100 * (theStats.GetServerDuration() + thePrefs.GetConnServerDuration())) / totalRunTime);
1988			stattree.SetItemText(tvitime_t[i], cbuffer);
1989			i++;
1990		}
1991		// TIME STATISTICS -> PROJECTED AVERAGES SECTION
1992		if ( (forceUpdate || stattree.IsExpanded(htime_aap)) && timeDiff > 0 ) 
1993		{
1994			double avgModifier[3];
1995			avgModifier[0] = (double) 86400 / timeDiff; // Days
1996			avgModifier[1] = (double) 2628000 / timeDiff; // Months
1997			avgModifier[2] = (double) 31536000 / timeDiff; // Years
1998			// TIME STATISTICS -> PROJECTED AVERAGES -> TIME PERIODS
1999			// This section is completely scalable.  Might add "Week" to it in the future.
2000			// For each time period that we are calculating a projected average for...
2001			for (int mx = 0; mx<3; mx++) 
2002			{
2003				if (forceUpdate || stattree.IsExpanded(time_aaph[mx])) 
2004				{
2005					// TIME STATISTICS -> PROJECTED AVERAGES -> TIME PERIOD -> UPLOADS SECTION
2006					if (forceUpdate || stattree.IsExpanded(time_aap_hup[mx])) 
2007					{
2008						// Uploaded Data
2009						cbuffer.Format(GetResString(IDS_STATS_UDATA),CastItoXBytes( ((double)(theStats.sessionSentBytes+thePrefs.GetTotalUploaded()))*avgModifier[mx], false, false));
2010						stattree.SetItemText(time_aap_up[mx][0],cbuffer);
2011						if (forceUpdate || stattree.IsExpanded(time_aap_up[mx][0])) 
2012						{
2013							// Uploaded Data By Client
2014							if (forceUpdate || stattree.IsExpanded(time_aap_up_hd[mx][0])) 
2015							{
2016								int i = 0;
2017								uint64 UpDataTotal = (uint64)(thePrefs.GetUpTotalClientData() * avgModifier[mx]);
2018								uint64 UpDataClient = (uint64)(thePrefs.GetCumUpData_EMULE() * avgModifier[mx]);
2019								double percentClientTransferred = 0;
2020								if ( UpDataTotal!=0 && UpDataClient!=0 )
2021									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2022								cbuffer.Format( _T("eMule: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ) , percentClientTransferred);
2023								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2024								i++;
2025
2026								UpDataClient = (uint64)(thePrefs.GetCumUpData_EDONKEYHYBRID() * avgModifier[mx]);
2027								if ( UpDataTotal!=0 && UpDataClient!=0 )
2028									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2029								else
2030									percentClientTransferred = 0;
2031								cbuffer.Format( _T("eD Hybrid: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ) , percentClientTransferred );
2032								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2033								i++;
2034
2035								UpDataClient = (uint64)(thePrefs.GetCumUpData_EDONKEY() * avgModifier[mx]);
2036								if ( UpDataTotal!=0 && UpDataClient!=0 )
2037									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2038								else
2039									percentClientTransferred = 0;
2040								cbuffer.Format( _T("eDonkey: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
2041								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2042								i++;
2043
2044								UpDataClient = (uint64)(thePrefs.GetCumUpData_AMULE() * avgModifier[mx]);
2045								if ( UpDataTotal!=0 && UpDataClient!=0 )
2046									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2047								else
2048									percentClientTransferred = 0;
2049								cbuffer.Format( _T("aMule: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
2050								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2051								i++;
2052
2053								UpDataClient = (uint64)(thePrefs.GetCumUpData_MLDONKEY() * avgModifier[mx]);
2054								if ( UpDataTotal!=0 && UpDataClient!=0 )
2055									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2056								else
2057									percentClientTransferred = 0;
2058								cbuffer.Format( _T("MLdonkey: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
2059								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2060								i++;
2061
2062								UpDataClient = (uint64)(thePrefs.GetCumUpData_SHAREAZA() * avgModifier[mx]);
2063								if ( UpDataTotal!=0 && UpDataClient!=0 )
2064									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2065								else
2066									percentClientTransferred = 0;
2067								cbuffer.Format( _T("Shareaza: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
2068								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2069								i++;
2070
2071								UpDataClient = (uint64)(thePrefs.GetCumUpData_EMULECOMPAT() * avgModifier[mx]);
2072								if ( UpDataTotal!=0 && UpDataClient!=0 )
2073									percentClientTransferred = (double) 100 * UpDataClient / UpDataTotal;
2074								else
2075									percentClientTransferred = 0;
2076								cbuffer.Format( _T("eM Compat: %s (%1.1f%%)") , CastItoXBytes( UpDataClient, false, false ), percentClientTransferred );
2077								stattree.SetItemText( time_aap_up_dc[mx][i] , cbuffer );
2078								i++;
2079							}
2080							// Uploaded Data By Port
2081							if (forceUpdate || stattree.IsExpanded(time_aap_up_hd[mx][1])) 
2082							{
2083								int i = 0;
2084								uint64	PortDataDefault =	(uint64)(thePrefs.GetCumUpDataPort_4662() * avgModifier[mx]);
2085								uint64	PortDataOther =		(uint64)(thePrefs.GetCumUpDataPort_OTHER() * avgModifier[mx]);
2086								uint64	PortDataPeerCache =	(uint64)(thePrefs.GetCumUpDataPort_PeerCache() * avgModifier[mx]);
2087								uint64	PortDataTotal =		(uint64)( thePrefs.GetUpTotalPortData() * avgModifier[mx]);
2088								double	percentPortTransferred = 0;
2089
2090								if ( PortDataTotal!=0 && PortDataDefault!=0 )
2091									percentPortTransferred = (double) 100 * PortDataDefault / PortDataTotal;
2092								cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTDEF) , CastItoXBytes( PortDataDefault, false, false ) , percentPortTransferred);
2093								stattree.SetItemText( time_aap_up_dp[mx][i] , cbuffer );
2094								i++;
2095
2096								if ( PortDataTotal!=0 && PortDataOther!=0 )
2097									percentPortTransferred = (double) 100 * PortDataOther / PortDataTotal;
2098								else
2099									percentPortTransferred = 0;
2100								cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataOther, false, false ) , percentPortTransferred);
2101								stattree.SetItemText( time_aap_up_dp[mx][i] , cbuffer );
2102								i++;
2103
2104								if ( PortDataTotal!=0 && PortDataPeerCache!=0 )
2105									percentPortTransferred = (double) 100 * PortDataPeerCache / PortDataTotal;
2106								else
2107									percentPortTransferred = 0;
2108								cbuffer.Format( _T("%s: %s (%1.1f%%)") , thePrefs.GetPeerCacheShow() ? _T("PeerCache") : GetResString(IDS_STATS_PRTOTHER) , CastItoXBytes( PortDataPeerCache, false, false ) , percentPortTransferred);
2109								stattree.SetItemText( time_aap_up_dp[mx][i] , cbuffer );
2110								i++;
2111							}
2112							// Uploaded Data By Source
2113							if (forceUpdate || stattree.IsExpanded(time_aap_up_hd[mx][2])) 
2114							{
2115								int i = 0;
2116								uint64	DataSourceFile =	(uint64)(thePrefs.GetCumUpData_File() * avgModifier[mx]);
2117								uint64	DataSourcePF =		(uint64)(thePrefs.GetCumUpData_Partfile() * avgModifier[mx]);
2118								uint64	DataSourceTotal =	(uint64)(thePrefs.GetUpTotalDataFile() * avgModifier[mx]);
2119								double	percentFileTransferred = 0;
2120
2121								if ( DataSourceTotal!=0 && DataSourceFile!=0 )
2122									percentFileTransferred = (double) 100 * DataSourceFile / DataSourceTotal;
2123								cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_DSFILE) , CastItoXBytes( DataSourceFile, false, false ) , percentFileTransferred);
2124								stattree.SetItemText( time_aap_up_ds[mx][i] , cbuffer );
2125								i++;
2126
2127								if ( DataSourceTotal!=0 && DataSourcePF!=0 )
2128									percentFileTransferred = (double) 100 * DataSourcePF / DataSourceTotal;
2129								else
2130									percentFileTransferred = 0;
2131								cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_DSPF) , CastItoXBytes( DataSourcePF, false, false ) , percentFileTransferred);
2132								stattree.SetItemText( time_aap_up_ds[mx][i] , cbuffer );
2133								i++;
2134							}
2135						}
2136						// Upload Sessions
2137						uint32 statGoodSessions = (uint32)((theApp.uploadqueue->GetSuccessfullUpCount() + thePrefs.GetUpSuccessfulSessions() + theApp.uploadqueue->GetUploadQueueLength()) * avgModifier[mx]);
2138						uint32 statBadSessions = (uint32)((theApp.uploadqueue->GetFailedUpCount() + thePrefs.GetUpFailedSessions()) * avgModifier[mx]);
2139						double percentSessions;
2140						cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_ULSES), statGoodSessions + statBadSessions);
2141						stattree.SetItemText(time_aap_up[mx][1], cbuffer);
2142						if (forceUpdate || stattree.IsExpanded(time_aap_up[mx][1])) 
2143						{
2144							// Set Successful Upload Sessions
2145							if (statGoodSessions>0) 
2146								percentSessions = (double) 100*statGoodSessions/(statGoodSessions+statBadSessions);
2147							else 
2148								percentSessions = 0;
2149							cbuffer.Format(GetResString(IDS_STATS_SUCCUPCOUNT),statGoodSessions,percentSessions);
2150							stattree.SetItemText(time_aap_up_s[mx][0], cbuffer);
2151							// Set Failed Upload Sessions
2152							if (percentSessions != 0 && statBadSessions > 0) 
2153								percentSessions = 100 - percentSessions; // There were some good sessions and bad ones...
2154							else if (percentSessions == 0 && statBadSessions > 0) 
2155								percentSessions = 100; // There were bad sessions and no good ones, must be 100%
2156							else 
2157								percentSessions = 0; // No sessions at all, or no bad ones.
2158							cbuffer.Format(GetResString(IDS_STATS_FAILUPCOUNT),statBadSessions,percentSessions);
2159							stattree.SetItemText(time_aap_up_s[mx][1], cbuffer);
2160						}
2161
2162						// Calculate Upline OH Totals
2163						uint64 UpOHTotal = (uint64)((theStats.GetUpDataOverheadFileRequest() + 
2164													 theStats.GetUpDataOverheadSourceExchange() + 
2165													 theStats.GetUpDataOverheadServer() + 
2166													 theStats.GetUpDataOverheadKad() + 
2167													 theStats.GetUpDataOverheadOther()
2168												    ) * avgModifier[mx]);
2169						uint64 UpOHTotalPackets = (uint64)((theStats.GetUpDataOverheadFileRequestPackets() + 
2170														    theStats.GetUpDataOverheadSourceExchangePackets() + 
2171														    theStats.GetUpDataOverheadServerPackets() + 
2172														    theStats.GetUpDataOverheadKadPackets() + 
2173														    theStats.GetUpDataOverheadOtherPackets()
2174														   ) * avgModifier[mx]);
2175
2176						// Set Cumulative Total Overhead
2177						cbuffer.Format(GetResString(IDS_TOVERHEAD),CastItoXBytes(UpOHTotal + ((uint64)thePrefs.GetUpOverheadTotal() * avgModifier[mx]), false, false), CastItoIShort((uint64)(UpOHTotalPackets + ((uint64)thePrefs.GetUpOverheadTotalPackets() * avgModifier[mx]))));
2178						stattree.SetItemText(time_aap_up[mx][2], cbuffer);
2179						if (forceUpdate || stattree.IsExpanded(time_aap_up[mx][2])) 
2180						{
2181							int i = 0;
2182							// Set up total file req OH
2183							cbuffer.Format(GetResString(IDS_FROVERHEAD), CastItoXBytes( (uint64)(theStats.GetUpDataOverheadFileRequest() + thePrefs.GetUpOverheadFileReq()) * avgModifier[mx], false, false), CastItoIShort( (uint64)(theStats.GetUpDataOverheadFileRequestPackets() + thePrefs.GetUpOverheadFileReqPackets()) * avgModifier[mx]));
2184							stattree.SetItemText(time_aap_up_oh[mx][i], cbuffer);
2185							i++;
2186							// Set up total source exch OH
2187							cbuffer.Format(GetResString(IDS_SSOVERHEAD), CastItoXBytes( (uint64)(theStats.GetUpDataOverheadSourceExchange()+thePrefs.GetUpOverheadSrcEx()) * avgModifier[mx], false, false), CastItoIShort( (uint64)(theStats.GetUpDataOverheadSourceExchangePackets()+thePrefs.GetUpOverheadSrcExPackets()) * avgModifier[mx]));
2188							stattree.SetItemText(time_aap_up_oh[mx][i], cbuffer);
2189							i++;
2190							// Set up total server OH
2191							cbuffer.Format(GetResString(IDS_SOVERHEAD), 
2192										   CastItoXBytes((theStats.GetUpDataOverheadServer() + 
2193														          thePrefs.GetUpOverheadServer()
2194																 ) * avgModifier[mx], false, false), 
2195										   CastItoIShort((uint64)(theStats.GetUpDataOverheadServerPackets() + 
2196																  thePrefs.GetUpOverheadServerPackets()
2197																 ) * avgModifier[mx]));
2198							stattree.SetItemText(time_aap_up_oh[mx][i], cbuffer);
2199							i++;
2200							// Set up total Kad OH
2201							cbuffer.Format(GetResString(IDS_KADOVERHEAD), 
2202										   CastItoXBytes((uint64)(theStats.GetUpDataOverheadKad() + 
2203																  thePrefs.GetUpOverheadKad()
2204																 ) * avgModifier[mx], false, false), 
2205										   CastItoIShort((uint64)(theStats.GetUpDataOverheadKadPackets() + 
2206																  thePrefs.GetUpOverheadKadPackets()
2207																 ) * avgModifier[mx]));
2208							stattree.SetItemText(time_aap_up_oh[mx][i], cbuffer);
2209							i++;
2210						}
2211					} // - End Time Statistics -> Projected Averages -> Time Period -> Uploads Section
2212					// TIME STATISTICS -> PROJECTED AVERAGES -> TIME PERIOD -> DOWNLOADS SECTION
2213					if (forceUpdate || stattree.IsExpanded(time_aap_hdown[mx])) 
2214					{
2215						CDownloadQueue::SDownloadStats myStats;
2216						theApp.downloadqueue->GetDownloadSourcesStats(myStats);
2217						// Downloaded Data
2218						cbuffer.Format(GetResString(IDS_STATS_DDATA),CastItoXBytes( (uint64)(theStats.sessionReceivedBytes+thePrefs.GetTotalDownloaded()) * avgModifier[mx], false, false ));
2219						stattree.SetItemText(time_aap_down[mx][0], cbuffer);
2220						if (forceUpdate || stattree.IsExpanded(time_aap_down[mx][0])) 
2221						{
2222							// Downloaded Data By Client
2223							if (forceUpdate || stattree.IsExpanded(time_aap_down_hd[mx][0])) 
2224							{
2225								int i = 0;
2226								uint64 DownDataTotal = (uint64)(thePrefs.GetDownTotalClientData() * avgModifier[mx]);
2227								uint64 DownDataClient = (uint64)(thePrefs.GetCumDownData_EMULE() * avgModifier[mx]);
2228								double percentClientTransferred = 0;
2229								if ( DownDataTotal!=0 && DownDataClient!=0 )
2230									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2231								cbuffer.Format( _T("eMule: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ) , percentClientTransferred);
2232								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2233								i++;
2234
2235								DownDataClient = (uint64)(thePrefs.GetCumDownData_EDONKEYHYBRID() * avgModifier[mx]);
2236								if ( DownDataTotal!=0 && DownDataClient!=0 )
2237									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2238								else
2239									percentClientTransferred = 0;
2240								cbuffer.Format( _T("eD Hybrid: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ) , percentClientTransferred );
2241								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2242								i++;
2243
2244								DownDataClient = (uint64)(thePrefs.GetCumDownData_EDONKEY() * avgModifier[mx]);
2245								if ( DownDataTotal!=0 && DownDataClient!=0 )
2246									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2247								else
2248									percentClientTransferred = 0;
2249								cbuffer.Format( _T("eDonkey: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
2250								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2251								i++;
2252
2253								DownDataClient = (uint64)(thePrefs.GetCumDownData_AMULE() * avgModifier[mx]);
2254								if ( DownDataTotal!=0 && DownDataClient!=0 )
2255									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2256								else
2257									percentClientTransferred = 0;
2258								cbuffer.Format( _T("aMule: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
2259								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2260								i++;
2261
2262								DownDataClient = (uint64)(thePrefs.GetCumDownData_MLDONKEY() * avgModifier[mx]);
2263								if ( DownDataTotal!=0 && DownDataClient!=0 )
2264									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2265								else
2266									percentClientTransferred = 0;
2267								cbuffer.Format( _T("MLdonkey: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
2268								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2269								i++;
2270
2271								DownDataClient = (uint64)(thePrefs.GetCumDownData_SHAREAZA() * avgModifier[mx]);
2272								if ( DownDataTotal!=0 && DownDataClient!=0 )
2273									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2274								else
2275									percentClientTransferred = 0;
2276								cbuffer.Format( _T("Shareaza: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
2277								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2278								i++;
2279
2280								DownDataClient = (uint64)(thePrefs.GetCumDownData_EMULECOMPAT() * avgModifier[mx]);
2281								if ( DownDataTotal!=0 && DownDataClient!=0 )
2282									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2283								else
2284									percentClientTransferred = 0;
2285								cbuffer.Format( _T("eM Compat: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
2286								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2287								i++;
2288
2289								DownDataClient = (uint64)(thePrefs.GetCumDownData_URL() * avgModifier[mx]);
2290								if ( DownDataTotal!=0 && DownDataClient!=0 )
2291									percentClientTransferred = (double) 100 * DownDataClient / DownDataTotal;
2292								else
2293									percentClientTransferred = 0;
2294								cbuffer.Format( _T("URL: %s (%1.1f%%)") , CastItoXBytes( DownDataClient, false, false ), percentClientTransferred );
2295								stattree.SetItemText( time_aap_down_dc[mx][i] , cbuffer );
2296								i++;
2297							}
2298							// Downloaded Data By Port
2299							if (forceUpdate || stattree.IsExpanded(time_aap_down_hd[mx][1])) 
2300							{
2301								int i = 0;
2302								uint64	PortDataDefault =	(uint64)(thePrefs.GetCumDownDataPort_4662() * avgModifier[mx]);
2303								uint64	PortDataOther =		(uint64)(thePrefs.GetCumDownDataPort_OTHER() * avgModifier[mx]);
2304								uint64	PortDataPeerCache =	(uint64)(thePrefs.GetCumDownDataPort_PeerCache() * avgModifier[mx]);
2305								uint64	PortDataTotal =		(uint64)(thePrefs.GetDownTotalPortData() * avgModifier[mx]);
2306								double	percentPortTransferred = 0;
2307
2308								if ( PortDataTotal!=0 && PortDataDefault!=0 )
2309									percentPortTransferred = (double) 100 * PortDataDefault / PortDataTotal;
2310								cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTDEF) , CastItoXBytes( PortDataDefault, false, false ) , percentPortTransferred);
2311								stattree.SetItemText( time_aap_down_dp[mx][i] , cbuffer );
2312								i++;
2313
2314								if ( PortDataTotal!=0 && PortDataOther!=0 )
2315									percentPortTransferred = (double) 100 * PortDataOther / PortDataTotal;
2316								else
2317									percentPortTransferred = 0;
2318								cbuffer.Format( _T("%s: %s (%1.1f%%)") , GetResString(IDS_STATS_PRTOTHER), CastItoXBytes( PortDataOther, false, false ) , percentPortTransferred);
2319								stattree.SetItemText( time_aap_down_dp[mx][i] , cbuffer );
2320								i++;
2321
2322								if ( PortDataTotal!=0 && PortDataPeerCache!=0 )
2323									percentPortTransferred = (double) 100 * PortDataPeerCache / PortDataTotal;
2324								else
2325									percentPortTransferred = 0;
2326								cbuffer.Format( _T("%s: %s (%1.1f%%)") , thePrefs.GetPeerCacheShow() ? _T("PeerCache") : GetResString(IDS_STATS_PRTOTHER), CastItoXBytes( PortDataPeerCache, false, false ) , percentPortTransferred);
2327								stattree.SetItemText( time_aap_down_dp[mx][i] , cbuffer );
2328								i++;
2329							}
2330						}
2331						// Set Cum Completed Downloads
2332						cbuffer.Format(_T("%s: %I64u"), GetResString(IDS_STATS_COMPDL), (uint64) (thePrefs.GetDownCompletedFiles() * avgModifier[mx]) );
2333						stattree.SetItemText(time_aap_down[mx][1], cbuffer);
2334						// Set Cum Download Sessions
2335						uint32	statGoodSessions = (uint32)((thePrefs.GetDownC_SuccessfulSessions() + myStats.a[1]) * avgModifier[mx]);
2336						uint32	statBadSessions = (uint32)(thePrefs.GetDownC_FailedSessions() * avgModifier[mx]);
2337						double	percentSessions;
2338						cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_DLSES), statGoodSessions+statBadSessions );
2339						stattree.SetItemText(time_aap_down[mx][2], cbuffer);
2340						if (forceUpdate || stattree.IsExpanded(time_aap_down[mx][2])) 
2341						{
2342							// Set Cum Successful Download Sessions
2343							if (statGoodSessions > 0) 
2344								percentSessions = (double) 100 * statGoodSessions / (statGoodSessions + statBadSessions);
2345							else 
2346								percentSessions = 0;
2347							cbuffer.Format( _T("%s: %u (%1.1f%%)"), GetResString(IDS_STATS_SDLSES) , statGoodSessions , percentSessions );
2348							stattree.SetItemText( time_aap_down_s[mx][0] , cbuffer ); // Set Successful Sessions
2349							// Set Cum Failed Download Sessions
2350							if (percentSessions != 0 && statBadSessions > 0) 
2351								percentSessions = 100 - percentSessions; // There were some good sessions and bad ones...
2352							else if (percentSessions == 0 && statBadSessions > 0) 
2353								percentSessions = 100; // There were bad sessions and no good ones, must be 100%
2354							else 
2355								percentSessions = 0; // No sessions at all, or no bad ones.
2356							cbuffer.Format( _T("%s: %u (%1.1f%%)") , GetResString(IDS_STATS_FDLSES) , statBadSessions , percentSessions);
2357							stattree.SetItemText( time_aap_down_s[mx][1] , cbuffer );
2358						}
2359						// Set Cumulative Gained Due To Compression
2360						cbuffer.Format( GetResString( IDS_STATS_GAINCOMP ) , CastItoXBytes( (uint64)(thePrefs.GetSesSavedFromCompression()+ thePrefs.GetCumSavedFromCompression()) * avgModifier[mx], false, false ) );
2361						stattree.SetItemText( time_aap_down[mx][3] , cbuffer );
2362						// Set Cumulative Lost Due To Corruption
2363						cbuffer.Format( GetResString( IDS_STATS_LOSTCORRUPT ) , CastItoXBytes( (uint64)(thePrefs.GetSesLostFromCorruption() + thePrefs.GetCumLostFromCorruption()) * avgModifier[mx], false, false ) );
2364						stattree.SetItemText( time_aap_down[mx][4] , cbuffer );
2365						// Set Cumulative Saved Due To ICH
2366						cbuffer.Format(GetResString(IDS_STATS_ICHSAVED), (uint32)((thePrefs.GetSesPartsSavedByICH() + thePrefs.GetCumPartsSavedByICH()) * avgModifier[mx]));
2367						stattree.SetItemText( time_aap_down[mx][5] , cbuffer );
2368
2369						uint64 DownOHTotal =	theStats.GetDownDataOverheadFileRequest() + 
2370												theStats.GetDownDataOverheadSourceExchange() + 
2371												theStats.GetDownDataOverheadServer() + 
2372												theStats.GetDownDataOverheadKad() + 
2373												theStats.GetDownDataOverheadOther();
2374						uint64 DownOHTotalPackets = 
2375												theStats.GetDownDataOverheadFileRequestPackets() + 
2376												theStats.GetDownDataOverheadSourceExchangePackets() + 
2377												theStats.GetDownDataOverheadServerPackets() + 
2378												theStats.GetDownDataOverheadKadPackets() + 
2379												theStats.GetDownDataOverheadOtherPackets();
2380						// Total Overhead
2381						cbuffer.Format(GetResString(IDS_TOVERHEAD),CastItoXBytes( (uint64)(DownOHTotal + thePrefs.GetDownOverheadTotal()) * avgModifier[mx], false, false), CastItoIShort((uint64)(DownOHTotalPackets + thePrefs.GetDownOverheadTotalPackets()) * avgModifier[mx]));
2382						stattree.SetItemText(time_aap_down[mx][6], cbuffer);
2383						if (forceUpdate || stattree.IsExpanded(time_aap_down[mx][6])) 
2384						{
2385							int i = 0;
2386							// File Request Overhead
2387							cbuffer.Format(GetResString(IDS_FROVERHEAD), CastItoXBytes( (uint64)(theStats.GetDownDataOverheadFileRequest() + thePrefs.GetDownOverheadFileReq()) * avgModifier[mx], false, false), CastItoIShort((uint64)(theStats.GetDownDataOverheadFileRequestPackets() + thePrefs.GetDownOverheadFileReqPackets()) * avgModifier[mx]));
2388							stattree.SetItemText(time_aap_down_oh[mx][i], cbuffer);
2389							i++;
2390							// Source Exchange Overhead
2391							cbuffer.Format(GetResString(IDS_SSOVERHEAD), CastItoXBytes( (uint64)(theStats.GetDownDataOverheadSourceExchange()+thePrefs.GetDownOverheadSrcEx()) * avgModifier[mx], false, false), CastItoIShort((uint64)(theStats.GetDownDataOverheadSourceExchangePackets()+thePrefs.GetDownOverheadSrcExPackets()) * avgModifier[mx]));
2392							stattree.SetItemText(time_aap_down_oh[mx][i], cbuffer);
2393							i++;
2394							// Server Overhead
2395							cbuffer.Format(GetResString(IDS_SOVERHEAD), 
2396										   CastItoXBytes((uint64)(theStats.GetDownDataOverheadServer() +
2397													     thePrefs.GetDownOverheadServer()) * avgModifier[mx], false, false), 
2398										   CastItoIShort((uint64)(theStats.GetDownDataOverheadServerPackets() + 
2399														 thePrefs.GetDownOverheadServerPackets()) * avgModifier[mx]));
2400							stattree.SetItemText(time_aap_down_oh[mx][i], cbuffer);
2401							i++;
2402							// Kad Overhead
2403							cbuffer.Format(GetResString(IDS_KADOVERHEAD), 
2404										   CastItoXBytes((uint64)(theStats.GetDownDataOverheadKad() +
2405													              thePrefs.GetDownOverheadKad()
2406																 ) * avgModifier[mx], false, false), 
2407										   CastItoIShort((uint64)(theStats.GetDownDataOverheadKadPackets() + 
2408														          thePrefs.GetDownOverheadKadPackets()
2409																 ) * avgModifier[mx]));
2410							stattree.SetItemText(time_aap_down_oh[mx][i], cbuffer);
2411							i++;
2412						}
2413					} // - End Time Statistics -> Projected Averages -> Time Period -> Downloads Section
2414				} // - End Time Statistics -> Projected Averages -> Time Period Sections
2415			} // - End Time Statistics -> Projected Averages Section
2416		} // - End Time Statistics -> Projected Averages Section Loop
2417	} // - END TIME STATISTICS SECTION
2418	
2419	
2420	// CLIENTS SECTION
2421	//						Note:	This section now has dynamic tree items.  This technique
2422	//								may appear in other areas, however, there is usually an
2423	//								advantage to displaying 0 datems.  Here, with the ver-
2424	//								sions being displayed the way they are, it makes sense.
2425	//								Who wants to stare at totally blank tree items?  ;)
2426	if (forceUpdate || stattree.IsExpanded(h_clients)) 
2427	{
2428		CMap<uint32, uint32, uint32, uint32>	clientVersionEDonkey;
2429		CMap<uint32, uint32, uint32, uint32>	clientVersionEDonkeyHybrid;
2430		CMap<uint32, uint32, uint32, uint32>	clientVersionEMule;
2431		CMap<uint32, uint32, uint32, uint32>	clientVersionAMule;
2432		uint32									totalclient;
2433		int										myStats[NUM_CLIENTLIST_STATS];
2434
2435		theApp.clientlist->GetStatistics(totalclient, myStats, 
2436										 clientVersionEDonkey, 
2437										 clientVersionEDonkeyHybrid, 
2438										 clientVersionEMule, 
2439										 clientVersionAMule);
2440
2441		cbuffer.Format(_T("%s: %u "), GetResString(IDS_CLIENTLIST), totalclient);
2442		stattree.SetItemText(cligen[5], cbuffer);
2443
2444		int SIclients=myStats[12]+myStats[13];
2445		cbuffer.Format(_T("%s: %u (%.1f%%) : %u (%.1f%%)"), GetResString(IDS_STATS_SECUREIDENT), myStats[12] , (SIclients>0)?((double)100*myStats[12] / SIclients):0, myStats[13] , (SIclients>0)?((double)100*myStats[13] / SIclients ):0);
2446		stattree.SetItemText(cligen[3], cbuffer);
2447
2448		cbuffer.Format(_T("%s: %u (%.1f%%)"), GetResString(IDS_IDLOW), myStats[14] , (totalclient>0)?((double)100*myStats[14] / totalclient):0);
2449		stattree.SetItemText(cligen[4], cbuffer);
2450
2451		if( !totalclient )
2452			totalclient = 1;
2453
2454		// CLIENTS -> CLIENT SOFTWARE SECTION
2455		if (forceUpdate || stattree.IsExpanded(hclisoft)) 
2456		{
2457			cbuffer.Format(_T("eMule: %i (%1.1f%%)"),		myStats[ 2],(double)100*myStats[ 2]/totalclient);stattree.SetItemText(clisoft[0], cbuffer);
2458			cbuffer.Format(_T("eD Hybrid: %i (%1.1f%%)"),	myStats[ 4],(double)100*myStats[ 4]/totalclient);stattree.SetItemText(clisoft[1], cbuffer);
2459			cbuffer.Format(_T("eDonkey: %i (%1.1f%%)"),		myStats[ 1],(double)100*myStats[ 1]/totalclient);stattree.SetItemText(clisoft[2], cbuffer);
2460			cbuffer.Format(_T("aMule: %i (%1.1f%%)"),		myStats[10],(double)100*myStats[10]/totalclient);stattree.SetItemText(clisoft[3], cbuffer);
2461			cbuffer.Format(_T("MLdonkey: %i (%1.1f%%)"),	myStats[ 3],(double)100*myStats[ 3]/totalclient);stattree.SetItemText(clisoft[4], cbuffer);
2462			cbuffer.Format(_T("Shareaza: %i (%1.1f%%)"),	myStats[11],(double)100*myStats[11]/totalclient);stattree.SetItemText(clisoft[5], cbuffer);
2463			cbuffer.Format(_T("eM Compat: %i (%1.1f%%)"),	myStats[ 5],(double)100*myStats[ 5]/totalclient);stattree.SetItemText(clisoft[6], cbuffer);
2464			cbuffer.Format(GetResString(IDS_STATS_UNKNOWNCLIENT)+_T(" (%1.1f%%)"),myStats[0] , (double)100*myStats[0]/totalclient);stattree.SetItemText(clisoft[7], cbuffer);
2465
2466			// CLIENTS -> CLIENT SOFTWARE -> EMULE SECTION
2467			if (forceUpdate || stattree.IsExpanded(clisoft[0]) || cli_lastCount[0] == 0) 
2468			{
2469				uint32 verCount = 0;
2470				
2471				//--- find top 4 eMule client versions ---
2472				uint32 currtopcnt = 0;
2473				uint32 currtopver = 0;
2474				uint32 totalOther = 0;
2475				for (uint32 i = 0; i < MAX_SUB_CLIENT_VERSIONS; i++)
2476				{
2477					POSITION pos = clientVersionEMule.GetStartPosition();
2478					uint32 topver = 0;
2479					uint32 topcnt = 0;
2480					double topper = 0.0;
2481					while (pos)
2482					{
2483						uint32 ver;
2484						uint32 cnt;
2485						clientVersionEMule.GetNextAssoc(pos, ver, cnt);
2486						if (currtopcnt < cnt)
2487						{
2488							topper = (double)cnt/myStats[2];
2489							topver = ver;
2490							topcnt = cnt;
2491							currtopcnt = cnt;
2492							currtopver = ver;
2493						}
2494						else if (currtopcnt == cnt && currtopver < ver)
2495						{
2496							topver = ver;
2497							currtopver = ver;
2498						}
2499					}
2500					currtopcnt = 0;
2501					currtopver = 0;
2502					clientVersionEMule.RemoveKey(topver);
2503
2504					if (topcnt)
2505					{
2506						UINT verMaj = topver/(100*10*100);
2507						UINT verMin = (topver - (verMaj*100*10*100))/(100*10);
2508						UINT verUp = (topver - (verMaj*100*10*100) - (verMin*100*10))/(100);
2509						if (topver >= MAKE_CLIENT_VERSION(0,40,0) || verUp != 0)
2510						{
2511							if (verUp < 26)
2512								cbuffer.Format(_T("v%u.%u%c: %i (%1.1f%%)"), verMaj, verMin, _T('a') + verUp, topcnt, topper*100);
2513							else
2514								cbuffer.Format(_T("v%u.%u.%u: %i (%1.1f%%)"), verMaj, verMin, verUp, topcnt, topper*100);
2515						}
2516						else
2517							cbuffer.Format(_T("v%u.%u: %i (%1.1f%%)"), verMaj, verMin, topcnt, topper*100);
2518					}
2519					else 
2520						continue;
2521					
2522					if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2523						totalOther += topcnt;
2524					
2525					if (i >= cli_lastCount[0]) 
2526					{
2527						if (i == MAX_SUB_CLIENT_VERSIONS/2)
2528							cli_other[0] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), clisoft[0]);
2529						if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2530							cli_versions[MAX_SUB_CLIENT_VERSIONS*0+i] = stattree.InsertItem(cbuffer, cli_other[0]);
2531						else
2532							cli_versions[MAX_SUB_CLIENT_VERSIONS*0+i] = stattree.InsertItem(cbuffer, clisoft[0]);
2533					}
2534					else
2535						stattree.SetItemText(cli_versions[MAX_SUB_CLIENT_VERSIONS*0+i], cbuffer);
2536
2537					verCount++;
2538				}
2539				if (verCount > MAX_SUB_CLIENT_VERSIONS/2) 
2540				{
2541					cbuffer.Format(_T("%s: %i (%1.1f%%)"), GetResString(IDS_STATS_MINORCLIENTS), totalOther, (double)100 * totalOther / myStats[2]);
2542					stattree.SetItemText(cli_other[0], cbuffer);
2543				}
2544				if (verCount < cli_lastCount[0]) 
2545				{
2546					for (uint32 i = 0; i < cli_lastCount[0] - verCount; i++) 
2547					{
2548						stattree.DeleteItem(cli_versions[cli_lastCount[0] + (MAX_SUB_CLIENT_VERSIONS*0-1) - i]);
2549						if (cli_lastCount[0] + (MAX_SUB_CLIENT_VERSIONS*0-1) - i == MAX_SUB_CLIENT_VERSIONS/2)
2550							stattree.DeleteItem(cli_other[0]);
2551					}
2552				}
2553				cli_lastCount[0] = verCount;
2554			} // End Clients -> Client Software -> eMule Section
2555
2556
2557			// CLIENTS -> CLIENT SOFTWARE -> eD HYBRID SECTION
2558			if (forceUpdate || stattree.IsExpanded(clisoft[1]) || cli_lastCount[1] == 0) 
2559			{
2560				uint32 verCount = 0;
2561				
2562				//--- find top 4 eD Hybrid client versions ---
2563				uint32 currtopcnt = 0;
2564				uint32 currtopver = 0;
2565				uint32 totalOther = 0;
2566				for (uint32 i = 0; i < MAX_SUB_CLIENT_VERSIONS; i++)
2567				{
2568					POSITION pos = clientVersionEDonkeyHybrid.GetStartPosition();
2569					uint32 topver = 0;
2570					uint32 topcnt = 0;
2571					double topper = 0.0;
2572					while (pos)
2573					{
2574						uint32 ver;
2575						uint32 cnt;
2576						clientVersionEDonkeyHybrid.GetNextAssoc(pos, ver, cnt);
2577						if (currtopcnt < cnt)
2578						{
2579							topper = (double)cnt/myStats[4];
2580							topver = ver;
2581							topcnt = cnt;
2582							currtopcnt = cnt;
2583							currtopver = ver;
2584						}
2585						else if (currtopcnt == cnt && currtopver < ver)
2586						{
2587							topver = ver;
2588							currtopver = ver;
2589						}
2590					}
2591					currtopcnt = 0;
2592					currtopver = 0;
2593					clientVersionEDonkeyHybrid.RemoveKey(topver);
2594
2595					if (topcnt)
2596					{
2597						UINT verMaj = topver/(100*10*100);
2598						UINT verMin = (topver - (verMaj*100*10*100))/(100*10);
2599						UINT verUp = (topver - (verMaj*100*10*100) - (verMin*100*10))/(100);
2600						cbuffer.Format(_T("v%u.%u.%u: %i (%1.1f%%)"), verMaj, verMin, verUp, topcnt, topper*100);
2601					}
2602					else
2603						continue;
2604
2605					if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2606						totalOther += topcnt;
2607
2608					if (i >= cli_lastCount[1]) 
2609					{
2610						if (i == MAX_SUB_CLIENT_VERSIONS/2)
2611							cli_other[1] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), clisoft[1]);
2612						if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2613							cli_versions[MAX_SUB_CLIENT_VERSIONS*1+i] = stattree.InsertItem(cbuffer, cli_other[1]);
2614						else
2615							cli_versions[MAX_SUB_CLIENT_VERSIONS*1+i] = stattree.InsertItem(cbuffer, clisoft[1]);
2616					}
2617					else
2618						stattree.SetItemText(cli_versions[MAX_SUB_CLIENT_VERSIONS*1+i], cbuffer);
2619
2620					verCount++;
2621				}
2622				if (verCount > MAX_SUB_CLIENT_VERSIONS/2) 
2623				{
2624					cbuffer.Format(_T("%s: %i (%1.1f%%)"), GetResString(IDS_STATS_MINORCLIENTS), totalOther, (double)100 * totalOther / myStats[4]);
2625					stattree.SetItemText(cli_other[1], cbuffer);
2626				}
2627				if (verCount < cli_lastCount[1]) 
2628				{
2629					for (uint32 i = 0; i < cli_lastCount[1] - verCount; i++) 
2630					{
2631						stattree.DeleteItem(cli_versions[cli_lastCount[1] + (MAX_SUB_CLIENT_VERSIONS*1-1) - i]);
2632						if (cli_lastCount[1] + (MAX_SUB_CLIENT_VERSIONS*1-1) - i == MAX_SUB_CLIENT_VERSIONS/2)
2633							stattree.DeleteItem(cli_other[1]);
2634					}
2635				}
2636				cli_lastCount[1] = verCount;
2637			} // End Clients -> Client Software -> eD Hybrid Section
2638
2639			
2640			// CLIENTS -> CLIENT SOFTWARE -> EDONKEY SECTION
2641			if (forceUpdate || stattree.IsExpanded(clisoft[2]) || cli_lastCount[2] == 0) 
2642			{				
2643				uint32 verCount = 0;
2644				
2645				//--- find top 4 eDonkey client versions ---
2646				uint32 currtopcnt = 0;
2647				uint32 currtopver = 0;
2648				uint32 totalOther = 0;
2649				for (uint32 i = 0; i < MAX_SUB_CLIENT_VERSIONS; i++)
2650				{
2651					POSITION pos = clientVersionEDonkey.GetStartPosition();
2652					uint32 topver = 0;
2653					uint32 topcnt = 0;
2654					double topper = 0.0;
2655					while (pos)
2656					{
2657						uint32 ver;
2658						uint32 cnt;
2659						clientVersionEDonkey.GetNextAssoc(pos, ver, cnt);
2660						if (currtopcnt < cnt)
2661						{
2662							topper = (double)cnt/myStats[1];
2663							topver = ver;
2664							topcnt = cnt;
2665							currtopcnt = cnt;
2666							currtopver = ver;
2667						}
2668						else if (currtopcnt == cnt && currtopver < ver)
2669						{
2670							topver = ver;
2671							currtopver = ver;
2672						}
2673					}
2674					currtopcnt = 0;
2675					currtopver = 0;
2676					clientVersionEDonkey.RemoveKey(topver);
2677
2678					if (topcnt)
2679					{
2680						UINT verMaj = topver/(100*10*100);
2681						UINT verMin = (topver - (verMaj*100*10*100))/(100*10);
2682						UINT verUp = (topver - (verMaj*100*10*100) - (verMin*100*10))/(100);
2683						cbuffer.Format(_T("v%u.%u.%u: %i (%1.1f%%)"), verMaj, verMin, verUp, topcnt, topper*100);
2684					}
2685					else
2686						continue;
2687
2688					if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2689						totalOther += topcnt;
2690
2691					if (i >= cli_lastCount[2]) 
2692					{
2693						if (i == MAX_SUB_CLIENT_VERSIONS/2)
2694							cli_other[2] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), clisoft[2]);
2695						if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2696							cli_versions[MAX_SUB_CLIENT_VERSIONS*2+i] = stattree.InsertItem(cbuffer, cli_other[2]);
2697						else
2698							cli_versions[MAX_SUB_CLIENT_VERSIONS*2+i] = stattree.InsertItem(cbuffer, clisoft[2]);
2699					}
2700					else
2701						stattree.SetItemText(cli_versions[MAX_SUB_CLIENT_VERSIONS*2+i], cbuffer);
2702
2703					verCount++;
2704				}
2705				if (verCount > MAX_SUB_CLIENT_VERSIONS/2) 
2706				{
2707					cbuffer.Format(_T("%s: %i (%1.1f%%)"), GetResString(IDS_STATS_MINORCLIENTS), totalOther, (double)100 * totalOther / myStats[1]);
2708					stattree.SetItemText(cli_other[2], cbuffer);
2709				}
2710				if (verCount < cli_lastCount[2]) 
2711				{
2712					for (uint32 i = 0; i < cli_lastCount[2] - verCount; i++) 
2713					{
2714						stattree.DeleteItem(cli_versions[cli_lastCount[2] + (MAX_SUB_CLIENT_VERSIONS*2-1) - i]);
2715						if (cli_lastCount[2] + (MAX_SUB_CLIENT_VERSIONS*2-1) - i == MAX_SUB_CLIENT_VERSIONS/2)
2716							stattree.DeleteItem(cli_other[2]);
2717					}
2718				}
2719				cli_lastCount[2] = verCount;
2720			} // End Clients -> Client Software -> eDonkey Section
2721
2722
2723			// CLIENTS -> CLIENT SOFTWARE -> AMULE SECTION
2724			if (forceUpdate || stattree.IsExpanded(clisoft[3]) || cli_lastCount[3] == 0) 
2725			{
2726				uint32 verCount = 0;
2727				
2728				//--- find top 4 client versions ---
2729				uint32 currtopcnt = 0;
2730				uint32 currtopver = 0;
2731				uint32 totalOther = 0;
2732				for (uint32 i = 0; i < MAX_SUB_CLIENT_VERSIONS; i++)
2733				{
2734					POSITION pos = clientVersionAMule.GetStartPosition();
2735					uint32 topver = 0;
2736					uint32 topcnt = 0;
2737					double topper = 0.0;
2738					while (pos)
2739					{
2740						uint32 ver;
2741						uint32 cnt;
2742						clientVersionAMule.GetNextAssoc(pos, ver, cnt);
2743						if (currtopcnt < cnt)
2744						{
2745							topper = (double)cnt/myStats[10];
2746							topver = ver;
2747							topcnt = cnt;
2748							currtopcnt = cnt;
2749							currtopver = ver;
2750						}
2751						else if (currtopcnt == cnt && currtopver < ver)
2752						{
2753							topver = ver;
2754							currtopver = ver;
2755						}
2756					}
2757					currtopcnt = 0;
2758					currtopver = 0;
2759					clientVersionAMule.RemoveKey(topver);
2760
2761					if (topcnt)
2762					{
2763						UINT verMaj = topver/(100*10*100);
2764						UINT verMin = (topver - (verMaj*100*10*100))/(100*10);
2765						UINT verUp = (topver - (verMaj*100*10*100) - (verMin*100*10))/(100);
2766						if (topver >= MAKE_CLIENT_VERSION(0,40,0) || verUp != 0)
2767							cbuffer.Format(_T("v%u.%u.%u: %i (%1.1f%%)"), verMaj, verMin, verUp, topcnt, topper*100);
2768						else
2769							cbuffer.Format(_T("v%u.%u: %i (%1.1f%%)"), verMaj, verMin, topcnt, topper*100);
2770					}
2771					else 
2772						continue;
2773
2774					if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2775						totalOther += topcnt;
2776					
2777					if (i >= cli_lastCount[3]) 
2778					{
2779						if (i == MAX_SUB_CLIENT_VERSIONS/2)
2780							cli_other[3] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), clisoft[3]);
2781						if (i >= MAX_SUB_CLIENT_VERSIONS/2)
2782							cli_versions[MAX_SUB_CLIENT_VERSIONS*3+i] = stattree.InsertItem(cbuffer, cli_other[3]);
2783						else
2784							cli_versions[MAX_SUB_CLIENT_VERSIONS*3+i] = stattree.InsertItem(cbuffer, clisoft[3]);
2785					}
2786					else
2787						stattree.SetItemText(cli_versions[MAX_SUB_CLIENT_VERSIONS*3+i], cbuffer);
2788
2789					verCount++;
2790				}
2791				if (verCount > MAX_SUB_CLIENT_VERSIONS/2) 
2792				{
2793					cbuffer.Format(_T("%s: %i (%1.1f%%)"), GetResString(IDS_STATS_MINORCLIENTS), totalOther, (double)100 * totalOther / myStats[10]);
2794					stattree.SetItemText(cli_other[3], cbuffer);
2795				}
2796				if (verCount < cli_lastCount[3]) 
2797				{
2798					for (uint32 i = 0; i < cli_lastCount[3] - verCount; i++) 
2799					{
2800						stattree.DeleteItem(cli_versions[cli_lastCount[3] + (MAX_SUB_CLIENT_VERSIONS*3-1) - i]);
2801						if (cli_lastCount[3] + (MAX_SUB_CLIENT_VERSIONS*3-1) - i == MAX_SUB_CLIENT_VERSIONS/2)
2802							stattree.DeleteItem(cli_other[3]);
2803					}
2804				}
2805				cli_lastCount[3] = verCount;
2806			} // End Clients -> Client Software -> aMule Section
2807
2808		} // - End Clients -> Client Software Section
2809		// CLIENTS -> NETWORK SECTION
2810		if (forceUpdate || stattree.IsExpanded(hclinet)) 
2811		{
2812			cbuffer.Format( _T("eD2K: %u (%.1f%%)") , myStats[15], totalclient ? (myStats[15] * 100.0 / totalclient) : 0.0 );
2813			stattree.SetItemText( clinet[0] , cbuffer );
2814			cbuffer.Format( _T("Kad: %u (%.1f%%)") , myStats[16], totalclient ? (myStats[16] * 100.0 / totalclient) : 0.0 );
2815			stattree.SetItemText( clinet[1] , cbuffer );
2816			cbuffer.Format( _T("eD2K/Kad: %u (%.1f%%)") , myStats[17], totalclient ? (myStats[17] * 100.0 / totalclient) : 0.0 );
2817			stattree.SetItemText( clinet[2] , cbuffer );
2818			cbuffer.Format( _T("%s: %u (%.1f%%)") , GetResString(IDS_UNKNOWN), myStats[18], totalclient ? (myStats[18] * 100.0 / totalclient) : 0.0 );
2819			stattree.SetItemText( clinet[3] , cbuffer );
2820		}
2821		// End Clients -> Network Section
2822
2823		// CLIENTS -> PORT SECTION
2824		if (forceUpdate || stattree.IsExpanded(hcliport)) 
2825		{
2826			cbuffer.Format(_T("%s: %u (%1.1f%%)"), GetResString(IDS_STATS_PRTDEF), myStats[8], myStats[8]>0?((double)100*myStats[8]/(myStats[8]+myStats[9])):0);
2827			stattree.SetItemText(cliport[0], cbuffer);
2828			cbuffer.Format(_T("%s: %u (%1.1f%%)"), GetResString(IDS_STATS_PRTOTHER), myStats[9], myStats[9]>0?((double)100*myStats[9]/(myStats[8]+myStats[9])):0);
2829			stattree.SetItemText(cliport[1], cbuffer);
2830		} // - End Clients -> Port Section
2831
2832		// CLIENTS -> FIREWALLED (KAD) SECTION
2833		if (forceUpdate || stattree.IsExpanded(hclifirewalled)) 
2834		{
2835			if (!Kademlia::CKademlia::IsRunning() || Kademlia::CUDPFirewallTester::IsFirewalledUDP(true)) {
2836				cbuffer.Format(_T("UDP: %s"), GetResString(IDS_KAD_UNKNOWN));
2837				stattree.SetItemText(clifirewalled[0], cbuffer);
2838				cbuffer.Format(_T("TCP: %s"), GetResString(IDS_KAD_UNKNOWN));
2839				stattree.SetItemText(clifirewalled[1], cbuffer);
2840			}
2841			else {
2842				if (Kademlia::CKademlia::GetPrefs()->StatsGetFirewalledRatio(true) > 0)
2843					cbuffer.Format(_T("UDP: %1.1f%%"), Kademlia::CKademlia::GetPrefs()->StatsGetFirewalledRatio(true) * 100);
2844				else
2845					cbuffer.Format(_T("UDP: %s"), GetResString(IDS_FSTAT_WAITING));
2846				stattree.SetItemText(clifirewalled[0], cbuffer);
2847				if (Kademlia::CKademlia::GetPrefs()->StatsGetFirewalledRatio(false) > 0)
2848					cbuffer.Format(_T("TCP: %1.1f%%"), Kademlia::CKademlia::GetPrefs()->StatsGetFirewalledRatio(false) * 100);
2849				else
2850					cbuffer.Format(_T("TCP: %s"), GetResString(IDS_FSTAT_WAITING));
2851				stattree.SetItemText(clifirewalled[1], cbuffer);
2852			}
2853		} // - End Clients -> Firewalled (Kad) Section
2854
2855		// General Client Statistics
2856		cbuffer.Format(_T("%s: %u (%1.1f%%)"), GetResString(IDS_STATS_PROBLEMATIC), myStats[6], (double)100*myStats[6]/totalclient);
2857		stattree.SetItemText(cligen[0], cbuffer);
2858		
2859		cbuffer.Format(_T("%s: %u"), GetResString(IDS_BANNED), theApp.clientlist->GetBannedCount());
2860		stattree.SetItemText(cligen[1], cbuffer);
2861		
2862		cbuffer.Format(GetResString(IDS_STATS_FILTEREDCLIENTS), theStats.filteredclients);
2863		stattree.SetItemText(cligen[2], cbuffer);
2864	} // - END CLIENTS SECTION
2865
2866
2867	// UPDATE RECORDS FOR SERVERS AND SHARED FILES
2868	thePrefs.SetRecordStructMembers();
2869
2870	// SERVERS SECTION
2871	if (forceUpdate || stattree.IsExpanded(h_servers)) 
2872	{		
2873		// Get stat values
2874		uint32	servtotal, servfail, servuser, servfile, servlowiduser, servtuser, servtfile;
2875		float	servocc;
2876		theApp.serverlist->GetStatus( servtotal, servfail, servuser, servfile, servlowiduser, servtuser, servtfile, servocc);
2877		// Set working servers value
2878		cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_WORKING),CastItoIShort(servtotal-servfail));stattree.SetItemText(srv[0], cbuffer);
2879		if (forceUpdate || stattree.IsExpanded(srv[0])) 
2880		{			
2881			// Set users on working servers value
2882			cbuffer.Format(_T("%s: %s; %s: %s (%.1f%%)"),GetResString(IDS_SF_WUSER),CastItoIShort(servuser),GetResString(IDS_IDLOW),CastItoIShort(servlowiduser),servuser ? (servlowiduser * 100.0 / servuser) : 0.0);stattree.SetItemText(srv_w[0], cbuffer);
2883			// Set files on working servers value
2884			cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_WFILE),CastItoIShort(servfile));stattree.SetItemText(srv_w[1], cbuffer);
2885			// Set server occ value
2886			cbuffer.Format(GetResString(IDS_SF_SRVOCC),servocc);stattree.SetItemText(srv_w[2], cbuffer);
2887		}
2888		// Set failed servers value
2889		cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_FAIL),CastItoIShort(servfail));stattree.SetItemText(srv[1], cbuffer);
2890		// Set deleted servers value
2891		cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_DELCOUNT),CastItoIShort(theApp.serverlist->GetDeletedServerCount()));stattree.SetItemText(srv[2], cbuffer);
2892		// Set total servers value
2893		cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_TOTAL),CastItoIShort(servtotal));stattree.SetItemText(srv[3], cbuffer);
2894		// Set total users value
2895		cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_USER),CastItoIShort(servtuser));stattree.SetItemText(srv[4], cbuffer);
2896		// Set total files value
2897		cbuffer.Format(_T("%s: %s"),GetResString(IDS_SF_FILE),CastItoIShort(servtfile));stattree.SetItemText(srv[5], cbuffer);
2898		// SERVERS -> RECORDS SECTION
2899		if (forceUpdate || stattree.IsExpanded(hsrv_records)) 
2900		{			
2901			// Set most working servers
2902			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_SVRECWORKING), CastItoIShort(thePrefs.GetSrvrsMostWorkingServers()));
2903			stattree.SetItemText(srv_r[0], cbuffer);
2904			// Set most users online
2905			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_SVRECUSERS), CastItoIShort(thePrefs.GetSrvrsMostUsersOnline()));
2906			stattree.SetItemText(srv_r[1], cbuffer);
2907			// Set most files avail
2908			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_SVRECFILES), CastItoIShort(thePrefs.GetSrvrsMostFilesAvail()));
2909			stattree.SetItemText(srv_r[2], cbuffer);
2910		} // - End Servers -> Records Section
2911	} // - END SERVERS SECTION
2912
2913	
2914	// SHARED FILES SECTION
2915	if (forceUpdate || stattree.IsExpanded(h_shared)) 
2916	{		
2917		// Set Number of Shared Files
2918		cbuffer.Format(GetResString(IDS_SHAREDFILESCOUNT),theApp.sharedfiles->GetCount());
2919		// SLUGFILLER: SafeHash - extra statistics
2920		if (theApp.sharedfiles->GetHashingCount())
2921		{
2922			CString tempbuffer;
2923			tempbuffer.Format(GetResString(IDS_HASHINGFILESCOUNT),theApp.sharedfiles->GetHashingCount());
2924			cbuffer += tempbuffer;
2925		}
2926		// SLUGFILLER: SafeHash
2927		stattree.SetItemText(shar[0], cbuffer);
2928		// Set Average File Size
2929		uint64 bytesLargestFile = 0;
2930		uint64 allsize=theApp.sharedfiles->GetDatasize(bytesLargestFile); // Func returns total share size and sets pointeredd uint64 to largest single filesize
2931		CString cbuffer2;
2932		if(theApp.sharedfiles->GetCount() != 0)
2933			cbuffer2.Format( _T("%s"), CastItoXBytes(allsize/(uint64)theApp.sharedfiles->GetCount(), false, false));
2934		else 
2935			cbuffer2.Format( _T("%s"), CastItoXBytes((uint32)0, false, false) );
2936		cbuffer.Format(GetResString(IDS_SF_AVERAGESIZE),cbuffer2);
2937		stattree.SetItemText(shar[1], cbuffer);
2938		// Set Largest File Size
2939		cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_LARGESTFILE), CastItoXBytes(bytesLargestFile, false, false) );
2940		stattree.SetItemText(shar[2], cbuffer);
2941		// Set Total Share Size
2942		cbuffer.Format(GetResString(IDS_SF_SIZE),CastItoXBytes(allsize, false, false));
2943		stattree.SetItemText(shar[3], cbuffer);
2944
2945		// SHARED FILES -> RECORDS SECTION
2946		if (forceUpdate || stattree.IsExpanded(hshar_records)) 
2947		{			
2948			// Set Most Files Shared
2949			cbuffer.Format(_T("%s: %u"), GetResString(IDS_STATS_SHRECNUM), thePrefs.GetSharedMostFilesShared() );
2950			stattree.SetItemText(shar_r[0], cbuffer);
2951			// Set largest avg file size
2952			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_SHRECASIZE), CastItoXBytes(thePrefs.GetSharedLargestAvgFileSize(), false, false) );
2953			stattree.SetItemText(shar_r[1], cbuffer);
2954			// Set largest file size
2955			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_LARGESTFILE), CastItoXBytes(thePrefs.GetSharedLargestFileSize(), false, false) );
2956			stattree.SetItemText(shar_r[2], cbuffer);
2957			// Set largest share size
2958			cbuffer.Format(_T("%s: %s"), GetResString(IDS_STATS_SHRECSIZE), CastItoXBytes(thePrefs.GetSharedLargestShareSize(), false, false) );
2959			stattree.SetItemText(shar_r[3], cbuffer);
2960		} // - End Shared Files -> Records Section
2961	} // - END SHARED FILES SECTION
2962
2963	if (forceUpdate || stattree.IsExpanded(h_total_downloads)) 
2964	{			
2965		uint64 ui64TotalFileSize = 0;
2966		uint64 ui64TotalLeftToTransfer = 0;
2967		uint64 ui64TotalAdditionalNeededSpace = 0;
2968		int iActiveFiles = theApp.downloadqueue->GetDownloadFilesStats(ui64TotalFileSize, ui64TotalLeftToTransfer, ui64TotalAdditionalNeededSpace);
2969
2970		cbuffer.Format(GetResString(IDS_DWTOT_NR), iActiveFiles);
2971		stattree.SetItemText(h_total_num_of_dls, cbuffer);
2972
2973		cbuffer.Format(GetResString(IDS_DWTOT_TSD), CastItoXBytes(ui64TotalFileSize, false, false));
2974		stattree.SetItemText(h_total_size_of_dls, cbuffer);
2975
2976		uint64 ui64TotalTransferred = ui64TotalFileSize - ui64TotalLeftToTransfer;
2977		double fPercent = 0.0;
2978		if (ui64TotalFileSize != 0)
2979			fPercent = (ui64TotalTransferred * 100.0) / ui64TotalFileSize;
2980		cbuffer.Format(GetResString(IDS_DWTOT_TCS), CastItoXBytes(ui64TotalTransferred, false, false), fPercent);
2981		stattree.SetItemText(h_total_size_dld, cbuffer);
2982
2983		cbuffer.Format(GetResString(IDS_DWTOT_TSL), CastItoXBytes(ui64TotalLeftToTransfer, false, false));
2984		stattree.SetItemText(h_total_size_left_to_dl, cbuffer);
2985
2986		cbuffer.Format(GetResString(IDS_DWTOT_TSN), CastItoXBytes(ui64TotalAdditionalNeededSpace, false, false));
2987		stattree.SetItemText(h_total_size_needed, cbuffer);
2988
2989		CString buffer2;
2990		uint64 ui64TotalFreeSpace = GetFreeTempSpace(-1);
2991		buffer2.Format(GetResString(IDS_DWTOT_FS), CastItoXBytes(ui64TotalFreeSpace, false, false));
2992
2993		if (ui64TotalAdditionalNeededSpace > ui64TotalFreeSpace)
2994			cbuffer.Format(GetResString(IDS_NEEDFREEDISKSPACE), buffer2, CastItoXBytes(ui64TotalAdditionalNeededSpace - ui64TotalFreeSpace, false, false));
2995		else
2996			cbuffer = buffer2;
2997		stattree.SetItemText(h_total_size_left_on_drive, cbuffer);
2998	}
2999	// - End Set Tree Values
3000
3001
3002#ifdef _DEBUG
3003	if (g_pfnPrevCrtAllocHook)
3004	{
3005		_CrtMemState memState;
3006		_CrtMemCheckpoint(&memState);
3007
3008		cbuffer.Format(_T("%s: %u bytes in %u blocks"),_T("Free"),memState.lSizes[ 0 ],memState.lCounts[ 0 ] );
3009		stattree.SetItemText(debug1, cbuffer);
3010		cbuffer.Format(_T("%s: %u bytes in %u blocks"),_T("Normal"),memState.lSizes[ 1 ],memState.lCounts[ 1 ] );
3011		stattree.SetItemText(debug2, cbuffer);
3012		cbuffer.Format(_T("%s: %u bytes in %u blocks"),_T("CRT"),memState.lSizes[ 2 ],memState.lCounts[ 2 ] );
3013		stattree.SetItemText(debug3, cbuffer);
3014		cbuffer.Format(_T("%s: %u bytes in %u blocks"),_T("Ignore"),memState.lSizes[ 3 ],memState.lCounts[ 3 ] );
3015		stattree.SetItemText(debug4, cbuffer);
3016		cbuffer.Format(_T("%s: %u bytes in %u blocks"),_T("Client"),memState.lSizes[ 4 ],memState.lCounts[ 4 ] );
3017		stattree.SetItemText(debug5, cbuffer);
3018
3019		extern CMap<const unsigned char*, const unsigned char*, UINT, UINT> g_allocations;
3020
3021		POSITION pos = blockFiles.GetStartPosition();
3022		while (pos != NULL) 
3023		{
3024			const unsigned char* pszFileName;
3025			HTREEITEM* pTag;
3026			blockFiles.GetNextAssoc(pos, pszFileName, pTag);
3027			stattree.SetItemText(*pTag, _T(""));
3028		}
3029		pos = g_allocations.GetStartPosition();
3030		while (pos != NULL) 
3031		{
3032			const unsigned char* pszFileName;
3033			UINT count;
3034			g_allocations.GetNextAssoc(pos, pszFileName, count);
3035			HTREEITEM* pTag;
3036			if (blockFiles.Lookup(pszFileName, pTag) == 0) 
3037			{
3038				pTag = new HTREEITEM;
3039				*pTag = stattree.InsertItem(_T("0"), debug2);
3040				stattree.SetItemData(*pTag, 1);
3041				blockFiles.SetAt(pszFileName, pTag);
3042			}
3043			cbuffer.Format(_T("%s : %u blocks"), pszFileName, count);
3044			stattree.SetItemText(*pTag, cbuffer);
3045		}
3046	}
3047#endif
3048
3049#ifdef USE_MEM_STATS
3050	if (forceUpdate || stattree.IsExpanded(h_allocs))
3051	{
3052		ULONGLONG ullTotalAllocs = 0;
3053		for (int i = 0; i < ALLOC_SLOTS; i++)
3054			ullTotalAllocs += g_aAllocStats[i];
3055		for (int i = 0; i < ALLOC_SLOTS; i++)
3056		{
3057			unsigned uStart, uEnd;
3058			if (i <= 1)
3059				uStart = uEnd = i;
3060			else {
3061				uStart = 1 << (i - 1);
3062				uEnd = (i == ALLOC_SLOTS - 1) ? (unsigned)-1 : (uStart << 1) - 1;
3063			}
3064			CString strLabel;
3065			strLabel.Format(_T("Block size %08X-%08X: %s (%1.1f%%)"), uStart, uEnd, CastItoIShort(g_aAllocStats[i], false, 2), ullTotalAllocs != 0 ? g_aAllocStats[i] * 100.0 / ullTotalAllocs : 0.0);
3066			stattree.SetItemText(h_allocSizes[i], strLabel);
3067		}
3068	}
3069#endif
3070
3071	stattree.SetRedraw(true);
3072
3073} // ShowStatistics(bool forceRedraw = false){}
3074
3075void CStatisticsDlg::UpdateConnectionsGraph()
3076{
3077	// This updates the Y-Axis scale of the Connections Statistics graph...
3078	// And it updates the trend ratio for the active connections trend.
3079
3080	m_Statistics.SetRanges(0, thePrefs.GetStatsMax());
3081	m_Statistics.SetTrendRatio(0, thePrefs.GetStatsConnectionsGraphRatio());
3082}
3083
3084void CStatisticsDlg::OnShowWindow(BOOL /*bShow*/, UINT /*nStatus*/)
3085{
3086}
3087
3088void CStatisticsDlg::OnSize(UINT nType, int cx, int cy)
3089{
3090	CResizableDialog::OnSize(nType, cx, cy);
3091	if (cx > 0 && cy > 0 && (cx != m_oldcx || cy != m_oldcy))
3092	{
3093		m_oldcx=cx;
3094		m_oldcy=cy;
3095		ShowInterval();
3096	}
3097}
3098
3099void CStatisticsDlg::ShowInterval()
3100{
3101	if (!theApp.emuledlg->IsRunning())
3102		return;
3103
3104	// Check if OScope already initialized
3105	if (m_DownloadOMeter.GetSafeHwnd() != NULL && m_UploadOMeter.GetSafeHwnd() != NULL)
3106	{
3107		// Retrieve the size (in pixel) of the OScope
3108		CRect plotRect;
3109		m_UploadOMeter.GetPlotRect(plotRect);
3110		
3111		// Dynamic update of time scale [Maella]
3112		int shownSecs = plotRect.Width() * thePrefs.GetTrafficOMeterInterval(); 
3113		
3114		// CB Mod ---> Make Setters
3115		m_Statistics.m_nXPartial = m_DownloadOMeter.m_nXPartial = m_UploadOMeter.m_nXPartial = shownSecs % 3600;
3116		m_Statistics.m_nXGrids = m_DownloadOMeter.m_nXGrids = m_UploadOMeter.m_nXGrids = shownSecs / 3600;
3117
3118		if(shownSecs <= 0)
3119		{
3120			m_DownloadOMeter.SetXUnits(GetResString(IDS_STOPPED)); 
3121			m_UploadOMeter.SetXUnits(GetResString(IDS_STOPPED)); 
3122			m_Statistics.SetXUnits(GetResString(IDS_STOPPED)); 
3123		} 
3124		else 
3125		{
3126			const CString buffer = CastSecondsToHM(shownSecs);
3127			m_UploadOMeter.SetXUnits(buffer);
3128			m_DownloadOMeter.SetXUnits(buffer); 
3129			m_Statistics.SetXUnits(buffer); 
3130		}
3131		UpdateData(FALSE);
3132	}
3133}
3134
3135void CStatisticsDlg::SetARange(bool SetDownload, int maxValue)
3136{
3137	if (SetDownload) 
3138	{
3139		m_DownloadOMeter.SetRange(0, maxValue, 0);
3140		m_DownloadOMeter.SetRange(0, maxValue, 1);
3141		m_DownloadOMeter.SetRange(0, maxValue, 2);
3142	}
3143	else
3144	{
3145		m_UploadOMeter.SetRange(0, maxValue, 0) ;
3146		m_UploadOMeter.SetRange(0, maxValue, 1);
3147		m_UploadOMeter.SetRange(0, maxValue, 2);
3148		m_UploadOMeter.SetRange(0, maxValue, 3);
3149		m_UploadOMeter.SetRange(0, maxValue, 4);
3150	}
3151}
3152
3153// Various changes in Localize() and a new button event...
3154void CStatisticsDlg::Localize()
3155{
3156	RepaintMeters();
3157
3158	CString myBuffer;
3159	myBuffer.Format(GetResString(IDS_STATS_LASTRESETSTATIC), thePrefs.GetStatsLastResetStr(false));
3160	GetDlgItem(IDC_STATIC_LASTRESET)->SetWindowText(myBuffer);
3161}
3162// End Localize
3163
3164// Menu Button: Displays the menu of stat tree commands.
3165void CStatisticsDlg::OnMenuButtonClicked()
3166{
3167	CRect rectBn;
3168	CPoint thePoint;
3169	GetDlgItem(IDC_BNMENU)->GetWindowRect(&rectBn);
3170	thePoint = rectBn.BottomRight();
3171	stattree.DoMenu(thePoint);
3172}
3173
3174void CStatisticsDlg::CreateMyTree() 
3175{
3176	stattree.DeleteAllItems();
3177
3178	// Setup Tree
3179	h_transfer = stattree.InsertItem(GetResString(IDS_FSTAT_TRANSFER),1,1);				// Transfers Section
3180	CString buffer;
3181	buffer.Format(_T("%s %s"),GetResString(IDS_STATS_SRATIO),GetResString(IDS_FSTAT_WAITING));// Make It Pretty
3182	trans[0]= stattree.InsertItem(buffer, h_transfer);										// Session Ratio
3183
3184	buffer.Format(_T("%s %s"),GetResString(IDS_STATS_FRATIO),GetResString(IDS_FSTAT_WAITING));// Make It Pretty
3185	trans[1]= stattree.InsertItem(buffer, h_transfer);										// Friend Session Ratio
3186
3187	buffer.Format(_T("%s %s"),GetResString(IDS_STATS_CRATIO),GetResString(IDS_FSTAT_WAITING));// Make It Pretty
3188	trans[2]= stattree.InsertItem(buffer, h_transfer);										// Cumulative Ratio
3189
3190	h_upload = stattree.InsertItem(GetResString(IDS_TW_UPLOADS), 6,6,h_transfer);		// Uploads Section
3191	
3192	h_up_session= stattree.InsertItem(GetResString(IDS_STATS_SESSION), 8,8,h_upload);		// Session Section (Uploads)
3193	for(int i = 0; i<6; i++) 
3194		up_S[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_up_session); //MORPH - Added by Yun.SF3, ZZ Upload System
3195	hup_scb= stattree.InsertItem(GetResString(IDS_CLIENTS),up_S[0]);							// Clients Section
3196	for(int i = 0; i<_countof(up_scb); i++) 
3197		up_scb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_scb);
3198	hup_spb= stattree.InsertItem(GetResString(IDS_PORT),up_S[0]);								// Ports Section
3199	for(int i = 0; i<_countof(up_spb); i++) 
3200		up_spb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_spb);
3201	hup_ssb= stattree.InsertItem(GetResString(IDS_STATS_DATASOURCE),up_S[0]);					// Data Source Section
3202	for(int i = 0; i<2; i++) 
3203		up_ssb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_ssb);
3204	for(int i = 0; i<4; i++) 
3205		up_ssessions[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), up_S[5]); //MORPH - Added by Yun.SF3, ZZ Upload System
3206	hup_soh= stattree.InsertItem(GetResString(IDS_STATS_OVRHD),h_up_session);					// Upline Overhead (Session)
3207	for(int i = 0; i<_countof(up_soh); i++) 
3208		up_soh[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_soh);
3209	h_up_total= stattree.InsertItem(GetResString(IDS_STATS_CUMULATIVE),9,9, h_upload);		// Cumulative Section (Uploads)
3210	up_T[0]= stattree.InsertItem(GetResString(IDS_FSTAT_WAITING),h_up_total);				// Uploaded Data (Total)
3211	hup_tcb= stattree.InsertItem(GetResString(IDS_CLIENTS),up_T[0]);							// Clients Section
3212	for(int i = 0; i<_countof(up_tcb); i++) 
3213		up_tcb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_tcb);
3214	hup_tpb= stattree.InsertItem(GetResString(IDS_PORT),up_T[0]);								// Ports Section
3215	for(int i = 0; i<_countof(up_tpb); i++) 
3216		up_tpb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_tpb);
3217	hup_tsb= stattree.InsertItem(GetResString(IDS_STATS_DATASOURCE),up_T[0]);					// Data Source Section
3218	for(int i = 0; i<2; i++) 
3219		up_tsb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_tsb);
3220	up_T[1]= stattree.InsertItem(GetResString(IDS_FSTAT_WAITING),h_up_total);				// Upload Sessions (Total)
3221	for(int i = 0; i<4; i++) 
3222		up_tsessions[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), up_T[1]);
3223	hup_toh= stattree.InsertItem(GetResString(IDS_STATS_OVRHD),h_up_total);						// Upline Overhead (Total)
3224	for(int i = 0; i<_countof(up_toh); i++) 
3225		up_toh[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hup_toh);
3226	h_download = stattree.InsertItem(GetResString(IDS_TW_DOWNLOADS), 7,7,h_transfer);	// Downloads Section
3227	h_down_session= stattree.InsertItem(GetResString(IDS_STATS_SESSION),8,8, h_download);	// Session Section (Downloads)
3228	for(int i = 0; i<8; i++) 
3229		down_S[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_down_session);
3230	hdown_scb= stattree.InsertItem(GetResString(IDS_CLIENTS),down_S[0]);						// Clients Section
3231	for(int i = 0; i<_countof(down_scb); i++) 
3232		down_scb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hdown_scb);
3233	hdown_spb= stattree.InsertItem(GetResString(IDS_PORT),down_S[0]);							// Ports Section
3234	for(int i = 0; i<_countof(down_spb); i++) 
3235		down_spb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hdown_spb);
3236	for(int i = 0; i<_countof(down_sources); i++) 
3237		down_sources[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), down_S[3]);
3238	for(int i = 0; i<4; i++) 
3239		down_ssessions[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), down_S[4]);
3240	hdown_soh= stattree.InsertItem(GetResString(IDS_STATS_OVRHD),h_down_session);				// Downline Overhead (Session)
3241	for(int i = 0; i<_countof(down_soh); i++) 
3242		down_soh[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hdown_soh);
3243	h_down_total= stattree.InsertItem(GetResString(IDS_STATS_CUMULATIVE),9,9, h_download);	// Cumulative Section (Downloads)
3244	for(int i = 0; i<6; i++)
3245		down_T[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_down_total);
3246	hdown_tcb= stattree.InsertItem(GetResString(IDS_CLIENTS),down_T[0]);						// Clients Section
3247	for(int i = 0; i<_countof(down_tcb); i++) 
3248		down_tcb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hdown_tcb);
3249	hdown_tpb= stattree.InsertItem(GetResString(IDS_PORT),down_T[0]);							// Ports Section
3250	for(int i = 0; i<_countof(down_tpb); i++) 
3251		down_tpb[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hdown_tpb);
3252	for(int i = 0; i<4; i++)
3253		down_tsessions[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), down_T[2]);
3254	hdown_toh= stattree.InsertItem(GetResString(IDS_STATS_OVRHD),h_down_total);					// Downline Overhead (Total)
3255	for(int i = 0; i<_countof(down_toh); i++) 
3256		down_toh[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hdown_toh);
3257	h_connection = stattree.InsertItem(GetResString(IDS_FSTAT_CONNECTION),2,2);				// Connection Section
3258	h_conn_session= stattree.InsertItem(GetResString(IDS_STATS_SESSION),8,8,h_connection);	// Session Section (Connection)
3259	hconn_sg= stattree.InsertItem(GetResString(IDS_STATS_GENERAL),11,11,h_conn_session);	// General Section (Session)
3260	for(int i = 0; i<5; i++) 
3261		conn_sg[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hconn_sg);
3262	hconn_su= stattree.InsertItem(GetResString(IDS_PW_CON_UPLBL),6,6,h_conn_session);		// Uploads Section (Session)
3263	for(int i = 0; i<4; i++)
3264		conn_su[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hconn_su);
3265	hconn_sd= stattree.InsertItem(GetResString(IDS_PW_CON_DOWNLBL),7,7,h_conn_session);			// Downloads Section (Session)
3266	for(int i = 0; i<4; i++)
3267		conn_sd[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hconn_sd);
3268	h_conn_total= stattree.InsertItem(GetResString(IDS_STATS_CUMULATIVE),9,9,h_connection);	// Cumulative Section (Connection)
3269	hconn_tg= stattree.InsertItem(GetResString(IDS_STATS_GENERAL),11,11,h_conn_total);		// General (Total)
3270	for(int i = 0; i<4; i++)
3271		conn_tg[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hconn_tg);
3272	hconn_tu= stattree.InsertItem(GetResString(IDS_PW_CON_UPLBL),6,6,h_conn_total);			// Uploads (Total)
3273	for(int i = 0; i<3; i++)
3274		conn_tu[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hconn_tu);
3275	hconn_td= stattree.InsertItem(GetResString(IDS_PW_CON_DOWNLBL),7,7,h_conn_total);				// Downloads (Total)
3276	for(int i = 0; i<3; i++)
3277		conn_td[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hconn_td);
3278	h_time = stattree.InsertItem(GetResString(IDS_STATS_TIMESTATS),12,12);					// Time Statistics Section
3279	for(int i = 0; i<2; i++)
3280		tvitime[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_time);
3281	htime_s = stattree.InsertItem(GetResString(IDS_STATS_SESSION),8,8,h_time);				// Session Section (Time)
3282	for(int i = 0; i<4; i++)
3283		tvitime_s[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), htime_s);
3284	for(int i = 0; i<2; i++)
3285		tvitime_st[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), tvitime_s[1]);
3286	htime_t = stattree.InsertItem(GetResString(IDS_STATS_CUMULATIVE),9,9,h_time);			// Cumulative Section (Time)
3287	for(int i = 0; i<3; i++)
3288		tvitime_t[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), htime_t);
3289	for(int i = 0; i<2; i++)
3290		tvitime_tt[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), tvitime_t[1]);
3291	htime_aap = stattree.InsertItem(GetResString(IDS_STATS_AVGANDPROJ),13,13,h_time);		// Projected Averages Section
3292	time_aaph[0] = stattree.InsertItem(GetResString(IDS_DAYLY),14,14,htime_aap);			// Daily Section
3293	time_aaph[1] = stattree.InsertItem(GetResString(IDS_STATS_MONTHLY),15,15,htime_aap);	// Monthly Section
3294	time_aaph[2] = stattree.InsertItem(GetResString(IDS_STATS_YEARLY),16,16,htime_aap);		// Yearly Section
3295	for(int x = 0; x<3; x++) 
3296	{
3297		time_aap_hup[x] = stattree.InsertItem(GetResString(IDS_TW_UPLOADS),6,6,time_aaph[x]);	// Upload Section
3298		for(int i = 0; i<3; i++)
3299			time_aap_up[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING),time_aap_hup[x]);
3300		time_aap_up_hd[x][0] = stattree.InsertItem(GetResString(IDS_CLIENTS),time_aap_up[x][0]);							// Clients Section
3301		for(int i = 0; i<7; i++)
3302			time_aap_up_dc[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_up_hd[x][0]);
3303		time_aap_up_hd[x][1] = stattree.InsertItem(GetResString(IDS_PORT),time_aap_up[x][0]);								// Ports Section
3304		for(int i = 0; i<_countof(time_aap_up_dp[0]); i++)
3305			time_aap_up_dp[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_up_hd[x][1]);
3306		time_aap_up_hd[x][2] = stattree.InsertItem(GetResString(IDS_STATS_DATASOURCE),time_aap_up[x][0]);					// Data Source Section
3307		for(int i = 0; i<2; i++)
3308			time_aap_up_ds[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_up_hd[x][2]);
3309		for(int i = 0; i<2; i++)
3310			time_aap_up_s[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_up[x][1]);
3311		for(int i = 0; i<4; i++)
3312			time_aap_up_oh[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_up[x][2]);
3313        time_aap_hdown[x] = stattree.InsertItem(GetResString(IDS_TW_DOWNLOADS),7,7,time_aaph[x]);// Download Section
3314		for(int i = 0; i<7; i++)
3315			time_aap_down[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING),time_aap_hdown[x]);
3316		time_aap_down_hd[x][0] = stattree.InsertItem(GetResString(IDS_CLIENTS),time_aap_down[x][0]);							// Clients Section
3317		for(int i = 0; i<8; i++)
3318			time_aap_down_dc[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_down_hd[x][0]);
3319		time_aap_down_hd[x][1] = stattree.InsertItem(GetResString(IDS_PORT),time_aap_down[x][0]);								// Ports Section
3320		for(int i = 0; i<_countof(time_aap_down_dp[0]); i++)
3321			time_aap_down_dp[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_down_hd[x][1]);
3322		for(int i = 0; i<2; i++)
3323			time_aap_down_s[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_down[x][2]);
3324		for(int i = 0; i<4; i++)
3325			time_aap_down_oh[x][i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), time_aap_down[x][6]);
3326	}
3327	h_clients = stattree.InsertItem(GetResString(IDS_CLIENTS),3,3);							// Clients Section
3328	cligen[5] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_clients);
3329	hclisoft = stattree.InsertItem(GetResString(IDS_CD_CSOFT),h_clients);				// Client Software Section
3330	for(int i = 0; i<8; i++)
3331		clisoft[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hclisoft);
3332	hclinet = stattree.InsertItem(GetResString(IDS_NETWORK),h_clients);						// Client Network Section
3333	for(int i = 0; i<4; i++)
3334		clinet[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hclinet);
3335	hcliport = stattree.InsertItem(GetResString(IDS_PORT),h_clients);						// Client Port Section
3336	for(int i = 0; i<2; i++)
3337		cliport[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hcliport);
3338	hclifirewalled = stattree.InsertItem(GetResString(IDS_FIREWALLED) + _T(" (") + GetResString(IDS_KADEMLIA) + _T(")"),h_clients);
3339	for (int i = 0; i < 2; i++)
3340		clifirewalled[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hclifirewalled);	
3341	cligen[4] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_clients);
3342	cligen[3] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_clients);
3343	for(int i = 0; i<3; i++)
3344		cligen[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_clients);
3345	h_servers = stattree.InsertItem(GetResString(IDS_FSTAT_SERVERS),4,4);					// Servers section
3346	for(int i = 0; i<6; i++)
3347		srv[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_servers);		// Servers Items
3348	for(int i = 0; i<3; i++)
3349		srv_w[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), srv[0]);	// Working Servers Items
3350	hsrv_records = stattree.InsertItem(GetResString(IDS_STATS_RECORDS),10,10,h_servers);	// Servers Records Section
3351	for(int i = 0; i<3; i++)
3352		srv_r[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hsrv_records);	// Record Items
3353	h_shared = stattree.InsertItem( GetResString(IDS_SHAREDFILES),5,5 );					// Shared Files Section
3354	for(int i = 0; i<4; i++)
3355		shar[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), h_shared);
3356	hshar_records= stattree.InsertItem(GetResString(IDS_STATS_RECORDS),10,10,h_shared);		// Shared Records Section
3357	for(int i = 0; i<4; i++)
3358		shar_r[i] = stattree.InsertItem(GetResString(IDS_FSTAT_WAITING), hshar_records);
3359	h_total_downloads=stattree.InsertItem(GetResString(IDS_DWTOT),17,17);
3360	h_total_num_of_dls=stattree.InsertItem(GetResString(IDS_DWTOT_NR),h_total_downloads);
3361	h_total_size_of_dls=stattree.InsertItem(GetResString(IDS_DWTOT_TSD),h_total_downloads);
3362	h_total_size_dld=stattree.InsertItem(GetResString(IDS_DWTOT_TCS),h_total_downloads);
3363	h_total_size_left_to_dl=stattree.InsertItem(GetResString(IDS_DWTOT_TSL),h_total_downloads);
3364	h_total_size_left_on_drive=stattree.InsertItem(GetResString(IDS_DWTOT_FS),h_total_downloads);
3365	h_total_size_needed=stattree.InsertItem(GetResString(IDS_DWTOT_TSN),h_total_downloads);
3366
3367#ifdef _DEBUG
3368	if (g_pfnPrevCrtAllocHook)
3369	{
3370		h_debug = stattree.InsertItem( _T("Debug info") );stattree.SetItemData(h_debug,0);
3371		h_blocks = stattree.InsertItem(_T("Blocks"),h_debug);stattree.SetItemData(h_blocks,1);
3372		debug1 =  stattree.InsertItem(_T("Free"),h_blocks);stattree.SetItemData(debug1,1);
3373		debug2 =  stattree.InsertItem(_T("Normal"),h_blocks);stattree.SetItemData(debug2,1);
3374		debug3 =  stattree.InsertItem(_T("CRT"),h_blocks);stattree.SetItemData(debug3,1);
3375		debug4 =  stattree.InsertItem(_T("Ignore"),h_blocks);stattree.SetItemData(debug4,1);
3376		debug5 =  stattree.InsertItem(_T("Client"),h_blocks);stattree.SetItemData(debug5,1);
3377		stattree.Expand(h_debug,TVE_EXPAND);
3378		stattree.Expand(h_blocks,TVE_EXPAND);
3379	}
3380#endif
3381
3382#ifdef USE_MEM_STATS
3383	h_allocs = stattree.InsertItem(_T("Allocations"));
3384	for (int i = 0; i < ALLOC_SLOTS; i++)
3385	{
3386		unsigned uStart, uEnd;
3387		if (i <= 1)
3388			uStart = uEnd = i;
3389		else {
3390			uStart = 1 << (i - 1);
3391			uEnd = (i == ALLOC_SLOTS - 1) ? (unsigned)-1 : (uStart << 1) - 1;
3392		}
3393		CString strLabel;
3394		strLabel.Format(_T("Block size %08X-%08X: %s (%1.1f%%)"), uStart, uEnd, CastItoIShort(g_aAllocStats[i], false, 2), 0.0);
3395		h_allocSizes[i] = stattree.InsertItem(strLabel, h_allocs);
3396	}
3397#endif
3398
3399	// Make section headers bold in order to make the tree easier to view at a glance.
3400	stattree.SetItemState(h_transfer, TVIS_BOLD, TVIS_BOLD);
3401	stattree.SetItemState(h_connection, TVIS_BOLD, TVIS_BOLD);
3402	stattree.SetItemState(h_time, TVIS_BOLD, TVIS_BOLD);
3403	stattree.SetItemState(htime_s, TVIS_BOLD, TVIS_BOLD);
3404	stattree.SetItemState(htime_t, TVIS_BOLD, TVIS_BOLD);
3405	stattree.SetItemState(htime_aap, TVIS_BOLD, TVIS_BOLD);
3406	stattree.SetItemState(h_total_downloads, TVIS_BOLD, TVIS_BOLD);
3407	for(int i = 0; i<3; i++) 
3408	{
3409		stattree.SetItemState(time_aaph[i], TVIS_BOLD, TVIS_BOLD);
3410		stattree.SetItemState(time_aap_hup[i], TVIS_BOLD, TVIS_BOLD);
3411		stattree.SetItemState(time_aap_hdown[i], TVIS_BOLD, TVIS_BOLD);
3412	}
3413	stattree.SetItemState(h_clients, TVIS_BOLD, TVIS_BOLD);
3414	stattree.SetItemState(h_servers, TVIS_BOLD, TVIS_BOLD);
3415	stattree.SetItemState(h_shared, TVIS_BOLD, TVIS_BOLD);
3416	stattree.SetItemState(h_upload, TVIS_BOLD, TVIS_BOLD);
3417	stattree.SetItemState(h_download, TVIS_BOLD, TVIS_BOLD);
3418	stattree.SetItemState(h_up_session, TVIS_BOLD, TVIS_BOLD);
3419	stattree.SetItemState(h_up_total, TVIS_BOLD, TVIS_BOLD);
3420	stattree.SetItemState(h_down_session, TVIS_BOLD, TVIS_BOLD);
3421	stattree.SetItemState(h_down_total, TVIS_BOLD, TVIS_BOLD);
3422	stattree.SetItemState(h_conn_session, TVIS_BOLD, TVIS_BOLD);
3423	stattree.SetItemState(h_conn_total, TVIS_BOLD, TVIS_BOLD);
3424	stattree.SetItemState(hsrv_records, TVIS_BOLD, TVIS_BOLD);
3425	stattree.SetItemState(hshar_records, TVIS_BOLD, TVIS_BOLD);
3426	stattree.SetItemState(hconn_sg, TVIS_BOLD, TVIS_BOLD);	
3427	stattree.SetItemState(hconn_su, TVIS_BOLD, TVIS_BOLD);	
3428	stattree.SetItemState(hconn_sd, TVIS_BOLD, TVIS_BOLD);	
3429	stattree.SetItemState(hconn_tg, TVIS_BOLD, TVIS_BOLD);	
3430	stattree.SetItemState(hconn_tu, TVIS_BOLD, TVIS_BOLD);	
3431	stattree.SetItemState(hconn_td, TVIS_BOLD, TVIS_BOLD);	
3432	
3433	// Expand our purdy new tree...
3434	stattree.ApplyExpandedMask(thePrefs.GetExpandedTreeItems());
3435	
3436	// Select the top item so that the tree is not scrolled to the bottom when first viewed.
3437	stattree.SelectItem(h_transfer);
3438	stattree.Init();
3439
3440	// Initialize our client version counts
3441	for (int i = 0; i < _countof(cli_lastCount); i++)
3442		cli_lastCount[i] = 0;
3443
3444	// End Tree Setup
3445}
3446
3447void CStatisticsDlg::OnStnDblclickScopeD()
3448{
3449	theApp.emuledlg->ShowPreferences(IDD_PPG_STATS);
3450}
3451
3452void CStatisticsDlg::OnStnDblclickScopeU()
3453{
3454	theApp.emuledlg->ShowPreferences(IDD_PPG_STATS);
3455}
3456
3457void CStatisticsDlg::OnStnDblclickStatsscope()
3458{
3459	theApp.emuledlg->ShowPreferences(IDD_PPG_STATS);
3460}
3461
3462LRESULT CStatisticsDlg::OnOscopePositionMsg(WPARAM /*wParam*/, LPARAM lParam)
3463{
3464	LPCTSTR pszInfo = (LPCTSTR)lParam;
3465	m_TimeToolTips->UpdateTipText(pszInfo, GetDlgItem(IDC_SCOPE_D));
3466	m_TimeToolTips->UpdateTipText(pszInfo, GetDlgItem(IDC_SCOPE_U));
3467	m_TimeToolTips->UpdateTipText(pszInfo, GetDlgItem(IDC_STATSSCOPE));
3468	m_TimeToolTips->Update();
3469	return 0;
3470}
3471
3472BOOL CStatisticsDlg::PreTranslateMessage(MSG* pMsg) 
3473{
3474	m_TimeToolTips->RelayEvent(pMsg);
3475
3476	if (pMsg->message == WM_KEYDOWN)
3477	{
3478		// Don't handle Ctrl+Tab in this window. It will be handled by main window.
3479		if (pMsg->wParam == VK_TAB && GetAsyncKeyState(VK_CONTROL) < 0)
3480			return FALSE;
3481	}
3482
3483	return CDialog::PreTranslateMessage(pMsg);
3484}
3485
3486BOOL CStatisticsDlg::OnHelpInfo(HELPINFO* /*pHelpInfo*/)
3487{
3488	theApp.ShowHelp(eMule_FAQ_GUI_Statistics);
3489	return TRUE;
3490}
3491
3492HBRUSH CStatisticsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
3493{
3494	HBRUSH hbr = theApp.emuledlg->GetCtlColor(pDC, pWnd, nCtlColor);
3495	if (hbr)
3496		return hbr;
3497	return __super::OnCtlColor(pDC, pWnd, nCtlColor);
3498}