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;
}
Esempio n. 3
0
bool CLocalSearch::ExecuteSharedFiles(INT_PTR nMaximum, INT_PTR& nHits)
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 250 ) )
		return false;

	auto_ptr< CFileList > pFiles( Library.Search(
		m_pSearch, nMaximum, FALSE,
		// Ghost files only for G2
		m_nProtocol != PROTOCOL_G2 ) );

	if ( pFiles.get() )
	{
		CFileList oFilesInPacket;

		for ( POSITION pos = pFiles->GetHeadPosition() ;
			pos && ( ! nMaximum || ( nHits + oFilesInPacket.GetCount() < nMaximum ) ); )
		{
			CLibraryFile* pFile = pFiles->GetNext( pos );

			if ( IsValidForHit( pFile ) )
			{
				oFilesInPacket.AddTail( pFile );
			}
		}

		SendHits( oFilesInPacket );

		nHits += oFilesInPacket.GetCount();
	}

	// Is it a browser request?
	if ( ! m_pSearch && m_nProtocol == PROTOCOL_G2 )
	{
		// Send virtual tree		
		DispatchPacket( AlbumToPacket( Library.GetAlbumRoot() ) );

		// Send physical tree
		DispatchPacket( FoldersToPacket() );
	}

	return true;
}
Esempio n. 4
0
void CLibraryFrame::UpdatePanel(BOOL bForce)
{
	CQuickLock oLock( Library.m_pSection );

	if ( ! bForce && ! m_bViewSelection )
		return;

	m_bViewSelection = FALSE;
	m_pViewSelection = HasView() ? m_pView->GetSelection() : m_pViewEmpty;

	if ( m_bPanelShow )
	{
		CLibraryTreeItem* pFolders = m_wndTree.GetFirstSelected();
		CLibraryListPtr pFiles( GetViewSelection() );

		BOOL bMetaPanelAvailable = ( pFolders != NULL );
		BOOL bHistoryPanelAvailable = ( LibraryHistory.GetCount() > 0 );

		// Do not display any panel for the collection folder
		if ( pFolders && pFolders->m_pVirtual && pFolders->m_pVirtual->m_oCollSHA1 )
			bMetaPanelAvailable = bHistoryPanelAvailable = FALSE;

		// Prefer history panel if no files selected for meta panel
		if ( bMetaPanelAvailable && bHistoryPanelAvailable && pFiles && pFiles->GetCount() <= 0 )
			bMetaPanelAvailable = FALSE;

		CPanelCtrl* pBestPanel = bMetaPanelAvailable ?
			static_cast< CPanelCtrl* >( &m_pMetaPanel ) : ( bHistoryPanelAvailable ?
			static_cast< CPanelCtrl* >( &m_pHistoryPanel ) : NULL );

		if ( ! HasPanel() || m_pPanel != pBestPanel )
			SetPanel( pBestPanel );
		else
			SetPanel( m_pPanel );
	}
}
// Given path to folder of compressed bit files, go over all the files and put them in a a map
// data structure as described above.
void PopulateMaps(boost::filesystem::path libPath, TiletypeElementMap &outTileMap,
	std::vector<ElementConfigMap> &outElemMapVector, std::vector<ConfigBitMap> &outConfigMapVector) {

	// Go over all the files in the directory
	boost::filesystem::directory_iterator eFiles;
	boost::filesystem::directory_iterator pFiles(libPath);
	while(pFiles != eFiles) {

		// If it is a compressed bit file (.cbit extension)
		if(pFiles->path().extension() == ".cbit") {

			std::ifstream libBitFile(pFiles->path().string().c_str(), std::ios::binary);
			if(!libBitFile.good()) {
				std::cerr << "ERROR: Could not open micro-bitstream file " << pFiles->path().string() << std::endl;
				return;
			}

			// Get number of bits set and put the bit addresses in a vector
			int32_t numSetBits, bitAddr;
			libBitFile.read((char *) &numSetBits, 4);
			std::cout << pFiles->path().filename() <<  " opened. Bit count " << numSetBits << std::endl;
			std::vector<uint32_t> bitAddresses;
			for(int i = 0; i < numSetBits && !libBitFile.eof(); i++) {
				libBitFile.read((char *) &bitAddr, 4);
				bitAddresses.push_back(bitAddr);
			}

			// Get the file name without extension and split the name to get tile name, element/source wire and config/sink wire.
			boost::filesystem::path filePath(pFiles->path());
			std::string fileName(filePath.replace_extension().filename());

			std::vector<std::string> splitVector;
			boost::algorithm::split(splitVector, fileName, boost::algorithm::is_any_of(kNameSeparator));
			for(std::vector<std::string>::const_iterator splitIter = splitVector.begin(); splitIter
				!= splitVector.end(); splitIter++) {
				std::cout << "   " << *splitIter << std::endl;

			}

			// Get the tile type, element(source wire) and config (sink wire)from the split string
			std::string tileType(splitVector[1]);
			std::string element(splitVector[2]);
			std::string config(splitVector[3]);

			// if tile not found in map, a new tile type has come up. Add it to the map.
			// Create another map for Element-config and push it in vector so that it is not destroyed.
			if(outTileMap.find(tileType) == outTileMap.end()) {
				ElementConfigMap elementConfigMap;
				outElemMapVector.push_back(elementConfigMap);
				outTileMap[tileType] = outElemMapVector.back();
			}

			// if the element in the tile doesn't exist
			if(outTileMap[tileType].find(element) == outTileMap[tileType].end()) {
				ConfigBitMap configBitmap;
				outConfigMapVector.push_back(configBitmap);
				outTileMap[tileType][element] = outConfigMapVector.back();
			}

			// Mapping the config to bit addresses
			outTileMap[tileType][element][config] = bitAddresses;

		}

		pFiles++;
	}
}