void CDownloadQueue::CheckDiskspace( const CPath& path )
{
	if ( ::GetTickCount() - m_lastDiskCheck < DISKSPACERECHECKTIME ) {
		return;
	}
	
	m_lastDiskCheck = ::GetTickCount();

	uint64 min = 0;
	// Check if the user has set an explicit limit
	if ( thePrefs::IsCheckDiskspaceEnabled() ) {
		min = thePrefs::GetMinFreeDiskSpace();
	}

	// The very least acceptable diskspace is a single PART
	if ( min < PARTSIZE ) {
		min = PARTSIZE;
	}

	uint64 free = CPath::GetFreeSpaceAt(path);
	if (free == static_cast<uint64>(wxInvalidOffset)) {
		return;
	} else if (free < min) {
		CUserEvents::ProcessEvent(
			CUserEvents::OutOfDiskSpace,
			wxT("Temporary partition"));
	}
	
	for (unsigned int i = 0; i < m_filelist.size(); ++i) {
		CPartFile* file = m_filelist[i];
		
		switch ( file->GetStatus() ) {
			case PS_ERROR:
			case PS_COMPLETING:
			case PS_COMPLETE:
				continue;
		}
	
		if ( free >= min && file->GetInsufficient() ) {
			// We'll try to resume files if there is enough free space
			if ( free - file->GetNeededSpace() > min ) {
				file->ResumeFile();
			}
		} else if ( free < min && !file->IsPaused() ) {
			// No space left, stop the files.
			file->PauseFile( true );
		}
	}
}
Exemple #2
0
void CMMServer::ProcessFileCommand(CMMData* data, CMMSocket* sender){
	uint8 byCommand = data->ReadByte();
	uint8 byFileIndex = data->ReadByte();
	if (byFileIndex >= m_SentFileList.GetSize()
		|| !theApp.downloadqueue->IsPartFile(m_SentFileList[byFileIndex]))
	{
		CMMPacket* packet = new CMMPacket(MMP_GENERALERROR);
		sender->SendPacket(packet);
		ASSERT ( false );
		return;		
	}
	CPartFile* selFile = m_SentFileList[byFileIndex];
	switch (byCommand){
		case MMT_PAUSE:
			selFile->PauseFile();
			break;
		case MMT_RESUME:
			selFile->ResumeFile();
			break;
		case MMT_CANCEL:{
			switch(selFile->GetStatus()) { 
				case PS_WAITINGFORHASH: 
				case PS_HASHING: 
				case PS_COMPLETING: 
				case PS_COMPLETE:  
					break;
				case PS_PAUSED:
					selFile->DeleteFile(); 
					break;
				default:
                    theApp.downloadqueue->StartNextFileIfPrefs(selFile->GetCategory());
					selFile->DeleteFile(); 
			}
			break;
		}
		default:
			CMMPacket* packet = new CMMPacket(MMP_GENERALERROR);
			sender->SendPacket(packet);
			return;
	}
	CMMPacket* packet = new CMMPacket(MMP_FILECOMMANDANS);
	ProcessFileListRequest(sender,packet); 

}
BOOL CFeedIcoItemListCtrl::OnCommand(WPARAM wParam, LPARAM lParam)
{
	// TODO: 在此添加专用代码和/或调用基类

	if (  /*LOWORD(wParam) == MP_STOP
		||*/LOWORD(wParam) == MP_DOWNLOAD_ALL
		||LOWORD(wParam) == MP_OPEN
		||LOWORD(wParam) == MP_OPENFOLDER
		||LOWORD(wParam) == MP_RESUME
		||LOWORD(wParam) == MP_PAUSE
		||LOWORD(wParam) == MP_CANCEL
		||LOWORD(wParam) == MP_OPTIONS)
	{
		POSITION Pos = this->GetFirstSelectedItemPosition();
		if (Pos == NULL)
		{
			return 0;
		}
		int nIndex = this->GetNextSelectedItem(Pos);

		if( CRssFeed* pFeed = this->GetFeed(nIndex) )
		{
			if ( LOWORD(wParam) == MP_OPENFOLDER)
			{
				if( CRssFeed* pFeed = this->GetFeed(nIndex) )
				{
					if(PathFileExists(pFeed->m_strSaveDir))
						ShellExecute(NULL, _T("open"), _T("explorer.exe"), pFeed->m_strSaveDir, NULL, SW_SHOW);
				}
			}

			if ( LOWORD(wParam) == MP_DOWNLOAD_ALL )
			{
				((CRssFeedWnd*)GetParent())->DownloadAllItem(nIndex);
			}
			if ( LOWORD(wParam) == MP_RESUME )
			{
				((CRssFeedWnd*)GetParent())->ResumeAllItem(nIndex);
			}
			if ( LOWORD(wParam) == MP_PAUSE)
			{
				for ( CRssFeed::ItemIterator it = pFeed->GetItemIterBegin();
					it != pFeed->GetItemIterEnd();
					++it
					)
				{
					CPartFile* pPartFile = it->second.GetPartFile();
					if (pPartFile != NULL)
					{
						if (pPartFile->CanPauseFile())
							pPartFile->PauseFile();		
					}
				}
			}

			if ( LOWORD(wParam) == MP_CANCEL)
			{
				::SendMessage(CGlobalVariable::s_wndRssCtrl->GetSafeHwnd(), WM_COMMAND, wParam, lParam);
			}

			if ( LOWORD(wParam) == MP_OPTIONS)
			{
				CDlgFeedConfig dlgFeedConfig(*pFeed);
				if ( dlgFeedConfig.DoModal() == IDOK )
				{
					// 保存设置
					pFeed->SetUpdateInterval(dlgFeedConfig.m_uUpdateInterval);
					pFeed->SetAutoDownload(dlgFeedConfig.m_uAutoDownload);
					CGlobalVariable::s_wndRssCtrl->SaveFeed(*pFeed);
					//RedrawItems(nIndex, nIndex);
				}
			}

			CDownloadTabWnd & wd = theApp.emuledlg->m_mainTabWnd.m_dlgDownload.m_DownloadTabWnd;
			UpdateToolBarState(wd.m_Toolbar);

			return 0;
		}
	}

	::SendMessage(CGlobalVariable::s_wndRssCtrl->GetSafeHwnd(), WM_COMMAND, wParam, lParam);
	
	return CListCtrl::OnCommand(wParam, lParam);
}