📄 filedetaildialog.cpp
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include "emule.h"
#include "OtherFunctions.h"
#include "FileInfoDialog.h"
#include "FileDetailDialog.h"
#include "Preferences.h"
#include "UpDownClient.h"
#include "TitleMenu.h"
#include "MenuCmds.h"
#include "PartFile.h"
#include "StringConversion.h"
#include "shahashset.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
///////////////////////////////////////////////////////////////////////////////
// CFileDetailDialog
LPCTSTR CFileDetailDialog::m_pPshStartPage;
IMPLEMENT_DYNAMIC(CFileDetailDialog, CResizableSheet)
BEGIN_MESSAGE_MAP(CFileDetailDialog, CResizableSheet)
ON_WM_DESTROY()
END_MESSAGE_MAP()
CFileDetailDialog::CFileDetailDialog(const CSimpleArray<CPartFile*>* paFiles, EInvokePage eInvokePage)
{
m_file = (*paFiles)[0];
for (int i = 0; i < paFiles->GetSize(); i++)
m_aKnownFiles.Add((*paFiles)[i]);
m_psh.dwFlags &= ~PSH_HASHELP;
m_psh.dwFlags |= PSH_NOAPPLYNOW;
m_wndInfo.m_psp.dwFlags &= ~PSP_HASHELP;
m_wndInfo.SetMyfile(paFiles);
AddPage(&m_wndInfo);
if (paFiles->GetSize() == 1)
{
m_wndName.m_psp.dwFlags &= ~PSP_HASHELP;
m_wndName.SetMyfile(m_file);
AddPage(&m_wndName);
m_wndComments.m_psp.dwFlags &= ~PSP_HASHELP;
m_wndComments.SetMyfile(m_file);
AddPage(&m_wndComments);
}
m_wndVideo.m_psp.dwFlags &= ~PSP_HASHELP;
m_wndVideo.SetMyfile(&m_aKnownFiles);
AddPage(&m_wndVideo);
if (paFiles->GetSize() == 1)
{
if (thePrefs.IsExtControlsEnabled()){
m_wndMetaData.m_psp.dwFlags &= ~PSP_HASHELP;
m_wndMetaData.SetFile(m_file);
AddPage(&m_wndMetaData);
}
}
m_wndFileLink.m_psp.dwFlags &= ~PSP_HASHELP;
m_wndFileLink.SetMyfile(&m_aKnownFiles);
AddPage(&m_wndFileLink);
m_eInvokePage = eInvokePage;
}
CFileDetailDialog::~CFileDetailDialog()
{
}
void CFileDetailDialog::OnDestroy()
{
if (m_eInvokePage == INP_NONE)
m_pPshStartPage = GetPage(GetActiveIndex())->m_psp.pszTemplate;
CResizableSheet::OnDestroy();
}
BOOL CFileDetailDialog::OnInitDialog()
{
EnableStackedTabs(FALSE);
BOOL bResult = CResizableSheet::OnInitDialog();
InitWindowStyles(this);
EnableSaveRestore(_T("FileDetailDialog")); // call this after(!) OnInitDialog
SetWindowText(GetResString(IDS_FD_TITLE));
LPCTSTR pPshStartPage = m_pPshStartPage;
switch(m_eInvokePage){
case INP_COMMENTPAGE:
pPshStartPage = MAKEINTRESOURCE(IDD_COMMENTLST);
break;
case INP_LINKPAGE:
pPshStartPage = MAKEINTRESOURCE(IDD_ED2KLINK);
break;
case INP_NONE:
break;
default:
ASSERT ( false );
}
for (int i = 0; i < m_pages.GetSize(); i++)
{
CPropertyPage* pPage = GetPage(i);
if (pPage->m_psp.pszTemplate == pPshStartPage)
{
SetActivePage(i);
break;
}
}
return bResult;
}
///////////////////////////////////////////////////////////////////////////////
// CFileDetailDialogInfo dialog
LPCTSTR CFileDetailDialogInfo::sm_pszNotAvail = _T("-");
IMPLEMENT_DYNAMIC(CFileDetailDialogInfo, CResizablePage)
BEGIN_MESSAGE_MAP(CFileDetailDialogInfo, CResizablePage)
ON_WM_TIMER()
ON_WM_DESTROY()
END_MESSAGE_MAP()
CFileDetailDialogInfo::CFileDetailDialogInfo()
: CResizablePage(CFileDetailDialogInfo::IDD, 0)
{
m_strCaption = GetResString(IDS_FILEINFORMATION);
m_psp.pszTitle = m_strCaption;
m_psp.dwFlags |= PSP_USETITLE;
m_timer = 0;
}
CFileDetailDialogInfo::~CFileDetailDialogInfo()
{
}
void CFileDetailDialogInfo::OnTimer(UINT nIDEvent)
{
RefreshData();
}
void CFileDetailDialogInfo::DoDataExchange(CDataExchange* pDX)
{
CResizablePage::DoDataExchange(pDX);
}
BOOL CFileDetailDialogInfo::OnInitDialog()
{
CResizablePage::OnInitDialog();
InitWindowStyles(this);
AddAnchor(IDC_FD_X0, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FD_X6, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FD_X8, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FNAME, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_METFILE, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FHASH, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FSIZE, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FD_AICHHASH, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_PARTCOUNT, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_HASHSET, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_COMPLSIZE, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_DATARATE, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_SOURCECOUNT, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_RECOVERED, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_FILECREATED, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_DL_ACTIVE_TIME, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_LASTSEENCOMPL, TOP_LEFT, TOP_RIGHT);
AddAnchor(IDC_LASTRECEIVED, TOP_LEFT, TOP_RIGHT);
Localize();
// properties which won't change during the dialog is open - no need to fresh them and mess with the focus
if (m_paFiles->GetSize() == 1)
{
// if file is completed, we output the 'file path' and not the 'part.met file path'
if ((*m_paFiles)[0]->GetStatus(true) == PS_COMPLETE)
GetDlgItem(IDC_FD_X2)->SetWindowText(GetResString(IDS_DL_FILENAME));
SetDlgItemText(IDC_FNAME, (*m_paFiles)[0]->GetFileName());
SetDlgItemText(IDC_METFILE, (*m_paFiles)[0]->GetFullName());
SetDlgItemText(IDC_FHASH, md4str((*m_paFiles)[0]->GetFileHash()));
}
else
{
SetDlgItemText(IDC_FNAME, sm_pszNotAvail);
SetDlgItemText(IDC_METFILE, sm_pszNotAvail);
SetDlgItemText(IDC_FHASH, sm_pszNotAvail);
}
RefreshData();
VERIFY( (m_timer = SetTimer(301, 5000, 0)) != NULL );
return true;
}
BOOL CFileDetailDialogInfo::OnSetActive()
{
if (!CResizablePage::OnSetActive())
return FALSE;
if (m_paFiles->GetSize() == 1)
SetDlgItemText(IDC_FNAME, (*m_paFiles)[0]->GetFileName());
return TRUE;
}
void CFileDetailDialogInfo::RefreshData()
{
CString str;
if (m_paFiles->GetSize() == 1)
{
if ((*m_paFiles)[0]->GetTransferingSrcCount() > 0)
str.Format(GetResString(IDS_PARTINFOS2), (*m_paFiles)[0]->GetTransferingSrcCount());
else
str = (*m_paFiles)[0]->getPartfileStatus();
SetDlgItemText(IDC_PFSTATUS, str);
str.Format(_T("%u; %s: %u (%.1f%%)"), (*m_paFiles)[0]->GetPartCount(), GetResString(IDS_AVAILABLE) , (*m_paFiles)[0]->GetAvailablePartCount(), (float)(((*m_paFiles)[0]->GetAvailablePartCount()*100)/(*m_paFiles)[0]->GetPartCount()));
SetDlgItemText(IDC_PARTCOUNT, str);
// date created
if ((*m_paFiles)[0]->GetCrFileDate() != 0){
str.Format(_T("%s ") + GetResString(IDS_TIMEBEFORE),
(*m_paFiles)[0]->GetCrCFileDate().Format(thePrefs.GetDateTimeFormat()),
CastSecondsToLngHM(time(NULL) - (*m_paFiles)[0]->GetCrFileDate()));
}
else
str = GetResString(IDS_UNKNOWN);
SetDlgItemText(IDC_FILECREATED, str);
// active download time
uint32 nDlActiveTime = (*m_paFiles)[0]->GetDlActiveTime();
if (nDlActiveTime)
str = CastSecondsToLngHM(nDlActiveTime);
else
str = GetResString(IDS_UNKNOWN);
SetDlgItemText(IDC_DL_ACTIVE_TIME, str);
// last seen complete
struct tm* ptimLastSeenComplete = (*m_paFiles)[0]->lastseencomplete.GetLocalTm();
if ((*m_paFiles)[0]->lastseencomplete == NULL || ptimLastSeenComplete == NULL)
str.Format(GetResString(IDS_UNKNOWN));
else{
str.Format(_T("%s ") + GetResString(IDS_TIMEBEFORE),
(*m_paFiles)[0]->lastseencomplete.Format(thePrefs.GetDateTimeFormat()),
CastSecondsToLngHM(time(NULL) - safe_mktime(ptimLastSeenComplete)));
}
SetDlgItemText(IDC_LASTSEENCOMPL, str);
// last receive
if ((*m_paFiles)[0]->GetFileDate() != 0 && (*m_paFiles)[0]->GetRealFileSize() > 0)
{
// 'Last Modified' sometimes is up to 2 seconds greater than the current time ???
// If it's related to the FAT32 seconds time resolution the max. failure should still be only 1 sec.
// Happens at least on FAT32 with very high download speed.
uint32 tLastModified = (*m_paFiles)[0]->GetFileDate();
uint32 tNow = time(NULL);
uint32 tAgo;
if (tNow >= tLastModified)
tAgo = tNow - tLastModified;
else{
TRACE("tNow = %s\n", CTime(tNow).Format("%X"));
TRACE("tLMd = %s, +%u\n", CTime(tLastModified).Format("%X"), tLastModified - tNow);
TRACE("\n");
tAgo = 0;
}
str.Format(_T("%s ") + GetResString(IDS_TIMEBEFORE),
(*m_paFiles)[0]->GetCFileDate().Format(thePrefs.GetDateTimeFormat()),
CastSecondsToLngHM(tAgo));
}
else
str = GetResString(IDS_UNKNOWN);
SetDlgItemText(IDC_LASTRECEIVED, str);
// AICH Hash
switch((*m_paFiles)[0]->GetAICHHashset()->GetStatus()){
case AICH_TRUSTED:
case AICH_VERIFIED:
case AICH_HASHSETCOMPLETE:
if ((*m_paFiles)[0]->GetAICHHashset()->HasValidMasterHash()){
SetDlgItemText(IDC_FD_AICHHASH, (*m_paFiles)[0]->GetAICHHashset()->GetMasterHash().GetString());
break;
}
default:
SetDlgItemText(IDC_FD_AICHHASH, GetResString(IDS_UNKNOWN));
}
}
else
{
SetDlgItemText(IDC_PFSTATUS, sm_pszNotAvail);
SetDlgItemText(IDC_PARTCOUNT, sm_pszNotAvail);
SetDlgItemText(IDC_FILECREATED, sm_pszNotAvail);
SetDlgItemText(IDC_DL_ACTIVE_TIME, sm_pszNotAvail);
SetDlgItemText(IDC_LASTSEENCOMPL, sm_pszNotAvail);
SetDlgItemText(IDC_LASTRECEIVED, sm_pszNotAvail);
SetDlgItemText(IDC_FD_AICHHASH, sm_pszNotAvail);
}
uint64 uFileSize = 0;
uint64 uRealFileSize = 0;
uint64 uTransfered = 0;
uint64 uCorrupted = 0;
uint64 uRecovered = 0;
uint64 uCompression = 0;
uint64 uCompleted = 0;
int iHashsetAvailable = 0;
uint32 uDataRate = 0;
UINT uSources = 0;
UINT uValidSources = 0;
UINT uNNPSources = 0;
UINT uA4AFSources = 0;
for (int i = 0; i < m_paFiles->GetSize(); i++)
{
uFileSize += (*m_paFiles)[i]->GetFileSize();
uRealFileSize += (*m_paFiles)[i]->GetRealFileSize();
uTransfered += (*m_paFiles)[i]->GetTransfered();
uCorrupted += (*m_paFiles)[i]->GetLostDueToCorruption();
uRecovered += (*m_paFiles)[i]->TotalPacketsSavedDueToICH();
uCompression += (*m_paFiles)[i]->GetGainDueToCompression();
uDataRate += (*m_paFiles)[i]->GetDatarate();
uCompleted += (*m_paFiles)[i]->GetCompletedSize();
iHashsetAvailable += ((*m_paFiles)[i]->GetHashCount() == (*m_paFiles)[i]->GetED2KPartHashCount()) ? 1 : 0;
if ((*m_paFiles)[i]->IsPartFile())
{
uSources += (*m_paFiles)[i]->GetSourceCount();
uValidSources += (*m_paFiles)[i]->GetValidSourcesCount();
uNNPSources += (*m_paFiles)[i]->GetSrcStatisticsValue(DS_NONEEDEDPARTS);
uA4AFSources += (*m_paFiles)[i]->GetSrcA4AFCount();
}
}
if (iHashsetAvailable == 0)
SetDlgItemText(IDC_HASHSET, GetResString(IDS_NO));
else if (iHashsetAvailable == m_paFiles->GetSize())
SetDlgItemText(IDC_HASHSET, GetResString(IDS_YES));
else
SetDlgItemText(IDC_HASHSET, _T(""));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -