Esempio n. 1
0
void CFileCommentsPage::OnOK()
{
	UpdateData();
	m_sComments.Trim();

	CLibraryListPtr pFiles( GetList() );

	if ( ! pFiles || pFiles->GetCount() == 1 )
	{
		CQuickLock oLock( Library.m_pSection );

		if ( CLibraryFile* pFile = GetFile() )
		{
			pFile->m_nRating	= m_nRating;
			pFile->m_sComments	= m_sComments;

			pFile->ModifyMetadata();
			Library.Update();
		}
	}
	else
	{
		CQuickLock oLock( Library.m_pSection );

		for ( POSITION pos = pFiles->GetHeadPosition(); pos; )
		{
			if ( CLibraryFile* pFile = pFiles->GetNextFile( pos ) )
				pFile->m_nRating = m_nRating;
		}

		Library.Update();
	}

	CFilePropertiesPage::OnOK();
}
Esempio n. 2
0
BOOL CFileCommentsPage::OnInitDialog()
{
	CFilePropertiesPage::OnInitDialog();

	CLibraryListPtr pFiles( GetList() );
	if ( ! pFiles ) return TRUE;

	if ( pFiles->GetCount() == 1 )
	{
		CQuickLock oLock( Library.m_pSection );

		CLibraryFile* pFile = GetFile();
		if ( pFile == NULL ) return TRUE;

		m_nRating	= pFile->m_nRating;
		m_sComments	= pFile->m_sComments;
	}
	else
	{
		m_wndComments.EnableWindow( FALSE );

		CQuickLock oLock( Library.m_pSection );

		for ( POSITION pos = pFiles->GetHeadPosition(); pos; )
		{
			if ( CLibraryFile* pFile = pFiles->GetNextFile( pos ) )
				m_nRating = pFile->m_nRating;
		}
	}

	UpdateData( FALSE );

	return TRUE;
}
void CFileMetadataPage::OnOK()
{
	CLibraryList* pFiles = GetList();
	if ( pFiles == NULL ) return;

	if ( pFiles->GetCount() >= 10 )
	{
		CString strFormat, strMessage;
		LoadString( strFormat, IDS_LIBRARY_METADATA_MANY );
		strMessage.Format( strFormat, pFiles->GetCount() );
		if ( AfxMessageBox( strMessage, MB_YESNO|MB_ICONQUESTION ) != IDYES ) return;
	}

	if ( CSchema* pSchema = m_wndSchemas.GetSelected() )
	{
		CQuickLock oLock( Library.m_pSection );

		for ( POSITION pos1 = pFiles->GetIterator() ; pos1 ; )
		{
			if ( CLibraryFile* pFile = pFiles->GetNextFile( pos1 ) )
			{
				if ( pSchema->Equals( pFile->m_pSchema ) && pFile->m_pMetadata != NULL )
				{
					CXMLElement* pContainer	= pSchema->Instantiate( TRUE );
					CXMLElement* pXML		= pContainer->AddElement( pFile->m_pMetadata->Clone() );
					m_wndData.UpdateData( pXML, TRUE );
					if ( pContainer ) pFile->SetMetadata( pContainer );
					delete pContainer;
				}
				else
				{
					CXMLElement* pContainer	= pSchema->Instantiate( TRUE );
					CXMLElement* pXML		= pContainer->AddElement( pSchema->m_sSingular );
					m_wndData.UpdateData( pXML, TRUE );
					if ( pContainer ) pFile->SetMetadata( pContainer );
					delete pContainer;
				}
			}
		}
	}
	else
	{
		CQuickLock oLock( Library.m_pSection );

		for ( POSITION pos1 = pFiles->GetIterator() ; pos1 ; )
		{
			if ( CLibraryFile* pFile = pFiles->GetNextFile( pos1 ) )
			{
				pFile->SetMetadata( NULL );
			}
		}

		Library.Update();
	}

	CFilePropertiesPage::OnOK();
}
Esempio n. 4
0
void CLibraryMetaPanel::OnLButtonUp(UINT nFlags, CPoint point)
{
	point.y += GetScrollPos( SB_VERT );

	if ( m_nSelected > 0 && m_rcFolder.PtInRect( point ) )
	{
		CQuickLock oLock( Library.m_pSection );

		if ( CLibraryFolder* pFolder = LibraryFolders.GetFolder( m_sFolder ) )
		{
			if ( Settings.Library.ShowVirtual )
			{
				CLibraryFrame* pFrame = (CLibraryFrame*)GetOwner();
				ASSERT_KINDOF(CLibraryFrame, pFrame );
				pFrame->Display( pFolder );
			}
			else if ( LibraryFolders.CheckFolder( pFolder, TRUE ) )
			{
				ShellExecute( AfxGetMainWnd()->GetSafeHwnd(), NULL,
					m_sFolder, NULL, NULL, SW_SHOWNORMAL );
			}
		}
	}
	else if ( m_nSelected > 0 && m_rcRating.PtInRect( point ) )
	{
		CLibraryListPtr pList( GetViewSelection() );

		if ( pList && pList->GetCount() > 0 )
		{
			CFilePropertiesSheet dlg;
			dlg.Add( pList );
			dlg.DoModal( 2 );
		}
	}
	else if ( CMetaItem* pItem = m_pMetadata->HitTest( point, TRUE ) )
	{
		CQuickLock oLock( Library.m_pSection );

		if ( CAlbumFolder* pFolder = pItem->GetLinkTarget() )
		{
			CLibraryFrame* pFrame = (CLibraryFrame*)GetOwner();
			ASSERT_KINDOF(CLibraryFrame, pFrame );
			pFrame->Display( pFolder );
		}
	}

	CPanelCtrl::OnLButtonUp( nFlags, point );
}
Esempio n. 5
0
void CLibraryTileView::SelectTo(int nDelta)
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 250 ) ) return;

	if ( empty() ) return;

	iterator pFocus = m_pFocus;

	if ( pFocus == end() )
	{
		pFocus = begin();
	}
	else if ( nDelta < 0 )
	{
		for ( ; nDelta != 0 && pFocus != begin(); --pFocus, ++nDelta );
	}
	else
	{
		for ( ; nDelta != 0 && pFocus != end(); ++pFocus, --nDelta );
		if ( pFocus == end() )
			--pFocus;
	}

	if ( SelectTo( pFocus ) )
		Invalidate();
}
Esempio n. 6
0
HICON CShellIcons::ExtractIcon(int nIndex, int nSize)
{
	CQuickLock oLock( m_pSection );

	HICON hIcon;
	switch ( nSize )
	{
	case 16:
		hIcon = m_i16.ExtractIcon( nIndex );
		break;
//	case 24:
//		hIcon = m_i24.ExtractIcon( nIndex );
//		break;
	case 32:
		hIcon = m_i32.ExtractIcon( nIndex );
		break;
	case 48:
		hIcon = m_i48.ExtractIcon( nIndex );
		break;
	default:
		ASSERT( FALSE );
		return NULL;
	}

	if ( Settings.General.LanguageRTL )
		hIcon = CreateMirroredIcon( hIcon );

	return hIcon;
}
STDMETHODIMP CHtmlCollection::XView::Hover(BSTR sURN)
{
    METHOD_PROLOGUE(CHtmlCollection, View)
    CQuickLock oLock( Library.m_pSection );
    CLibraryCollectionView* pView = pThis->m_pView;

    if ( pView->m_bLockdown )
        return S_OK;

    if ( pView->m_pWebCtrl == NULL )
        return S_OK;

    if ( pView->GetFrame() == NULL )
        return S_OK;

    pView->m_nWebIndex = 0;

    if ( sURN && *sURN )	// wcslen
    {
        if ( CLibraryFile* pFile = LibraryMaps.LookupFileByURN( CString( sURN ) ) )
        {
            pView->m_nWebIndex = pFile->m_nIndex;
        }
    }

    if ( pView->m_nWebIndex != 0 )
        pView->GetToolTip()->Show( pView->m_nWebIndex, pView->m_pWebCtrl->GetSafeHwnd() );
    else
        pView->GetToolTip()->Hide();

    return S_OK;
}
Esempio n. 8
0
    void cancel()
    {
        boost::mutex::scoped_lock oLock( _sentinel );

        _cancel = true;
        std::cout << "cancel is true." << std::endl;
    }
Esempio n. 9
0
bool xaeSound::load_resource_from_snd(string path)
{
    /** 锁定临界区 */
    xaeResourceObject::LockScope oLock(*this);
    path = xaeResourceMgrObject::path_to_upper(path);

    /** 置零 */
    if(0 != m_hChannel) m_pHGE->Channel_Stop(m_hChannel);
    if(0 != m_hEffect) m_pHGE->Effect_Free(m_hEffect);
    m_hChannel = 0;
    m_hEffect = 0;

    m_hEffect = _get_effect(path);
    /** 创建纹理失败 */
    if(0 == m_hEffect)
    {
        m_pHGE->System_Log("[!] Sound [%s] can't be created.", path.c_str());

        /** 跳出临界区 */

        return false;
    }
    m_szPath = path;

    /** 跳出临界区 */

    return true;
}
Esempio n. 10
0
void xaeSound::release()
{
    xaeResourceObject::LockScope oLock(*this);
    ::LockScope oScope(_eff_cs);
    if(0 != m_hChannel) m_pHGE->Channel_Stop(m_hChannel);
    map<string, _eff_time>::iterator it;
    for(it = _hEffect.begin(); it != _hEffect.end(); it++)
    {
        if(it->second.eff == m_hEffect)
        {
            it->second.time--;
            if(it->second.time == 0)
            {
                if(0 != m_hEffect)
                {
                    /** 释放音效句柄 */
                    m_pHGE->Effect_Free(m_hEffect);

                    /** 释放内存资源 */
                    xae::Instance().get_resource_mgr()->free_resource(it->first);
                }
                _hEffect.erase(it);
            }
            break;
        }
    }
    m_hChannel = 0;
    m_hEffect = 0;
}
void CFileSharingPage::OnOK()
{
    UpdateData();

    if ( CLibraryList* pList = GetList() )
    {
        CQuickLock oLock( Library.m_pSection );

        for ( POSITION pos = pList->GetIterator() ; pos ; )
        {
            if ( CLibraryFile* pFile = pList->GetNextFile( pos ) )
            {
                if ( m_bOverride )
                {
                    pFile->m_bShared = m_bShare ? TS_TRUE : TS_FALSE;
                }
                else
                {
                    pFile->m_bShared = TS_UNKNOWN;
                }

                pFile->m_sShareTags = m_sTags;
            }
        }

    }

    CFilePropertiesPage::OnOK();
}
Esempio n. 12
0
int clsAsyncPipeMng::GetIdlePipeIdx(uint32_t &iIdx, uint64_t iEntityID)
{
    clsThreadLock oLock(&m_oMutex);

    int iGroupID = m_poCertain->GetCertainUser()->GetControlGroupID(iEntityID);
    if (iGroupID != -1 && m_aiGroupCnt[iGroupID] >= m_iMaxGroupLimit)
    {
        return eRetCodeNoGroupIdlePipe;
    }

    if (m_tIdleIdxList.empty())
    {
        return eRetCodeNoIdlePipe;
    }

    iIdx = m_tIdleIdxList.front();
    m_tIdleIdxList.pop_front();

    if (iGroupID != -1)
    {
        assert(m_aiEntityIDMap[iIdx] == INVALID_ENTITY_ID);
        m_aiEntityIDMap[iIdx] = iEntityID;
        m_aiGroupCnt[iGroupID]++;
    }

    return 0;
}
Esempio n. 13
0
void CLibraryTileView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	CSingleLock oLock( &Library.m_pSection );
	if ( oLock.Lock( 200 ) )
	{
		if ( _istalnum( TCHAR( nChar ) ) )
		{
			iterator pStart = m_pFocus;

			for ( int nLoop = 0; nLoop < 2; nLoop++ )
			{
				for ( iterator pChild = begin(); pChild != end(); ++pChild )
				{
					if ( pStart != end() )
					{
						if ( pStart == pChild )
							pStart = end();
					}
					else if ( toupper( (*pChild)->GetTitle().GetAt( 0 ) ) == toupper( (int)nChar ) )
					{
						DeselectAll( m_pFocus = pChild );
						Select( m_pFocus, TRI_TRUE );
						Highlight( m_pFocus );
						Invalidate();
						return;
					}
				}
			}
		}
	}

	CLibraryView::OnChar( nChar, nRepCnt, nFlags );
}
Esempio n. 14
0
bool CLibraryTileView::GetItemRect(iterator pTile, CRect* pRect)
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 200 ) )
		return false;

	CRect rcClient;
	GetClientRect( &rcClient );

	CPoint pt( rcClient.left, rcClient.top - m_nScroll );

	for ( iterator pItem = begin(); pItem != end(); ++pItem )
	{
		CRect rcBlock( pt.x, pt.y, pt.x + m_szBlock.cx, pt.y + m_szBlock.cy );

		if ( pTile == pItem )
		{
			*pRect = rcBlock;
			return true;
		}

		pt.x += m_szBlock.cx;

		if ( pt.x + m_szBlock.cx > rcClient.right )
		{
			pt.x = rcClient.left;
			pt.y += m_szBlock.cy;
		}
	}

	return false;
}
Esempio n. 15
0
void CLibraryTileView::UpdateScroll()
{
	if ( m_nColumns == 0 )
		return;

	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 200 ) )
		return;

	CRect rc;
	GetClientRect( &rc );

	SCROLLINFO pInfo = {};
	pInfo.cbSize	= sizeof( pInfo );
	pInfo.fMask		= SIF_ALL & ~SIF_TRACKPOS;
	pInfo.nMin		= 0;
	pInfo.nMax		= (int)( ( size() + m_nColumns - 1 ) / m_nColumns ) * m_szBlock.cy;
	pInfo.nPage		= rc.Height();
	pInfo.nPos		= m_nScroll = max( 0, min( m_nScroll, pInfo.nMax - (int)pInfo.nPage + 1 ) );

	SetScrollInfo( SB_VERT, &pInfo, TRUE );

	oLock.Unlock();

	Invalidate();
}
Esempio n. 16
0
void rhoPlainLogArgW(const char* file, int line, int severity, const char* szCategory,
                     const wchar_t* format, va_list ap )
{
    rho::LogMessage oLogMsg(file, line, severity, LOGCONF(), rho::LogCategory(szCategory) );

    if ( oLogMsg.isEnabled() )
    {
        rho::common::CMutexLock oLock(g_plainBufferLock);

        int buflen = sizeof(g_plainBuffer)/2-1;
        wchar_t* buf = (wchar_t*)g_plainBuffer;

        int len = vswnprintf(buf, buflen, format, ap);

        if (len < 0 || len >= buflen){
#ifdef OS_SYMBIAN
            len = buflen - 1;
#else
            len = buflen;
#endif
        }
        buf[len] = 0;

        oLogMsg + buf;
    }
}
Esempio n. 17
0
BOOL CSearchManager::OnQueryHits(const CQueryHit* pHits)
{
	CSingleLock oLock( &m_pSection );
	if ( ! oLock.Lock( 150 ) )
	{
		theApp.Message( MSG_ERROR | MSG_FACILITY_SEARCH, _T("Rejecting query hit operation, search manager overloaded.") );
		return FALSE;
	}

	if ( CSearchPtr pSearch = Find( pHits->m_oSearchID ) )
	{
		pSearch->OnHostAcknowledge( *(DWORD*)&pHits->m_pAddress );

		while ( pHits != NULL )
		{
		// Specific network hitcounts, if needed:
		//	if ( pHits->m_nProtocol == PROTOCOL_G2 )
		//		pSearch->m_nG2Hits++;
		//	else if ( pHits->m_nProtocol == PROTOCOL_G1 )
		//		pSearch->m_nG1Hits++;
		//	else if ( pHits->m_nProtocol == PROTOCOL_ED2K )
		//		pSearch->m_nEDHits++;
		//	else if ( pHits->m_nProtocol == PROTOCOL_DC )
		//		pSearch->m_nDCHits++;

			pSearch->m_nHits ++;
			pHits = pHits->m_pNext;
		}

		return FALSE;
	}

	return TRUE;	// Route it
}
Esempio n. 18
0
BOOL CFilesProfilePage::OnInitDialog()
{
	CSettingsPage::OnInitDialog();

	CRect rc;
	m_wndList.GetClientRect( &rc );
	rc.right -= GetSystemMetrics( SM_CXVSCROLL ) + 1;
	m_wndList.InsertColumn( 0, _T("File"), LVCFMT_LEFT, rc.right, -1 );
	ShellIcons.AttachTo( &m_wndList, 16 );	// m_wndList.SetImageList()

	{
		CQuickLock oLock( Library.m_pSection );

		CAlbumFolder* pFolder = LibraryFolders.GetAlbumTarget( CSchema::uriFavouritesFolder, _T("Title"), NULL );
		if ( pFolder != NULL )
		{
			for ( POSITION pos = pFolder->GetFileIterator() ; pos ; )
			{
				CLibraryFile* pFile = pFolder->GetNextFile( pos );

				if ( pFile->IsShared() )
				{
					m_wndList.InsertItem( LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM, m_wndList.GetItemCount(),
						pFile->m_sName, 0, 0, ShellIcons.Get( pFile->GetPath(), 16 ), pFile->m_nIndex );
				}
			}
		}
	}

	UpdateData( FALSE );

	return TRUE;
}
Esempio n. 19
0
void CBTClients::Add(CBTClient* pClient)
{
	CQuickLock oLock( m_pListSection );

	ASSERT( m_pList.Find( pClient ) == NULL );
	m_pList.AddHead( pClient );
}
Esempio n. 20
0
void CLocalSearch::DispatchPacket(CPacket* pPacket)
{
	if ( ! pPacket )
		return;

	if ( m_pBuffer )
	{
		pPacket->ToBuffer( m_pBuffer );
	}
	else if ( m_bUDP )
	{
		Datagrams.Send( &m_pEndpoint, pPacket, FALSE );
	}
	else
	{
		CQuickLock oLock( Network.m_pSection );
		if ( CNeighbour* pNeighbour = Neighbours.Get( m_pEndpoint.sin_addr ) )
		{
			if ( pNeighbour->m_nProtocol == m_nProtocol )
			{
				pNeighbour->Send( pPacket, FALSE, TRUE );
			}
		}
	}

	pPacket->Release();
}
BOOL CLibraryCollectionView::CheckAvailable(CLibraryTreeItem* pSel)
{
    BOOL bAvailable = FALSE;

    CQuickLock oLock( Library.m_pSection );

    if ( CAlbumFolder* pFolder = GetSelectedAlbum( pSel ) )
    {
        if ( pFolder->m_oCollSHA1 )
        {
            if ( LibraryMaps.LookupFileBySHA1( pFolder->m_oCollSHA1, FALSE, TRUE ) )
            {
                bAvailable = TRUE;
            }
            else
            {
                pFolder->m_oCollSHA1.clear();
                Library.Update();
            }
        }
    }

    if ( bAvailable != m_bAvailable )
    {
        m_bAvailable = bAvailable;
        m_bLockdown = FALSE;
    }

    return m_bAvailable;
}
void CLibraryDetailView::OnGetDispInfoA(NMLVDISPINFO* pNotify, LRESULT* pResult)
{
	*pResult = 0;
	
	LDVITEM* pItem = &m_pList[ pNotify->item.iItem ];
	
	if ( pNotify->item.mask & LVIF_STATE )
	{
		pNotify->item.state &= ~LVIS_SELECTED;
		if ( pItem->nState & LDVI_SELECTED ) pNotify->item.state |= LVIS_SELECTED;
	}
	
	if ( pItem->nCookie != m_nListCookie )
	{
		{
			CSingleLock oLock( &Library.m_pSection );
			if ( !oLock.Lock( 100 ) ) return;
			CacheItem( pNotify->item.iItem );
		}
		if ( pItem->nCookie != m_nListCookie ) return;
	}
	
	if ( pNotify->item.mask & LVIF_TEXT )
	{
		if ( pNotify->item.iSubItem < pItem->pText->GetSize() )
		{
			WideCharToMultiByte( CP_ACP, 0, pItem->pText->GetAt( pNotify->item.iSubItem ), -1, (LPSTR)pNotify->item.pszText, pNotify->item.cchTextMax, NULL, NULL );
		}
	}
	
	if ( pNotify->item.mask & LVIF_IMAGE )
	{
		pNotify->item.iImage = pItem->nIcon;
	}
}
STDMETHODIMP CHtmlCollection::XView::Enqueue(BSTR sURN, VARIANT_BOOL *pbResult)
{
    METHOD_PROLOGUE(CHtmlCollection, View)
    *pbResult = VARIANT_FALSE;
    CSingleLock oLock( &Library.m_pSection, TRUE );
    CLibraryCollectionView* pView = pThis->m_pView;

    if ( pView->m_bLockdown )
        return S_OK;

    if ( sURN && *sURN )
    {
        if ( pView->m_pCollection->FindByURN( CString( sURN ) ) != NULL )
        {
            if ( CLibraryFile* pFile = LibraryMaps.LookupFileByURN( CString( sURN ), FALSE, TRUE ) )
            {
                CString strPath = pFile->GetPath();
                oLock.Unlock();
                *pbResult = CFileExecutor::Enqueue( strPath ) ? VARIANT_TRUE : VARIANT_FALSE;
            }
        }
    }

    return S_OK;
}
void CLibraryDetailView::OnEndLabelEditA(LV_DISPINFO* pNotify, LRESULT* pResult)
{
	*pResult = 0;
	
	if ( pNotify->item.pszText && *pNotify->item.pszText )
	{
		CSingleLock oLock( &Library.m_pSection, TRUE );
		if ( CLibraryFile* pFile = Library.LookupFile( m_pList[ pNotify->item.iItem ].nIndex ) )
		{
			m_pList[ pNotify->item.iItem ].nState &= ~LDVI_SELECTED;
			CString strName = (LPCSTR)pNotify->item.pszText;
			LPCTSTR pszType = _tcsrchr( pFile->m_sName, '.' );
			if ( pszType ) strName += pszType;
			*pResult = pFile->Rename( strName );
			Library.Update();
			oLock.Unlock();
			
			if ( *pResult == FALSE )
			{
				CString strFormat, strMessage, strError = theApp.GetErrorString();
				LoadString( strFormat, IDS_LIBRARY_RENAME_FAIL );
				strMessage.Format( strFormat, (LPCTSTR)pFile->m_sName, (LPCTSTR)strName );
				strMessage += _T("\r\n\r\n") + strError;
				AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
			}
		}
	}
	
	m_bEditing = FALSE;
}
Esempio n. 25
0
int CLocalSearch::ExecuteSharedFiles(int nMaximum)
{
	CQuickLock oLock( Library.m_pSection );
	CPtrList* pFiles = Library.Search( m_pSearch, nMaximum );
	if ( pFiles == NULL ) return 0;

	int nHits = pFiles->GetCount();

	while ( pFiles->GetCount() )
	{
		int nInThisPacket = min( pFiles->GetCount(), (int)Settings.Gnutella.HitsPerPacket );

		CreatePacket( nInThisPacket );

        int nHitB = 0;
		for ( int nHitA = 0 ; nHitA < nInThisPacket ; nHitA++ )
		{
			CLibraryFile* pFile = (CLibraryFile*)pFiles->RemoveHead();
			if ( AddHit( pFile, nHitB ) ) nHitB ++;
		}

		WriteTrailer();
		if ( nHitB > 0 ) DispatchPacket(); else DestroyPacket();
	}

	delete pFiles;

	return nHits;
}
void CLibraryDetailView::OnFindItemA(NMLVFINDITEM* pNotify, LRESULT* pResult)
{
	USES_CONVERSION;
	LPCTSTR pszFind = A2CT( (LPCSTR)pNotify->lvfi.psz );
	
	GET_LIST();
	CQuickLock oLock( Library.m_pSection );

	for ( int nLoop = 0 ; nLoop < 2 ; nLoop++ )
	{
		for ( int nItem = pNotify->iStart ; nItem < pList->GetItemCount() ; nItem++ )
		{
			if ( CLibraryFile* pFile = Library.LookupFile( m_pList[ nItem ].nIndex ) )
			{
				if ( pNotify->lvfi.flags & LVFI_STRING )
				{
					if ( _tcsnicmp( pszFind, pFile->m_sName, _tcslen( pszFind ) ) == 0 )
					{
						*pResult = nItem;
						return;
					}
				}
			}
		}
		pNotify->iStart = 0;
	}

	*pResult = -1;
}
BOOL CUploadTransferED2K::OpenFile()
{
	ASSERT( m_nState == upsRequest || m_nState == upsUploading );
	ASSERT( m_pBaseFile != NULL );
	
	if ( m_pDiskFile != NULL ) return TRUE;
	m_pDiskFile = TransferFiles.Open( m_sFilePath, FALSE, FALSE );
	
	if ( m_pDiskFile != NULL )
	{
		CQuickLock oLock( Library.m_pSection );
		if ( CLibraryFile* pFile = LibraryMaps.LookupFileByPath( m_sFilePath, TRUE, TRUE ) )
		{
			pFile->m_nUploadsToday++;
			pFile->m_nUploadsTotal++;
		}
		
		return TRUE;
	}
	
	theApp.Message( MSG_ERROR, IDS_UPLOAD_CANTOPEN, (LPCTSTR)m_sFileName, (LPCTSTR)m_sAddress );	
	
	CEDPacket* pReply = CEDPacket::New( ED2K_C2C_FILENOTFOUND );
	pReply->Write( &m_pED2K, sizeof(MD4) );
	Send( pReply );
	
	Cleanup();
	Close();
	
	return FALSE;
}
Esempio n. 28
0
bool CEDClients::IsFull(const CEDClient* pCheckThis)
{
	CQuickLock oLock( m_pSection );

	// Count the number of connected clients
	DWORD nCount = 0;
	for ( CEDClient* pClient = m_pFirst ; pClient ; pClient = pClient->m_pEdNext )
	{
		if ( pClient->IsValid() )
			++nCount;
	}

	// Get current time
	const DWORD tNow = GetTickCount();

	// If there are more clients current connected than there should be, set full timer
	if ( nCount >= Settings.eDonkey.MaxLinks )
		m_tLastMaxClients = tNow;

	// If we have not been full in the past 2 seconds, then we're okay to start new connections
	if ( tNow - m_tLastMaxClients > 2ul * 1000ul )
		return false;

	// If we're checking a client that's already connected, say we aren't full. (don't drop it)
	if ( pCheckThis && pCheckThis->IsValid() )
		return false;

	// We're too full to start new connections
	return true;
}
Esempio n. 29
0
CString	CShellIcons::GetName(LPCTSTR pszType)
{
	CString strType( pszType );
	strType.MakeLower();

	CQuickLock oLock( m_pSection );

	CString strName;
	if ( ! m_Name.Lookup( strType, strName ) )
	{
		Lookup( pszType, &strName, NULL, NULL, NULL, NULL );

		if ( strName.IsEmpty() )
		{
			if ( *pszType )
				strName = pszType + 1;	// Use extension without dot
			else
				strName = LoadString( IDS_STATUS_UNKNOWN );
		}

		m_Name.SetAt( strType, strName );
	}

	return strName;
}
Esempio n. 30
0
void CLibraryTileView::OnLibraryAlbumProperties()
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 250 ) )
	{
		// Retry
		PostMessage( WM_COMMAND, ID_LIBRARY_ALBUM_PROPERTIES );
		return;
	}

	if ( m_oSelTile.empty() )
		return;

	const_iterator pTile = m_oSelTile.front();
	if ( CAlbumFolder* pFolder = (*pTile)->GetAlbum() )
	{
		CFolderPropertiesDlg dlg( NULL, pFolder );

		oLock.Unlock();

		if ( dlg.DoModal() == IDOK )
		{
			if ( oLock.Lock( 250 ) )
			{
				if ( CAlbumFolder* pFolder = (*pTile)->GetAlbum() )
				{
					GetFrame()->Display( pFolder );
				}
			}
		}
	}
}