📄 serverwnd.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 "ServerWnd.h"
#include "HttpDownloadDlg.h"
#include "HTRichEditCtrl.h"
#include "ED2KLink.h"
#include "kademlia/kademlia/kademlia.h"
#include "kademlia/kademlia/prefs.h"
#include "kademlia/utils/MiscUtils.h"
#include "OtherFunctions.h"
#include "emuledlg.h"
#include "WebServer.h"
#include "CustomAutoComplete.h"
#include "Server.h"
#include "ServerList.h"
#include "Sockets.h"
#include "MuleStatusBarCtrl.h"
#include "HelpIDs.h"
#include "NetworkInfoDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define SERVERMET_STRINGS_PROFILE _T("AC_ServerMetURLs.dat")
#define SZ_DEBUG_LOG_TITLE _T("Verbose")
// CServerWnd dialog
IMPLEMENT_DYNAMIC(CServerWnd, CDialog)
CServerWnd::CServerWnd(CWnd* pParent /*=NULL*/)
: CResizableDialog(CServerWnd::IDD, pParent)
{
servermsgbox = new CHTRichEditCtrl;
m_pacServerMetURL=NULL;
m_uLangID = MAKELANGID(LANG_ENGLISH,SUBLANG_DEFAULT);
icon_srvlist = NULL;
memset(&m_cfDef, 0, sizeof m_cfDef);
memset(&m_cfBold, 0, sizeof m_cfBold);
StatusSelector.m_bCloseable = false;
}
CServerWnd::~CServerWnd()
{
if (icon_srvlist)
VERIFY( DestroyIcon(icon_srvlist) );
if (m_pacServerMetURL){
m_pacServerMetURL->Unbind();
m_pacServerMetURL->Release();
}
delete servermsgbox;
}
BOOL CServerWnd::OnInitDialog()
{
#ifdef _UNICODE
ReplaceRichEditCtrl(GetDlgItem(IDC_MYINFOLIST), this, GetDlgItem(IDC_SSTATIC)->GetFont());
#endif
CResizableDialog::OnInitDialog();
logbox.Init(GetResString(IDS_SV_LOG), _T("Log"));
if (theApp.emuledlg->m_fontLog.m_hObject)
logbox.SetFont(&theApp.emuledlg->m_fontLog);
else{
CFont* pFont = logbox.GetFont();
if (pFont){
LOGFONT lf;
pFont->GetObject(sizeof lf, &lf);
theApp.emuledlg->m_fontLog.CreateFontIndirect(&lf);
}
}
logbox.ApplySkin();
debuglog.Init(SZ_DEBUG_LOG_TITLE, _T("VerboseLog"));
if (theApp.emuledlg->m_fontLog.m_hObject)
debuglog.SetFont(&theApp.emuledlg->m_fontLog);
debuglog.ApplySkin();
SetAllIcons();
Localize();
serverlistctrl.Init(theApp.serverlist);
((CEdit*)GetDlgItem(IDC_SPORT))->SetLimitText(5);
GetDlgItem(IDC_SPORT)->SetWindowText(_T("4661"));
CRect rect;
GetDlgItem(IDC_SERVMSG)->GetWindowRect(rect);
::MapWindowPoints(NULL, m_hWnd, (LPPOINT)&rect, 2);
if (servermsgbox->Create(WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_VSCROLL | ES_MULTILINE | ES_READONLY, rect, this, 123)){
servermsgbox->SetProfileSkinKey(_T("ServerInfoLog"));
servermsgbox->ModifyStyleEx(0, WS_EX_STATICEDGE, SWP_FRAMECHANGED);
servermsgbox->SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(3, 3));
servermsgbox->SetEventMask(servermsgbox->GetEventMask() | ENM_LINK);
servermsgbox->SetFont(&theApp.emuledlg->m_fontHyperText);
servermsgbox->ApplySkin();
servermsgbox->SetTitle(GetResString(IDS_SV_SERVERINFO));
servermsgbox->AppendText(CString(CString("eMule v")+theApp.m_strCurVersionLong+CString("\n")));
// MOD Note: Do not remove this part - Merkur
m_strClickNewVersion = GetResString(IDS_EMULEW) + _T(" ") + GetResString(IDS_EMULEW3) + _T(" ") + GetResString(IDS_EMULEW2);
//servermsgbox->AppendHyperLink(_T(""),_T(""),m_strClickNewVersion,_T(""),false);
// MOD Note: end
servermsgbox->AppendText(GetResString(IDS_DOWN_NEWEMULE));
servermsgbox->AppendText(CString("\n"));
servermsgbox->AppendText(GetResString(IDS_WELCOME_VERYCD));
servermsgbox->AppendText(CString("\n\n"));
}
TCITEM newitem;
CString name;
name = GetResString(IDS_SV_SERVERINFO);
newitem.mask = TCIF_TEXT|TCIF_IMAGE;
newitem.pszText = const_cast<LPTSTR>((LPCTSTR)name);
newitem.iImage = 1;
VERIFY( StatusSelector.InsertItem(StatusSelector.GetItemCount(), &newitem) == PaneServerInfo );
name = GetResString(IDS_SV_LOG);
newitem.mask = TCIF_TEXT|TCIF_IMAGE;
newitem.pszText = const_cast<LPTSTR>((LPCTSTR)name);
newitem.iImage = 0;
VERIFY( StatusSelector.InsertItem(StatusSelector.GetItemCount(), &newitem) == PaneLog );
name=SZ_DEBUG_LOG_TITLE;
newitem.mask = TCIF_TEXT|TCIF_IMAGE;
newitem.pszText = const_cast<LPTSTR>((LPCTSTR)name);
newitem.iImage = 0;
VERIFY( StatusSelector.InsertItem(StatusSelector.GetItemCount(), &newitem) == PaneVerboseLog );
AddAnchor(IDC_SERVLIST,TOP_LEFT, CSize(100,50));
AddAnchor(IDC_LOGBOX, CSize(0,50), BOTTOM_RIGHT);
AddAnchor(IDC_DEBUG_LOG, CSize(0,50), BOTTOM_RIGHT);
AddAnchor(IDC_SSTATIC,TOP_RIGHT);
AddAnchor(IDC_SSTATIC4,TOP_RIGHT);
AddAnchor(IDC_SSTATIC7,TOP_RIGHT);
AddAnchor(IDC_IPADDRESS,TOP_RIGHT);
AddAnchor(IDC_SSTATIC3,TOP_RIGHT);
AddAnchor(IDC_SNAME,TOP_RIGHT);
AddAnchor(IDC_ADDSERVER,TOP_RIGHT );
AddAnchor(IDC_SSTATIC5,TOP_RIGHT);
AddAnchor(IDC_MYINFO,TOP_RIGHT ,CSize(100, 100));
AddAnchor(IDC_MYINFOLIST,TOP_RIGHT,CSize(100,100));
AddAnchor(IDC_SPORT,TOP_RIGHT);
AddAnchor(IDC_SSTATIC6,TOP_RIGHT);
AddAnchor(IDC_SERVERMETURL,TOP_RIGHT);
AddAnchor(IDC_UPDATESERVERMETFROMURL,TOP_RIGHT);
AddAnchor(IDC_TAB3,CSize(0,50), BOTTOM_RIGHT);
AddAnchor(IDC_LOGRESET,CSize(100,50)); // avoid resizing GUI glitches with the tab control by adding this control as the last one (Z-order)
AddAnchor(IDC_ED2KCONNECT,TOP_RIGHT);
AddAnchor(IDC_DD,TOP_RIGHT);
if (servermsgbox->m_hWnd)
AddAnchor(*servermsgbox, CSize(0,50), BOTTOM_RIGHT);
debug = true;
ToggleDebugWindow();
debuglog.ShowWindow(SW_HIDE);
logbox.ShowWindow(SW_HIDE);
if (servermsgbox->m_hWnd)
servermsgbox->ShowWindow(SW_SHOW);
// optional: restore last used log pane
if (thePrefs.GetRestoreLastLogPane())
{
if (thePrefs.GetLastLogPaneID() >= 0 && thePrefs.GetLastLogPaneID() < StatusSelector.GetItemCount())
{
int iCurSel = StatusSelector.GetCurSel();
StatusSelector.SetCurSel(thePrefs.GetLastLogPaneID());
if (thePrefs.GetLastLogPaneID() == StatusSelector.GetCurSel())
UpdateLogTabSelection();
else
StatusSelector.SetCurSel(iCurSel);
}
}
m_MyInfo.SendMessage(EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(3, 3));
m_MyInfo.SetAutoURLDetect();
m_MyInfo.SetEventMask(m_MyInfo.GetEventMask() | ENM_LINK);
PARAFORMAT pf = {0};
pf.cbSize = sizeof pf;
if (m_MyInfo.GetParaFormat(pf)){
pf.dwMask |= PFM_TABSTOPS;
pf.cTabCount = 4;
pf.rgxTabs[0] = 900;
pf.rgxTabs[1] = 1000;
pf.rgxTabs[2] = 1100;
pf.rgxTabs[3] = 1200;
m_MyInfo.SetParaFormat(pf);
}
m_cfDef.cbSize = sizeof m_cfDef;
if (m_MyInfo.GetSelectionCharFormat(m_cfDef)){
m_cfBold = m_cfDef;
m_cfBold.dwMask |= CFM_BOLD;
m_cfBold.dwEffects |= CFE_BOLD;
}
if (thePrefs.GetUseAutocompletion()){
m_pacServerMetURL = new CCustomAutoComplete();
m_pacServerMetURL->AddRef();
if (m_pacServerMetURL->Bind(::GetDlgItem(m_hWnd, IDC_SERVERMETURL), ACO_UPDOWNKEYDROPSLIST | ACO_AUTOSUGGEST | ACO_FILTERPREFIXES ))
m_pacServerMetURL->LoadList(CString(thePrefs.GetConfigDir()) + _T("\\") SERVERMET_STRINGS_PROFILE);
if (theApp.emuledlg->m_fontMarlett.m_hObject){
GetDlgItem(IDC_DD)->SetFont(&theApp.emuledlg->m_fontMarlett);
GetDlgItem(IDC_DD)->SetWindowText(_T("6")); // show a down-arrow
}
}
else
GetDlgItem(IDC_DD)->ShowWindow(SW_HIDE);
InitWindowStyles(this);
return true;
}
void CServerWnd::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_SERVLIST, serverlistctrl);
DDX_Control(pDX, IDC_LOGBOX, logbox);
DDX_Control(pDX, IDC_DEBUG_LOG, debuglog);
DDX_Control(pDX, IDC_SSTATIC, m_ctrlNewServerFrm);
DDX_Control(pDX, IDC_SSTATIC6, m_ctrlUpdateServerFrm);
DDX_Control(pDX, IDC_MYINFO, m_ctrlMyInfo);
DDX_Control(pDX, IDC_TAB3, StatusSelector);
DDX_Control(pDX, IDC_MYINFOLIST, m_MyInfo);
}
bool CServerWnd::UpdateServerMetFromURL(CString strURL)
{
if (strURL.IsEmpty() || (strURL.Find(_T("://")) == -1)) // not a valid URL
{
AddLogLine(true, GetResString(IDS_INVALIDURL) );
return false;
}
// add entered URL to LRU list even if it's not yet known whether we can download from this URL (it's just more convenient this way)
if (m_pacServerMetURL && m_pacServerMetURL->IsBound())
m_pacServerMetURL->AddItem(strURL, 0);
CString strTempFilename;
strTempFilename.Format(_T("%stemp-%d-server.met"), thePrefs.GetConfigDir(), ::GetTickCount());
// try to download server.met
CHttpDownloadDlg dlgDownload;
dlgDownload.m_sURLToDownload = strURL;
dlgDownload.m_sFileToDownloadInto = strTempFilename;
if (dlgDownload.DoModal() != IDOK)
{
AddLogLine(true, GetResString(IDS_ERR_FAILEDDOWNLOADMET), strURL);
return false;
}
// add content of server.met to serverlist
serverlistctrl.Hide();
serverlistctrl.AddServermetToList(strTempFilename);
serverlistctrl.Visable();
_tremove(strTempFilename);
return true;
}
void CServerWnd::OnSysColorChange()
{
CResizableDialog::OnSysColorChange();
SetAllIcons();
}
void CServerWnd::SetAllIcons()
{
m_ctrlNewServerFrm.Init(_T("AddServer"));
m_ctrlUpdateServerFrm.Init(_T("ServerUpdateMET"));
m_ctrlMyInfo.Init(_T("MyInfo"));
CImageList iml;
iml.Create(16,16,theApp.m_iDfltImageListColorFlags|ILC_MASK,0,1);
iml.Add(CTempIconLoader(_T("Log")));
iml.Add(CTempIconLoader(_T("ServerInfo")));
StatusSelector.SetImageList(&iml);
m_imlLogPanes.DeleteImageList();
m_imlLogPanes.Attach(iml.Detach());
if (icon_srvlist)
VERIFY( DestroyIcon(icon_srvlist) );
icon_srvlist = theApp.LoadIcon(_T("ServerList"), 16, 16);
((CStatic*)GetDlgItem(IDC_SERVLST_ICO))->SetIcon(icon_srvlist);
}
void CServerWnd::Localize()
{
serverlistctrl.Localize();
if (thePrefs.GetLanguageID() != m_uLangID){
m_uLangID = thePrefs.GetLanguageID();
GetDlgItem(IDC_SERVLIST_TEXT)->SetWindowText(GetResString(IDS_SV_SERVERLIST));
GetDlgItem(IDC_SSTATIC)->SetWindowText(GetResString(IDS_SV_NEWSERVER));
m_ctrlNewServerFrm.SetText(GetResString(IDS_SV_NEWSERVER));
GetDlgItem(IDC_SSTATIC4)->SetWindowText(GetResString(IDS_SV_ADDRESS));
GetDlgItem(IDC_SSTATIC7)->SetWindowText(GetResString(IDS_SV_PORT));
GetDlgItem(IDC_SSTATIC3)->SetWindowText(GetResString(IDS_SW_NAME));
GetDlgItem(IDC_ADDSERVER)->SetWindowText(GetResString(IDS_SV_ADD));
GetDlgItem(IDC_SSTATIC6)->SetWindowText(GetResString(IDS_SV_MET));
m_ctrlUpdateServerFrm.SetText(GetResString(IDS_SV_MET));
GetDlgItem(IDC_UPDATESERVERMETFROMURL)->SetWindowText(GetResString(IDS_SV_UPDATE));
GetDlgItem(IDC_LOGRESET)->SetWindowText(GetResString(IDS_PW_RESET));
GetDlgItem(IDC_MYINFO)->SetWindowText(GetResString(IDS_MYINFO));
m_ctrlMyInfo.SetText(GetResString(IDS_MYINFO));
TCITEM item;
CString name;
name = GetResString(IDS_SV_SERVERINFO);
item.mask = TCIF_TEXT;
item.pszText = const_cast<LPTSTR>((LPCTSTR)name);
StatusSelector.SetItem(PaneServerInfo, &item);
name = GetResString(IDS_SV_LOG);
item.mask = TCIF_TEXT;
item.pszText = const_cast<LPTSTR>((LPCTSTR)name);
StatusSelector.SetItem(PaneLog, &item);
name = SZ_DEBUG_LOG_TITLE;
item.mask = TCIF_TEXT;
item.pszText = const_cast<LPTSTR>((LPCTSTR)name);
StatusSelector.SetItem(PaneVerboseLog, &item);
}
UpdateLogTabSelection();
UpdateControlsState();
}
BEGIN_MESSAGE_MAP(CServerWnd, CResizableDialog)
ON_BN_CLICKED(IDC_ADDSERVER, OnBnClickedAddserver)
ON_BN_CLICKED(IDC_UPDATESERVERMETFROMURL, OnBnClickedUpdateservermetfromurl)
ON_BN_CLICKED(IDC_LOGRESET, OnBnClickedResetLog)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB3, OnTcnSelchangeTab3)
ON_NOTIFY(EN_LINK, 123, OnEnLinkServerBox)
ON_BN_CLICKED(IDC_ED2KCONNECT, OnBnConnect)
ON_WM_SYSCOLORCHANGE()
ON_BN_CLICKED(IDC_DD,OnDDClicked)
ON_WM_HELPINFO()
ON_EN_CHANGE(IDC_IPADDRESS, OnSvrTextChange)
ON_EN_CHANGE(IDC_SPORT, OnSvrTextChange)
ON_EN_CHANGE(IDC_SNAME, OnSvrTextChange)
ON_EN_CHANGE(IDC_SERVERMETURL, OnSvrTextChange)
END_MESSAGE_MAP()
// CServerWnd message handlers
void CServerWnd::OnBnClickedAddserver()
{
CString serveraddr;
if (!GetDlgItem(IDC_IPADDRESS)->GetWindowTextLength()){
AfxMessageBox(GetResString(IDS_SRV_ADDR));
return;
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -