|
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 { |
|
186 theReader.OpenLC( &iResFile, C_EXTRADATAFILES ); |
|
187 somethingToDo = ETrue; |
|
188 } |
|
189 else if(CMseng::IsRemovableDrive(aFsSession, aDrive)) |
|
190 { |
|
191 theReader.OpenLC( &iResFile, E_EXTRADATAFILES ); |
|
192 somethingToDo = ETrue; |
|
193 } |
|
194 if(somethingToDo) |
|
195 { |
|
196 //the first WORD contains the number of elements in the resource |
|
197 const TInt length = theReader.ReadInt16L(); |
|
198 |
|
199 // Read the array resource, |
|
200 TInt groupindex; // value from enum TDataGroups |
|
201 for(TInt i=0; i<length; i++) |
|
202 { |
|
203 groupindex = theReader.ReadInt8L(); |
|
204 HBufC* name = theReader.ReadHBufCL(); |
|
205 TChar ch; |
|
206 if ( RFs::DriveToChar( aDrive, ch ) == KErrNone ) |
|
207 { |
|
208 CleanupStack::PushL(name); |
|
209 TPtr ptrName = name->Des(); |
|
210 TBuf<1> drive; |
|
211 drive.Append(ch); |
|
212 ptrName.Replace(0, drive.Length(), drive); |
|
213 |
|
214 // check the size of the file whose path was in the resource. |
|
215 TEntry file; |
|
216 TInt err = aFsSession.Entry(ptrName, file); |
|
217 if (err == KErrNone) |
|
218 { |
|
219 TInt size = file.iSize; |
|
220 iScanArray->AddSizeByGroupL(groupindex, size); |
|
221 } |
|
222 |
|
223 CleanupStack::PopAndDestroy(name); |
|
224 } |
|
225 } |
|
226 } |
|
227 CleanupStack::PopAndDestroy(&theReader); |
|
228 } |
|
229 |
|
230 // End of File |