📄 emule.cpp
字号:
// 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?' -> always try to use 'LoadImage'!
//
// If the ICO file contains a 16x16 icon, 'LoadImage' will though return a 32x32 icon,
// if LR_DEFAULTSIZE is specified! -> always specify the requested size!
hIcon = (HICON)::LoadImage(NULL, szFullResPath, IMAGE_ICON, cx, cy, uFlags | LR_LOADFROMFILE);
}
}
}
if (hIcon == NULL)
{
if (cx != LR_DEFAULTSIZE || cy != LR_DEFAULTSIZE || uFlags != LR_DEFAULTCOLOR)
hIcon = (HICON)::LoadImage(AfxGetResourceHandle(), lpszResourceName, IMAGE_ICON, cx, cy, uFlags);
if (hIcon == NULL)
hIcon = CWinApp::LoadIcon(lpszResourceName);
}
return hIcon;
}
HBITMAP CemuleApp::LoadImage(LPCTSTR lpszResourceName, LPCTSTR pszResourceType) const
{
HBITMAP hBmp = NULL;
LPCTSTR pszSkinProfile = thePrefs.GetSkinProfile();
if (pszSkinProfile != NULL && pszSkinProfile[0] != _T('\0'))
{
// load resource file specification from skin profile
TCHAR szSkinResource[MAX_PATH];
GetPrivateProfileString(_T("Bitmaps"), 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 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');
}
CEnBitmap bmp;
if (bmp.LoadImage(szFullResPath))
return (HBITMAP)bmp.Detach();
}
}
CEnBitmap bmp;
if (bmp.LoadImage(lpszResourceName, pszResourceType))
return (HBITMAP)bmp.Detach();
return NULL;
}
bool CemuleApp::LoadSkinColor(LPCTSTR pszKey, COLORREF& crColor)
{
LPCTSTR pszSkinProfile = thePrefs.GetSkinProfile();
if (pszSkinProfile != NULL && pszSkinProfile[0] != _T('\0'))
{
TCHAR szColor[MAX_PATH];
GetPrivateProfileString(_T("Colors"), pszKey, _T(""), szColor, ARRSIZE(szColor), pszSkinProfile);
if (szColor[0] != _T('\0'))
{
UINT red, grn, blu;
int iVals = _stscanf(szColor, _T("%i , %i , %i"), &red, &grn, &blu);
if (iVals == 3)
{
crColor = RGB(red, grn, blu);
return true;
}
}
}
return false;
}
void CemuleApp::ApplySkin(LPCTSTR pszSkinProfile)
{
thePrefs.SetSkinProfile(pszSkinProfile);
AfxGetMainWnd()->SendMessage(WM_SYSCOLORCHANGE);
}
CTempIconLoader::CTempIconLoader(LPCTSTR pszResourceID, int cx, int cy, UINT uFlags)
{
m_hIcon = theApp.LoadIcon(pszResourceID, cx, cy, uFlags);
}
CTempIconLoader::~CTempIconLoader()
{
if (m_hIcon)
VERIFY( DestroyIcon(m_hIcon) );
}
void CemuleApp::AddEd2kLinksToDownload(CString strlink, uint8 cat)
{
int curPos = 0;
CString resToken = strlink.Tokenize(_T("\t\n\r"), curPos);
while (resToken != _T(""))
{
if (resToken.Right(1) != _T("/"))
resToken += _T("/");
try
{
CED2KLink* pLink = CED2KLink::CreateLinkFromUrl(resToken.Trim());
if (pLink)
{
if (pLink->GetKind() == CED2KLink::kFile)
{
downloadqueue->AddFileLinkToDownload(pLink->GetFileLink(), cat);
}
else
{
delete pLink;
throw CString(_T("bad link"));
}
delete pLink;
}
}
catch(CString error)
{
TCHAR szBuffer[200];
_sntprintf(szBuffer, ARRSIZE(szBuffer), GetResString(IDS_ERR_INVALIDLINK), error);
AddLogLine(true, GetResString(IDS_ERR_LINKERROR), szBuffer);
}
resToken = strlink.Tokenize(_T("\t\n\r"), curPos);
}
}
void CemuleApp::SearchClipboard()
{
if (m_bGuardClipboardPrompt)
return;
CString strLinks = CopyTextFromClipboard();
if (strLinks.IsEmpty())
return;
if (strLinks.Compare(m_strLastClipboardContents) == 0)
return;
if (strLinks.Left(13).CompareNoCase(_T("ed2k://|file|")) == 0)
{
m_bGuardClipboardPrompt = true;
if (AfxMessageBox(GetResString(IDS_ED2KLINKFIX) + _T("\r\n\r\n") + GetResString(IDS_ADDDOWNLOADSFROMCB)+_T("\r\n") + strLinks, MB_YESNO | MB_TOPMOST) == IDYES)
AddEd2kLinksToDownload(strLinks, 0);
}
m_strLastClipboardContents = strLinks;
m_bGuardClipboardPrompt = false;
}
void CemuleApp::PasteClipboard(uint8 uCategory)
{
CString strLinks = CopyTextFromClipboard();
strLinks.Trim();
if (strLinks.IsEmpty())
return;
AddEd2kLinksToDownload(strLinks, uCategory);
}
bool CemuleApp::IsEd2kLinkInClipboard(LPCSTR pszLinkType, int iLinkTypeLen)
{
bool bFoundLink = false;
if (IsClipboardFormatAvailable(CF_TEXT))
{
if (OpenClipboard(NULL))
{
HGLOBAL hText = GetClipboardData(CF_TEXT);
if (hText != NULL)
{
// Use the ANSI string
LPCSTR pszText = (LPCSTR)GlobalLock(hText);
if (pszText != NULL)
{
while (*pszText == ' ' || *pszText == '\t' || *pszText == '\r' || *pszText == '\n')
pszText++;
bFoundLink = (strncmp(pszText, pszLinkType, iLinkTypeLen) == 0);
GlobalUnlock(hText);
}
}
CloseClipboard();
}
}
return bFoundLink;
}
bool CemuleApp::IsEd2kFileLinkInClipboard()
{
static const CHAR _szEd2kFileLink[] = "ed2k://|file|"; // Use the ANSI string
return IsEd2kLinkInClipboard(_szEd2kFileLink, ARRSIZE(_szEd2kFileLink)-1);
}
bool CemuleApp::IsEd2kServerLinkInClipboard()
{
static const CHAR _szEd2kServerLink[] = "ed2k://|server|"; // Use the ANSI string
return IsEd2kLinkInClipboard(_szEd2kServerLink, ARRSIZE(_szEd2kServerLink)-1);
}
// VeryCD版
// Added by MoNKi [MoNKi: -UPnPNAT Support-]
BOOL CemuleApp::AddUPnPNatPort(CUPnPNat::UPNPNAT_MAPPING *mapping, bool tryRandom){
if(m_UPnPNat.AddNATPortMapping(mapping, tryRandom) == CUPnPNat::UNAT_OK ){
if(theApp.emuledlg->IsRunning()){
theApp.emuledlg->AddLogLine(false, "Added UPnP NAT Support: (%s) NAT ROUTER/FIREWALL:%i -> %s:%i",
mapping->description, mapping->externalPort, m_UPnPNat.GetLocalIPStr(), mapping->internalPort);
}
return true;
}
else{
//if(theApp.emuledlg->IsRunning()){
// theApp.emuledlg->AddLogLine(false, "Error adding UPnP NAT Support: (%s) NAT ROUTER/FIREWALL:%i -> %s:%i (%s)",
// mapping->description, mapping->externalPort, m_UPnPNat.GetLocalIPStr(), mapping->internalPort, m_UPnPNat.GetLastError());
//}
return false;
}
}
BOOL CemuleApp::RemoveUPnPNatPort(CUPnPNat::UPNPNAT_MAPPING *mapping){
if(m_UPnPNat.RemoveNATPortMapping(*mapping) == CUPnPNat::UNAT_OK )
return true;
else
return false;
}
// VeryCD版
// Elandal:ThreadSafeLogging -->
void CemuleApp::QueueDebugLogLine(bool addtostatusbar, LPCTSTR line, ...)
{
if (!thePrefs.GetVerbose())
return;
m_queueLock.Lock();
TCHAR bufferline[1000];
va_list argptr;
va_start(argptr, line);
_vsntprintf(bufferline, ARRSIZE(bufferline), line, argptr);
va_end(argptr);
SLogItem* newItem = new SLogItem;
newItem->addtostatusbar = addtostatusbar;
newItem->line = bufferline;
m_QueueDebugLog.AddTail(newItem);
m_queueLock.Unlock();
}
void CemuleApp::QueueLogLine(bool addtostatusbar, LPCTSTR line,...)
{
m_queueLock.Lock();
TCHAR bufferline[1000];
va_list argptr;
va_start(argptr, line);
_vsntprintf(bufferline, ARRSIZE(bufferline), line, argptr);
va_end(argptr);
SLogItem* newItem = new SLogItem;
newItem->addtostatusbar = addtostatusbar;
newItem->line = bufferline;
m_QueueLog.AddTail(newItem);
m_queueLock.Unlock();
}
void CemuleApp::HandleDebugLogQueue()
{
m_queueLock.Lock();
while(!m_QueueDebugLog.IsEmpty()) {
const SLogItem* newItem = m_QueueDebugLog.RemoveHead();
if (thePrefs.GetVerbose())
AddDebugLogLine(newItem->addtostatusbar, newItem->line);
delete newItem;
}
m_queueLock.Unlock();
}
void CemuleApp::HandleLogQueue()
{
m_queueLock.Lock();
while(!m_QueueLog.IsEmpty()) {
const SLogItem* newItem = m_QueueLog.RemoveHead();
AddLogLine(newItem->addtostatusbar, newItem->line);
delete newItem;
}
m_queueLock.Unlock();
}
void CemuleApp::ClearDebugLogQueue(bool bDebugPendingMsgs)
{
m_queueLock.Lock();
while(!m_QueueDebugLog.IsEmpty())
{
if (bDebugPendingMsgs)
TRACE("Queued dbg log msg: %s\n", m_QueueDebugLog.GetHead()->line);
delete m_QueueDebugLog.RemoveHead();
}
m_queueLock.Unlock();
}
void CemuleApp::ClearLogQueue(bool bDebugPendingMsgs)
{
m_queueLock.Lock();
while(!m_QueueLog.IsEmpty())
{
if (bDebugPendingMsgs)
TRACE("Queued log msg: %s\n", m_QueueLog.GetHead()->line);
delete m_QueueLog.RemoveHead();
}
m_queueLock.Unlock();
}
// Elandal:ThreadSafeLogging <--
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -