📄 emuledlg.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 <math.h>
#include <afxinet.h>
#define MMNODRV // mmsystem: Installable driver support
//#define MMNOSOUND // mmsystem: Sound support
#define MMNOWAVE // mmsystem: Waveform support
#define MMNOMIDI // mmsystem: MIDI support
#define MMNOAUX // mmsystem: Auxiliary audio support
#define MMNOMIXER // mmsystem: Mixer support
#define MMNOTIMER // mmsystem: Timer support
#define MMNOJOY // mmsystem: Joystick support
#define MMNOMCI // mmsystem: MCI support
#define MMNOMMIO // mmsystem: Multimedia file I/O support
#define MMNOMMSYSTEM // mmsystem: General MMSYSTEM functions
#include <Mmsystem.h>
#include <HtmlHelp.h>
#include <share.h>
#include "emule.h"
#include "emuleDlg.h"
#include "ServerWnd.h"
#include "KademliaWnd.h"
#include "TransferWnd.h"
#include "SearchResultsWnd.h"
#include "SearchDlg.h"
#include "SharedFilesWnd.h"
#include "ChatWnd.h"
#include "IrcWnd.h"
#include "StatisticsDlg.h"
#include "CreditsDlg.h"
#include "PreferencesDlg.h"
#include "Sockets.h"
#include "KnownFileList.h"
#include "ServerList.h"
#include "Opcodes.h"
#include "SharedFileList.h"
#include "ED2KLink.h"
#include "Splashscreen.h"
#include "PartFileConvert.h"
#include "EnBitmap.h"
#include "Wizard.h"
#include "Exceptions.h"
#include "SearchList.h"
#include "HTRichEditCtrl.h"
#include "FrameGrabThread.h"
#include "kademlia/kademlia/kademlia.h"
#include "kademlia/kademlia/SearchManager.h"
#include "kademlia/routing/RoutingZone.h"
#include "kademlia/routing/contact.h"
#include "kademlia/kademlia/prefs.h"
#include "KadSearchListCtrl.h"
#include "KadContactListCtrl.h"
#include "PerfLog.h"
#include "version.h"
#include "DropTarget.h"
#include "LastCommonRouteFinder.h"
#include "WebServer.h"
#include "MMServer.h"
#include "DownloadQueue.h"
#include "ClientUDPSocket.h"
#include "UploadQueue.h"
#include "ClientList.h"
#include "UploadBandwidthThrottler.h"
#include "FriendList.h"
#include "IPFilter.h"
#include "Statistics.h"
#include "MuleToolbarCtrl.h"
#include "TaskbarNotifier.h"
#include "MuleStatusbarCtrl.h"
#include "ListenSocket.h"
#include "Server.h"
#include "PartFile.h"
#include "Scheduler.h"
#include "ClientCredits.h"
#include "MenuCmds.h"
#include "MuleSystrayDlg.h"
#include "IPFilterDlg.h"
#include "WebServices.h"
#include "DirectDownloadDlg.h"
#include "PeerCacheFinder.h"
#include "Statistics.h"
#include "FirewallOpener.h"
#include "StringConversion.h"
#include "aichsyncthread.h"
#include "Log.h"
#include "MiniMule.h"
#include "UserMsgs.h"
#ifndef RBBS_USECHEVRON
#define RBBS_USECHEVRON 0x00000200 // display drop-down button for this band if it's sized smaller than ideal width
#endif
#ifndef RBN_CHEVRONPUSHED
#define RBN_CHEVRONPUSHED (RBN_FIRST - 10)
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "IP2Country.h" //EastShare - added by AndCycle, IP to Country
#define SYS_TRAY_ICON_COOKIE_FORCE_UPDATE (UINT)-1
BOOL (WINAPI *_TransparentBlt)(HDC, int, int, int, int, HDC, int, int, int, int, UINT)= NULL;
const static UINT UWM_ARE_YOU_EMULE = RegisterWindowMessage(EMULE_GUID);
UINT _uMainThreadId = 0;
///////////////////////////////////////////////////////////////////////////
// CemuleDlg Dialog
IMPLEMENT_DYNAMIC(CMsgBoxException, CException)
BEGIN_MESSAGE_MAP(CemuleDlg, CTrayDialog)
///////////////////////////////////////////////////////////////////////////
// Windows messages
//
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_ENDSESSION()
ON_WM_SIZE()
ON_WM_CLOSE()
ON_WM_MENUCHAR()
ON_WM_QUERYENDSESSION()
ON_WM_SYSCOLORCHANGE()
ON_MESSAGE(WM_COPYDATA, OnWMData)
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
ON_WM_SHOWWINDOW()
///////////////////////////////////////////////////////////////////////////
// WM_COMMAND messages
//
ON_COMMAND(MP_CONNECT, StartConnection)
ON_COMMAND(MP_DISCONNECT, CloseConnection)
ON_COMMAND(MP_EXIT, OnClose)
ON_COMMAND(MP_RESTORE, RestoreWindow)
// quick-speed changer --
ON_COMMAND_RANGE(MP_QS_U10, MP_QS_UP10, QuickSpeedUpload)
ON_COMMAND_RANGE(MP_QS_D10, MP_QS_DC, QuickSpeedDownload)
//--- quickspeed - paralize all ---
ON_COMMAND_RANGE(MP_QS_PA, MP_QS_UA, QuickSpeedOther)
// quick-speed changer -- based on xrmb
ON_NOTIFY_EX_RANGE(RBN_CHEVRONPUSHED, 0, 0xFFFF, OnChevronPushed)
ON_REGISTERED_MESSAGE(UWM_ARE_YOU_EMULE, OnAreYouEmule)
ON_BN_CLICKED(IDC_HOTMENU, OnBnClickedHotmenu)
///////////////////////////////////////////////////////////////////////////
// WM_USER messages
//
ON_MESSAGE(UM_TASKBARNOTIFIERCLICKED, OnTaskbarNotifierClicked)
ON_MESSAGE(UM_CLOSE_MINIMULE, OnCloseMiniMule)
ON_MESSAGE(UM_WEB_CONNECT_TO_SERVER, OnWebServerConnect)
ON_MESSAGE(UM_WEB_DISCONNECT_SERVER, OnWebServerDisonnect)
ON_MESSAGE(UM_WEB_REMOVE_SERVER, OnWebServerRemove)
ON_MESSAGE(UM_WEB_SHARED_FILES_RELOAD, OnWebSharedFilesReload)
// Version Check DNS
ON_MESSAGE(UM_VERSIONCHECK_RESPONSE, OnVersionCheckResponse)
// PeerCache DNS
ON_MESSAGE(UM_PEERCHACHE_RESPONSE, OnPeerCacheResponse)
///////////////////////////////////////////////////////////////////////////
// WM_APP messages
//
ON_MESSAGE(TM_FINISHEDHASHING, OnFileHashed)
ON_MESSAGE(TM_FILEOPPROGRESS, OnFileOpProgress)
ON_MESSAGE(TM_HASHFAILED, OnHashFailed)
ON_MESSAGE(TM_FRAMEGRABFINISHED, OnFrameGrabFinished)
ON_MESSAGE(TM_FILEALLOCEXC, OnFileAllocExc)
ON_MESSAGE(TM_FILECOMPLETED, OnFileCompleted)
END_MESSAGE_MAP()
CemuleDlg::CemuleDlg(CWnd* pParent /*=NULL*/)
: CTrayDialog(CemuleDlg::IDD, pParent)
{
_uMainThreadId = GetCurrentThreadId();
preferenceswnd = new CPreferencesDlg;
serverwnd = new CServerWnd;
kademliawnd = new CKademliaWnd;
transferwnd = new CTransferWnd;
sharedfileswnd = new CSharedFilesWnd;
searchwnd = new CSearchDlg;
chatwnd = new CChatWnd;
ircwnd = new CIrcWnd;
statisticswnd = new CStatisticsDlg;
toolbar = new CMuleToolbarCtrl;
statusbar = new CMuleStatusBarCtrl;
m_wndTaskbarNotifier = new CTaskbarNotifier;
// NOTE: the application icon name is prefixed with "AAA" to make sure it's alphabetically sorted by the
// resource compiler as the 1st icon in the resource table!
m_hIcon = AfxGetApp()->LoadIcon(_T("AAAEMULEAPP"));
theApp.m_app_state = APP_STATE_RUNNING;
ready = false;
m_bStartMinimizedChecked = false;
m_bStartMinimized = false;
memset(&m_wpFirstRestore, 0, sizeof m_wpFirstRestore);
m_uUpDatarate = 0;
m_uDownDatarate = 0;
status = 0;
activewnd = NULL;
for (int i = 0; i < ARRSIZE(connicons); i++)
connicons[i] = NULL;
transicons[0] = NULL;
transicons[1] = NULL;
transicons[2] = NULL;
transicons[3] = NULL;
imicons[0] = NULL;
imicons[1] = NULL;
imicons[2] = NULL;
m_iMsgIcon = 0;
m_icoSysTrayConnected = NULL;
m_icoSysTrayDisconnected = NULL;
m_icoSysTrayLowID = NULL;
usericon = NULL;
m_icoSysTrayCurrent = NULL;
m_hTimer = 0;
notifierenabled = false;
m_pDropTarget = new CMainFrameDropTarget;
m_pSplashWnd = NULL;
m_dwSplashTime = (DWORD)-1;
m_pSystrayDlg = NULL;
m_pMiniMule = NULL;
m_uLastSysTrayIconCookie = SYS_TRAY_ICON_COOKIE_FORCE_UPDATE;
}
CemuleDlg::~CemuleDlg()
{
DestroyMiniMule();
if (m_icoSysTrayCurrent) VERIFY( DestroyIcon(m_icoSysTrayCurrent) );
if (m_hIcon) VERIFY( ::DestroyIcon(m_hIcon) );
for (int i = 0; i < ARRSIZE(connicons); i++){
if (connicons[i]) VERIFY( ::DestroyIcon(connicons[i]) );
}
if (transicons[0]) VERIFY( ::DestroyIcon(transicons[0]) );
if (transicons[1]) VERIFY( ::DestroyIcon(transicons[1]) );
if (transicons[2]) VERIFY( ::DestroyIcon(transicons[2]) );
if (transicons[3]) VERIFY( ::DestroyIcon(transicons[3]) );
if (imicons[0]) VERIFY( ::DestroyIcon(imicons[0]) );
if (imicons[1]) VERIFY( ::DestroyIcon(imicons[1]) );
if (imicons[2]) VERIFY( ::DestroyIcon(imicons[2]) );
if (m_icoSysTrayConnected) VERIFY( ::DestroyIcon(m_icoSysTrayConnected) );
if (m_icoSysTrayDisconnected) VERIFY( ::DestroyIcon(m_icoSysTrayDisconnected) );
if (m_icoSysTrayLowID) VERIFY( ::DestroyIcon(m_icoSysTrayLowID) );
if (usericon) VERIFY( ::DestroyIcon(usericon) );
// already destroyed by windows?
//VERIFY( m_menuUploadCtrl.DestroyMenu() );
//VERIFY( m_menuDownloadCtrl.DestroyMenu() );
//VERIFY( m_SysMenuOptions.DestroyMenu() );
delete preferenceswnd;
delete serverwnd;
delete kademliawnd;
delete transferwnd;
delete sharedfileswnd;
delete chatwnd;
delete ircwnd;
delete statisticswnd;
delete toolbar;
delete statusbar;
delete m_wndTaskbarNotifier;
delete m_pDropTarget;
}
void CemuleDlg::DoDataExchange(CDataExchange* pDX)
{
CTrayDialog::DoDataExchange(pDX);
}
LRESULT CemuleDlg::OnAreYouEmule(WPARAM, LPARAM)
{
return UWM_ARE_YOU_EMULE;
}
BOOL CemuleDlg::OnInitDialog()
{
m_bStartMinimized = thePrefs.GetStartMinimized();
if (!m_bStartMinimized)
m_bStartMinimized = theApp.DidWeAutoStart();
// temporary disable the 'startup minimized' option, otherwise no window will be shown at all
if (thePrefs.IsFirstStart())
m_bStartMinimized = false;
// show splashscreen as early as possible to "entertain" user while starting emule up
if (thePrefs.UseSplashScreen() && !m_bStartMinimized)
ShowSplash();
// Create global GUI objects
theApp.CreateAllFonts();
theApp.CreateBackwardDiagonalBrush();
CTitleMenu::Init();
CTrayDialog::OnInitDialog();
InitWindowStyles(this);
//CreateMenuCmdIconMap();
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL){
pSysMenu->AppendMenu(MF_SEPARATOR);
ASSERT( (MP_ABOUTBOX & 0xFFF0) == MP_ABOUTBOX && MP_ABOUTBOX < 0xF000);
pSysMenu->AppendMenu(MF_STRING, MP_ABOUTBOX, GetResString(IDS_ABOUTBOX));
ASSERT( (MP_VERSIONCHECK & 0xFFF0) == MP_VERSIONCHECK && MP_VERSIONCHECK < 0xF000);
pSysMenu->AppendMenu(MF_STRING, MP_VERSIONCHECK, GetResString(IDS_VERSIONCHECK));
// remaining system menu entries are created later...
}
SetIcon(m_hIcon, TRUE);
// this scales the 32x32 icon down to 16x16, does not look nice at least under WinXP
//SetIcon(m_hIcon, FALSE);
CWnd* pwndToolbarX = toolbar;
if (toolbar->Create(WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, IDC_TOOLBAR))
{
toolbar->Init();
if (thePrefs.GetUseReBarToolbar())
{
if (m_ctlMainTopReBar.Create(WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
RBS_BANDBORDERS | RBS_AUTOSIZE | CCS_NODIVIDER,
CRect(0, 0, 0, 0), this, AFX_IDW_REBAR))
{
CSize sizeBar;
VERIFY( toolbar->GetMaxSize(&sizeBar) );
REBARBANDINFO rbbi = {0};
rbbi.cbSize = sizeof(rbbi);
rbbi.fMask = RBBIM_STYLE | RBBIM_SIZE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_ID;
rbbi.fStyle = RBBS_NOGRIPPER | RBBS_BREAK | RBBS_USECHEVRON;
rbbi.hwndChild = toolbar->m_hWnd;
rbbi.cxMinChild = sizeBar.cy;
rbbi.cyMinChild = sizeBar.cy;
rbbi.cxIdeal = sizeBar.cx;
rbbi.cx = rbbi.cxIdeal;
rbbi.wID = 0;
VERIFY( m_ctlMainTopReBar.InsertBand((UINT)-1, &rbbi) );
toolbar->SaveCurHeight();
toolbar->UpdateBackground();
pwndToolbarX = &m_ctlMainTopReBar;
}
}
}
//set title
CString buffer = _T("eMule v");
buffer += theApp.m_strCurVersionLong;
SetWindowText(buffer);
//START - enkeyDEV(kei-kun) -TaskbarNotifier-
m_wndTaskbarNotifier->Create(this);
if (_tcscmp(thePrefs.GetNotifierConfiguration(),_T("")) == 0) {
CString defaultTBN;
defaultTBN.Format(_T("%sNotifier.ini"), thePrefs.GetAppDir());
LoadNotifier(defaultTBN);
thePrefs.SetNotifierConfiguration(defaultTBN);
}
else
LoadNotifier(thePrefs.GetNotifierConfiguration());
//END - enkeyDEV(kei-kun) -TaskbarNotifier-
// set statusbar
statusbar->Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM,CRect(0,0,0,0), this, IDC_STATUSBAR);
statusbar->EnableToolTips(true);
SetStatusBarPartsSize();
// create main window dialog pages
serverwnd->Create(IDD_SERVER);
sharedfileswnd->Create(IDD_FILES);
searchwnd->Create(this);
chatwnd->Create(IDD_CHAT);
transferwnd->Create(IDD_TRANSFER);
statisticswnd->Create(IDD_STATISTICS);
kademliawnd->Create(IDD_KADEMLIAWND);
ircwnd->Create(IDD_IRC);
// with the top rebar control, some XP themes look better with some additional lite borders.. some not..
//serverwnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//sharedfileswnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//searchwnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//chatwnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//transferwnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//statisticswnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//kademliawnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
//ircwnd->ModifyStyleEx(0, WS_EX_STATICEDGE);
// optional: restore last used main window dialog
if (thePrefs.GetRestoreLastMainWndDlg()){
switch (thePrefs.GetLastMainWndDlgID()){
case IDD_SERVER:
SetActiveDialog(serverwnd);
break;
case IDD_FILES:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -