Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

UploadQueues.cpp

Go to the documentation of this file.
00001 //
00002 // UploadQueues.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "UploadQueues.h"
00026 #include "UploadQueue.h"
00027 #include "UploadTransfer.h"
00028 #include "Transfers.h"
00029 #include "SharedFile.h"
00030 #include "Download.h"
00031 
00032 #ifdef _DEBUG
00033 #undef THIS_FILE
00034 static char THIS_FILE[]=__FILE__;
00035 #define new DEBUG_NEW
00036 #endif
00037 
00038 CUploadQueues UploadQueues;
00039 
00040 
00042 // CUploadQueues construction
00043 
00044 CUploadQueues::CUploadQueues()
00045 {
00046         m_pTorrentQueue = new CUploadQueue();
00047         m_pHistoryQueue = new CUploadQueue();
00048         m_pHistoryQueue->m_bExpanded = FALSE;
00049         m_bDonkeyLimited = FALSE;
00050 }
00051 
00052 CUploadQueues::~CUploadQueues()
00053 {
00054         Clear();
00055         delete m_pHistoryQueue;
00056         delete m_pTorrentQueue;
00057 }
00058 
00060 // CUploadQueues enqueue and dequeue
00061 
00062 BOOL CUploadQueues::Enqueue(CUploadTransfer* pUpload, BOOL bForce)
00063 {
00064         CSingleLock pLock( &m_pSection, TRUE );
00065 
00066         ASSERT( pUpload != NULL );
00067 
00068         Dequeue( pUpload );
00069 
00070         ASSERT( pUpload->m_pQueue == NULL );
00071 
00072         if ( pUpload->m_nFileSize == 0 ) return FALSE;
00073 
00074         for ( POSITION pos = GetIterator() ; pos ; )
00075         {
00076                 CUploadQueue* pQueue = GetNext( pos );
00077 
00078                 if ( pQueue->CanAccept( pUpload->m_nProtocol,
00079                                                                 pUpload->m_sFileName,
00080                                                                 pUpload->m_nFileSize,
00081                                                                 pUpload->m_bFilePartial,
00082                                                                 pUpload->m_sFileTags ) )
00083                 {
00084                         if ( pQueue->Enqueue( pUpload, bForce, bForce ) ) return TRUE;
00085                 }
00086         }
00087 
00088         return FALSE;
00089 }
00090 
00091 BOOL CUploadQueues::Dequeue(CUploadTransfer* pUpload)
00092 {
00093         CSingleLock pLock( &m_pSection, TRUE );
00094 
00095         ASSERT( pUpload != NULL );
00096 
00097         if ( Check( pUpload->m_pQueue ) )
00098         {
00099                 return pUpload->m_pQueue->Dequeue( pUpload );
00100         }
00101         else
00102         {
00103                 pUpload->m_pQueue = NULL;
00104                 return FALSE;
00105         }
00106 }
00107 
00109 // CUploadQueues position lookup and optional start
00110 
00111 int CUploadQueues::GetPosition(CUploadTransfer* pUpload, BOOL bStart)
00112 {
00113         CSingleLock pLock( &m_pSection, TRUE );
00114 
00115         ASSERT( pUpload != NULL );
00116 
00117         if ( Check( pUpload->m_pQueue ) )
00118         {
00119                 return pUpload->m_pQueue->GetPosition( pUpload, bStart );
00120         }
00121         else
00122         {
00123                 pUpload->m_pQueue = NULL;
00124                 return -1;
00125         }
00126 }
00127 
00129 // CUploadQueues position stealing
00130 
00131 BOOL CUploadQueues::StealPosition(CUploadTransfer* pTarget, CUploadTransfer* pSource)
00132 {
00133         CSingleLock pLock( &m_pSection, TRUE );
00134 
00135         ASSERT( pTarget != NULL );
00136         ASSERT( pSource != NULL );
00137 
00138         Dequeue( pTarget );
00139 
00140         if ( ! Check( pSource->m_pQueue ) ) return FALSE;
00141 
00142         return pSource->m_pQueue->StealPosition( pTarget, pSource );
00143 }
00144 
00146 // CUploadQueues create and delete queues
00147 
00148 CUploadQueue* CUploadQueues::Create(LPCTSTR pszName, BOOL bTop)
00149 {
00150         CSingleLock pLock( &m_pSection, TRUE );
00151 
00152         CUploadQueue* pQueue = new CUploadQueue();
00153         if ( pszName != NULL ) pQueue->m_sName = pszName;
00154         pQueue->m_bEnable = ! bTop;
00155 
00156         if ( bTop )
00157                 m_pList.AddHead( pQueue );
00158         else
00159                 m_pList.AddTail( pQueue );
00160 
00161         return pQueue;
00162 }
00163 
00164 void CUploadQueues::Delete(CUploadQueue* pQueue)
00165 {
00166         CSingleLock pLock( &m_pSection, TRUE );
00167         if ( ! Check( pQueue ) ) return;
00168         if ( POSITION pos = m_pList.Find( pQueue ) ) m_pList.RemoveAt( pos );
00169         delete pQueue;
00170 }
00171 
00172 BOOL CUploadQueues::Reorder(CUploadQueue* pQueue, CUploadQueue* pBefore)
00173 {
00174         CSingleLock pLock( &m_pSection, TRUE );
00175 
00176         POSITION pos1 = m_pList.Find( pQueue );
00177         if ( pos1 == NULL ) return FALSE;
00178 
00179         if ( pBefore != NULL )
00180         {
00181                 POSITION pos2 = m_pList.Find( pBefore );
00182                 if ( pos2 == NULL || pos1 == pos2 ) return FALSE;
00183                 m_pList.RemoveAt( pos1 );
00184                 m_pList.InsertBefore( pos2, pQueue );
00185         }
00186         else
00187         {
00188                 m_pList.RemoveAt( pos1 );
00189                 m_pList.AddTail( pQueue );
00190         }
00191 
00192         return TRUE;
00193 }
00194 
00196 // CUploadQueues queue selection
00197 
00198 CUploadQueue* CUploadQueues::SelectQueue(PROTOCOLID nProtocol, CLibraryFile* pFile)
00199 {
00200         return SelectQueue( nProtocol, pFile->m_sName, pFile->GetSize(), FALSE, pFile->m_sShareTags );
00201 }
00202 
00203 CUploadQueue* CUploadQueues::SelectQueue(PROTOCOLID nProtocol, CDownload* pFile)
00204 {
00205         return SelectQueue( nProtocol, pFile->m_sRemoteName, pFile->m_nSize, TRUE );
00206 }
00207 
00208 CUploadQueue* CUploadQueues::SelectQueue(PROTOCOLID nProtocol, LPCTSTR pszName, QWORD nSize, BOOL bPartial, LPCTSTR pszShareTags)
00209 {
00210         CSingleLock pLock( &m_pSection, TRUE );
00211         int nIndex = 0;
00212 
00213         for ( POSITION pos = GetIterator() ; pos ; nIndex++ )
00214         {
00215                 CUploadQueue* pQueue = GetNext( pos );
00216                 pQueue->m_nIndex = nIndex;
00217                 if ( pQueue->CanAccept( nProtocol, pszName, nSize, bPartial, pszShareTags ) ) return pQueue;
00218         }
00219 
00220         return NULL;
00221 }
00222 
00224 // CUploadQueues counting
00225 
00226 int CUploadQueues::GetTotalBandwidthPoints( BOOL ActiveOnly )
00227 {
00228         CSingleLock pLock( &m_pSection, TRUE );
00229         int nCount = 0;
00230         CUploadQueue *pQptr;
00231 
00232         for ( POSITION pos = GetIterator() ; pos ; )
00233         {
00234                 pQptr=GetNext( pos );
00235                 if ( ActiveOnly )
00236                 {
00237                         if ( pQptr->m_bEnable )
00238                         {
00239                                 if ( ( ( pQptr->m_nProtocols & ( 1 << PROTOCOL_ED2K ) ) != 0 ) && ( Settings.Connection.RequireForTransfers ) )
00240                                 {
00241                                         if ( ! ( Settings.eDonkey.EnableAlways | Settings.eDonkey.EnableToday ) )
00242                                                 continue;
00243                                 }
00244                         }
00245                         else
00246                                 continue;
00247                 }
00248                 nCount += pQptr->m_nBandwidthPoints;
00249         }
00250 
00251         return nCount;
00252 }
00253 
00254 int CUploadQueues::GetQueueCapacity()
00255 {
00256         CSingleLock pLock( &m_pSection, TRUE );
00257         int nCount = 0;
00258 
00259         for ( POSITION pos = GetIterator() ; pos ; )
00260         {
00261                 nCount += GetNext( pos )->GetQueueCapacity();
00262         }
00263 
00264         return nCount;
00265 }
00266 
00267 int CUploadQueues::GetQueuedCount()
00268 {
00269         CSingleLock pLock( &m_pSection, TRUE );
00270         int nCount = 0;
00271 
00272         for ( POSITION pos = GetIterator() ; pos ; )
00273         {
00274                 nCount += GetNext( pos )->GetQueuedCount();
00275         }
00276 
00277         return nCount;
00278 }
00279 
00280 int CUploadQueues::GetQueueRemaining()
00281 {
00282         CSingleLock pLock( &m_pSection, TRUE );
00283         int nCount = 0;
00284 
00285         for ( POSITION pos = GetIterator() ; pos ; )
00286         {
00287                 nCount += GetNext( pos )->GetQueueRemaining();
00288         }
00289 
00290         return nCount;
00291 }
00292 
00293 int CUploadQueues::GetTransferCount()
00294 {
00295         CSingleLock pLock( &m_pSection, TRUE );
00296         int nCount = 0;
00297 
00298         for ( POSITION pos = GetIterator() ; pos ; )
00299         {
00300                 nCount += GetNext( pos )->GetTransferCount();
00301         }
00302 
00303         return nCount;
00304 }
00305 
00306 BOOL CUploadQueues::IsTransferAvailable()
00307 {
00308         CSingleLock pLock( &m_pSection, TRUE );
00309 
00310         for ( POSITION pos = GetIterator() ; pos ; )
00311         {
00312                 if ( GetNext( pos )->GetAvailableBandwidth() > 0 ) return TRUE;
00313         }
00314 
00315         return FALSE;
00316 }
00317 
00318 DWORD CUploadQueues::GetMinimumDonkeyBandwidth()
00319 {
00320         CSingleLock pLock( &m_pSection, TRUE );
00321 
00322         // Check ED2K ratio limiter
00323         DWORD nTotal = Settings.Connection.OutSpeed * 128;
00324         DWORD nLimit = Settings.Bandwidth.Uploads;
00325         DWORD nDonkeyPoints = 0;
00326         DWORD nTotalPoints = 0;
00327         DWORD nBandwidth = 0;
00328 
00329         if ( nLimit == 0 || nLimit > nTotal ) nLimit = nTotal;
00330 
00331         for ( POSITION pos = GetIterator() ; pos ; )
00332         {
00333                 CUploadQueue* pQueue = GetNext( pos );
00334 
00335                 nTotalPoints += pQueue->m_nBandwidthPoints;
00336 
00337                 if ( pQueue->m_nProtocols == 0 || ( pQueue->m_nProtocols & ( 1 << PROTOCOL_ED2K ) ) != 0 )
00338                         nDonkeyPoints += pQueue->m_nBandwidthPoints;
00339         }
00340 
00341         if ( nTotalPoints < 1 ) nTotalPoints = 1;
00342 
00343 
00344         nBandwidth = nLimit * nDonkeyPoints / nTotalPoints;
00345 
00346         return nBandwidth;
00347 }
00348 
00349 DWORD CUploadQueues::GetCurrentDonkeyBandwidth()
00350 {
00351         CSingleLock pLock( &m_pSection, TRUE );
00352         DWORD nBandwidth = 0;
00353 
00354         for ( POSITION pos = GetIterator() ; pos ; )
00355         {
00356                 CUploadQueue* pQueue = GetNext( pos );
00357 
00358                 if ( pQueue->m_nProtocols == 0 || ( pQueue->m_nProtocols & ( 1 << PROTOCOL_ED2K ) ) != 0 )
00359                         nBandwidth += pQueue->GetBandwidthLimit( pQueue->m_nMaxTransfers );
00360         }
00361 
00362         return nBandwidth;
00363 }
00364 
00365 BOOL CUploadQueues::CanUpload(PROTOCOLID nProtocol, CLibraryFile *pFile, BOOL bCanQueue )
00366 {       // Can the specified file be uploaded with the current queue setup?
00367 
00368         // Don't bother with 0 byte files
00369         if ( pFile->m_nSize == 0 ) return FALSE;
00370 
00371         // Detect Ghosts
00372         if ( pFile->IsGhost() ) return FALSE;
00373 
00374         // G1 and G2 both use HTTP transfers, Sharaza doesn't consider them different.
00375         if ( ( nProtocol == PROTOCOL_G1 ) || ( nProtocol == PROTOCOL_G2 ) )
00376                 nProtocol = PROTOCOL_HTTP;
00377 
00378         CSingleLock pLock( &m_pSection, TRUE );
00379 
00380         //Check each queue
00381         for ( POSITION pos = GetIterator() ; pos ; )
00382         {
00383                 CUploadQueue* pQueue = GetNext( pos );
00384 
00385                 if ( pQueue->CanAccept( nProtocol, pFile->m_sName, pFile->m_nSize, FALSE, pFile->m_sShareTags ) )
00386                 {       // If this queue will accept this file
00387                         if ( ( ! bCanQueue ) || ( pQueue->GetQueueRemaining() > 0 ) )
00388                         {       // And we don't care if there is space now, or the queue isn't full)
00389                                 return TRUE; // Then this file can be uploaded
00390                         }
00391                 }
00392         }
00393 
00394         return FALSE;   //This file is not uploadable with the current queue setup
00395 }
00396 
00397 int CUploadQueues::QueueRank(PROTOCOLID nProtocol, CLibraryFile *pFile )
00398 {       // if the specified file was requested now, what queue position would it be in?
00399         // 0x7FFF (max int) indicates the file cannot be downloaded
00400 
00401 
00402         // Don't bother with 0 byte files
00403         if ( pFile->m_nSize == 0 ) return 0x7FFF;
00404 
00405         // Detect Ghosts
00406         if ( pFile->IsGhost() ) return 0x7FFF;
00407 
00408         // G1 and G2 both use HTTP transfers, Sharaza doesn't consider them different.
00409         if ( ( nProtocol == PROTOCOL_G1 ) || ( nProtocol == PROTOCOL_G2 ) )
00410                 nProtocol = PROTOCOL_HTTP;
00411 
00412         CSingleLock pLock( &m_pSection, TRUE );
00413 
00414         //Check each queue
00415         for ( POSITION pos = GetIterator() ; pos ; )
00416         {
00417                 CUploadQueue* pQueue = GetNext( pos );
00418 
00419                 if ( pQueue->CanAccept( nProtocol, pFile->m_sName, pFile->m_nSize, FALSE, pFile->m_sShareTags ) )
00420                 {       // If this queue will accept this file
00421 
00422                         if ( pQueue->GetQueueRemaining() > 0 )
00423                                 return pQueue->GetQueuedCount();
00424                 }
00425         }
00426 
00427         return 0x7FFF;  //This file is not uploadable with the current queue setup
00428 }
00429 
00431 // CUploadQueues clear
00432 
00433 void CUploadQueues::Clear()
00434 {
00435         CSingleLock pLock( &m_pSection, TRUE );
00436 
00437         for ( POSITION pos = GetIterator() ; pos ; )
00438         {
00439                 delete GetNext( pos );
00440         }
00441 
00442         m_pList.RemoveAll();
00443 }
00444 
00446 // CUploadQueues load and save
00447 
00448 BOOL CUploadQueues::Load()
00449 {
00450         CSingleLock pLock( &m_pSection, TRUE );
00451         CFile pFile;
00452 
00453         LoadString( m_pTorrentQueue->m_sName, IDS_UPLOAD_QUEUE_TORRENT );
00454         LoadString( m_pHistoryQueue->m_sName, IDS_UPLOAD_QUEUE_HISTORY );
00455 
00456         CString strFile = Settings.General.UserPath + _T("\\Data\\UploadQueues.dat");
00457 
00458         if ( ! pFile.Open( strFile, CFile::modeRead ) )
00459         {
00460                 CreateDefault();
00461                 return FALSE;
00462         }
00463 
00464         try
00465         {
00466                 CArchive ar( &pFile, CArchive::load );
00467                 Serialize( ar );
00468                 ar.Close();
00469         }
00470         catch ( CException* pException )
00471         {
00472                 pFile.Close();
00473                 pException->Delete();
00474                 CreateDefault();
00475                 return FALSE;
00476         }
00477 
00478         if ( GetCount() == 0 ) CreateDefault();
00479 
00480         Validate();
00481 
00482         return TRUE;
00483 }
00484 
00485 BOOL CUploadQueues::Save()
00486 {
00487         CSingleLock pLock( &m_pSection, TRUE );
00488         CFile pFile;
00489 
00490         CString strFile = Settings.General.UserPath + _T("\\Data\\UploadQueues.dat");
00491         if ( !pFile.Open( strFile, CFile::modeWrite|CFile::modeCreate ) )
00492                 return FALSE;
00493 
00494         CArchive ar( &pFile, CArchive::store );
00495         Serialize( ar );
00496         ar.Close();
00497 
00498         return TRUE;
00499 }
00500 
00502 // CUploadQueues serialize
00503 
00504 void CUploadQueues::Serialize(CArchive& ar)
00505 {
00506         int nVersion = 5;
00507 
00508         if ( ar.IsStoring() )
00509         {
00510                 ar << nVersion;
00511 
00512                 ar.WriteCount( GetCount() );
00513 
00514                 for ( POSITION pos = GetIterator() ; pos ; )
00515                 {
00516                         GetNext( pos )->Serialize( ar, nVersion );
00517                 }
00518         }
00519         else
00520         {
00521                 Clear();
00522 
00523                 ar >> nVersion;
00524                 if ( nVersion < 2 ) AfxThrowUserException();
00525 
00526                 for ( int nCount = ar.ReadCount() ; nCount > 0 ; nCount-- )
00527                 {
00528                         Create()->Serialize( ar, nVersion );
00529                 }
00530         }
00531 }
00532 
00534 // CUploadQueues create default
00535 
00536 void CUploadQueues::CreateDefault()
00537 {
00538         CSingleLock pLock( &m_pSection, TRUE );
00539 
00540         CUploadQueue* pQueue = NULL;
00541 
00542         Clear();
00543         CString strQueueName;
00544 
00545         if ( Settings.Connection.OutSpeed > 1200 )  // 1200 Kb/s (Massive connection)
00546         {
00547                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_PARTIALS );
00548                 pQueue                                          = Create( strQueueName );
00549                 pQueue->m_nBandwidthPoints      = 40;
00550                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00551                 pQueue->m_bPartial                      = TRUE;
00552                 pQueue->m_nCapacity                     = 2000;
00553                 pQueue->m_nMinTransfers         = 4;
00554                 pQueue->m_nMaxTransfers         = 6;
00555                 pQueue->m_bRotate                       = TRUE;
00556                 pQueue->m_nRotateTime           = 10*60;
00557                 pQueue->m_bRewardUploaders      = TRUE;
00558 
00559                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_CORE );
00560                 pQueue                                          = Create( strQueueName );
00561                 pQueue->m_nBandwidthPoints      = 20;
00562                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00563                 pQueue->m_nCapacity                     = 2000;
00564                 pQueue->m_nMinTransfers         = 2;
00565                 pQueue->m_nMaxTransfers         = 5;
00566                 pQueue->m_bRotate                       = TRUE;
00567                 pQueue->m_nRotateTime           = 10*60;
00568                 pQueue->m_bRewardUploaders      = TRUE;
00569 
00570                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_PARTIAL_FILES );
00571                 pQueue                                          = Create( strQueueName );
00572                 pQueue->m_nBandwidthPoints      = 50;
00573                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00574                 pQueue->m_bPartial                      = TRUE;
00575                 pQueue->m_nMinTransfers         = 4;
00576                 pQueue->m_nMaxTransfers         = 6;
00577                 pQueue->m_bRotate                       = TRUE;
00578                 pQueue->m_nRotateTime           = 5*60;
00579                 pQueue->m_bRewardUploaders      = TRUE;
00580 
00581                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_SMALL_FILES );
00582                 pQueue                                          = Create( strQueueName );
00583                 pQueue->m_nBandwidthPoints      = 10;
00584                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00585                 pQueue->m_nMaxSize                      = 1 * 1024 * 1024;
00586                 pQueue->m_nCapacity                     = 10;
00587                 pQueue->m_nMinTransfers         = 2;
00588                 pQueue->m_nMaxTransfers         = 5;
00589                 pQueue->m_bRewardUploaders      = FALSE;
00590 
00591                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_MEDIUM_FILES );
00592                 pQueue                                          = Create( strQueueName );
00593                 pQueue->m_nBandwidthPoints      = 10;
00594                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00595                 pQueue->m_nMinSize                      = 1  * 1024 * 1024 + 1;
00596                 pQueue->m_nMaxSize                      = 10 * 1024 * 1024 - 1;
00597                 pQueue->m_nCapacity                     = 10;
00598                 pQueue->m_nMinTransfers         = 2;
00599                 pQueue->m_nMaxTransfers         = 5;
00600                 pQueue->m_bRewardUploaders      = FALSE;
00601 
00602                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_LARGE_FILES );
00603                 pQueue                                          = Create( strQueueName );
00604                 pQueue->m_nBandwidthPoints      = 20;
00605                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00606                 pQueue->m_nMinSize                      = 10 * 1024 * 1024;
00607                 pQueue->m_nCapacity                     = 10;
00608                 pQueue->m_nMinTransfers         = 3;
00609                 pQueue->m_nMaxTransfers         = 5;
00610                 pQueue->m_bRotate                       = TRUE;
00611                 pQueue->m_nRotateTime           = 60*60;
00612                 pQueue->m_bRewardUploaders      = FALSE;
00613         }
00614         else if ( Settings.Connection.OutSpeed > 800 )  // 800 Kb/s (Fast Broadband)
00615         {
00616                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_PARTIALS );
00617                 pQueue                                          = Create( strQueueName );
00618                 pQueue->m_nBandwidthPoints      = 40;
00619                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00620                 pQueue->m_bPartial                      = TRUE;
00621                 pQueue->m_nCapacity                     = 2000;
00622                 pQueue->m_nMinTransfers         = 3;
00623                 pQueue->m_nMaxTransfers         = 5;
00624                 pQueue->m_bRotate                       = TRUE;
00625                 pQueue->m_nRotateTime           = 10*60;
00626                 pQueue->m_bRewardUploaders      = TRUE;
00627 
00628                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_CORE );
00629                 pQueue                                          = Create( strQueueName );
00630                 pQueue->m_nBandwidthPoints      = 20;
00631                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00632                 pQueue->m_nCapacity                     = 2000;
00633                 pQueue->m_nMinTransfers         = 2;
00634                 pQueue->m_nMaxTransfers         = 5;
00635                 pQueue->m_bRotate                       = TRUE;
00636                 pQueue->m_nRotateTime           = 10*60;
00637                 pQueue->m_bRewardUploaders      = TRUE;
00638 
00639                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_PARTIAL_FILES );
00640                 pQueue                                          = Create( strQueueName );
00641                 pQueue->m_nBandwidthPoints      = 50;
00642                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00643                 pQueue->m_bPartial                      = TRUE;
00644                 pQueue->m_nMinTransfers         = 3;
00645                 pQueue->m_nMaxTransfers         = 5;
00646                 pQueue->m_bRotate                       = TRUE;
00647                 pQueue->m_nRotateTime           = 5*60;
00648                 pQueue->m_bRewardUploaders      = TRUE;
00649 
00650                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_SMALL_FILES );
00651                 pQueue                                          = Create( strQueueName );
00652                 pQueue->m_nBandwidthPoints      = 10;
00653                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00654                 pQueue->m_nMaxSize                      = 1 * 1024 * 1024;
00655                 pQueue->m_nCapacity                     = 10;
00656                 pQueue->m_nMinTransfers         = 1;
00657                 pQueue->m_nMaxTransfers         = 4;
00658                 pQueue->m_bRewardUploaders      = FALSE;
00659 
00660                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_MEDIUM_FILES );
00661                 pQueue                                          = Create( strQueueName );
00662                 pQueue->m_nBandwidthPoints      = 10;
00663                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00664                 pQueue->m_nMinSize                      = 1  * 1024 * 1024 + 1;
00665                 pQueue->m_nMaxSize                      = 10 * 1024 * 1024 - 1;
00666                 pQueue->m_nCapacity                     = 10;
00667                 pQueue->m_nMinTransfers         = 2;
00668                 pQueue->m_nMaxTransfers         = 4;
00669                 pQueue->m_bRewardUploaders      = FALSE;
00670 
00671                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_LARGE_FILES );
00672                 pQueue                                          = Create( strQueueName );
00673                 pQueue->m_nBandwidthPoints      = 20;
00674                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00675                 pQueue->m_nMinSize                      = 10 * 1024 * 1024;
00676                 pQueue->m_nCapacity                     = 10;
00677                 pQueue->m_nMinTransfers         = 3;
00678                 pQueue->m_nMaxTransfers         = 4;
00679                 pQueue->m_bRotate                       = TRUE;
00680                 pQueue->m_nRotateTime           = 60*60;
00681                 pQueue->m_bRewardUploaders      = FALSE;
00682         }
00683         else if ( Settings.Connection.OutSpeed > 250 )  // >250 Kb/s (Good Broadband)
00684         {
00685                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_PARTIALS );
00686                 pQueue                                          = Create( strQueueName );
00687                 pQueue->m_nBandwidthPoints      = 30;
00688                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00689                 pQueue->m_bPartial                      = TRUE;
00690                 pQueue->m_nCapacity                     = 2000;
00691                 pQueue->m_nMinTransfers         = 2;
00692                 pQueue->m_nMaxTransfers         = 4;
00693                 pQueue->m_bRotate                       = TRUE;
00694                 pQueue->m_nRotateTime           = 10*60;
00695                 pQueue->m_bRewardUploaders      = TRUE;
00696 
00697                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_CORE );
00698                 pQueue                                          = Create( strQueueName );
00699                 pQueue->m_nBandwidthPoints      = 10;
00700                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00701                 pQueue->m_nCapacity                     = 2000;
00702                 pQueue->m_nMinTransfers         = 1;
00703                 pQueue->m_nMaxTransfers         = 4;
00704                 pQueue->m_bRotate                       = TRUE;
00705                 pQueue->m_nRotateTime           = 10*60;
00706                 pQueue->m_bRewardUploaders      = TRUE;
00707 
00708                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_PARTIAL_FILES );
00709                 pQueue                                          = Create( strQueueName );
00710                 pQueue->m_nBandwidthPoints      = 30;
00711                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00712                 pQueue->m_bPartial                      = TRUE;
00713                 pQueue->m_nMinTransfers         = 2;
00714                 pQueue->m_nMaxTransfers         = 4;
00715                 pQueue->m_bRotate                       = TRUE;
00716                 pQueue->m_nRotateTime           = 5*60;
00717                 pQueue->m_bRewardUploaders      = TRUE;
00718 
00719                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_SMALL_FILES );
00720                 pQueue                                          = Create( strQueueName );
00721                 pQueue->m_nBandwidthPoints      = 10;
00722                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00723                 pQueue->m_nMaxSize                      = 10 * 1024 * 1024;
00724                 pQueue->m_nCapacity                     = 8;
00725                 pQueue->m_nMinTransfers         = 2;
00726                 pQueue->m_nMaxTransfers         = 4;
00727                 pQueue->m_bRewardUploaders      = FALSE;
00728 
00729                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_LARGE_FILES );
00730                 pQueue                                          = Create( strQueueName );
00731                 pQueue->m_nBandwidthPoints      = 30;
00732                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00733                 pQueue->m_nMinSize                      = 10 * 1024 * 1024;
00734                 pQueue->m_nMinTransfers         = 3;
00735                 pQueue->m_nMaxTransfers         = 4;
00736                 pQueue->m_nCapacity                     = 10;
00737                 pQueue->m_bRotate                       = TRUE;
00738                 pQueue->m_nRotateTime           = 60*60;
00739                 pQueue->m_bRewardUploaders      = FALSE;
00740         }
00741         else if ( Settings.Connection.OutSpeed > 120 )  // >120 Kb/s (Average Broadband)
00742         {
00743                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_PARTIALS );
00744                 pQueue                                          = Create( strQueueName );
00745                 pQueue->m_nBandwidthPoints      = 30;
00746                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00747                 pQueue->m_bPartial                      = TRUE;
00748                 pQueue->m_nCapacity                     = 2000;
00749                 pQueue->m_nMinTransfers         = 1;
00750                 pQueue->m_nMaxTransfers         = 4;
00751                 pQueue->m_bRotate                       = TRUE;
00752                 pQueue->m_nRotateTime           = 10*60;
00753                 pQueue->m_bRewardUploaders      = TRUE;
00754 
00755                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_CORE );
00756                 pQueue                                          = Create( strQueueName );
00757                 pQueue->m_nBandwidthPoints      = 10;
00758                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00759                 pQueue->m_nCapacity                     = 1000;
00760                 pQueue->m_nMinTransfers         = 1;
00761                 pQueue->m_nMaxTransfers         = 4;
00762                 pQueue->m_bRotate                       = TRUE;
00763                 pQueue->m_nRotateTime           = 10*60;
00764                 pQueue->m_bRewardUploaders      = TRUE;
00765 
00766                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_PARTIAL_FILES );
00767                 pQueue                                          = Create( strQueueName );
00768                 pQueue->m_nBandwidthPoints      = 30;
00769                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00770                 pQueue->m_bPartial                      = TRUE;
00771                 pQueue->m_nMinTransfers         = 2;
00772                 pQueue->m_nMaxTransfers         = 4;
00773                 pQueue->m_bRotate                       = TRUE;
00774                 pQueue->m_nRotateTime           = 5*60;
00775                 pQueue->m_bRewardUploaders      = TRUE;
00776 
00777                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_COMPLETE );
00778                 pQueue                                          = Create( strQueueName );
00779                 pQueue->m_nBandwidthPoints      = 40;
00780                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00781                 pQueue->m_nMinTransfers         = 2;
00782                 pQueue->m_nMaxTransfers         = 4;
00783                 pQueue->m_nCapacity                     = 10;
00784                 pQueue->m_bRotate                       = TRUE;
00785                 pQueue->m_nRotateTime           = 60*60;
00786                 pQueue->m_bRewardUploaders      = FALSE;
00787         }
00788         else if ( Settings.Connection.OutSpeed > 50 ) // >50 Kb/s (Slow Broadband/ISDN)
00789         {
00790                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_CORE );
00791                 pQueue                                          = Create( strQueueName );
00792                 pQueue->m_nBandwidthPoints      = 20;
00793                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00794                 pQueue->m_nCapacity                     = 500;
00795                 pQueue->m_nMinTransfers         = 1;
00796                 pQueue->m_nMaxTransfers         = 3;
00797                 pQueue->m_bRotate                       = TRUE;
00798                 pQueue->m_nRotateTime           = 30*60;
00799                 pQueue->m_bRewardUploaders      = TRUE;
00800 
00801                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_PARTIAL_FILES );
00802                 pQueue                                          = Create( strQueueName );
00803                 pQueue->m_nBandwidthPoints      = 20;
00804                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00805                 pQueue->m_bPartial                      = TRUE;
00806                 pQueue->m_nCapacity                     = 8;
00807                 pQueue->m_nMinTransfers         = 1;
00808                 pQueue->m_nMaxTransfers         = 3;
00809                 pQueue->m_bRotate                       = TRUE;
00810                 pQueue->m_nRotateTime           = 20*60;
00811                 pQueue->m_bRewardUploaders      = TRUE;
00812 
00813                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_COMPLETE );
00814                 pQueue                                          = Create( strQueueName );
00815                 pQueue->m_nBandwidthPoints      = 20;
00816                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00817                 pQueue->m_nCapacity                     = 8;
00818                 pQueue->m_nMinTransfers         = 2;
00819                 pQueue->m_nMaxTransfers         = 3;
00820                 pQueue->m_bRotate                       = TRUE;
00821                 pQueue->m_nRotateTime           = 20*60;
00822                 pQueue->m_bRewardUploaders      = FALSE;
00823         }
00824         else  // <50 Kb/s (Dial up modem)
00825         {
00826                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_CORE );
00827                 pQueue                                          = Create( strQueueName );
00828                 pQueue->m_nBandwidthPoints      = 20;
00829                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00830                 pQueue->m_bPartial                      = TRUE;
00831                 pQueue->m_nCapacity                     = 500;
00832                 pQueue->m_nMinTransfers         = 1;
00833                 pQueue->m_nMaxTransfers         = 2;
00834                 pQueue->m_bRotate                       = TRUE;
00835                 pQueue->m_nRotateTime           = 30*60;
00836                 pQueue->m_bRewardUploaders      = TRUE;
00837 
00838                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_QUEUE );
00839                 pQueue                                          = Create( strQueueName );
00840                 pQueue->m_nBandwidthPoints      = 30;
00841                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00842                 pQueue->m_nCapacity                     = 5;
00843                 pQueue->m_nMinTransfers         = 1;
00844                 pQueue->m_nMaxTransfers         = 2;
00845                 pQueue->m_bRotate                       = TRUE;
00846                 pQueue->m_nRotateTime           = 20*60;
00847                 pQueue->m_bRewardUploaders      = FALSE;
00848         }
00849 
00850         Save();
00851 }
00852 
00854 // CUploadQueues validate
00855 
00856 void CUploadQueues::Validate()
00857 {
00858         CString strQueueName;
00859         if ( SelectQueue( PROTOCOL_ED2K, _T("Filename"), 0x00A00000, TRUE ) == NULL &&
00860                  SelectQueue( PROTOCOL_ED2K, _T("Filename"), 0x03200000, TRUE ) == NULL &&
00861                  SelectQueue( PROTOCOL_ED2K, _T("Filename"), 0x1F400000, TRUE ) == NULL )
00862         {
00863                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_ED2K_GUARD );
00864                 CUploadQueue* pQueue            = Create( strQueueName );
00865                 pQueue->m_nProtocols            = (1<<PROTOCOL_ED2K);
00866                 pQueue->m_nMaxTransfers         = 5;
00867                 pQueue->m_bRotate                       = TRUE;
00868 
00869                 if ( Settings.Connection.OutSpeed > 100 )
00870                 {
00871                         pQueue->m_nMinTransfers         = 2;
00872                         pQueue->m_nBandwidthPoints      = 30;
00873                         pQueue->m_nCapacity                     = 2000;
00874                         pQueue->m_nRotateTime           = 10*60;
00875                         pQueue->m_bRewardUploaders      = TRUE;
00876                 }
00877                 else
00878                 {
00879                         pQueue->m_nMinTransfers         = 1;
00880                         pQueue->m_nBandwidthPoints      = 20;
00881                         pQueue->m_nCapacity                     = 500;
00882                         pQueue->m_nRotateTime           = 30*60;
00883                         pQueue->m_bPartial                      = TRUE;
00884                         pQueue->m_bRewardUploaders      = TRUE;
00885                 }
00886         }
00887 
00888         if ( SelectQueue( PROTOCOL_HTTP, _T("Filename"), 0x00A00000, TRUE ) == NULL &&
00889                  SelectQueue( PROTOCOL_HTTP, _T("Filename"), 0x03200000, TRUE ) == NULL &&
00890                  SelectQueue( PROTOCOL_HTTP, _T("Filename"), 0x1F400000, TRUE ) == NULL )
00891         {
00892                 LoadString ( strQueueName, IDS_UPLOAD_QUEUE_HTTP_GUARD );
00893                 CUploadQueue* pQueue            = Create( strQueueName );
00894                 pQueue->m_nProtocols            = (1<<PROTOCOL_HTTP);
00895                 pQueue->m_nMaxTransfers         = 5;
00896                 pQueue->m_bRotate                       = TRUE;
00897 
00898                 if ( Settings.Connection.OutSpeed > 100 )
00899                 {
00900                         pQueue->m_nMinTransfers         = 2;
00901                         pQueue->m_nBandwidthPoints      = 30;
00902                         pQueue->m_nCapacity                     = 10;
00903                         pQueue->m_nRotateTime           = 10*60;
00904                 }
00905                 else
00906                 {
00907                         pQueue->m_nMinTransfers         = 1;
00908                         pQueue->m_nBandwidthPoints      = 20;
00909                         pQueue->m_nCapacity                     = 5;
00910                         pQueue->m_nRotateTime           = 30*60;
00911                 }
00912         }
00913 
00914         if ( GetMinimumDonkeyBandwidth() < 10240 )
00915         {
00916                 m_bDonkeyLimited = TRUE;
00917         }
00918         else
00919         {
00920                 m_bDonkeyLimited = FALSE;
00921         }
00922 
00923         // Display warning if needed
00924         if ( Settings.eDonkey.EnableToday || Settings.eDonkey.EnableAlways )
00925         {
00926                 if ( m_bDonkeyLimited ) 
00927                         theApp.Message( MSG_SYSTEM, _T("eDonkey upload ratio active- Low upload may slow downloads.")  );
00928                 else
00929                         theApp.Message( MSG_DEBUG, _T("eDonkey upload ratio is OK.")  );
00930         }
00931 
00932 }
00933 

Generated on Thu Dec 15 10:39:50 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2