📄 emuledlg.cpp
字号:
rcClient.top += rcToolbar.Height();
rcClient.bottom -= rcStatusbar.Height();
CWnd* apWnds[] =
{
serverwnd,
kademliawnd,
//VeryCD
//ChanblardWnd,
transferwnd,
sharedfileswnd,
searchwnd,
chatwnd,
ircwnd,
statisticswnd
};
for (int i = 0; i < ARRSIZE(apWnds); i++)
apWnds[i]->SetWindowPos(NULL, rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), SWP_NOZORDER);
// anchors
AddAnchor(*serverwnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*kademliawnd, TOP_LEFT, BOTTOM_RIGHT);
if (thePrefs.GetBrowser())
AddAnchor(*ChanblardWnd, TOP_LEFT, BOTTOM_RIGHT); //VeryCD
AddAnchor(*transferwnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*sharedfileswnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*searchwnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*chatwnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*ircwnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*statisticswnd, TOP_LEFT, BOTTOM_RIGHT);
AddAnchor(*toolbar, TOP_LEFT, TOP_RIGHT);
AddAnchor(*statusbar, BOTTOM_LEFT, BOTTOM_RIGHT);
statisticswnd->ShowInterval();
// tray icon
TraySetMinimizeToTray(thePrefs.GetMinTrayPTR());
TrayMinimizeToTrayChange();
ShowTransferRate(true);
// ZZ:UploadSpeedSense -->
ShowPing();
// ZZ:UploadSpeedSense <--
searchwnd->UpdateCatTabs();
// Restore saved window placement
WINDOWPLACEMENT wp = {0};
wp.length = sizeof(wp);
wp = thePrefs.GetEmuleWindowPlacement();
SetWindowPlacement(&wp);
if (thePrefs.GetWSIsEnabled())
theApp.webserver->StartServer();
theApp.mmserver->Init();
VERIFY( (m_hTimer = ::SetTimer(NULL, NULL, 300, StartupTimer)) != NULL );
if (thePrefs.GetVerbose() && !m_hTimer)
AddDebugLogLine(true,_T("Failed to create 'startup' timer - %s"),GetErrorMessage(GetLastError()));
theStats.starttime = GetTickCount();
if (thePrefs.IsFirstStart())
{
// temporary disable the 'startup minimized' option, otherwise no window will be shown at all
m_bStartMinimized = false;
DestroySplash();
extern BOOL FirstTimeWizard();
if (FirstTimeWizard()){
// start connection wizard
Wizard conWizard;
conWizard.DoModal();
}
}
VERIFY( m_pDropTarget->Register(this) );
// initalize PeerCache
theApp.m_pPeerCache->Init(thePrefs.GetPeerCacheLastSearch(), thePrefs.WasPeerCacheFound(), thePrefs.IsPeerCacheDownloadEnabled(), thePrefs.GetPeerCachePort());
// start aichsyncthread
AfxBeginThread(RUNTIME_CLASS(CAICHSyncThread), THREAD_PRIORITY_BELOW_NORMAL,0);
return TRUE;
}
// modders: dont remove or change the original versioncheck! (additionals are ok)
void CemuleDlg::DoVersioncheck(bool manual) {
if (!manual && thePrefs.GetLastVC()!=0) {
CTime last(thePrefs.GetLastVC());
time_t tLast=safe_mktime(last.GetLocalTm());
time_t tNow=safe_mktime(CTime::GetCurrentTime().GetLocalTm());
if ( (difftime(tNow,tLast) / 86400)<thePrefs.GetUpdateDays() )
return;
}
if (WSAAsyncGetHostByName(m_hWnd, WM_VERSIONCHECK_RESPONSE, "vcdns2.verycd.com", m_acVCDNSBuffer, sizeof(m_acVCDNSBuffer)) == 0){ //VeryCD
AddLogLine(true,GetResString(IDS_NEWVERSIONFAILED));
}
}
void CALLBACK CemuleDlg::StartupTimer(HWND hwnd, UINT uiMsg, UINT idEvent, DWORD dwTime)
{
// NOTE: Always handle all type of MFC exceptions in TimerProcs - otherwise we'll get mem leaks
try
{
switch(theApp.emuledlg->status){
case 0:
theApp.emuledlg->status++;
theApp.emuledlg->ready = true;
theApp.sharedfiles->SetOutputCtrl(&theApp.emuledlg->sharedfileswnd->sharedfilesctrl);
theApp.emuledlg->status++;
break;
case 1:
break;
case 2:
theApp.emuledlg->status++;
try{
theApp.serverlist->Init();
}
catch(...){
ASSERT(0);
AddLogLine(true,_T("Failed to initialize server list - Unknown exception"));
}
theApp.emuledlg->status++;
break;
case 3:
break;
case 4:{
bool bError = false;
theApp.emuledlg->status++;
// NOTE: If we have an unhandled exception in CDownloadQueue::Init, MFC will silently catch it
// and the creation of the TCP and the UDP socket will not be done -> client will get a LowID!
try{
theApp.downloadqueue->Init();
}
catch(...){
ASSERT(0);
AddLogLine(true,_T("Failed to initialize download queue - Unknown exception"));
bError = true;
}
if(!theApp.listensocket->StartListening()){
AddLogLine(true, GetResString(IDS_MAIN_SOCKETERROR),thePrefs.GetPort());
bError = true;
}
if(!theApp.clientudp->Create()){
AddLogLine(true, GetResString(IDS_MAIN_SOCKETERROR),thePrefs.GetUDPPort());
bError = true;
}
if ((thePrefs.GetTotalDownloaded()>50000 && thePrefs.GetTotalUploaded()>0) && ((thePrefs.GetTotalDownloaded()/thePrefs.GetTotalUploaded())>1)){
AddLogLine(true, GetResString(IDS_YOUR_UDR),(float)(thePrefs.GetTotalDownloaded())/(thePrefs.GetTotalUploaded())); //VeryCD版
AddLogLine(true, GetResString(IDS_MOREUPLOAD)); //VeryCD版
theApp.emuledlg->ShowNotifier(GetResString(IDS_MOREUPLOAD), TBN_SERVERMSG);
}
if (!bError) // show the success msg, only if we had no serious error
AddLogLine(true, GetResString(IDS_MAIN_READY),theApp.m_strCurVersionLong);
if(thePrefs.DoAutoConnect())
theApp.emuledlg->OnBnClickedButton2();
theApp.emuledlg->status++;
break;
}
case 5:
break;
default:
theApp.emuledlg->StopTimer();
}
}
CATCH_DFLT_EXCEPTIONS(_T("CemuleDlg::StartupTimer"))
}
void CemuleDlg::StopTimer(){
try {
if (m_hTimer){
::KillTimer(NULL, m_hTimer);
m_hTimer = 0;
}
}
catch (...){
ASSERT(0);
}
if (thePrefs.UpdateNotify()) DoVersioncheck(false);
if (theApp.pendinglink){
OnWMData(NULL,(LPARAM) &theApp.sendstruct);//changed by Cax2 28/10/02
delete theApp.pendinglink;
}
}
void CemuleDlg::OnSysCommand(UINT nID, LPARAM lParam){
// Systemmenu-Speedselector
if (nID>=MP_QS_U10 && nID<=10512) {
QuickSpeedUpload(nID);
return;
}
if (nID>=MP_QS_D10 && nID<=10531) {
QuickSpeedDownload(nID);
return;
}
if (nID==MP_QS_PA || nID==MP_QS_UA) {
QuickSpeedOther(nID);
return;
}
switch (nID /*& 0xFFF0*/){
case MP_ABOUTBOX : {
CCreditsDlg dlgAbout;
dlgAbout.DoModal();
break;
}
case MP_VERSIONCHECK:
DoVersioncheck(true);
break;
case MP_CONNECT : {
StartConnection();
break;
}
case MP_DISCONNECT : {
CloseConnection();
break;
}
default:{
CTrayDialog::OnSysCommand(nID, lParam);
}
}
if (
(nID & 0xFFF0) == SC_MINIMIZE ||
(nID & 0xFFF0) == SC_MINIMIZETRAY ||
(nID & 0xFFF0) == SC_RESTORE ||
(nID & 0xFFF0) == SC_MAXIMIZE ) {
ShowTransferRate(true);
// ZZ:UploadSpeedSense -->
ShowPing();
// ZZ:UploadSpeedSense <--
transferwnd->UpdateCatTabTitles();
}
}
void CemuleDlg::OnPaint()
{
if (!startUpMinimizedChecked){
//TODO: Use full initialized 'WINDOWPLACEMENT' and remove the 'OnCancel' call...
startUpMinimizedChecked = true;
//I'm not a Gui person.. If you know a better way to do this, go for it.. :)
if(m_bStartMinimized)
{
if(theApp.DidWeAutoStart())
{
if (thePrefs.mintotray == false)
{
thePrefs.mintotray = true;
OnCancel();
thePrefs.mintotray = false;
}
else
OnCancel();
}
else
{
OnCancel();
}
}
}
if (IsIconic()){
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
dc.DrawIcon(x, y, m_hIcon);
}
else{
CTrayDialog::OnPaint();
}
}
HCURSOR CemuleDlg::OnQueryDragIcon(){
return static_cast<HCURSOR>(m_hIcon);
}
void CemuleDlg::OnBnClickedButton2(){
if (!theApp.IsConnected())
//connect if not currently connected
if (!theApp.serverconnect->IsConnecting() && !Kademlia::CKademlia::isRunning() ){
StartConnection();
}
else {
CloseConnection();
}
else{
//disconnect if currently connected
CloseConnection();
}
}
void CemuleDlg::ResetLog(){
serverwnd->logbox.Reset();
}
void CemuleDlg::ResetDebugLog(){
serverwnd->debuglog.Reset();
}
void CemuleDlg::AddLogText(bool addtostatusbar, const CString& txt, bool bDebug)
{
if (addtostatusbar)
{
if (statusbar->m_hWnd /*&& ready*/)
{
if (theApp.m_app_state != APP_STATE_SHUTINGDOWN)
{
statusbar->SetText(txt,0,0);
statusbar->SetTipText(0,txt);
}
}
else
AfxMessageBox(txt);
}
#if defined(_DEBUG) || defined(USE_DEBUG_DEVICE)
Debug(_T("%s\n"), txt);
#endif
#ifdef _DEBUG
// we have some emtpy log messages somewhere.. remove that check, after it fired..
ASSERT( !txt.IsEmpty() );
#endif
if (bDebug && !thePrefs.GetVerbose())
return;
TCHAR temp[1060];
int iLen = _sntprintf(temp, ARRSIZE(temp), _T("%s: %s\r\n"), CTime::GetCurrentTime().Format(thePrefs.GetDateTimeFormat4Log()), txt);
if (iLen >= 0)
{
if (!bDebug)
{
serverwnd->logbox.Add(temp, iLen);
if (IsWindow(serverwnd->StatusSelector) && serverwnd->StatusSelector.GetCurSel() != CServerWnd::PaneLog)
serverwnd->StatusSelector.HighlightItem(CServerWnd::PaneLog, TRUE);
if (ready)
ShowNotifier(txt, TBN_LOG);
if (thePrefs.GetLog2Disk())
theLog.Log(temp, iLen);
}
if (thePrefs.GetVerbose() && (bDebug || thePrefs.GetFullVerbose()))
{
serverwnd->debuglog.Add(temp, iLen);
if (IsWindow(serverwnd->StatusSelector) && serverwnd->StatusSelector.GetCurSel() != CServerWnd::PaneVerboseLog)
serverwnd->StatusSelector.HighlightItem(CServerWnd::PaneVerboseLog, TRUE);
if (thePrefs.GetDebug2Disk())
theVerboseLog.Log(temp, iLen);
}
}
}
CString CemuleDlg::GetLastLogEntry()
{
return serverwnd->logbox.GetLastLogEntry();
}
CString CemuleDlg::GetAllLogEntries()
{
return serverwnd->logbox.GetAllLogEntries();
}
CString CemuleDlg::GetLastDebugLogEntry()
{
return serverwnd->debuglog.GetLastLogEntry();
}
CString CemuleDlg::GetAllDebugLogEntries()
{
return serverwnd->debuglog.GetAllLogEntries();
}
void CemuleDlg::AddServerMessageLine(LPCTSTR pszLine)
{
serverwnd->servermsgbox->AppendText(pszLine + CString(_T('\n')));
if (IsWindow(serverwnd->StatusSelector) && serverwnd->StatusSelector.GetCurSel() != CServerWnd::PaneServerInfo)
serverwnd->StatusSelector.HighlightItem(CServerWnd::PaneServerInfo, TRUE);
theApp.emuledlg->ShowNotifier(pszLine, TBN_SERVERMSG); //VeryCD版
}
void CemuleDlg::ShowConnectionStateIcon()
{
if (theApp.serverconnect->IsConnected() && !Kademlia::CKademlia::isConnected())
{
if (theApp.serverconnect->IsLowID())
statusbar->SetIcon(3, connicons[3]); // LowNot
else
statusbar->SetIcon(3, connicons[6]); // HighNot
}
else if (!theApp.serverconnect->IsConnected() && Kademlia::CKademlia::isConnected())
{
if (Kademlia::CKademlia::isFirewalled())
statusbar->SetIcon(3, connicons[1]); // NotLow
else
statusbar->SetIcon(3, connicons[2]); // NotHigh
}
else if (theApp.serverconnect->IsConnected() && Kademlia::CKademlia::isConnected())
{
if (theApp.serverconnect->IsLowID() && Kademlia::CKademlia::isFirewalled())
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -