📄 emule.cpp
字号:
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()
{
//Once we can handle lowID users in Kad, we remove the IsFirewalled!
return (theApp.serverconnect->IsConnected() || (Kademlia::CKademlia::isConnected() && !Kademlia::CKademlia::isFirewalled()));
}
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
ID = 0; //Once we can handle lowID users in Kad, this may change.
return ID;
}
uint32 CemuleApp::GetPublicIP() const {
if (m_dwPublicIP == 0 && Kademlia::CKademlia::isConnected() && !Kademlia::CKademlia::isFirewalled() )
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::isFirewalled() && 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
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');
}
// check for optional icon index or resource identifier within the icon resource file
bool bExtractIcon = false;
CString strFullResPath = szFullResPath;
int iIconIndex = 0;
int iComma = strFullResPath.ReverseFind(_T(','));
if (iComma != -1){
if (_stscanf((LPCTSTR)strFullResPath + iComma + 1, _T("%d"), &iIconIndex) == 1)
bExtractIcon = true;
strFullResPath = strFullResPath.Left(iComma);
}
if (bExtractIcon)
{
HICON aIconsLarge[1] = {0};
HICON aIconsSmall[1] = {0};
int iExtractedIcons = ExtractIconEx(strFullResPath, iIconIndex, aIconsLarge, aIconsSmall, 1);
if (iExtractedIcons > 0) // 'iExtractedIcons' is 2(!) if we get a large and a small icon
{
// alway try to return the icon size which was requested
if (cx == 16 && aIconsSmall[0] != NULL)
{
hIcon = aIconsSmall[0];
aIconsSmall[0] = NULL;
}
else if (cx == 32 && aIconsLarge[0] != NULL)
{
hIcon = aIconsLarge[0];
aIconsLarge[0] = NULL;
}
else
{
if (aIconsSmall[0] != NULL)
{
hIcon = aIconsSmall[0];
aIconsSmall[0] = NULL;
}
else if (aIconsLarge[0] != NULL)
{
hIcon = aIconsLarge[0];
aIconsLarge[0] = NULL;
}
}
for (int i = 0; i < ARRSIZE(aIconsLarge); i++)
{
if (aIconsLarge[i] != NULL)
VERIFY( DestroyIcon(aIconsLarge[i]) );
if (aIconsSmall[i] != NULL)
VERIFY( DestroyIcon(aIconsSmall[i]) );
}
}
}
else
{
// WINBUG???: 'ExtractIcon' does not work well on ICO-files when using the color
// scheme 'Windows-Standard (extragro
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -