harvester/monitorplugins/mmcplugin/src/mmcfilelist.cpp
changeset 0 c53acadfccc6
child 1 acef663c1218
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <driveinfo.h>
       
    19 #include <e32msgqueue.h>
       
    20 
       
    21 #include "mmcfilelist.h"
       
    22 #include "mmcmounttaskao.h"
       
    23 #include "harvesterlog.h"
       
    24 #include "mdsfileserverpluginclient.h"
       
    25 #include "mdeharvestersession.h"
       
    26 #include "mdsutils.h"
       
    27 #include "fsutil.h"
       
    28 #include "harvestercenreputil.h"
       
    29 #include "harvestereventmanager.h"
       
    30 #include <placeholderdata.h>
       
    31 #include <harvesterdata.h>
       
    32 #include "harvesterpluginfactory.h"
       
    33 
       
    34 _LIT( KBackslash, "\\");
       
    35 
       
    36 const TInt KEntryBufferSize = 100;
       
    37 
       
    38 CMmcFileList::CMmcFileList() : iHem( NULL ), iMediaIdUtil( NULL )
       
    39 	{
       
    40 	}
       
    41 
       
    42 CMmcFileList* CMmcFileList::NewL()
       
    43 	{
       
    44 	CMmcFileList* self = new ( ELeave ) CMmcFileList();
       
    45 	CleanupStack::PushL( self );
       
    46 	self->ConstructL();
       
    47 	CleanupStack::Pop( self );
       
    48 	return self;
       
    49 	}
       
    50 
       
    51 void CMmcFileList::ConstructL()
       
    52 	{
       
    53 	iHem = CHarvesterEventManager::GetInstanceL();
       
    54 	iMediaIdUtil = &RMediaIdUtil::GetInstanceL();
       
    55 	}
       
    56 
       
    57 CMmcFileList::~CMmcFileList()
       
    58 	{
       
    59 	if( iHem )
       
    60 		{
       
    61 		iHem->ReleaseInstance();
       
    62 		}
       
    63 	RMediaIdUtil::ReleaseInstance();
       
    64 	}
       
    65 
       
    66 TBool CMmcFileList::IsDescInArray(const TPtrC& aSearch, const RPointerArray<HBufC>& aArray)
       
    67 	{
       
    68 	const TInt count = aArray.Count();
       
    69 	
       
    70 	for( TInt i = 0; i < count; i++ )
       
    71 		{
       
    72 		TInt result = MdsUtils::Compare( aSearch, aArray[i]->Des() );
       
    73 		
       
    74 		if( result == 0 )
       
    75 			{
       
    76 			return ETrue;
       
    77 			}
       
    78 		}
       
    79 
       
    80 	return EFalse;
       
    81 	}
       
    82 
       
    83 void CMmcFileList::BuildFileListL( RFs& aFs, const TDesC& aDrivePath, 
       
    84 		RPointerArray<CPlaceholderData>& aEntryArray )
       
    85 	{
       
    86 	WRITELOG( "CMmcFileList::BuildFileListL - start" );
       
    87 	CDesCArrayFlat* path = new(ELeave) CDesCArrayFlat( 8 );
       
    88 	CleanupStack::PushL( path );
       
    89 	TFileName firstPath;
       
    90 	firstPath.Copy( aDrivePath );
       
    91 	firstPath.Append( KBackslash );
       
    92 	path->AppendL( firstPath );
       
    93 
       
    94 	TUint32 mediaId( 0 );
       
    95 	iMediaIdUtil->GetMediaId( aDrivePath, mediaId );
       
    96 	
       
    97 	WRITELOG1( "CMmcFileList::BuildFileListL - mediaId: %d", mediaId );
       
    98 	
       
    99 	RPointerArray<HBufC> ignorePaths;
       
   100 	TCleanupItem cleanupItem( MdsUtils::CleanupPtrArray<HBufC>, &ignorePaths );
       
   101     CleanupStack::PushL( cleanupItem );
       
   102     
       
   103     CHarvesterCenRepUtil::GetIgnorePathL( ignorePaths );
       
   104 	
       
   105     CDir* directory = NULL;
       
   106     TFileName name; 
       
   107     
       
   108 	while ( path->Count() > 0 )
       
   109 		{
       
   110 		TInt error = aFs.GetDir( (*path)[0], KEntryAttDir, KHarvesterGetDirFlags, directory );
       
   111 		if ( error == KErrNone )
       
   112 			{
       
   113 			for ( TInt i=0; i < directory->Count(); ++i )
       
   114 				{
       
   115 				TEntry entry = (*directory)[i];
       
   116 				name.Zero();
       
   117 				name.Append( (*path)[0] );
       
   118 				// If filename is too long, skip it as the file cannot be supported
       
   119 				if( (name.Length() + entry.iName.Length()) > KMaxFileName )
       
   120 				    {
       
   121 				    continue;
       
   122 				    }
       
   123 				else
       
   124 				    {
       
   125 				    name.Append( entry.iName );     
       
   126 				    }
       
   127 			
       
   128 				if ( entry.IsDir() )
       
   129 					{
       
   130 					// If path is too long, skip it as the file cannot be supported
       
   131 	                if( name.Length() >= KMaxPath )
       
   132 	                    {
       
   133 	                    continue;
       
   134 	                    }
       
   135 	                else
       
   136 	                    {
       
   137 					    name.Append( KBackslash );
       
   138 	                    }
       
   139 					
       
   140 					// remove drive letter and colon from path
       
   141 					TPtrC pathOnly = name.Mid( 2 );
       
   142 					
       
   143 					if ( IsDescInArray( pathOnly, ignorePaths ) )
       
   144 						{
       
   145 						continue;
       
   146 						}
       
   147 
       
   148 					path->AppendL( name );
       
   149 					}
       
   150 				else
       
   151 					{
       
   152 					CPlaceholderData* phData = CPlaceholderData::NewL();
       
   153 					CleanupStack::PushL( phData );
       
   154 					phData->SetUri( name );
       
   155 					phData->SetModified( entry.iModified );
       
   156 					phData->SetFileSize( entry.iSize );
       
   157 					
       
   158 				    phData->SetMediaId( mediaId );
       
   159 #ifdef _DEBUG					
       
   160 					TBuf<256> debug;
       
   161 					debug.Copy( name );
       
   162 					WRITELOG1("CMmcFileList::BuildFileListL - Uri: %S", &debug );
       
   163 #endif
       
   164 					aEntryArray.AppendL( phData );
       
   165 					CleanupStack::Pop( phData );
       
   166 					}
       
   167 				}
       
   168 			}
       
   169 		path->Delete( 0 );
       
   170 		delete directory;
       
   171 		directory = NULL;
       
   172 		}
       
   173 	
       
   174 	CleanupStack::PopAndDestroy( &ignorePaths );
       
   175 	
       
   176 	CleanupStack::PopAndDestroy( path );
       
   177 	
       
   178 	WRITELOG( "CMmcFileList::BuildFileListL - end" );
       
   179 	}
       
   180 
       
   181 void CMmcFileList::HandleFileEntryL( CMdEHarvesterSession& aMdeSession,
       
   182 		RPointerArray<CPlaceholderData>& aEntryArray, 
       
   183 		RPointerArray<CPlaceholderData>& aHarvestEntryArray,
       
   184 		TUint32 aMediaID, CHarvesterPluginFactory* aPluginFactory )
       
   185 	{
       
   186 	WRITELOG( "CMmcFileList::HandleFileEntryL()" );
       
   187 	
       
   188 	// calculate batch size
       
   189 	TInt batchSize( 0 );
       
   190 	if ( aEntryArray.Count() >= KEntryBufferSize )
       
   191 		{
       
   192 		batchSize = KEntryBufferSize;
       
   193 		}
       
   194 	else
       
   195 		{
       
   196 		batchSize = aEntryArray.Count();
       
   197 		}
       
   198 
       
   199 #ifdef _DEBUG
       
   200 	WRITELOG2( "CMmcFileList::HandleFileEntryL() batchSize = %d, aEntryArray.Count() = %d", batchSize, aEntryArray.Count() );
       
   201 #endif
       
   202 	
       
   203 	RArray<TPtrC> uris;
       
   204 	RArray<TMdSFileInfo> fileInfos;
       
   205 	CleanupClosePushL( uris );
       
   206 	CleanupClosePushL( fileInfos );
       
   207 	
       
   208 	uris.ReserveL( batchSize );
       
   209 	fileInfos.ReserveL( batchSize );
       
   210 
       
   211 	for ( TInt i = 0; i < batchSize; i++ )
       
   212 		{
       
   213 		CPlaceholderData* e = aEntryArray[i];
       
   214 		
       
   215 		TPtr uriPtr = e->Uri();
       
   216 		TPtrC uriPtrC;
       
   217 		uriPtrC.Set( uriPtr.Ptr(), uriPtr.Length() );
       
   218 		uris.Append( uriPtr );
       
   219 
       
   220 		TMdSFileInfo fileInfo;
       
   221 		fileInfo.iModifiedTime = e->Modified().Int64();
       
   222 		fileInfo.iSize = e->FileSize();
       
   223 		fileInfos.Append( fileInfo );
       
   224 		}
       
   225 	
       
   226 	RArray<TFilePresentStates> results;
       
   227 	CleanupClosePushL( results );
       
   228 
       
   229 	WRITELOG( "CMmcFileList::HandleFileEntryL -- SetFilesToPresent start" );
       
   230 	aMdeSession.SetFilesToPresentL( aMediaID, uris, fileInfos, results );
       
   231 	WRITELOG( "CMmcFileList::HandleFileEntryL -- SetFilesToPresent end" );
       
   232 
       
   233 	for ( TInt i = 0; i < batchSize; i++ )
       
   234 		{
       
   235 		CPlaceholderData* e = aEntryArray[ 0 ];
       
   236 		aEntryArray.Remove( 0 );
       
   237 		CleanupStack::PushL( e );
       
   238 
       
   239 		TFilePresentStates found = results[ i ];
       
   240 
       
   241 		if ( found == EMdsNotFound )
       
   242 			{
       
   243 			if ( aPluginFactory && !aPluginFactory->IsSupportedFileExtension( e->Uri() ) )
       
   244 				{
       
   245 				iHem->DecreaseItemCountL( EHEObserverTypeMMC, 1 );
       
   246 				CleanupStack::PopAndDestroy( e );
       
   247 				continue;
       
   248 				}
       
   249 			e->SetPresentState( found );
       
   250 			aHarvestEntryArray.AppendL( e );
       
   251 			CleanupStack::Pop( e );
       
   252 			}
       
   253 		else if( found == EMdsPlaceholder )
       
   254 			{
       
   255 			e->SetPresentState( found );
       
   256 			aHarvestEntryArray.AppendL( e );
       
   257 			CleanupStack::Pop( e );
       
   258 			}
       
   259 		else if( found == EMdsModified )
       
   260 			{
       
   261 			e->SetPresentState( found );
       
   262 			aHarvestEntryArray.AppendL( e );
       
   263 			CleanupStack::Pop( e );
       
   264 			}
       
   265 		else
       
   266 			{
       
   267 			iHem->DecreaseItemCountL( EHEObserverTypeMMC, 1 );
       
   268 			CleanupStack::PopAndDestroy( e );
       
   269 			}
       
   270 		}
       
   271 	
       
   272 	if( aEntryArray.Count() == 0 )
       
   273 		{
       
   274 		aEntryArray.Compress();
       
   275 		}
       
   276 	
       
   277 	WRITELOG( "CMmcFileList::HandleFileEntryL -- cleanupstack" );
       
   278 	CleanupStack::PopAndDestroy( &results );
       
   279 	CleanupStack::PopAndDestroy( &fileInfos );
       
   280 	CleanupStack::PopAndDestroy( &uris );
       
   281 	WRITELOG( "CMmcFileList::HandleFileEntryL -- end" );
       
   282 	}