📄 downloadclient.cpp
字号:
if (!SwapTo) {
return true;
}
if(!curFileisNNPFile && cur_file->GetSourceCount() < thePrefs.GetMaxSourcePerFile() ||
curFileisNNPFile && cur_file->GetSourceCount() < thePrefs.GetMaxSourcePerFile()*.8) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: cur_file does probably not have too many sources."));
if(SwapTo->GetSourceCount() > thePrefs.GetMaxSourcePerFile() ||
SwapTo->GetSourceCount() >= thePrefs.GetMaxSourcePerFile()*.8 &&
SwapTo == reqfile &&
(
GetDownloadState() == DS_LOWTOLOWIP ||
GetDownloadState() == DS_REMOTEQUEUEFULL
)
) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: SwapTo is about to be deleted due to too many sources on that file, so we can steal it."));
return true;
}
if(ignoreSuspensions || !IsSwapSuspended(cur_file, doAgressiveSwapping, curFileisNNPFile)) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: No suspend block."));
DWORD tempTick = ::GetTickCount();
bool rightFileHasHigherPrio = CPartFile::RightFileHasHigherPrio(SwapTo, cur_file);
uint32 allNnpReaskTime = FILEREASKTIME*2*(m_OtherNoNeeded_list.GetSize() + (GetDownloadState() == DS_NONEEDEDPARTS)?1:0); // wait two reask interval for each nnp file before reasking an nnp file
if(!SwapToIsNNPFile && (!curFileisNNPFile || GetLastAskedTime(cur_file) == 0 || tempTick-GetLastAskedTime(cur_file) > allNnpReaskTime) && rightFileHasHigherPrio ||
SwapToIsNNPFile && curFileisNNPFile &&
(
GetLastAskedTime(SwapTo) != 0 &&
(
GetLastAskedTime(cur_file) == 0 ||
tempTick-GetLastAskedTime(SwapTo) < tempTick-GetLastAskedTime(cur_file)
) ||
rightFileHasHigherPrio && GetLastAskedTime(SwapTo) == 0 && GetLastAskedTime(cur_file) == 0
) ||
SwapToIsNNPFile && !curFileisNNPFile) {
if(printDebug)
if(!SwapToIsNNPFile && !curFileisNNPFile && rightFileHasHigherPrio)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: Higher prio."));
else if(!SwapToIsNNPFile && (GetLastAskedTime(cur_file) == 0 || tempTick-GetLastAskedTime(cur_file) > allNnpReaskTime) && rightFileHasHigherPrio)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: Time to reask nnp and it had higher prio."));
else if(GetLastAskedTime(SwapTo) != 0 &&
(
GetLastAskedTime(cur_file) == 0 ||
tempTick-GetLastAskedTime(SwapTo) < tempTick-GetLastAskedTime(cur_file)
)
)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: Both nnp and cur_file has longer time since reasked."));
else if(SwapToIsNNPFile && !curFileisNNPFile)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: SwapToIsNNPFile && !curFileisNNPFile"));
else
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: Higher prio for unknown reason!"));
if(IsSourceRequestAllowed(cur_file) && (cur_file->AllowSwapForSourceExchange() || cur_file == reqfile && RecentlySwappedForSourceExchange()) ||
!(IsSourceRequestAllowed(SwapTo) && (SwapTo->AllowSwapForSourceExchange() || SwapTo == reqfile && RecentlySwappedForSourceExchange())) ||
(GetDownloadState()==DS_ONQUEUE && GetRemoteQueueRank() <= 50)) {
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("oooo Debug: Source Request check ok."));
return true;
} else {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: Source Request check failed."));
wasSkippedDueToSourceExchange = true;
}
}
if(IsSourceRequestAllowed(cur_file, true) && (cur_file->AllowSwapForSourceExchange() || cur_file == reqfile && RecentlySwappedForSourceExchange()) &&
!(IsSourceRequestAllowed(SwapTo, true) && (SwapTo->AllowSwapForSourceExchange() || SwapTo == reqfile && RecentlySwappedForSourceExchange())) &&
(GetDownloadState()!=DS_ONQUEUE || GetDownloadState()==DS_ONQUEUE && GetRemoteQueueRank() > 50)) {
wasSkippedDueToSourceExchange = true;
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("oooo Debug: Source Exchange."));
return true;
}
} else if(printDebug) {
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: Suspend block."));
}
} else if(printDebug) {
AddDebugLogLine(DLP_VERYLOW, false, _T("oooo Debug: cur_file probably has too many sources."));
}
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("oooo Debug: Return false"));
return false;
}
// <-- ZZ:DownloadManager
// ZZ:DownloadManager -->
bool CUpDownClient::SwapToAnotherFile(LPCTSTR reason, bool bIgnoreNoNeeded, bool ignoreSuspensions, bool bRemoveCompletely, CPartFile* toFile, bool allowSame, bool isAboutToAsk, bool debug){
bool printDebug = debug && thePrefs.GetLogA4AF();
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: Switching source %s Remove = %s; bIgnoreNoNeeded = %s; allowSame = %s; Reason = \"%s\""), DbgGetClientInfo(), (bRemoveCompletely ? _T("Yes") : _T("No")), (bIgnoreNoNeeded ? _T("Yes") : _T("No")), (allowSame ? _T("Yes") : _T("No")), reason);
if(!bRemoveCompletely && allowSame && thePrefs.GetA4AFSaveCpu()) {
// Only swap if we can't keep the old source
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: return false since prefs setting to save cpu is enabled."));
return false;
}
bool doAgressiveSwapping = (bRemoveCompletely || !allowSame || isAboutToAsk);
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: doAgressiveSwapping: %s"), doAgressiveSwapping?_T("true"):_T("false"));
if(!bRemoveCompletely && !ignoreSuspensions && allowSame && IsSwapSuspended(reqfile, doAgressiveSwapping, false)) {
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: return false due to IsSwapSuspended(reqfile)."));
return false;
}
if(!bRemoveCompletely && allowSame && m_OtherRequests_list.IsEmpty() && (!bIgnoreNoNeeded || m_OtherNoNeeded_list.IsEmpty())) {
// no file to swap too, and it's ok to keep it
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: return false due to no file to swap too, and it's ok to keep it."));
return false;
}
if (!bRemoveCompletely &&
(GetDownloadState() != DS_ONQUEUE &&
GetDownloadState() != DS_NONEEDEDPARTS &&
GetDownloadState() != DS_TOOMANYCONNS &&
GetDownloadState() != DS_REMOTEQUEUEFULL &&
GetDownloadState() != DS_CONNECTED
)) {
if(printDebug)
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: return false due to wrong state."));
return false;
}
CPartFile* SwapTo = NULL;
CPartFile* cur_file = NULL;
//int cur_prio= -1; //ZZ:DownloadManager
POSITION finalpos = NULL;
CTypedPtrList<CPtrList, CPartFile*>* usedList;
if(allowSame && !bRemoveCompletely) {
SwapTo = reqfile;
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: allowSame: File %s SourceReq: %s"), reqfile->GetFileName(), IsSourceRequestAllowed(reqfile)?_T("true"):_T("false"));
}
bool SwapToIsNNP = (SwapTo != NULL && SwapTo == reqfile && GetDownloadState() == DS_NONEEDEDPARTS);
CPartFile* skippedDueToSourceExchange = NULL;
bool skippedIsNNP = false;
if (!m_OtherRequests_list.IsEmpty()){
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: m_OtherRequests_list"));
usedList = &m_OtherRequests_list;
for (POSITION pos = m_OtherRequests_list.GetHeadPosition();pos != 0;m_OtherRequests_list.GetNext(pos)){
cur_file = m_OtherRequests_list.GetAt(pos);
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Checking file: %s SoureReq: %s"), cur_file->GetFileName(), IsSourceRequestAllowed(cur_file)?_T("true"):_T("false"));
if(!bRemoveCompletely && !ignoreSuspensions && allowSame && IsSwapSuspended(cur_file, doAgressiveSwapping, false)) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: continue due to IsSwapSuspended(file) == true"));
continue;
}
if (cur_file != reqfile && theApp.downloadqueue->IsPartFile(cur_file) && !cur_file->IsStopped()
&& (cur_file->GetStatus(false) == PS_READY || cur_file->GetStatus(false) == PS_EMPTY))
{
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: It's a partfile, not stopped, etc."));
if (toFile != NULL){
if (cur_file == toFile){
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Found toFile."));
SwapTo = cur_file;
SwapToIsNNP = false;
finalpos = pos;
break;
}
} else {
bool wasSkippedDueToSourceExchange = false;
if(SwapToRightFile(SwapTo, cur_file, ignoreSuspensions, SwapToIsNNP, false, wasSkippedDueToSourceExchange, doAgressiveSwapping, debug)) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Swapping to file %s"), cur_file->GetFileName());
if(SwapTo && wasSkippedDueToSourceExchange) {
if(debug && thePrefs.GetLogA4AF()) AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Swapped due to source exchange possibility"));
bool discardSkipped = false;
if(SwapToRightFile(skippedDueToSourceExchange, SwapTo, ignoreSuspensions, skippedIsNNP, SwapToIsNNP, discardSkipped, doAgressiveSwapping, debug)) {
skippedDueToSourceExchange = SwapTo;
skippedIsNNP = skippedIsNNP?true:(SwapTo == reqfile && GetDownloadState() == DS_NONEEDEDPARTS);
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Skipped file was better than last skipped file."));
}
}
SwapTo = cur_file;
SwapToIsNNP = false;
finalpos=pos;
} else {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Keeping file %s"), SwapTo->GetFileName());
if(wasSkippedDueToSourceExchange) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Kept the file due to source exchange possibility"));
bool discardSkipped = false;
if(SwapToRightFile(skippedDueToSourceExchange, cur_file, ignoreSuspensions, skippedIsNNP, false, discardSkipped, doAgressiveSwapping, debug)) {
skippedDueToSourceExchange = cur_file;
skippedIsNNP = false;
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Skipped file was better than last skipped file."));
}
}
}
}
}
}
}
if ((!SwapTo || SwapTo == reqfile && GetDownloadState() == DS_NONEEDEDPARTS) && bIgnoreNoNeeded){
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: m_OtherNoNeeded_list"));
usedList = &m_OtherNoNeeded_list;
for (POSITION pos = m_OtherNoNeeded_list.GetHeadPosition();pos != 0;m_OtherNoNeeded_list.GetNext(pos)){
cur_file = m_OtherNoNeeded_list.GetAt(pos);
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Checking file: %s "), cur_file->GetFileName());
if(!bRemoveCompletely && !ignoreSuspensions && allowSame && IsSwapSuspended(cur_file, doAgressiveSwapping, true)) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: continue due to !IsSwapSuspended(file) == true"));
continue;
}
if (cur_file != reqfile && theApp.downloadqueue->IsPartFile(cur_file) && !cur_file->IsStopped()
&& (cur_file->GetStatus(false) == PS_READY || cur_file->GetStatus(false) == PS_EMPTY) )
{
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: It's a partfile, not stopped, etc."));
if (toFile != NULL){
if (cur_file == toFile){
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Found toFile."));
SwapTo = cur_file;
finalpos = pos;
break;
}
} else {
bool wasSkippedDueToSourceExchange = false;
if(SwapToRightFile(SwapTo, cur_file, ignoreSuspensions, SwapToIsNNP, true, wasSkippedDueToSourceExchange, doAgressiveSwapping, debug)) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Swapping to file %s"), cur_file->GetFileName());
if(SwapTo && wasSkippedDueToSourceExchange) {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Swapped due to source exchange possibility"));
bool discardSkipped = false;
if(SwapToRightFile(skippedDueToSourceExchange, SwapTo, ignoreSuspensions, skippedIsNNP, SwapToIsNNP, discardSkipped, doAgressiveSwapping, debug)) {
skippedDueToSourceExchange = SwapTo;
skippedIsNNP = skippedIsNNP?true:(SwapTo == reqfile && GetDownloadState() == DS_NONEEDEDPARTS);
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Skipped file was better than last skipped file."));
}
}
SwapTo = cur_file;
SwapToIsNNP = true;
finalpos=pos;
} else {
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Keeping file %s"), SwapTo->GetFileName());
if(wasSkippedDueToSourceExchange) {
if(debug && thePrefs.GetVerbose()) AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Kept the file due to source exchange possibility"));
bool discardSkipped = false;
if(SwapToRightFile(skippedDueToSourceExchange, cur_file, ignoreSuspensions, skippedIsNNP, true, discardSkipped, doAgressiveSwapping, debug)) {
skippedDueToSourceExchange = cur_file;
skippedIsNNP = true;
if(printDebug)
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Skipped file was better than last skipped file."));
}
}
}
}
}
}
}
if (SwapTo){
if(printDebug) {
if(SwapTo != reqfile) {
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: Found file to swap to %s"), SwapTo->GetFileName());
} else {
AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: Will keep current file. %s"), SwapTo->GetFileName());
}
}
CString strInfo(reason);
if(skippedDueToSourceExchange) {
bool wasSkippedDueToSourceExchange = false;
bool skippedIsBetter = SwapToRightFile(SwapTo, skippedDueToSourceExchange, ignoreSuspensions, SwapToIsNNP, skippedIsNNP, wasSkippedDueToSourceExchange, doAgressiveSwapping, debug);
if(skippedIsBetter || wasSkippedDueToSourceExchange) {
SwapTo->SetSwapForSourceExchangeTick();
SetSwapForSourceExchangeTick();
strInfo = _T("******SourceExchange-Swap****** ") + strInfo;
if(printDebug) {
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Due to sourceExchange."));
} else if(thePrefs.GetLogA4AF() && reqfile == SwapTo) {
AddDebugLogLine(DLP_LOW, false, _T("ooo Didn't swap source due to source exchange possibility. %s Remove = %s '%s' Reason: %s"), DbgGetClientInfo(), (bRemoveCompletely ? _T("Yes") : _T("No") ), (this->reqfile)?this->reqfile->GetFileName():_T("null"), strInfo);
}
} else if(printDebug) {
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Normal. SwapTo better than skippedDueToSourceExchange."));
}
} else if(printDebug) {
AddDebugLogLine(DLP_VERYLOW, false, _T("ooo Debug: Normal. skippedDueToSourceExchange == NULL"));
}
if (SwapTo != reqfile && DoSwap(SwapTo,bRemoveCompletely, strInfo)){
if(debug && thePrefs.GetLogA4AF()) AddDebugLogLine(DLP_LOW, false, _T("ooo Debug: Swap successful."));
usedList->RemoveAt(finalpos);
return true;
} else if(printDebug) {
AddDebug
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -