📄 emule.cpp
字号:
CloseClipboard();
if (bResult)
return strClipboard;
}
}
#endif
if (!IsClipboardFormatAvailable(CF_TEXT))
return _T("");
if (!OpenClipboard(NULL))
return _T("");
CString retstring;
HGLOBAL hglb = GetClipboardData(CF_TEXT);
if (hglb != NULL)
{
LPCSTR lptstr = (LPCSTR)GlobalLock(hglb);
if (lptstr != NULL)
{
retstring = lptstr;
GlobalUnlock(hglb);
}
}
CloseClipboard();
return retstring;
}
void CemuleApp::OnlineSig() // Added By Bouc7
{
if (!thePrefs.IsOnlineSignatureEnabled())
return;
static const TCHAR _szFileName[] = _T("onlinesig.dat");
CString strFullPath = thePrefs.GetAppDir();
strFullPath += _szFileName;
// The 'onlinesig.dat' is potentially read by other applications at more or less frequent intervals.
// - Set the file shareing mode to allow other processes to read the file while we are writing
// it (see also next point).
// - Try to write the hole file data at once, so other applications are always reading
// a consistent amount of file data. C-RTL uses a 4 KB buffer, this is large enough to write
// those 2 lines into the onlinesig.dat file with one IO operation.
// - Although this file is a text file, we set the file mode to 'binary' because of backward
// compatibility with older eMule versions.
CSafeBufferedFile file;
CFileException fexp;
if (!file.Open(strFullPath, CFile::modeCreate | CFile::modeWrite | CFile::shareDenyWrite | CFile::typeBinary, &fexp)){
CString strError = GetResString(IDS_ERROR_SAVEFILE) + _T(" ") + CString(_szFileName);
TCHAR szError[MAX_CFEXP_ERRORMSG];
fexp.GetErrorMessage(szError, ARRSIZE(szError));
strError += _T(" - ");
strError += szError;
AddLogLine(true, _T("%s"), strError);
return;
}
try
{
char buffer[20];
CStringA strBuff;
if (IsConnected()){
file.Write("1",1);
file.Write("|",1);
if(serverconnect->IsConnected()){
strBuff = serverconnect->GetCurrentServer()->GetListName();
file.Write(strBuff, strBuff.GetLength());
}
else{
strBuff = "Kademlia";
file.Write(strBuff,strBuff.GetLength());
}
file.Write("|",1);
if(serverconnect->IsConnected()){
strBuff = serverconnect->GetCurrentServer()->GetFullIP();
file.Write(strBuff,strBuff.GetLength());
}
else{
strBuff = "0.0.0.0";
file.Write(strBuff,strBuff.GetLength());
}
file.Write("|",1);
if(serverconnect->IsConnected()){
itoa(serverconnect->GetCurrentServer()->GetPort(),buffer,10);
file.Write(buffer,strlen(buffer));
}
else{
strBuff = "0";
file.Write(strBuff,strBuff.GetLength());
}
}
else
file.Write("0",1);
file.Write("\n",1);
sprintf(buffer,"%.1f",(float)downloadqueue->GetDatarate()/1024);
file.Write(buffer,strlen(buffer));
file.Write("|",1);
sprintf(buffer,"%.1f",(float)uploadqueue->GetDatarate()/1024);
file.Write(buffer,strlen(buffer));
file.Write("|",1);
itoa(uploadqueue->GetWaitingUserCount(),buffer,10);
file.Write(buffer,strlen(buffer));
file.Close();
}
catch (CFileException* ex)
{
CString strError = GetResString(IDS_ERROR_SAVEFILE) + _T(" ") + CString(_szFileName);
TCHAR szError[MAX_CFEXP_ERRORMSG];
ex->GetErrorMessage(szError, ARRSIZE(szError));
strError += _T(" - ");
strError += szError;
AddLogLine(true, _T("%s"), strError);
ex->Delete();
}
} //End Added By Bouc7
CString CemuleApp::GetLangHelpFilePath()
{
// Change extension for help file
CString strHelpFile = m_pszHelpFilePath;
CFileFind ff;
if (thePrefs.GetLanguageID() != MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT))
{
int pos = strHelpFile.ReverseFind(_T('.'));
CString temp;
temp.Format(_T("%s.%u.chm"), strHelpFile.Left(pos), thePrefs.GetLanguageID());
if (pos>0)
strHelpFile = temp;
// if not exists, use original help (english)
if (!ff.FindFile(strHelpFile, 0))
strHelpFile = m_pszHelpFilePath;
}
ff.Close();
strHelpFile.Replace(_T(".HLP"), _T(".chm"));
return strHelpFile;
}
void CemuleApp::SetHelpFilePath(LPCTSTR pszHelpFilePath)
{
if (m_pszHelpFilePath)
{
free((void*)m_pszHelpFilePath);
m_pszHelpFilePath = NULL;
}
m_pszHelpFilePath = _tcsdup(pszHelpFilePath);
}
void CemuleApp::OnHelp()
{
if (m_dwPromptContext != 0)
{
// do not call WinHelp when the error is failing to lauch help
if (m_dwPromptContext != HID_BASE_PROMPT+AFX_IDP_FAILED_TO_LAUNCH_HELP)
ShowHelp(m_dwPromptContext);
return;
}
ShowHelp(0, HELP_CONTENTS);
}
void CemuleApp::ShowHelp(UINT uTopic, UINT uCmd)
{
CString strHelpFilePath = GetLangHelpFilePath();
SetHelpFilePath(strHelpFilePath);
WinHelpInternal(uTopic, uCmd);
}
int CemuleApp::GetFileTypeSystemImageIdx(LPCTSTR pszFilePath, int iLength /* = -1 */)
{
//TODO: This has to be MBCS aware..
DWORD dwFileAttributes;
LPCTSTR pszCacheExt = NULL;
if (iLength == -1)
iLength = _tcslen(pszFilePath);
if (iLength > 0 && (pszFilePath[iLength - 1] == _T('\\') || pszFilePath[iLength - 1] == _T('/'))){
// it's a directory
pszCacheExt = _T("\\");
dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
}
else{
dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
// search last '.' character *after* the last '\\' character
for (int i = iLength - 1; i >= 0; i--){
if (pszFilePath[i] == _T('\\') || pszFilePath[i] == _T('/'))
break;
if (pszFilePath[i] == _T('.')) {
// point to 1st character of extension (skip the '.')
pszCacheExt = &pszFilePath[i+1];
break;
}
}
if (pszCacheExt == NULL)
pszCacheExt = _T(""); // empty extension
}
// Search extension in "ext->idx" cache.
LPVOID vData;
if (!m_aExtToSysImgIdx.Lookup(pszCacheExt, vData)){
// Get index for the system's small icon image list
SHFILEINFO sfi;
DWORD dwResult = SHGetFileInfo(pszFilePath, dwFileAttributes, &sfi, sizeof(sfi),
SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
if (dwResult == 0)
return 0;
ASSERT( m_hSystemImageList == NULL || m_hSystemImageList == (HIMAGELIST)dwResult );
m_hSystemImageList = (HIMAGELIST)dwResult;
// Store icon index in local cache
m_aExtToSysImgIdx.SetAt(pszCacheExt, (LPVOID)sfi.iIcon);
return sfi.iIcon;
}
// Return already cached value
// Elandal: Assumes sizeof(void*) == sizeof(int)
return (int)vData;
}
bool CemuleApp::IsConnected()
{
return (theApp.serverconnect->IsConnected() || Kademlia::CKademlia::isConnected());
}
bool CemuleApp::IsPortchangeAllowed() {
return ( theApp.clientlist->GetClientCount()==0 && !IsConnected() );
}
uint32 CemuleApp::GetID(){
uint32 ID;
if( Kademlia::CKademlia::isConnected() && !Kademlia::CKademlia::isFirewalled() )
ID = ntohl(Kademlia::CKademlia::getIPAddress());
else if( theApp.serverconnect->IsConnected() )
ID = theApp.serverconnect->GetClientID();
else if ( Kademlia::CKademlia::isConnected() && Kademlia::CKademlia::isFirewalled() )
ID = 1;
else
ID = 0;
return ID;
}
uint32 CemuleApp::GetPublicIP() const {
if (m_dwPublicIP == 0 && Kademlia::CKademlia::isConnected() && Kademlia::CKademlia::getIPAddress() )
return ntohl(Kademlia::CKademlia::getIPAddress());
return m_dwPublicIP;
}
void CemuleApp::SetPublicIP(const uint32 dwIP){
if (dwIP != 0){
ASSERT ( !IsLowID(dwIP));
ASSERT ( m_pPeerCache );
if ( GetPublicIP() == 0)
AddDebugLogLine(DLP_VERYLOW, false, _T("My public IP Address is: %s"),ipstr(dwIP));
else if (Kademlia::CKademlia::isConnected() && Kademlia::CKademlia::getPrefs() && Kademlia::CKademlia::getPrefs()->getIPAddress())
if(ntohl(Kademlia::CKademlia::getIPAddress()) != dwIP)
AddDebugLogLine(DLP_DEFAULT, false, _T("Public IP Address reported from Kademlia (%s) differs from new found (%s)"),ipstr(ntohl(Kademlia::CKademlia::getIPAddress())),ipstr(dwIP));
m_pPeerCache->FoundMyPublicIPAddress(dwIP);
}
else
AddDebugLogLine(DLP_VERYLOW, false, _T("Deleted public IP"));
m_dwPublicIP = dwIP;
}
bool CemuleApp::IsFirewalled()
{
if (theApp.serverconnect->IsConnected() && !theApp.serverconnect->IsLowID())
return false; // we have an eD2K HighID -> not firewalled
if (Kademlia::CKademlia::isConnected() && !Kademlia::CKademlia::isFirewalled())
return false; // we have an Kad HighID -> not firewalled
return true; // firewalled
}
bool CemuleApp::DoCallback( CUpDownClient *client )
{
if(Kademlia::CKademlia::isConnected())
{
if(theApp.serverconnect->IsConnected())
{
if(theApp.serverconnect->IsLowID())
{
if(Kademlia::CKademlia::isFirewalled())
{
//Both Connected - Both Firewalled
return false;
}
else
{
if(client->GetServerIP() == theApp.serverconnect->GetCurrentServer()->GetIP() && client->GetServerPort() == theApp.serverconnect->GetCurrentServer()->GetPort())
{
//Both Connected - Server lowID, Kad Open - Client on same server
//We prevent a callback to the server as this breaks the protocol and will get you banned.
return false;
}
else
{
//Both Connected - Server lowID, Kad Open - Client on remote server
return true;
}
}
}
else
{
//Both Connected - Server HighID, Kad don't care
return true;
}
}
else
{
if(Kademlia::CKademlia::isFirewalled())
{
//Only Kad Connected - Kad Firewalled
return false;
}
else
{
//Only Kad Conected - Kad Open
return true;
}
}
}
else
{
if( theApp.serverconnect->IsConnected() )
{
if( theApp.serverconnect->IsLowID() )
{
//Only Server Connected - Server LowID
return false;
}
else
{
//Only Server Connected - Server HighID
return true;
}
}
else
{
//We are not connected at all!
return false;
}
}
}
HICON CemuleApp::LoadIcon(UINT nIDResource) const
{
// use string resource identifiers!!
ASSERT(0);
return CWinApp::LoadIcon(nIDResource);
}
HICON CemuleApp::LoadIcon(LPCTSTR lpszResourceName, int cx, int cy, UINT uFlags) const
{
HICON hIcon = NULL;
LPCTSTR pszSkinProfile = thePrefs.GetSkinProfile();
if (pszSkinProfile != NULL && pszSkinProfile[0] != _T('\0'))
{
// load icon resource file specification from skin profile
TCHAR szSkinResource[MAX_PATH];
GetPrivateProfileString(_T("Icons"), lpszResourceName, _T(""), szSkinResource, ARRSIZE(szSkinResource), pszSkinProfile);
if (szSkinResource[0] != _T('\0'))
{
// expand any optional available environment strings
TCHAR szExpSkinRes[MAX_PATH];
if (ExpandEnvironmentStrings(szSkinResource, szExpSkinRes, ARRSIZE(szExpSkinRes)) != 0)
{
_tcsncpy(szSkinResource, szExpSkinRes, ARRSIZE(szSkinResource));
szSkinResource[ARRSIZE(szSkinResource)-1] = _T('\0');
}
// create absolute path to icon resource file
TCHAR szFullResPath[MAX_PATH];
if (PathIsRelative(szSkinResource))
{
TCHAR szSkinResFolder[MAX_PATH];
_tcsncpy(szSkinResFolder, pszSkinProfile, ARRSIZE(szSkinResFolder));
szSkinResFolder[ARRSIZE(szSkinResFolder)-1] = _T('\0');
PathRemoveFileSpec(szSkinResFolder);
_tmakepath(szFullResPath, NULL, szSkinResFolder, szSkinResource, NULL);
}
else
{
_tcsncpy(szFullResPath, szSkinResource, ARRSIZE(szFullResPath));
szFullResPath[ARRSIZE(szFullResPath)-1] = _T('\0');
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -