mmappcomponents/harvester/filehandler/src/mpxharvesterfilehandlerimp.cpp
branchRCL_3
changeset 23 4740b34b83ce
parent 19 51035f0751c2
child 30 6f9f6e99a23e
equal deleted inserted replaced
19:51035f0751c2 23:4740b34b83ce
    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.1.4 % << Don't touch! Updated by Synergy at check-out.
    15 *  Version     : %version: da1mmcf#72.1.14.2.4.1.4.1.2.1.6 % << 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 
   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     // 7: Disk dismount: stop scanning, close the dismounting DB
   418     // 7: Disk dismount: stop scanning, close the dismounting DB
   442     //
   419     //
   443 #ifdef RD_MULTIPLE_DRIVE
       
   444     // Get all visible drives
   420     // Get all visible drives
   445     TDriveList driveList;
   421     TDriveList driveList;
   446     TInt driveCount(0);
   422     TInt driveCount(0);
   447     TPtrC drivePresent(_L("present"));
   423     TPtrC drivePresent(_L("present"));
   448     TPtrC driveNotPresent(_L("not present"));
   424     TPtrC driveNotPresent(_L("not present"));
   471                 (driveStatus&DriveInfo::EDrivePresent)?&drivePresent:&driveNotPresent,
   447                 (driveStatus&DriveInfo::EDrivePresent)?&drivePresent:&driveNotPresent,
   472                 (driveStatus&DriveInfo::EDriveInUse)?&driveInUse:&driveAvailable,
   448                 (driveStatus&DriveInfo::EDriveInUse)?&driveInUse:&driveAvailable,
   473                 (driveStatus&DriveInfo::EDriveFormatted)?&driveFormatted:&driveNotFormatted);
   449                 (driveStatus&DriveInfo::EDriveFormatted)?&driveFormatted:&driveNotFormatted);
   474             }
   450             }
   475         }
   451         }
   476 #endif //RD_MULTIPLE_DRIVE
   452 
   477     switch( aEvent )
   453     switch( aEvent )
   478         {
   454         {
   479         case EFormatStartEvent:
   455         case EFormatStartEvent:
   480             {
   456             {
   481             MPX_DEBUG1("Disk Format start event");
   457             MPX_DEBUG2("Disk Format start event, drive %d", aData);
       
   458             iIdle->Cancel();
   482             CancelScan();
   459             CancelScan();
   483             iDBManager->CloseDatabase( (TDriveNumber) aData );
   460             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   461             RefreshScanDrivesL();
   484             break;
   462             break;
   485             }
   463             }
   486         case EDiskRemovedEvent:
   464         case EDiskRemovedEvent:
   487             {
   465             {
   488             MPX_DEBUG1("Disk Removed event");
   466             MPX_DEBUG2("Disk Removed event, drive %d", aData);
   489             iIdle->Cancel();
   467             iIdle->Cancel();
   490             CancelScan();
   468             CancelScan();
   491 #ifdef RD_MULTIPLE_DRIVE
   469             iDBManager->DropDatabase ( TDriveNumber( aData ) );
   492             TBool dbClosed( EFalse );
   470             RefreshScanDrivesL();
   493             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
   494                 {
       
   495                 if (driveList[driveNum] && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
       
   496                     {
       
   497                     TUint driveStatus(0);
       
   498                     User::LeaveIfError( DriveInfo::GetDriveStatus(
       
   499                         iFs, driveNum, driveStatus ) );
       
   500                     if (!(driveStatus & DriveInfo::EDrivePresent ))
       
   501                         {
       
   502                         // Close database for non-present drive
       
   503                         iDBManager->CloseDatabase( (TDriveNumber) driveNum );
       
   504                         // Save the drive
       
   505                         iRemovedDrive = driveNum;
       
   506                         dbClosed = ETrue;
       
   507                         break;
       
   508                         }
       
   509                     }
       
   510                 }
       
   511             
       
   512             if( !dbClosed )
       
   513                 {
       
   514                 // GetUserVisibleDrives / RFs::DriveList does not return drive at all
       
   515                 // if it is dismounted using file server methods. This occurs at least
       
   516                 // when removing card using power menu eject. 
       
   517                 // If the drive reported as removed is not ready, close db on that drive.
       
   518                 TUint driveStatus(0);
       
   519                 TInt err( DriveInfo::GetDriveStatus( iFs, aData, driveStatus ) );
       
   520                 MPX_DEBUG4("Drive %d status 0x%x, err %d", aData, driveStatus, err);
       
   521                 if( err == KErrNotReady )
       
   522                     {
       
   523                     iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   524                     iRemovedDrive = aData;
       
   525                     }
       
   526                 }
       
   527 #else
       
   528             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   529 #endif // RD_MULTIPLE_DRIVE
       
   530             break;
   471             break;
   531             }
   472             }
   532         case EFormatEndEvent:
   473         case EFormatEndEvent:
   533             {
   474             {
   534             MPX_DEBUG1("Disk Format end event");
   475             MPX_DEBUG2("Disk Format end event, drive %d", aData);
   535             CancelScan();
   476             CancelScan();
   536             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   477             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
       
   478             RefreshScanDrivesL();
   537             break;
   479             break;
   538             }
   480             }
   539         case EDiskInsertedEvent:
   481         case EDiskInsertedEvent:
   540             {
   482             {
   541             MPX_DEBUG1("Disk Insert event");
   483             MPX_DEBUG2("Disk Insert event %d", aData);
   542             CancelScan();
   484             CancelScan();
   543 #ifdef RD_MULTIPLE_DRIVE
       
   544             iDBManager->OpenDatabaseL( (TDriveNumber) iRemovedDrive );
       
   545 #else
       
   546             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   485             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
   547 #endif // RD_MULTIPLE_DRIVE
   486             RefreshScanDrivesL();
   548             break;
   487             break;
   549             }
   488             }
   550         case EUSBMassStorageStartEvent:
   489         case EUSBMassStorageStartEvent:
   551             {
   490             {
   552             if (iCurUSBEvent == EUSBMassStorageStartEvent)
   491             if (iCurUSBEvent == EUSBMassStorageStartEvent)
   553             	{
   492                 {
   554             	break;
   493                 break;
   555             	}            
   494                 }            
   556             iIdle->Cancel();
   495             iIdle->Cancel();
       
   496             iDBManager->CloseMassStorageDatabases();
       
   497             RefreshScanDrivesL();
   557             CancelScan();
   498             CancelScan();
   558 #ifdef RD_MULTIPLE_DRIVE
       
   559             // Close all databases other than the phone memory database
       
   560             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
   561                 {
       
   562                 if (driveList[driveNum]  && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
       
   563                     {
       
   564                     if ( driveNum != EDriveC )
       
   565                         {
       
   566                         iDBManager->CloseDatabase( (TDriveNumber) driveNum );
       
   567                         }
       
   568                     }
       
   569                 }
       
   570 #else
       
   571             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   572 #endif // RD_MULTIPLE_DRIVE
       
   573             iCurUSBEvent = EUSBMassStorageStartEvent;
   499             iCurUSBEvent = EUSBMassStorageStartEvent;
   574             break;
   500             break;
   575             }
   501             }
   576         case EUSBMassStorageEndEvent:
   502         case EUSBMassStorageEndEvent:
   577             {
   503             {
   578 #ifdef RD_MULTIPLE_DRIVE
   504             iDBManager->OpenAllDatabasesL();
   579             // Open all databases other than the phone memory
   505             RefreshScanDrivesL();
   580             for( TInt driveNum = EDriveA; driveNum <= EDriveZ; driveNum++ )
       
   581                 {
       
   582                 if (driveList[driveNum] && (!iDBManager->IsRemoteDrive(static_cast<TDriveNumber>(driveNum))))
       
   583                     {
       
   584                     if ( driveNum != EDriveC )
       
   585                         {
       
   586                         iDBManager->OpenDatabaseL( (TDriveNumber) driveNum );
       
   587                         }
       
   588                     }
       
   589                 }
       
   590 #else
       
   591             iDBManager->OpenDatabaseL( (TDriveNumber) aData );
       
   592 #endif // RD_MULTIPLE_DRIVE
       
   593             iCurUSBEvent = EUSBMassStorageEndEvent;
   506             iCurUSBEvent = EUSBMassStorageEndEvent;
   594             break;
   507             break;
   595             }
   508             }
   596         case EUSBMTPNotActiveEvent: // deliberate fall through
   509         case EUSBMTPNotActiveEvent:
   597             {
   510             {
   598             if (iCurUSBEvent == EUSBMTPNotActiveEvent)
   511             if (iCurUSBEvent == EUSBMTPNotActiveEvent)
   599             	{
   512             	{
   600             	break;
   513             	break;
   601             	}
   514             	}
   610             }
   523             }
   611         case EUSBMTPStartEvent:
   524         case EUSBMTPStartEvent:
   612             {
   525             {
   613             CancelScan();
   526             CancelScan();
   614             iCurUSBEvent = EUSBMTPStartEvent;
   527             iCurUSBEvent = EUSBMTPStartEvent;
   615             // nothing to do, db is needed for MTP
       
   616 #ifdef __RAMDISK_PERF_ENABLE
   528 #ifdef __RAMDISK_PERF_ENABLE
   617             // if statement needed because of fall through above.
   529             iDBManager->CopyDBsToRamL(ETrue);
   618             if ( aEvent == EUSBMTPStartEvent )
       
   619                 {
       
   620                 // copy dbs to ram drive
       
   621                 iDBManager->CopyDBsToRamL(ETrue);
       
   622                 }
       
   623 #endif //__RAMDISK_PERF_ENABLE
   530 #endif //__RAMDISK_PERF_ENABLE
   624             break;
   531             break;
   625             }
   532             }
   626         case EUSBMTPEndEvent:
   533         case EUSBMTPEndEvent:
   627             {
   534             {
   628             iCurUSBEvent = EUSBMTPEndEvent;
   535             iCurUSBEvent = EUSBMTPEndEvent;
   629             // nothing to do, db is updated by MTP
       
   630 #ifdef __RAMDISK_PERF_ENABLE
   536 #ifdef __RAMDISK_PERF_ENABLE
   631             // copy dbs from ram drive
   537             // copy dbs from ram drive
   632             iDBManager->CopyDBsFromRamL();
   538             iDBManager->CopyDBsFromRamL();
   633 #endif //__RAMDISK_PERF_ENABLE
   539 #endif //__RAMDISK_PERF_ENABLE
   634             break;
   540             break;
   635             }
   541             }
   636         case EDiskDismountEvent:
   542         case EDiskDismountEvent:
   637             {
   543             {
   638             MPX_DEBUG2("Disk dismount notification, drive %d", aData);
   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();
   639             CancelScan();
   555             CancelScan();
   640             iDBManager->CloseDatabase( (TDriveNumber) aData );
       
   641             break;
   556             break;
   642             }
   557             }
   643         default:
   558         default:
   644             {
   559             {
   645             MPX_DEBUG1("CCMPXHarvesterFileHandlerImp::HandleSystemEventL Unknown system event!");
   560             MPX_DEBUG1("CCMPXHarvesterFileHandlerImp::HandleSystemEventL Unknown system event!");
   928 // Re-create all databases
   843 // Re-create all databases
   929 // ---------------------------------------------------------------------------
   844 // ---------------------------------------------------------------------------
   930 //
   845 //
   931 void CMPXHarvesterFileHandlerImp::RecreateDatabases()
   846 void CMPXHarvesterFileHandlerImp::RecreateDatabases()
   932     {
   847     {
   933     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabasesL <--");
   848     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabases <--");
   934     iDBManager->RecreateDatabases();
   849     iDBManager->RecreateDatabases();
   935     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabasesL -->");
   850     TRAP_IGNORE(RefreshScanDrivesL());
       
   851     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::RecreateDatabases -->");
   936     }
   852     }
   937 
   853 
   938 // ---------------------------------------------------------------------------
   854 // ---------------------------------------------------------------------------
   939 // Close database transaction
   855 // Close database transaction
   940 // ---------------------------------------------------------------------------
   856 // ---------------------------------------------------------------------------
  1257 // 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
  1258 // ---------------------------------------------------------------------------
  1174 // ---------------------------------------------------------------------------
  1259 //
  1175 //
  1260 void CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL( const TDesC& aPath )
  1176 void CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL( const TDesC& aPath )
  1261     {
  1177     {
       
  1178     MPX_DEBUG2("--->CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL path=%S", &aPath);
  1262     // 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
  1263     // copying. If already active, means we just append onto the list
  1180     // copying. If already active, means we just append onto the list
  1264     //
  1181     // But don't scan if there is no DB == drive does not exist any more
  1265     iAutoScanPaths.AppendL( aPath );
  1182     TParsePtrC parse( aPath );
  1266     if( !iIdle->IsActive() )
  1183     TDriveUnit drive ( parse.Drive() );
  1267         {
  1184     if ( iDBManager->DatabaseIsOpen ((TDriveNumber) (TInt) drive) )
  1268         TCallBack cb( Callback, this );
  1185         {
  1269         iIdle->Start( TTimeIntervalMicroSeconds32( KAutoScanDelay ),
  1186         MPX_DEBUG1("CMPXHarvesterFileHandlerImp::HandleDirectoryChangedL adding in iAutoScanPaths");
  1270                       TTimeIntervalMicroSeconds32( KAutoScanAfter ),
  1187         iAutoScanPaths.AppendL( aPath );
  1271                       cb );
  1188         if( !iIdle->IsActive() )
  1272         }
  1189             {
  1273 
  1190             TCallBack cb( Callback, this );
       
  1191             iIdle->Start( TTimeIntervalMicroSeconds32( KAutoScanDelay ),
       
  1192                           TTimeIntervalMicroSeconds32( KAutoScanAfter ),
       
  1193                           cb );
       
  1194             }
       
  1195         }
  1274     }
  1196     }
  1275 
  1197 
  1276 // ---------------------------------------------------------------------------
  1198 // ---------------------------------------------------------------------------
  1277 // Handles opening the drive
  1199 // Handles opening the drive
  1278 // ---------------------------------------------------------------------------
  1200 // ---------------------------------------------------------------------------
  1279 //
  1201 //
  1280 void CMPXHarvesterFileHandlerImp::HandleOpenDriveL( TDriveNumber aDrive,
  1202 void CMPXHarvesterFileHandlerImp::HandleOpenDriveL( TDriveNumber aDrive,
  1281                                                     const TDesC& aFolder )
  1203                                                     const TDesC& aFolder )
  1282     {
  1204     {
       
  1205     MPX_DEBUG3("--->CMPXHarvesterFileHandlerImp::HandleOpenDriveL drive=%d, folder=%S", aDrive, &aFolder);
  1283 #ifdef __PRINTDB__
  1206 #ifdef __PRINTDB__
  1284     if( iCurTable )
  1207     if( iCurTable )
  1285         iCurTable->PrintItemsInTableL();
  1208         iCurTable->PrintItemsInTableL();
  1286 #endif //__PRINTDB__
  1209 #endif //__PRINTDB__
  1287 
  1210 
  1292     Reset();
  1215     Reset();
  1293 #ifdef __RAMDISK_PERF_ENABLE
  1216 #ifdef __RAMDISK_PERF_ENABLE
  1294     // 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.
  1295     iDBManager->EnsureRamSpaceL();
  1218     iDBManager->EnsureRamSpaceL();
  1296 #endif // __RAMDISK_PERF_ENABLE
  1219 #endif // __RAMDISK_PERF_ENABLE
  1297     MPX_TRAPD( err, iCurDB = &iDBManager->GetDatabaseL( aDrive ) );
  1220     iCurDB = &iDBManager->GetDatabaseL( aDrive );
  1298     if ( err != KErrNone )
       
  1299         {
       
  1300         iDBManager->OpenAllDatabasesL();
       
  1301         iCurDB = &iDBManager->GetDatabaseL( aDrive );
       
  1302         }
       
  1303     
       
  1304     if( iDrivesToScan.Find( aFolder ) != KErrNotFound )
  1221     if( iDrivesToScan.Find( aFolder ) != KErrNotFound )
  1305         {
  1222         {
  1306         iCurTable = iCurDB->OpenAllFilesTableL();
  1223         iCurTable = iCurDB->OpenAllFilesTableL();
  1307         }
  1224         }
  1308     else
  1225     else
  1309         {
  1226         {
  1310         iCurTable = iCurDB->OpenDirectoryL( aFolder );
  1227         iCurTable = iCurDB->OpenDirectoryL( aFolder );
  1311         }
  1228         }
  1312     iCurList = iCurTable->CreateTableRepresentationL();
  1229     iCurList = iCurTable->CreateTableRepresentationL();
       
  1230     MPX_DEBUG1("<--CMPXHarvesterFileHandlerImp::HandleOpenDriveL");
  1313     }
  1231     }
  1314 
  1232 
  1315 // ---------------------------------------------------------------------------
  1233 // ---------------------------------------------------------------------------
  1316 // Is this a media file we are interested in
  1234 // Is this a media file we are interested in
  1317 // ---------------------------------------------------------------------------
  1235 // ---------------------------------------------------------------------------
  1832         blockPath = KDefaultBlockPath;
  1750         blockPath = KDefaultBlockPath;
  1833         }
  1751         }
  1834 
  1752 
  1835     MPX_DEBUG2("ParseScanPathL scanPaths: %S", &scanPath);
  1753     MPX_DEBUG2("ParseScanPathL scanPaths: %S", &scanPath);
  1836     MPX_DEBUG2("ParseScanPathL blockPaths: %S", &blockPath);
  1754     MPX_DEBUG2("ParseScanPathL blockPaths: %S", &blockPath);
  1837     ::ExtractTokensL( scanPath, iDrivesToScan );
  1755     ::ExtractTokensL( scanPath, iConfiguredDrivesToScan );
  1838     ::ExtractTokensL( blockPath, iPathsToBlock );
  1756     ::ExtractTokensL( blockPath, iPathsToBlock );
  1839     }
  1757     }
  1840 
  1758 
  1841 // ---------------------------------------------------------------------------
  1759 // ---------------------------------------------------------------------------
  1842 // Parses cenrep setting for container file types
  1760 // Parses cenrep setting for container file types
  1899         monitor->StartL( array->MdcaPoint(i) );
  1817         monitor->StartL( array->MdcaPoint(i) );
  1900         }
  1818         }
  1901     CleanupStack::PopAndDestroy( array );
  1819     CleanupStack::PopAndDestroy( array );
  1902     }
  1820     }
  1903 
  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     
  1904 // ---------------------------------------------------------------------------
  1841 // ---------------------------------------------------------------------------
  1905 // Resets the scanning table and array
  1842 // Resets the scanning table and array
  1906 // ---------------------------------------------------------------------------
  1843 // ---------------------------------------------------------------------------
  1907 //
  1844 //
  1908 void CMPXHarvesterFileHandlerImp::Reset()
  1845 void CMPXHarvesterFileHandlerImp::Reset()
  2016 
  1953 
  2017     {
  1954     {
  2018     // 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
  2019     MPX_DEBUG2("Scan error %i", aErr );
  1956     MPX_DEBUG2("Scan error %i", aErr );
  2020     
  1957     
  2021     // Reopen databases (in case we removed them for out of disk drives before scan)
  1958     if( aErr == KErrNone || aErr == KErrCancel )
  2022     iDBManager->OpenAllDatabasesL();
       
  2023     
       
  2024     if( aErr == KErrNone )
       
  2025         {
  1959         {
  2026         // Commit the changes on databases in transaction
  1960         // Commit the changes on databases in transaction
  2027         iDBManager->CommitL();
  1961         iDBManager->CommitL();
  2028         }
  1962         }
  2029     else
  1963     else
  2035 #ifdef __RAMDISK_PERF_ENABLE
  1969 #ifdef __RAMDISK_PERF_ENABLE
  2036     // copy dbs from ram drive
  1970     // copy dbs from ram drive
  2037     iDBManager->CopyDBsFromRamL();
  1971     iDBManager->CopyDBsFromRamL();
  2038 #endif //__RAMDISK_PERF_ENABLE
  1972 #endif //__RAMDISK_PERF_ENABLE
  2039 
  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 
  2040     if( aErr == KErrNone || aErr == KErrCancel )
  1989     if( aErr == KErrNone || aErr == KErrCancel )
  2041         {
  1990         {
  2042         aErr = iAddedCount;
  1991         aErr = iAddedCount;
  2043         }
  1992         }
  2044     
  1993     
  2045     if (iFilteredDrivesToScan.Count() != iDrivesToScan.Count())
  1994     if ( iFilteredOutOfDisk )
  2046         {
  1995         {
  2047         aErr = KErrDiskFull; 
  1996         aErr = KErrDiskFull; 
  2048         }
  1997         }
  2049 
  1998 
  2050     if( iRefreshing )
  1999     if( iRefreshing )
  2192         {
  2141         {
  2193         // Add a path to scan
  2142         // Add a path to scan
  2194         iRefreshCount++;
  2143         iRefreshCount++;
  2195         CancelScan();
  2144         CancelScan();
  2196         Reset();
  2145         Reset();
  2197         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             }
  2198 
  2164 
  2199         // Cleanup
  2165         // Cleanup
  2200         iAutoScanPaths.Reset();
  2166         iAutoScanPaths.Reset();
  2201         iIdle->Cancel();
  2167         iIdle->Cancel();
  2202         }
  2168         }
  2314     RPointerArray<CMPXHarvesterDbItem>* tempList=NULL;
  2280     RPointerArray<CMPXHarvesterDbItem>* tempList=NULL;
  2315     RPointerArray<CMPXHarvesterDbItem>* drmFileList = new (ELeave) RPointerArray<CMPXHarvesterDbItem>;
  2281     RPointerArray<CMPXHarvesterDbItem>* drmFileList = new (ELeave) RPointerArray<CMPXHarvesterDbItem>;
  2316     
  2282     
  2317     CleanupStack::PushL( drmFileList );
  2283     CleanupStack::PushL( drmFileList );
  2318 
  2284 
  2319 #ifdef RD_MULTIPLE_DRIVE
       
  2320     TDriveList driveList;
  2285     TDriveList driveList;
  2321     TInt driveCount(0);
  2286     TInt driveCount(0);
  2322 
  2287 
  2323     // Get all visible drives
  2288     // Get all visible drives
  2324     if ( KErrNone == DriveInfo::GetUserVisibleDrives(
  2289     if ( KErrNone == DriveInfo::GetUserVisibleDrives(
  2345                 CleanupStack::PopAndDestroy( tempList );
  2310                 CleanupStack::PopAndDestroy( tempList );
  2346                 CleanupStack::PopAndDestroy( table );
  2311                 CleanupStack::PopAndDestroy( table );
  2347                 }
  2312                 }
  2348             }
  2313             }
  2349     	}
  2314     	}
  2350 #else
       
  2351     //ensure drive E is ready
       
  2352     //otherwise GetDataBaseL will leave if MMC is removed
       
  2353     if ( IsDriveReady( EDriveE ) )
       
  2354         {
       
  2355         // Get DRM files from database in E drive
       
  2356         db = &iDBManager->GetDatabaseL( EDriveE );
       
  2357         table = db->OpenDrmFileL(); 
       
  2358         CleanupStack::PushL( table );
       
  2359         tempList = table->CreateTableRepresentationL();
       
  2360         CleanupStack::PushL( tempList );
       
  2361         // copy content to drm file list
       
  2362         for ( TInt i=0; i<tempList->Count(); i++ )
       
  2363             {
       
  2364             drmFileList->AppendL( (*tempList)[i] );
       
  2365             }
       
  2366         // reset
       
  2367         tempList->Reset();
       
  2368         CleanupStack::PopAndDestroy( tempList );
       
  2369         CleanupStack::PopAndDestroy( table );
       
  2370         }
       
  2371 
       
  2372     // Get DRM files from database in C drive
       
  2373     db = &iDBManager->GetDatabaseL( EDriveC );
       
  2374     table = db->OpenDrmFileL(); 
       
  2375     CleanupStack::PushL( table );
       
  2376     tempList = table->CreateTableRepresentationL();
       
  2377     CleanupStack::PushL( tempList );
       
  2378     // copy content to iCurList
       
  2379     for ( TInt i=0; i<tempList->Count(); i++ )
       
  2380         {
       
  2381         drmFileList->AppendL( (*tempList)[i] );
       
  2382         }
       
  2383     tempList->Reset();
       
  2384     CleanupStack::PopAndDestroy( tempList );
       
  2385     CleanupStack::PopAndDestroy( table );
       
  2386 #endif
       
  2387     CleanupStack::Pop( drmFileList );
  2315     CleanupStack::Pop( drmFileList );
  2388     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::GetDrmFiles --->");
  2316     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::GetDrmFiles --->");
  2389     return drmFileList;
  2317     return drmFileList;
  2390     }
  2318     }
  2391 
  2319 
  2392 // ---------------------------------------------------------------------------
       
  2393 // Verifies if aDrive is ready.
       
  2394 // ---------------------------------------------------------------------------
       
  2395 //
       
  2396 TBool CMPXHarvesterFileHandlerImp::IsDriveReady( TDriveNumber aDrive )
       
  2397     {
       
  2398     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::IsDriveReady <---");
       
  2399 
       
  2400     TDriveInfo driveInfo;
       
  2401     TInt error = iFs.Drive( driveInfo, aDrive );
       
  2402     TBool ready = ETrue;
       
  2403     if ( error != KErrNone )
       
  2404         {
       
  2405         ready = EFalse;
       
  2406         }
       
  2407     else if ( driveInfo.iDriveAtt == static_cast<TUint>( KDriveAbsent ) )
       
  2408         {
       
  2409         //aDrive is absent
       
  2410         ready = EFalse;
       
  2411         }
       
  2412     else
       
  2413         {
       
  2414         TVolumeInfo volumeInfo;
       
  2415         TInt errCode = iFs.Volume( volumeInfo, aDrive );
       
  2416         if( errCode != KErrNone )
       
  2417             {
       
  2418             //aDrive is ready for use
       
  2419             ready = EFalse;
       
  2420             }
       
  2421         }
       
  2422 
       
  2423     MPX_DEBUG1("CMPXHarvesterFileHandlerImp::IsDriveReady --->");
       
  2424     return ready;
       
  2425     }
       
  2426 
       
  2427 // END OF FILE
  2320 // END OF FILE