mmappcomponents/harvester/filehandler/src/mpxharvesterfilehandlerimp.cpp
changeset 27 cbb1bfb7ebfb
parent 25 d881023c13eb
child 32 edd273b3192a
equal deleted inserted replaced
25:d881023c13eb 27:cbb1bfb7ebfb
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Handles all file related activities
    14 * Description:  Handles all file related activities
    15 *  Version     : %version: da1mmcf#72.1.14.2.4.1.4.1.2.5.1 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: da1mmcf#72.1.14.2.4.1.4.1.2.5.2 % << Don't touch! Updated by Synergy at check-out.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include <e32base.h>
    20 #include <e32base.h>
    21 #include <f32file.h>
    21 #include <f32file.h>
    22 #include <centralrepository.h>
    22 #include <centralrepository.h>
    23 #ifdef RD_MULTIPLE_DRIVE
       
    24 #include <pathinfo.h>
    23 #include <pathinfo.h>
    25 #include <driveinfo.h>
    24 #include <driveinfo.h>
    26 #endif //RD_MULTIPLE_DRIVE
       
    27 
    25 
    28 #include <mpxlog.h>
    26 #include <mpxlog.h>
    29 #include <mpxharvestercommon.h>
    27 #include <mpxharvestercommon.h>
    30 #include <mpxmedia.h>
    28 #include <mpxmedia.h>
    31 #include <mpxmediaarray.h>
    29 #include <mpxmediaarray.h>
   122     //
   120     //
   123     iDBManager = CMPXHarvesterDatabaseManager::NewL( iFs );
   121     iDBManager = CMPXHarvesterDatabaseManager::NewL( iFs );
   124     
   122     
   125     // List of watchers for different drives
   123     // List of watchers for different drives
   126     //
   124     //
   127 #ifdef RD_MULTIPLE_DRIVE
       
   128     TDriveList driveList;
   125     TDriveList driveList;
   129     TInt driveCount(0);
   126     TInt driveCount(0);
   130     User::LeaveIfError( DriveInfo::GetUserVisibleDrives(
   127     User::LeaveIfError( DriveInfo::GetUserVisibleDrives(
   131            iFs, driveList, driveCount ) );
   128            iFs, driveList, driveCount ) );
   132 
   129 
   139             CleanupStack::PushL( dw );
   136             CleanupStack::PushL( dw );
   140             iDiskMonitors.AppendL( dw );
   137             iDiskMonitors.AppendL( dw );
   141             CleanupStack::Pop( dw );
   138             CleanupStack::Pop( dw );
   142             }
   139             }
   143         }
   140         }
   144 #else
       
   145     CMPXDiskSpaceWatcher* dw_e = CMPXDiskSpaceWatcher::NewL( iFs, EDriveE, *this );
       
   146     CleanupStack::PushL( dw_e );
       
   147     iDiskMonitors.AppendL( dw_e );
       
   148     CleanupStack::Pop( dw_e );
       
   149     CMPXDiskSpaceWatcher* dw_c = CMPXDiskSpaceWatcher::NewL( iFs, EDriveC, *this );
       
   150     CleanupStack::PushL( dw_c );
       
   151     iDiskMonitors.AppendL( dw_c );
       
   152     CleanupStack::Pop( dw_c );
       
   153 #endif // RD_MULTIPLE_DRIVE
       
   154    
       
   155 
   141 
   156     TInt openerr = iDBManager->OpenAllDatabasesL();
   142     TInt openerr = iDBManager->OpenAllDatabasesL();
   157     
   143     
   158     // Temporary collection utility
   144     // Temporary collection utility
   159     //
   145     //
   185     colUtil->Close();
   171     colUtil->Close();
   186 
   172 
   187     // Get the scan drives from cenrep.
   173     // Get the scan drives from cenrep.
   188     //
   174     //
   189     ParseScanPathL();
   175     ParseScanPathL();
       
   176     RefreshScanDrivesL();
   190 
   177 
   191     // Get the list of container types
   178     // Get the list of container types
   192     iContainerTypes = new(ELeave) CDesCArrayFlat(2);  // granularity
   179     iContainerTypes = new(ELeave) CDesCArrayFlat(2);  // granularity
   193     ParseContainersL();
   180     ParseContainersL();
   194 
   181 
   211         }
   198         }
   212 
   199 
   213     // Create the database synchronizer
   200     // Create the database synchronizer
   214     iDbSynchronizer = CMPXDbSynchronizer::NewL(*this,*iDBManager,iMusicCollectionId,
   201     iDbSynchronizer = CMPXDbSynchronizer::NewL(*this,*iDBManager,iMusicCollectionId,
   215                                                iPodcastCollectionId,iFs, iDisablePodcasting);
   202                                                iPodcastCollectionId,iFs, iDisablePodcasting);
   216 
       
   217 #ifdef RD_MULTIPLE_DRIVE
       
   218     // Use default MMC drive as the Removable drive
       
   219     User::LeaveIfError( DriveInfo::GetDefaultDrive(
       
   220         DriveInfo::EDefaultRemovableMassStorage,
       
   221         iRemovedDrive ) );
       
   222 #endif
       
   223 
   203 
   224     // Create DRM Notifier and register for AddRemove event
   204     // Create DRM Notifier and register for AddRemove event
   225     iDrmNotifier = CDRMNotifier::NewL();
   205     iDrmNotifier = CDRMNotifier::NewL();
   226     iDrmNotifier->RegisterEventObserverL( *this, KEventAddRemove );
   206     iDrmNotifier->RegisterEventObserverL( *this, KEventAddRemove );
   227     iCurUSBEvent = KErrNotFound;
   207     iCurUSBEvent = KErrNotFound;
   268         {
   248         {
   269         iContainerTypes->Reset();
   249         iContainerTypes->Reset();
   270         }
   250         }
   271     delete iContainerTypes;
   251     delete iContainerTypes;
   272 
   252 
   273     iFilteredDrivesToScan.Reset();
       
   274     iFilteredDrivesToScan.Close();
   253     iFilteredDrivesToScan.Close();
   275     iDrivesToScan.Reset();
       
   276     iDrivesToScan.Close();
   254     iDrivesToScan.Close();
   277     iPathsToBlock.Reset();
   255     iConfiguredDrivesToScan.Close();
   278     iPathsToBlock.Close();
   256     iPathsToBlock.Close();
   279 
   257 
   280     // Cleans up the scanning tables and arrays
   258     // Cleans up the scanning tables and arrays
   281     Reset();
   259     Reset();
   282 
   260 
   335         return;
   313         return;
   336         }
   314         }
   337    
   315    
   338     iCollectionUtil->Collection().NotifyL( EMcMsgRefreshStart, KErrNone );
   316     iCollectionUtil->Collection().NotifyL( EMcMsgRefreshStart, KErrNone );
   339 
   317 
   340     // Reopen databases
       
   341     iDBManager->OpenAllDatabasesL();
       
   342 
       
   343     // Begin transaction on databases
   318     // Begin transaction on databases
   344     iDBManager->BeginL();
   319     iDBManager->BeginL();
   345     
   320     
   346     //Remove out of disk space drives from scanned drives list
   321     //Remove out of disk space drives from scanned drives list
   347     iFilteredDrivesToScan.Reset();
   322     iFilteredDrivesToScan.Reset();
       
   323     iFilteredOutOfDisk = EFalse;
   348     CopyArrayL(iDrivesToScan.Array(),iFilteredDrivesToScan);
   324     CopyArrayL(iDrivesToScan.Array(),iFilteredDrivesToScan);
   349 
   325 
   350     iOutOfDisk = EFalse;
   326     iOutOfDisk = EFalse;
   351     TInt driveCount (iDiskMonitors.Count());
   327     TInt driveCount (iDiskMonitors.Count());
   352     TBool outOfDisk(EFalse);
   328     TBool outOfDisk(EFalse);
   369                 TFileName driveName(fileNameParser.Drive());
   345                 TFileName driveName(fileNameParser.Drive());
   370                 TInt driveNumber = TDriveUnit( driveName );
   346                 TInt driveNumber = TDriveUnit( driveName );
   371                 if (currentDriveNumber == driveNumber)
   347                 if (currentDriveNumber == driveNumber)
   372                     {
   348                     {
   373                     iFilteredDrivesToScan.Remove(index);
   349                     iFilteredDrivesToScan.Remove(index);
       
   350                     iFilteredOutOfDisk = ETrue;
   374                     count--;
   351                     count--;
   375                     }
   352                     }
   376                 else
   353                 else
   377                     {
   354                     {
   378                     index++;
   355                     index++;
   379                     }
   356                     }
   380                 }
   357                 }
   381             TRAP_IGNORE(iDBManager->RemoveDatabaseL(static_cast<TDriveNumber>(currentDriveNumber)));
   358             iDBManager->CloseDatabase(static_cast<TDriveNumber>(currentDriveNumber));
   382             }
   359             }
   383         }
   360         }
   384 
   361 
   385     iSynchronizing = CheckDbInSyncL();
   362     iSynchronizing = CheckDbInSyncL();
   386 
   363 
   436     // 2: Format end and disk insert we reopen db and scan for new files
   413     // 2: Format end and disk insert we reopen db and scan for new files
   437     // 3: USB start we stop scan and close all db
   414     // 3: USB start we stop scan and close all db
   438     // 4: USB end we re-open all db and scan for new files
   415     // 4: USB end we re-open all db and scan for new files
   439     // 5: MTP start we stop monitoring for new files (no dismount)
   416     // 5: MTP start we stop monitoring for new files (no dismount)
   440     // 6: MTP end we re-open all db, files added already, restart monitor
   417     // 6: MTP end we re-open all db, files added already, restart monitor
   441     //
   418     // 7: Disk dismount: stop scanning, close the dismounting DB
   442 #ifdef RD_MULTIPLE_DRIVE
   419     //
   443     // Get all visible drives
   420     // Get all visible drives
   444     TDriveList driveList;
   421     TDriveList driveList;
   445     TInt driveCount(0);
   422     TInt driveCount(0);
   446     TPtrC drivePresent(_L("present"));
   423     TPtrC drivePresent(_L("present"));
   447     TPtrC driveNotPresent(_L("not present"));
   424     TPtrC driveNotPresent(_L("not present"));
   470                 (driveStatus&DriveInfo::EDrivePresent)?&drivePresent:&driveNotPresent,
   447                 (driveStatus&DriveInfo::EDrivePresent)?&drivePresent:&driveNotPresent,
   471                 (driveStatus&DriveInfo::EDriveInUse)?&driveInUse:&driveAvailable,
   448                 (driveStatus&DriveInfo::EDriveInUse)?&driveInUse:&driveAvailable,
   472                 (driveStatus&DriveInfo::EDriveFormatted)?&driveFormatted:&driveNotFormatted);
   449                 (driveStatus&DriveInfo::EDriveFormatted)?&driveFormatted:&driveNotFormatted);
   473             }
   450             }
   474         }
   451         }
   475 #endif //RD_MULTIPLE_DRIVE
   452 
   476     switch( aEvent )
   453     switch( aEvent )
   477         {
   454         {
   478         case EFormatStartEvent:
   455         case EFormatStartEvent:
   479             {
   456             {
   480             MPX_DEBUG1("Disk Format start event");
   457             MPX_DEBUG2("Disk Format start event, drive %d", aData);
       
   458             iIdle->Cancel();
   481             CancelScan();
   459             CancelScan();
   482             iDBManager->CloseDatabase( (TDriveNumber) aData );
   460             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   461             RefreshScanDrivesL();
   483             break;
   462             break;
   484             }
   463             }
   485         case EDiskRemovedEvent:
   464         case EDiskRemovedEvent:
   486             {
   465             {
   487             MPX_DEBUG1("Disk Removed event");
   466             MPX_DEBUG2("Disk Removed event, drive %d", aData);
   488             iIdle->Cancel();
   467             iIdle->Cancel();
   489             CancelScan();
   468             CancelScan();
   490 #ifdef RD_MULTIPLE_DRIVE
   469             iDBManager->DropDatabase ( TDriveNumber( aData ) );
   491             TBool dbClosed( EFalse );
   470             RefreshScanDrivesL();
   492             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
   493                 {
       
   494                 if (driveList[driveNum] && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
       
   495                     {
       
   496                     TUint driveStatus(0);
       
   497                     User::LeaveIfError( DriveInfo::GetDriveStatus(
       
   498                         iFs, driveNum, driveStatus ) );
       
   499                     if (!(driveStatus & DriveInfo::EDrivePresent ))
       
   500                         {
       
   501                         // Close database for non-present drive
       
   502                         iDBManager->CloseDatabase( (TDriveNumber) driveNum );
       
   503                         // Save the drive
       
   504                         iRemovedDrive = driveNum;
       
   505                         dbClosed = ETrue;
       
   506                         break;
       
   507                         }
       
   508                     }
       
   509                 }
       
   510             
       
   511             if( !dbClosed )
       
   512                 {
       
   513                 // GetUserVisibleDrives / RFs::DriveList does not return drive at all
       
   514                 // if it is dismounted using file server methods. This occurs at least
       
   515                 // when removing card using power menu eject. 
       
   516                 // If the drive reported as removed is not ready, close db on that drive.
       
   517                 TUint driveStatus(0);
       
   518                 TInt err( DriveInfo::GetDriveStatus( iFs, aData, driveStatus ) );
       
   519                 MPX_DEBUG4("Drive %d status 0x%x, err %d", aData, driveStatus, err);
       
   520                 if( err == KErrNotReady )
       
   521                     {
       
   522                     iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   523                     iRemovedDrive = aData;
       
   524                     }
       
   525                 }
       
   526 #else
       
   527             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   528 #endif // RD_MULTIPLE_DRIVE
       
   529             break;
   471             break;
   530             }
   472             }
   531         case EFormatEndEvent:
   473         case EFormatEndEvent:
   532             {
   474             {
   533             MPX_DEBUG1("Disk Format end event");
   475             MPX_DEBUG2("Disk Format end event, drive %d", aData);
   534             CancelScan();
   476             CancelScan();
   535             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   477             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
       
   478             RefreshScanDrivesL();
   536             break;
   479             break;
   537             }
   480             }
   538         case EDiskInsertedEvent:
   481         case EDiskInsertedEvent:
   539             {
   482             {
   540             MPX_DEBUG1("Disk Insert event");
   483             MPX_DEBUG2("Disk Insert event %d", aData);
   541             CancelScan();
   484             CancelScan();
   542 #ifdef RD_MULTIPLE_DRIVE
       
   543             iDBManager->OpenDatabaseL( (TDriveNumber) iRemovedDrive );
       
   544 #else
       
   545             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   485             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   546 #endif // RD_MULTIPLE_DRIVE
   486             RefreshScanDrivesL();
   547             break;
   487             break;
   548             }
   488             }
   549         case EUSBMassStorageStartEvent:
   489         case EUSBMassStorageStartEvent:
   550             {
   490             {
   551             if (iCurUSBEvent == EUSBMassStorageStartEvent)
   491             if (iCurUSBEvent == EUSBMassStorageStartEvent)
   552             	{
   492                 {
   553             	break;
   493                 break;
   554             	}            
   494                 }            
   555             iIdle->Cancel();
   495             iIdle->Cancel();
       
   496             iDBManager->CloseMassStorageDatabases();
       
   497             RefreshScanDrivesL();
   556             CancelScan();
   498             CancelScan();
   557 #ifdef RD_MULTIPLE_DRIVE
       
   558             // Close all databases other than the phone memory database
       
   559             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
   560                 {
       
   561                 if (driveList[driveNum]  && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
       
   562                     {
       
   563                     if ( driveNum != EDriveC )
       
   564                         {
       
   565                         iDBManager->CloseDatabase( (TDriveNumber) driveNum );
       
   566                         }
       
   567                     }
       
   568                 }
       
   569 #else
       
   570             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   571 #endif // RD_MULTIPLE_DRIVE
       
   572             iCurUSBEvent = EUSBMassStorageStartEvent;
   499             iCurUSBEvent = EUSBMassStorageStartEvent;
   573             break;
   500             break;
   574             }
   501             }
   575         case EUSBMassStorageEndEvent:
   502         case EUSBMassStorageEndEvent:
   576             {
   503             {
   577 #ifdef RD_MULTIPLE_DRIVE
   504             iDBManager->OpenAllDatabasesL();
   578             // Open all databases other than the phone memory
   505             RefreshScanDrivesL();
   579             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
   580                 {
       
   581                 if (driveList[driveNum] && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
       
   582                     {
       
   583                     if ( driveNum != EDriveC )
       
   584                         {
       
   585                         iDBManager->OpenDatabaseL( (TDriveNumber) driveNum );
       
   586                         }
       
   587                     }
       
   588                 }
       
   589 #else
       
   590             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
       
   591 #endif // RD_MULTIPLE_DRIVE
       
   592             iCurUSBEvent = EUSBMassStorageEndEvent;
   506             iCurUSBEvent = EUSBMassStorageEndEvent;
   593             break;
   507             break;
   594             }
   508             }
   595         case EUSBMTPNotActiveEvent: // deliberate fall through
   509         case EUSBMTPNotActiveEvent:
   596             {
   510             {
   597             if (iCurUSBEvent == EUSBMTPNotActiveEvent)
   511             if (iCurUSBEvent == EUSBMTPNotActiveEvent)
   598             	{
   512             	{
   599             	break;
   513             	break;
   600             	}
   514             	}
   609             }
   523             }
   610         case EUSBMTPStartEvent:
   524         case EUSBMTPStartEvent:
   611             {
   525             {
   612             CancelScan();
   526             CancelScan();
   613             iCurUSBEvent = EUSBMTPStartEvent;
   527             iCurUSBEvent = EUSBMTPStartEvent;
   614             // nothing to do, db is needed for MTP
       
   615 #ifdef __RAMDISK_PERF_ENABLE
   528 #ifdef __RAMDISK_PERF_ENABLE
   616             // if statement needed because of fall through above.
   529             iDBManager->CopyDBsToRamL(ETrue);
   617             if ( aEvent == EUSBMTPStartEvent )
       
   618                 {
       
   619                 // copy dbs to ram drive
       
   620                 iDBManager->CopyDBsToRamL(ETrue);
       
   621                 }
       
   622 #endif //__RAMDISK_PERF_ENABLE
   530 #endif //__RAMDISK_PERF_ENABLE
   623             break;
   531             break;
   624             }
   532             }
   625         case EUSBMTPEndEvent:
   533         case EUSBMTPEndEvent:
   626             {
   534             {
   627             iCurUSBEvent = EUSBMTPEndEvent;
   535             iCurUSBEvent = EUSBMTPEndEvent;
   628             // nothing to do, db is updated by MTP
       
   629 #ifdef __RAMDISK_PERF_ENABLE
   536 #ifdef __RAMDISK_PERF_ENABLE
   630             // copy dbs from ram drive
   537             // copy dbs from ram drive
   631             iDBManager->CopyDBsFromRamL();
   538             iDBManager->CopyDBsFromRamL();
   632 #endif //__RAMDISK_PERF_ENABLE
   539 #endif //__RAMDISK_PERF_ENABLE
   633             break;
   540             break;
   634             }
   541             }
   635         case EPowerKeyEjectEvent:
   542         case EDiskDismountEvent:
   636             {
   543             {
       
   544             MPX_DEBUG2("Disk dismount notification, drive %d", aData);
       
   545             iIdle->Cancel();
       
   546             if ( aData < 0 )
       
   547                 {
       
   548                 iDBManager->CloseMassStorageDatabases();
       
   549                 }
       
   550             else
       
   551                 {
       
   552                 iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   553                 }
       
   554             RefreshScanDrivesL();
   637             CancelScan();
   555             CancelScan();
   638             break;
   556             break;
   639             }
   557             }
   640         default:
   558         default:
   641             {
   559             {
   925 // Re-create all databases
   843 // Re-create all databases
   926 // ---------------------------------------------------------------------------
   844 // ---------------------------------------------------------------------------
   927 //
   845 //
   928 void CMPXHarvesterFileHandlerImp::RecreateDatabases()
   846 void CMPXHarvesterFileHandlerImp::RecreateDatabases()
   929     {
   847     {
   930     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabasesL <--");
   848     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabases <--");
   931     iDBManager->RecreateDatabases();
   849     iDBManager->RecreateDatabases();
   932     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabasesL -->");
   850     TRAP_IGNORE(RefreshScanDrivesL());
       
   851     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabases -->");
   933     }
   852     }
   934 
   853 
   935 // ---------------------------------------------------------------------------
   854 // ---------------------------------------------------------------------------
   936 // Close database transaction
   855 // Close database transaction
   937 // ---------------------------------------------------------------------------
   856 // ---------------------------------------------------------------------------
  1254 // Handle a change in the file system, could be a file added/removed
  1173 // Handle a change in the file system, could be a file added/removed
  1255 // ---------------------------------------------------------------------------
  1174 // ---------------------------------------------------------------------------
  1256 //
  1175 //
  1257 void CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL( const TDesC& aPath )
  1176 void CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL( const TDesC& aPath )
  1258     {
  1177     {
       
  1178     MPX_DEBUG2("--->CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL path=%S", &aPath);
  1259     // Delay the scanning for a few seconds so the files are finished
  1179     // Delay the scanning for a few seconds so the files are finished
  1260     // copying. If already active, means we just append onto the list
  1180     // copying. If already active, means we just append onto the list
  1261     //
  1181     // But don't scan if there is no DB == drive does not exist any more
  1262     iAutoScanPaths.AppendL( aPath );
  1182     TParsePtrC parse( aPath );
  1263     if( !iIdle->IsActive() )
  1183     TDriveUnit drive ( parse.Drive() );
  1264         {
  1184     if ( iDBManager->DatabaseIsOpen ((TDriveNumber) (TInt) drive) )
  1265         TCallBack cb( Callback, this );
  1185         {
  1266         iIdle->Start( TTimeIntervalMicroSeconds32( KAutoScanDelay ),
  1186         MPX_DEBUG1("CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL adding in iAutoScanPaths");
  1267                       TTimeIntervalMicroSeconds32( KAutoScanAfter ),
  1187         iAutoScanPaths.AppendL( aPath );
  1268                       cb );
  1188         if( !iIdle->IsActive() )
  1269         }
  1189             {
  1270 
  1190             TCallBack cb( Callback, this );
       
  1191             iIdle->Start( TTimeIntervalMicroSeconds32( KAutoScanDelay ),
       
  1192                           TTimeIntervalMicroSeconds32( KAutoScanAfter ),
       
  1193                           cb );
       
  1194             }
       
  1195         }
  1271     }
  1196     }
  1272 
  1197 
  1273 // ---------------------------------------------------------------------------
  1198 // ---------------------------------------------------------------------------
  1274 // Handles opening the drive
  1199 // Handles opening the drive
  1275 // ---------------------------------------------------------------------------
  1200 // ---------------------------------------------------------------------------
  1276 //
  1201 //
  1277 void CMPXHarvesterFileHandlerImp::HandleOpenDriveL( TDriveNumber aDrive,
  1202 void CMPXHarvesterFileHandlerImp::HandleOpenDriveL( TDriveNumber aDrive,
  1278                                                     const TDesC& aFolder )
  1203                                                     const TDesC& aFolder )
  1279     {
  1204     {
       
  1205     MPX_DEBUG3("--->CMPXHarvesterFileHandlerImp::HandleOpenDriveL drive=%d, folder=%S", aDrive, &aFolder);
  1280 #ifdef __PRINTDB__
  1206 #ifdef __PRINTDB__
  1281     if( iCurTable )
  1207     if( iCurTable )
  1282         iCurTable->PrintItemsInTableL();
  1208         iCurTable->PrintItemsInTableL();
  1283 #endif //__PRINTDB__
  1209 #endif //__PRINTDB__
  1284 
  1210 
  1289     Reset();
  1215     Reset();
  1290 #ifdef __RAMDISK_PERF_ENABLE
  1216 #ifdef __RAMDISK_PERF_ENABLE
  1291     // EnsureRamSpaceL will copy dbs from ram if ram space is low or dbs exceeded max space.
  1217     // EnsureRamSpaceL will copy dbs from ram if ram space is low or dbs exceeded max space.
  1292     iDBManager->EnsureRamSpaceL();
  1218     iDBManager->EnsureRamSpaceL();
  1293 #endif // __RAMDISK_PERF_ENABLE
  1219 #endif // __RAMDISK_PERF_ENABLE
  1294     MPX_TRAPD( err, iCurDB = &iDBManager->GetDatabaseL( aDrive ) );
  1220     iCurDB = &iDBManager->GetDatabaseL( aDrive );
  1295     if ( err != KErrNone )
       
  1296         {
       
  1297         iDBManager->OpenAllDatabasesL();
       
  1298         iCurDB = &iDBManager->GetDatabaseL( aDrive );
       
  1299         }
       
  1300     
       
  1301     if( iDrivesToScan.Find( aFolder ) != KErrNotFound )
  1221     if( iDrivesToScan.Find( aFolder ) != KErrNotFound )
  1302         {
  1222         {
  1303         iCurTable = iCurDB->OpenAllFilesTableL();
  1223         iCurTable = iCurDB->OpenAllFilesTableL();
  1304         }
  1224         }
  1305     else
  1225     else
  1306         {
  1226         {
  1307         iCurTable = iCurDB->OpenDirectoryL( aFolder );
  1227         iCurTable = iCurDB->OpenDirectoryL( aFolder );
  1308         }
  1228         }
  1309     iCurList = iCurTable->CreateTableRepresentationL();
  1229     iCurList = iCurTable->CreateTableRepresentationL();
       
  1230     MPX_DEBUG1("<--CMPXHarvesterFileHandlerImp::HandleOpenDriveL");
  1310     }
  1231     }
  1311 
  1232 
  1312 // ---------------------------------------------------------------------------
  1233 // ---------------------------------------------------------------------------
  1313 // Is this a media file we are interested in
  1234 // Is this a media file we are interested in
  1314 // ---------------------------------------------------------------------------
  1235 // ---------------------------------------------------------------------------
  1829         blockPath = KDefaultBlockPath;
  1750         blockPath = KDefaultBlockPath;
  1830         }
  1751         }
  1831 
  1752 
  1832     MPX_DEBUG2("ParseScanPathL scanPaths: %S", &scanPath);
  1753     MPX_DEBUG2("ParseScanPathL scanPaths: %S", &scanPath);
  1833     MPX_DEBUG2("ParseScanPathL blockPaths: %S", &blockPath);
  1754     MPX_DEBUG2("ParseScanPathL blockPaths: %S", &blockPath);
  1834     ::ExtractTokensL( scanPath, iDrivesToScan );
  1755     ::ExtractTokensL( scanPath, iConfiguredDrivesToScan );
  1835     ::ExtractTokensL( blockPath, iPathsToBlock );
  1756     ::ExtractTokensL( blockPath, iPathsToBlock );
  1836     }
  1757     }
  1837 
  1758 
  1838 // ---------------------------------------------------------------------------
  1759 // ---------------------------------------------------------------------------
  1839 // Parses cenrep setting for container file types
  1760 // Parses cenrep setting for container file types
  1896         monitor->StartL( array->MdcaPoint(i) );
  1817         monitor->StartL( array->MdcaPoint(i) );
  1897         }
  1818         }
  1898     CleanupStack::PopAndDestroy( array );
  1819     CleanupStack::PopAndDestroy( array );
  1899     }
  1820     }
  1900 
  1821 
       
  1822 // ---------------------------------------------------------------------------
       
  1823 // Refreshes scan drives
       
  1824 // ---------------------------------------------------------------------------
       
  1825 //
       
  1826 void CMPXHarvesterFileHandlerImp::RefreshScanDrivesL()
       
  1827     {
       
  1828     iDrivesToScan.Reset();
       
  1829     for (TInt i = 0; i < iConfiguredDrivesToScan.Count(); ++i)
       
  1830         {
       
  1831         const TDesC& path = iConfiguredDrivesToScan[i];
       
  1832         TParsePtrC parse(path);
       
  1833         TDriveUnit drive(parse.Drive());
       
  1834         if ( iDBManager->DatabaseIsOpen( (TDriveNumber)(TInt) drive) )
       
  1835             {
       
  1836             iDrivesToScan.AppendL(path);
       
  1837             }
       
  1838         }
       
  1839     }
       
  1840     
  1901 // ---------------------------------------------------------------------------
  1841 // ---------------------------------------------------------------------------
  1902 // Resets the scanning table and array
  1842 // Resets the scanning table and array
  1903 // ---------------------------------------------------------------------------
  1843 // ---------------------------------------------------------------------------
  1904 //
  1844 //
  1905 void CMPXHarvesterFileHandlerImp::Reset()
  1845 void CMPXHarvesterFileHandlerImp::Reset()
  2013 
  1953 
  2014     {
  1954     {
  2015     // If no error or cancel, return the final number of items added
  1955     // If no error or cancel, return the final number of items added
  2016     MPX_DEBUG2("Scan error %i", aErr );
  1956     MPX_DEBUG2("Scan error %i", aErr );
  2017     
  1957     
  2018     // Reopen databases (in case we removed them for out of disk drives before scan)
  1958     if( aErr == KErrNone || aErr == KErrCancel )
  2019     iDBManager->OpenAllDatabasesL();
       
  2020     
       
  2021     if( aErr == KErrNone )
       
  2022         {
  1959         {
  2023         // Commit the changes on databases in transaction
  1960         // Commit the changes on databases in transaction
  2024         iDBManager->CommitL();
  1961         iDBManager->CommitL();
  2025         }
  1962         }
  2026     else
  1963     else
  2032 #ifdef __RAMDISK_PERF_ENABLE
  1969 #ifdef __RAMDISK_PERF_ENABLE
  2033     // copy dbs from ram drive
  1970     // copy dbs from ram drive
  2034     iDBManager->CopyDBsFromRamL();
  1971     iDBManager->CopyDBsFromRamL();
  2035 #endif //__RAMDISK_PERF_ENABLE
  1972 #endif //__RAMDISK_PERF_ENABLE
  2036 
  1973 
       
  1974     // Reopen databases (in case we removed them for out of disk drives before scan)
       
  1975     for (TInt i = 0, j = 0; i < iDrivesToScan.Count(); ++i)
       
  1976         {
       
  1977         if ( j < iFilteredDrivesToScan.Count() && ! iDrivesToScan[i].Compare( iFilteredDrivesToScan[j] ) )
       
  1978             {
       
  1979              ++j;
       
  1980             }
       
  1981         else
       
  1982             {
       
  1983             TParsePtrC fileNameParser ( iDrivesToScan[i] );
       
  1984             TDriveUnit drive ( fileNameParser.Drive() );
       
  1985             TRAP_IGNORE( iDBManager->OpenDatabaseL( TDriveNumber ( (TInt) drive ) ) );
       
  1986             }
       
  1987         }
       
  1988 
  2037     if( aErr == KErrNone || aErr == KErrCancel )
  1989     if( aErr == KErrNone || aErr == KErrCancel )
  2038         {
  1990         {
  2039         aErr = iAddedCount;
  1991         aErr = iAddedCount;
  2040         }
  1992         }
  2041     
  1993     
  2042     if (iFilteredDrivesToScan.Count() != iDrivesToScan.Count())
  1994     if ( iFilteredOutOfDisk )
  2043         {
  1995         {
  2044         aErr = KErrDiskFull; 
  1996         aErr = KErrDiskFull; 
  2045         }
  1997         }
  2046 
  1998 
  2047     if( iRefreshing )
  1999     if( iRefreshing )
  2189         {
  2141         {
  2190         // Add a path to scan
  2142         // Add a path to scan
  2191         iRefreshCount++;
  2143         iRefreshCount++;
  2192         CancelScan();
  2144         CancelScan();
  2193         Reset();
  2145         Reset();
  2194         iFolderScanner->ScanL( iAutoScanPaths );
  2146         // ensure you don't try to scan paths that are on closed drives
       
  2147         for (TInt i = 0; i < iAutoScanPaths.Count(); )
       
  2148             {
       
  2149             TParsePtr parse(iAutoScanPaths[i]);
       
  2150             TDriveUnit drive(parse.Drive());
       
  2151             if ( iDBManager->DatabaseIsOpen( (TDriveNumber) (TInt) drive ) )
       
  2152                 {
       
  2153                 ++i;
       
  2154                 }
       
  2155             else
       
  2156                 {
       
  2157                 iAutoScanPaths.Remove(i);
       
  2158                 }
       
  2159             }
       
  2160         if ( iAutoScanPaths.Count() )
       
  2161             {
       
  2162             iFolderScanner->ScanL( iAutoScanPaths );
       
  2163             }
  2195 
  2164 
  2196         // Cleanup
  2165         // Cleanup
  2197         iAutoScanPaths.Reset();
  2166         iAutoScanPaths.Reset();
  2198         iIdle->Cancel();
  2167         iIdle->Cancel();
  2199         }
  2168         }
  2311     RPointerArray<CMPXHarvesterDbItem>* tempList=NULL;
  2280     RPointerArray<CMPXHarvesterDbItem>* tempList=NULL;
  2312     RPointerArray<CMPXHarvesterDbItem>* drmFileList = new (ELeave) RPointerArray<CMPXHarvesterDbItem>;
  2281     RPointerArray<CMPXHarvesterDbItem>* drmFileList = new (ELeave) RPointerArray<CMPXHarvesterDbItem>;
  2313     
  2282     
  2314     CleanupStack::PushL( drmFileList );
  2283     CleanupStack::PushL( drmFileList );
  2315 
  2284 
  2316 #ifdef RD_MULTIPLE_DRIVE
       
  2317     TDriveList driveList;
  2285     TDriveList driveList;
  2318     TInt driveCount(0);
  2286     TInt driveCount(0);
  2319 
  2287 
  2320     // Get all visible drives
  2288     // Get all visible drives
  2321     if ( KErrNone == DriveInfo::GetUserVisibleDrives(
  2289     if ( KErrNone == DriveInfo::GetUserVisibleDrives(
  2342                 CleanupStack::PopAndDestroy( tempList );
  2310                 CleanupStack::PopAndDestroy( tempList );
  2343                 CleanupStack::PopAndDestroy( table );
  2311                 CleanupStack::PopAndDestroy( table );
  2344                 }
  2312                 }
  2345             }
  2313             }
  2346     	}
  2314     	}
  2347 #else
       
  2348     //ensure drive E is ready
       
  2349     //otherwise GetDataBaseL will leave if MMC is removed
       
  2350     if ( IsDriveReady( EDriveE ) )
       
  2351         {
       
  2352         // Get DRM files from database in E drive
       
  2353         db = &iDBManager->GetDatabaseL( EDriveE );
       
  2354         table = db->OpenDrmFileL(); 
       
  2355         CleanupStack::PushL( table );
       
  2356         tempList = table->CreateTableRepresentationL();
       
  2357         CleanupStack::PushL( tempList );
       
  2358         // copy content to drm file list
       
  2359         for ( TInt i=0; i<tempList->Count(); i++ )
       
  2360             {
       
  2361             drmFileList->AppendL( (*tempList)[i] );
       
  2362             }
       
  2363         // reset
       
  2364         tempList->Reset();
       
  2365         CleanupStack::PopAndDestroy( tempList );
       
  2366         CleanupStack::PopAndDestroy( table );
       
  2367         }
       
  2368 
       
  2369     // Get DRM files from database in C drive
       
  2370     db = &iDBManager->GetDatabaseL( EDriveC );
       
  2371     table = db->OpenDrmFileL(); 
       
  2372     CleanupStack::PushL( table );
       
  2373     tempList = table->CreateTableRepresentationL();
       
  2374     CleanupStack::PushL( tempList );
       
  2375     // copy content to iCurList
       
  2376     for ( TInt i=0; i<tempList->Count(); i++ )
       
  2377         {
       
  2378         drmFileList->AppendL( (*tempList)[i] );
       
  2379         }
       
  2380     tempList->Reset();
       
  2381     CleanupStack::PopAndDestroy( tempList );
       
  2382     CleanupStack::PopAndDestroy( table );
       
  2383 #endif
       
  2384     CleanupStack::Pop( drmFileList );
  2315     CleanupStack::Pop( drmFileList );
  2385     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::GetDrmFiles --->");
  2316     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::GetDrmFiles --->");
  2386     return drmFileList;
  2317     return drmFileList;
  2387     }
  2318     }
  2388 
  2319 
  2389 // ---------------------------------------------------------------------------
       
  2390 // Verifies if aDrive is ready.
       
  2391 // ---------------------------------------------------------------------------
       
  2392 //
       
  2393 TBool CMPXHarvesterFileHandlerImp::IsDriveReady( TDriveNumber aDrive )
       
  2394     {
       
  2395     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::IsDriveReady <---");
       
  2396 
       
  2397     TDriveInfo driveInfo;
       
  2398     TInt error = iFs.Drive( driveInfo, aDrive );
       
  2399     TBool ready = ETrue;
       
  2400     if ( error != KErrNone )
       
  2401         {
       
  2402         ready = EFalse;
       
  2403         }
       
  2404     else if ( driveInfo.iDriveAtt == static_cast<TUint>( KDriveAbsent ) )
       
  2405         {
       
  2406         //aDrive is absent
       
  2407         ready = EFalse;
       
  2408         }
       
  2409     else
       
  2410         {
       
  2411         TVolumeInfo volumeInfo;
       
  2412         TInt errCode = iFs.Volume( volumeInfo, aDrive );
       
  2413         if( errCode != KErrNone )
       
  2414             {
       
  2415             //aDrive is ready for use
       
  2416             ready = EFalse;
       
  2417             }
       
  2418         }
       
  2419 
       
  2420     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::IsDriveReady --->");
       
  2421     return ready;
       
  2422     }
       
  2423 
       
  2424 // END OF FILE
  2320 // END OF FILE