📄 emuledlg.cpp
字号:
CKnownFile* result = (CKnownFile*)lParam;
ASSERT( result->IsKindOf(RUNTIME_CLASS(CKnownFile)) );
if (wParam)
{
// File hashing finished for a part file when:
// - part file just completed
// - part file was rehashed at startup because the file date of part.met did not match the part file date
CPartFile* requester = (CPartFile*)wParam;
ASSERT( requester->IsKindOf(RUNTIME_CLASS(CPartFile)) );
// SLUGFILLER: SafeHash - could have been canceled
if (theApp.downloadqueue->IsPartFile(requester))
requester->PartFileHashFinished(result);
else
delete result;
// SLUGFILLER: SafeHash
}
else
{
ASSERT( !result->IsKindOf(RUNTIME_CLASS(CPartFile)) );
// File hashing finished for a shared file (none partfile)
// - reading shared directories at startup and hashing files which were not found in known.met
// - reading shared directories during runtime (user hit Reload button, added a shared directory, ...)
theApp.sharedfiles->FileHashingFinished(result);
}
return TRUE;
}
LRESULT CemuleDlg::OnFileOpProgress(WPARAM wParam, LPARAM lParam)
{
if (theApp.m_app_state == APP_STATE_SHUTINGDOWN)
return FALSE;
CKnownFile* pKnownFile = (CKnownFile*)lParam;
ASSERT( pKnownFile->IsKindOf(RUNTIME_CLASS(CKnownFile)) );
if (pKnownFile->IsKindOf(RUNTIME_CLASS(CPartFile)))
{
CPartFile* pPartFile = static_cast<CPartFile*>(pKnownFile);
pPartFile->SetFileOpProgress(wParam);
pPartFile->UpdateDisplayedInfo(true);
}
return 0;
}
// SLUGFILLER: SafeHash
LRESULT CemuleDlg::OnHashFailed(WPARAM wParam, LPARAM lParam)
{
theApp.sharedfiles->HashFailed((UnknownFile_Struct*)lParam);
return 0;
}
// SLUGFILLER: SafeHash
LRESULT CemuleDlg::OnFileAllocExc(WPARAM wParam,LPARAM lParam)
{
if (lParam == 0)
((CPartFile*)wParam)->FlushBuffersExceptionHandler();
else
((CPartFile*)wParam)->FlushBuffersExceptionHandler((CFileException*)lParam);
return 0;
}
LRESULT CemuleDlg::OnFileCompleted(WPARAM wParam, LPARAM lParam)
{
CPartFile* partfile = (CPartFile*)lParam;
ASSERT( partfile != NULL );
if (partfile)
partfile->PerformFileCompleteEnd(wParam);
return 0;
}
bool CemuleDlg::CanClose()
{
if (theApp.m_app_state == APP_STATE_RUNNING && thePrefs.IsConfirmExitEnabled())
{
if (AfxMessageBox(GetResString(IDS_MAIN_EXIT), MB_YESNO | MB_DEFBUTTON2) == IDNO)
return false;
}
return true;
}
void CemuleDlg::OnClose()
{
if (!CanClose())
return;
m_pDropTarget->Revoke();
theApp.m_app_state = APP_STATE_SHUTINGDOWN;
theApp.serverconnect->Disconnect();
theApp.OnlineSig(); // Added By Bouc7
// get main window placement
WINDOWPLACEMENT wp;
wp.length = sizeof(wp);
GetWindowPlacement(&wp);
thePrefs.SetWindowLayout(wp);
// get active main window dialog
if (activewnd){
if (activewnd->IsKindOf(RUNTIME_CLASS(CServerWnd)))
thePrefs.SetLastMainWndDlgID(IDD_SERVER);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CSharedFilesWnd)))
thePrefs.SetLastMainWndDlgID(IDD_FILES);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CSearchDlg)))
thePrefs.SetLastMainWndDlgID(IDD_SEARCH);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CChatWnd)))
thePrefs.SetLastMainWndDlgID(IDD_CHAT);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CTransferWnd)))
thePrefs.SetLastMainWndDlgID(IDD_TRANSFER);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CStatisticsDlg)))
thePrefs.SetLastMainWndDlgID(IDD_STATISTICS);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CKademliaWnd)))
thePrefs.SetLastMainWndDlgID(IDD_KADEMLIAWND);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CChanblardWnd))) //VeryCD
if (thePrefs.GetBrowser())
thePrefs.SetLastMainWndDlgID(IDD_EMULEBROWSER);
else if (activewnd->IsKindOf(RUNTIME_CLASS(CIrcWnd)))
thePrefs.SetLastMainWndDlgID(IDD_IRC);
else{
ASSERT(0);
thePrefs.SetLastMainWndDlgID(0);
}
}
Kademlia::CKademlia::stop();
// try to wait untill the hashing thread notices that we are shutting down
CSingleLock sLock1(&theApp.hashing_mut); // only one filehash at a time
sLock1.Lock(2000);
// saving data & stuff
theApp.emuledlg->preferenceswnd->m_wndSecurity.DeleteDDB();
theApp.knownfiles->Save();
transferwnd->downloadlistctrl.SaveSettings(CPreferences::tableDownload);
transferwnd->uploadlistctrl.SaveSettings(CPreferences::tableUpload);
transferwnd->queuelistctrl.SaveSettings(CPreferences::tableQueue);
transferwnd->clientlistctrl.SaveSettings(CPreferences::tableClientList);
searchwnd->SaveAllSettings();
sharedfileswnd->sharedfilesctrl.SaveSettings(CPreferences::tableShared);
serverwnd->SaveAllSettings();
kademliawnd->SaveAllSettings();
theApp.m_pPeerCache->Save();
theApp.scheduler->RestoreOriginals();
thePrefs.Save();
thePerfLog.Shutdown();
// explicitly delete all listview items which may hold ptrs to objects which will get deleted
// by the dtors (some lines below) to avoid potential problems during application shutdown.
transferwnd->downloadlistctrl.DeleteAllItems();
chatwnd->chatselector.DeleteAllItems();
theApp.clientlist->DeleteAll();
searchwnd->DeleteAllSearchListCtrlItems();
sharedfileswnd->sharedfilesctrl.DeleteAllItems();
transferwnd->queuelistctrl.DeleteAllItems();
transferwnd->clientlistctrl.DeleteAllItems();
transferwnd->uploadlistctrl.DeleteAllItems();
CPartFileConvert::CloseGUI();
CPartFileConvert::RemoveAllJobs();
theApp.uploadBandwidthThrottler->EndThread();
// ZZ:UploadSpeedSense -->
theApp.lastCommonRouteFinder->EndThread();
// ZZ:UploadSpeedSense <--
theApp.sharedfiles->DeletePartFileInstances();
searchwnd->SendMessage(WM_CLOSE);
// NOTE: Do not move those dtors into 'CemuleApp::InitInstance' (althought they should be there). The
// dtors are indirectly calling functions which access several windows which would not be available
// after we have closed the main window -> crash!
delete theApp.mmserver; theApp.mmserver = NULL;
delete theApp.listensocket; theApp.listensocket = NULL;
delete theApp.clientudp; theApp.clientudp = NULL;
delete theApp.sharedfiles; theApp.sharedfiles = NULL;
delete theApp.serverconnect; theApp.serverconnect = NULL;
delete theApp.serverlist; theApp.serverlist = NULL;
delete theApp.knownfiles; theApp.knownfiles = NULL;
delete theApp.searchlist; theApp.searchlist = NULL;
delete theApp.clientcredits; theApp.clientcredits = NULL;
delete theApp.downloadqueue; theApp.downloadqueue = NULL;
delete theApp.uploadqueue; theApp.uploadqueue = NULL;
delete theApp.clientlist; theApp.clientlist = NULL;
delete theApp.friendlist; theApp.friendlist = NULL;
delete theApp.scheduler; theApp.scheduler = NULL;
delete theApp.ipfilter; theApp.ipfilter = NULL;
delete theApp.webserver; theApp.webserver = NULL;
delete theApp.m_pPeerCache; theApp.m_pPeerCache = NULL;
delete theApp.m_pFirewallOpener;theApp.m_pFirewallOpener = NULL;
//EastShare Start - added by AndCycle, IP to Country
delete theApp.ip2country; theApp.ip2country = NULL;
//EastShare End - added by AndCycle, IP to Country
// ZZ:UploadSpeedSense -->
delete theApp.uploadBandwidthThrottler; theApp.uploadBandwidthThrottler = NULL;
delete theApp.lastCommonRouteFinder; theApp.lastCommonRouteFinder = NULL;
// ZZ:UploadSpeedSense <--
thePrefs.Uninit();
theApp.m_app_state = APP_STATE_DONE;
CTrayDialog::OnCancel();
}
void CemuleDlg::OnTrayRButtonUp(CPoint pt)
{
if(m_pSystrayDlg)
{
m_pSystrayDlg->BringWindowToTop();
return;
}
m_pSystrayDlg = new CMuleSystrayDlg(this,pt,
thePrefs.GetMaxGraphUploadRate(),
thePrefs.GetMaxGraphDownloadRate(),
thePrefs.GetMaxUpload(),
thePrefs.GetMaxDownload());
if(m_pSystrayDlg)
{
UINT nResult = m_pSystrayDlg->DoModal();
delete m_pSystrayDlg;
m_pSystrayDlg = NULL;
switch(nResult)
{
case IDC_TOMAX:
QuickSpeedOther(MP_QS_UA);
break;
case IDC_TOMIN:
QuickSpeedOther(MP_QS_PA);
break;
case IDC_RESTORE:
RestoreWindow();
break;
case IDC_CONNECT:
StartConnection();
break;
case IDC_DISCONNECT:
CloseConnection();
break;
case IDC_EXIT:
OnClose();
break;
case IDC_PREFERENCES:
{
static int iOpen = 0;
if(!iOpen)
{
iOpen = 1;
preferenceswnd->DoModal();
iOpen = 0;
}
break;
}
default:
break;
}
}
}
void CemuleDlg::AddSpeedSelectorSys(CMenu* addToMenu)
{
CString text;
// creating UploadPopup Menu
ASSERT( m_menuUploadCtrl.m_hMenu == NULL );
if (m_menuUploadCtrl.CreateMenu())
{
//m_menuUploadCtrl.AddMenuTitle(GetResString(IDS_PW_TIT_UP));
text.Format(_T("20%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.2),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U20, text);
text.Format(_T("40%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.4),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U40, text);
text.Format(_T("60%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.6),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U60, text);
text.Format(_T("80%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()*0.8),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U80, text);
text.Format(_T("100%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphUploadRate()),GetResString(IDS_KBYTESEC)); m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_U100, text);
m_menuUploadCtrl.AppendMenu(MF_SEPARATOR);
if (GetRecMaxUpload()>0) {
text.Format(GetResString(IDS_PW_MINREC)+GetResString(IDS_KBYTESEC),GetRecMaxUpload());
m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_UP10, text );
}
//m_menuUploadCtrl.AppendMenu(MF_STRING, MP_QS_UPC, GetResString(IDS_PW_UNLIMITED));
text.Format(_T("%s:"), GetResString(IDS_PW_UPL));
addToMenu->AppendMenu(MF_STRING|MF_POPUP, (UINT_PTR)m_menuUploadCtrl.m_hMenu, text);
}
// creating DownloadPopup Menu
ASSERT( m_menuDownloadCtrl.m_hMenu == NULL );
if (m_menuDownloadCtrl.CreateMenu())
{
//m_menuDownloadCtrl.AddMenuTitle(GetResString(IDS_PW_TIT_DOWN));
text.Format(_T("20%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.2),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D20, text);
text.Format(_T("40%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.4),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D40, text);
text.Format(_T("60%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.6),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D60, text);
text.Format(_T("80%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()*0.8),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D80, text);
text.Format(_T("100%%\t%i %s"), (uint16)(thePrefs.GetMaxGraphDownloadRate()),GetResString(IDS_KBYTESEC)); m_menuDownloadCtrl.AppendMenu(MF_STRING|MF_POPUP, MP_QS_D100, text);
//m_menuDownloadCtrl.AppendMenu(MF_SEPARATOR);
//m_menuDownloadCtrl.AppendMenu(MF_STRING, MP_QS_DC, GetResString(IDS_PW_UNLIMITED));
// Show DownloadPopup Menu
text.Format(_T("%s:"), GetResString(IDS_PW_DOWNL));
addToMenu->AppendMenu(MF_STRING|MF_POPUP, (UINT_PTR)m_menuDownloadCtrl.m_hMenu, text);
}
addToMenu->AppendMenu(MF_SEPARATOR);
addToMenu->AppendMenu(MF_STRING, MP_CONNECT, GetResString(IDS_MAIN_BTN_CONNECT));
addToMenu->AppendMenu(MF_STRING, MP_DISCONNECT, GetResString(IDS_MAIN_BTN_DISCONNECT));
}
void CemuleDlg::StartConnection(){
if (!Kademlia::CKademlia::isRunning() && !theApp.serverconnect->IsConnecting()){
AddLogLine(true, GetResString(IDS_CONNECTING));
if( thePrefs.GetNetworkED2K() ){
if ( serverwnd->serverlistctrl.GetSelectedCount()>1 )
{
serverwnd->serverlistctrl.PostMessage(WM_COMMAND,MP_CONNECTTO,0L);
}
else
{
theApp.serverconnect->ConnectToAnyServer();
}
}
if( thePrefs.GetNetworkKademlia() )
{
Kademlia::CKademlia::start();
}
ShowConnectionState();
}
}
void CemuleDlg::CloseConnection()
{
if (theApp.serverconnect->IsConnected()){
theApp.serverconnect->Disconnect();
}
if (theApp.serverconnect->IsConnecting()){
theApp.serverconnect->StopConnectionTry();
}
Kademlia::CKademlia::stop();
theApp.OnlineSig(); // Added By Bouc7
ShowConnectionState();
}
void CemuleDlg::RestoreWindow()
{
if (TrayIsVisible())
TrayHide();
ShowWindow(SW_SHOW);
}
void CemuleDlg::UpdateTrayIcon(int procent)
{
// compute an id of the icon to be generated
uint8 m_newiconinfo=(procent>0)?(16-((procent*15/100)+1)):0;
if (theApp.IsConnected()){
if (!theApp.IsFirewalled())
m_newiconinfo += 50;
} else
m_newiconinfo += 100;
// dont update if the same icon as displayed would be generated
if ( m_lasticoninfo==m_newiconinfo )
return;
m_lasticoninfo=m_newiconinfo;
// prepare it up
if (theApp.IsConnected()){
if (theApp.IsFirewalled()) {
trayIcon.Init(sourceTrayIconLow,100,1,1,16,16,thePrefs.GetStatsColor(11));
}
else {
trayIcon.Init(sourceTrayIcon,100,1,1,16,16,thePrefs.GetStatsColor(11));
}
}
else
trayIcon.Init(sourceTrayIconGrey,100,1,1,16,16,thePrefs.GetStatsColor(11));
// load our limit and color info
int pLimits16[1] = {100}; // set the limits of where the bar color changes (low-high)
COLORREF pColors16[1] = {thePrefs.GetStatsColor(11)}; // set the corresponding color for each level
trayIcon.SetColorLevels(pLimits16,pColors16,1);
// generate the icon (destroy these icon using DestroyIcon())
int pVals16[1] = {procent};
mytrayIcon = trayIcon.Create(pVals16);
ASSERT (mytrayIcon != NULL);
if (mytrayIcon)
TraySetIcon(mytrayIcon,true);
TrayUpdate();
}
int CemuleDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
return CTrayDialog::OnCreate(lpCreateStruct);
}
void CemuleDlg::OnShowWindow( BOOL bShow, UINT nStatus) {
if (IsRunning())
ShowTransferRate(true);
}
void CemuleDlg::ShowNotifier(CString Text, int MsgType, LPCTSTR pszLink, bool bForceSoundOFF)
{
if (!notifierenabled)
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -