| 39 |      1 | /*
 | 
|  |      2 | * Copyright (c) 2006 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 | *     This is the class that is in control most of the time.
 | 
|  |     16 | *     It instantiates CMsengScannerBase derived scanner classes
 | 
|  |     17 | *     to do the job.
 | 
|  |     18 | *
 | 
|  |     19 | */
 | 
|  |     20 | 
 | 
|  |     21 | 
 | 
|  |     22 | // SYSTEM INCLUDES
 | 
|  |     23 | #include <bautils.h>
 | 
|  |     24 | #include <mseng.rsg>
 | 
|  |     25 | 
 | 
|  |     26 | // USER INCLUDES
 | 
|  |     27 | #include "msengscanner.h"
 | 
|  |     28 | #include "msengfileextscanner.h"
 | 
|  |     29 | #include "msengfindallscanner.h"
 | 
|  |     30 | #include "msengregistryscanner.h"
 | 
|  |     31 | #include "msenguihandler.h"
 | 
|  |     32 | #include "mseng.h"
 | 
|  |     33 | 
 | 
|  |     34 | 
 | 
|  |     35 | // LOCAL CONSTANTS AND MACROS
 | 
|  |     36 | #ifdef _DEBUG
 | 
|  |     37 | _LIT(KClassName, "CMsengScanner");
 | 
|  |     38 | #endif
 | 
|  |     39 | 
 | 
|  |     40 | // ================= MEMBER FUNCTIONS ========================================
 | 
|  |     41 | 
 | 
|  |     42 | // ---------------------------------------------------------------------------
 | 
|  |     43 | // CMsengScanner::CMsengScanner()
 | 
|  |     44 | //
 | 
|  |     45 | // C++ default constructor. Can NOT contain any code, that might leave.
 | 
|  |     46 | // ---------------------------------------------------------------------------
 | 
|  |     47 | CMsengScanner::CMsengScanner(MMsengUIHandler& aUIHandler, CResourceFile& aResFile) :
 | 
|  |     48 | iUIHandler(aUIHandler), iResFile(aResFile)
 | 
|  |     49 |     {
 | 
|  |     50 |     }
 | 
|  |     51 | 
 | 
|  |     52 | // ---------------------------------------------------------------------------
 | 
|  |     53 | // CMsengScanner::~CMsengScanner()
 | 
|  |     54 | //
 | 
|  |     55 | // Destructor
 | 
|  |     56 | // ---------------------------------------------------------------------------
 | 
|  |     57 | CMsengScanner::~CMsengScanner()
 | 
|  |     58 |     {
 | 
|  |     59 |     delete iScanArray;
 | 
|  |     60 |     delete iFileExtScanner;
 | 
|  |     61 |     delete iFindAllScanner;
 | 
|  |     62 |     delete iRegistryScanner;
 | 
|  |     63 |     }
 | 
|  |     64 | 
 | 
|  |     65 | 
 | 
|  |     66 | 
 | 
|  |     67 | // ---------------------------------------------------------------------------
 | 
|  |     68 | // CMsengScanner::Cancel()
 | 
|  |     69 | // 
 | 
|  |     70 | // ---------------------------------------------------------------------------
 | 
|  |     71 | //
 | 
|  |     72 | void CMsengScanner::Cancel()
 | 
|  |     73 |     {
 | 
|  |     74 |     iFileExtScanner->Cancel();
 | 
|  |     75 |     iFindAllScanner->Cancel();
 | 
|  |     76 |     iRegistryScanner->Cancel();
 | 
|  |     77 |     TRAP_IGNORE( iUIHandler.QuitL(KErrCancel) );
 | 
|  |     78 |     }
 | 
|  |     79 | 
 | 
|  |     80 | // ---------------------------------------------------------------------------
 | 
|  |     81 | // CMsengScanner::HaveActiveScanners()
 | 
|  |     82 | // 
 | 
|  |     83 | // ---------------------------------------------------------------------------
 | 
|  |     84 | //
 | 
|  |     85 | TBool CMsengScanner::HaveActiveScanners() const
 | 
|  |     86 |     {
 | 
|  |     87 |     const TBool isActive = 
 | 
|  |     88 |             (iFileExtScanner && iFileExtScanner->IsActive())
 | 
|  |     89 |             || (iFindAllScanner && iFindAllScanner->IsActive())
 | 
|  |     90 |             || (iRegistryScanner && iRegistryScanner->IsActive())
 | 
|  |     91 | 		 ;
 | 
|  |     92 | 	return isActive;
 | 
|  |     93 | 	}
 | 
|  |     94 | 
 | 
|  |     95 | // ---------------------------------------------------------------------------
 | 
|  |     96 | // CMsengScanner::ScanL()
 | 
|  |     97 | // 
 | 
|  |     98 | // ---------------------------------------------------------------------------
 | 
|  |     99 | //
 | 
|  |    100 | TInt CMsengScanner::ScanL(TDriveNumber aDrive, TInt aNumberOfDataGroups, RFs& aFsSession)
 | 
|  |    101 |     {
 | 
|  |    102 |     if(HaveActiveScanners())
 | 
|  |    103 |         {
 | 
|  |    104 |         return KErrInUse;
 | 
|  |    105 |         }
 | 
|  |    106 | 
 | 
|  |    107 |     // Create data structures; delete the old ones
 | 
|  |    108 |     CMsengInfoArray* infoArray = CMsengInfoArray::NewL( aDrive,
 | 
|  |    109 |                                                         aNumberOfDataGroups,
 | 
|  |    110 |                                                         aFsSession, iResFile );
 | 
|  |    111 |     
 | 
|  |    112 |     delete iScanArray;
 | 
|  |    113 | 	iScanArray = infoArray;
 | 
|  |    114 | 
 | 
|  |    115 |     // Do some scanning tasks not include in ScanL
 | 
|  |    116 |     PreScanL(aDrive, aFsSession);
 | 
|  |    117 | 
 | 
|  |    118 |     // Start the scan by filename extension
 | 
|  |    119 |     iFileExtScanner = CMsengFileExtScanner::NewL(*this, *iScanArray, aFsSession);
 | 
|  |    120 |     iFileExtScanner->ScanL(iScanArray->Dirs());
 | 
|  |    121 | 
 | 
|  |    122 |     // Start scanning data dirs (including messages)
 | 
|  |    123 |     iFindAllScanner = CMsengFindAllScanner::NewL(*this, *iScanArray, aFsSession);
 | 
|  |    124 |     iFindAllScanner->ScanL(iScanArray->DataDirs());
 | 
|  |    125 | 
 | 
|  |    126 |     // Start the scan from registries
 | 
|  |    127 |     iRegistryScanner = CMsengRegistryScanner::NewL( aDrive, *this, *iScanArray, aFsSession );
 | 
|  |    128 |     iRegistryScanner->Scan();
 | 
|  |    129 | 
 | 
|  |    130 |     return KErrNone;
 | 
|  |    131 |     }
 | 
|  |    132 | 
 | 
|  |    133 | // ---------------------------------------------------------------------------
 | 
|  |    134 | // MsengScanner::HandleScannerEventL()
 | 
|  |    135 | // 
 | 
|  |    136 | // Handle the events from scanning
 | 
|  |    137 | // ---------------------------------------------------------------------------
 | 
|  |    138 | //
 | 
|  |    139 | void CMsengScanner::HandleScannerEventL(TScannerEvent aEvent,
 | 
|  |    140 |                                         const CMsengScannerBase& /*aScanner*/,
 | 
|  |    141 |                                         TInt aError)
 | 
|  |    142 |     {
 | 
|  |    143 | #ifdef __SHOW_RDEBUG_PRINT_
 | 
|  |    144 |     RDebug::Print(_L("CMsengScanner::HandleScannerEventL() called with event: %d"), aEvent);
 | 
|  |    145 | #endif // __SHOW_RDEBUG_PRINT_
 | 
|  |    146 | 
 | 
|  |    147 |     switch(aEvent)
 | 
|  |    148 |         {
 | 
|  |    149 |         case MMsengScannerObserver::EScannerEventScanComplete:
 | 
|  |    150 |             // This scanner object has finished all of its scanning.
 | 
|  |    151 |             // If all the others are finished too,
 | 
|  |    152 |             // then we tell the UI that scanning is complete.
 | 
|  |    153 |             if (!HaveActiveScanners())
 | 
|  |    154 |                 {
 | 
|  |    155 |                 iUIHandler.QuitL(KErrNone);
 | 
|  |    156 |                 }
 | 
|  |    157 |             break;
 | 
|  |    158 | 
 | 
|  |    159 |         case MMsengScannerObserver::EScannerEventScanError:
 | 
|  |    160 |             // An error has happened
 | 
|  |    161 |             iUIHandler.ErrorL(aError);
 | 
|  |    162 |             break;
 | 
|  |    163 | 
 | 
|  |    164 |         default:
 | 
|  |    165 |             // should never happen
 | 
|  |    166 |             __ASSERT_DEBUG(EFalse,User::Panic(KClassName, KErrGeneral));
 | 
|  |    167 |             break;
 | 
|  |    168 |         }
 | 
|  |    169 |     }
 | 
|  |    170 | 
 | 
|  |    171 | // ---------------------------------------------------------------------------
 | 
|  |    172 | // CMsengScanner::PreScanL()
 | 
|  |    173 | // 
 | 
|  |    174 | // ---------------------------------------------------------------------------
 | 
|  |    175 | //
 | 
|  |    176 | void CMsengScanner::PreScanL(TDriveNumber aDrive, RFs& aFsSession)
 | 
|  |    177 |     {
 | 
|  |    178 |     // Before actual scanning, check the sizes of the few extra
 | 
|  |    179 |     // data files that are not scanned in normal way.
 | 
|  |    180 | 
 | 
|  |    181 |     RResourceReader theReader;  
 | 
|  |    182 |     
 | 
|  |    183 |     TBool somethingToDo = EFalse;
 | 
|  |    184 |     if( CMseng::IsInternalDrive( aFsSession, aDrive )
 | 
|  |    185 |         && !CMseng::IsMassStorageDrive( aFsSession, aDrive ) )
 | 
|  |    186 |         {
 | 
|  |    187 |         theReader.OpenLC( &iResFile, C_EXTRADATAFILES );
 | 
|  |    188 |         somethingToDo = ETrue;
 | 
|  |    189 |         }
 | 
|  |    190 |     else
 | 
|  |    191 |         {
 | 
|  |    192 |         theReader.OpenLC( &iResFile, E_EXTRADATAFILES );
 | 
|  |    193 |         somethingToDo = ETrue;
 | 
|  |    194 |         }
 | 
|  |    195 |     
 | 
|  |    196 |     if(somethingToDo)
 | 
|  |    197 |         {
 | 
|  |    198 |         //the first WORD contains the number of elements in the resource
 | 
|  |    199 |         const TInt length = theReader.ReadInt16L();
 | 
|  |    200 | 
 | 
|  |    201 |         // Read the array resource, 
 | 
|  |    202 |         TInt groupindex; // value from enum TDataGroups
 | 
|  |    203 |         for(TInt i=0; i<length; i++)
 | 
|  |    204 |             {
 | 
|  |    205 |             groupindex = theReader.ReadInt8L();
 | 
|  |    206 |             HBufC* name = theReader.ReadHBufCL();
 | 
|  |    207 |             TChar ch;
 | 
|  |    208 |             if ( RFs::DriveToChar( aDrive, ch ) == KErrNone )
 | 
|  |    209 |                 {
 | 
|  |    210 |                 CleanupStack::PushL(name);
 | 
|  |    211 |                 TPtr ptrName = name->Des();
 | 
|  |    212 |                 TBuf<1> drive;
 | 
|  |    213 |                 drive.Append(ch);
 | 
|  |    214 |                 ptrName.Replace(0, drive.Length(), drive);
 | 
|  |    215 | 
 | 
|  |    216 |                 // check the size of the file whose path was in the resource.
 | 
|  |    217 |                 TEntry file;
 | 
|  |    218 |                 TInt err = aFsSession.Entry(ptrName, file);
 | 
|  |    219 |                 if (err == KErrNone)
 | 
|  |    220 |                     {
 | 
|  |    221 |                     TInt64 size = file.FileSize();
 | 
|  |    222 |                     iScanArray->AddSizeByGroupL(groupindex, size);
 | 
|  |    223 |                     }
 | 
|  |    224 |                     
 | 
|  |    225 |                 CleanupStack::PopAndDestroy(name);
 | 
|  |    226 |                 }
 | 
|  |    227 |             }
 | 
|  |    228 |         }
 | 
|  |    229 |     CleanupStack::PopAndDestroy(&theReader);
 | 
|  |    230 |     }
 | 
|  |    231 | 
 | 
|  |    232 | //  End of File  
 |