|
1 /* |
|
2 * Copyright (c) 2006-2008 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 * An utility class to handle the UIDs and filename extensions used to |
|
16 * identify data types. It is also used to store the results per data type. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // SYSTEM INCLUDES |
|
23 #include <mseng.rsg> |
|
24 #include <bautils.h> |
|
25 #include <barsc.h> // RResourceFile |
|
26 |
|
27 // USER INCLUDES |
|
28 #include "msenginfoarray.h" |
|
29 #include "mseng.h" // KMsengRscFilePath |
|
30 |
|
31 |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CMsengInfoArray::CMsengInfoArray() |
|
38 // |
|
39 // C++ default constructor is prohibited |
|
40 // --------------------------------------------------------------------------- |
|
41 CMsengInfoArray::CMsengInfoArray(TDriveNumber aDrive) |
|
42 : iCurrentScannedDrive(aDrive) |
|
43 { |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CMsengInfoArray::NewL() |
|
48 // |
|
49 // Two-phased constructor. |
|
50 // --------------------------------------------------------------------------- |
|
51 CMsengInfoArray* CMsengInfoArray::NewL(TDriveNumber aDrive, |
|
52 TInt aNumberOfDataGroups, |
|
53 RFs& aFsSession, |
|
54 CResourceFile& aResFile) |
|
55 { |
|
56 CMsengInfoArray* self = new (ELeave) CMsengInfoArray(aDrive); |
|
57 |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL(aNumberOfDataGroups, aFsSession, aResFile); |
|
60 CleanupStack::Pop( self ); |
|
61 |
|
62 return self; |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CMsengInfoArray::ConstructL() |
|
68 // |
|
69 // Symbian OS default constructor can leave. |
|
70 // --------------------------------------------------------------------------- |
|
71 void CMsengInfoArray::ConstructL(TInt aNumberOfDataGroups, |
|
72 RFs& aFsSession, |
|
73 CResourceFile& aResFile) |
|
74 { |
|
75 // Create data structures and initialize them |
|
76 // using values from enumerations TUidTypes and TExtTypes |
|
77 // and data from the resource file mseng.rss |
|
78 |
|
79 TInt index = -1; // index used in for-loops |
|
80 TInt length = -1; // length of resource array being read |
|
81 |
|
82 RResourceReader theReader; |
|
83 |
|
84 theReader.OpenLC( &aResFile, UIDARRAY ); |
|
85 |
|
86 //the first WORD contains the number of elements in the resource |
|
87 length = theReader.ReadInt16L(); |
|
88 |
|
89 // Create the array with appropriate granularity |
|
90 iUidResultArray = new (ELeave) CArrayFixFlat<TInt64>(length); |
|
91 |
|
92 // Initialize the array to contain zeros |
|
93 for(index=0; index<length; index++) |
|
94 { |
|
95 iUidResultArray->InsertL(index, 0); |
|
96 } |
|
97 |
|
98 // Next, create the array for the actual UIDs |
|
99 // and read them from the resource file |
|
100 iUidArray = new (ELeave) CArrayFixFlat<TUid>(length); |
|
101 for(index=0; index<length; index++) |
|
102 { |
|
103 const TInt typeindex = theReader.ReadInt8L(); |
|
104 const TUid uid = TUid::Uid(theReader.ReadInt32L()); |
|
105 // |
|
106 iUidArray->InsertL(typeindex, uid); |
|
107 } |
|
108 CleanupStack::PopAndDestroy(&theReader); |
|
109 |
|
110 // Read extarray in a similar way |
|
111 theReader.OpenLC( &aResFile, EXTARRAY ); |
|
112 |
|
113 |
|
114 //the first WORD contains the number of elements in the resource |
|
115 length = theReader.ReadInt16L(); |
|
116 |
|
117 // Create the array with appropriate granularity |
|
118 iExtResultArray = new (ELeave) CArrayFixFlat<TInt64>(length); |
|
119 // Initialize the array to contain zeros |
|
120 for(index=0; index<length; index++) |
|
121 { |
|
122 iExtResultArray->InsertL(index, 0); |
|
123 } |
|
124 // Next, create the array for the actual extensions |
|
125 // and read them from the resource file |
|
126 iExtArray = new (ELeave) CDesCArrayFlat(length); |
|
127 for(index=0; index<length; index++) |
|
128 { |
|
129 TInt typeindex = theReader.ReadInt8L(); |
|
130 TPtrC ext = theReader.ReadTPtrCL(); |
|
131 |
|
132 iExtArray->InsertL(typeindex, ext); |
|
133 } |
|
134 CleanupStack::PopAndDestroy( &theReader ); |
|
135 |
|
136 // Create the array for results per group |
|
137 iGroupResultArray = new (ELeave) CArrayFixFlat<TInt64>(aNumberOfDataGroups); |
|
138 // Initialize the array to contain zeros |
|
139 for(index=0; index<aNumberOfDataGroups; index++) |
|
140 { |
|
141 iGroupResultArray->InsertL(index, 0); |
|
142 } |
|
143 |
|
144 // The directories to be scanned. Depends of which drive is scanned, |
|
145 // and the directories that are scanned as a whole (and excluded in the normal scan) |
|
146 _LIT(KPanic,"MSENG"); |
|
147 __ASSERT_ALWAYS((CMseng::IsInternalDrive(aFsSession, iCurrentScannedDrive) |
|
148 || CMseng::IsRemovableDrive(aFsSession, iCurrentScannedDrive)), |
|
149 User::Panic(KPanic, KErrNotSupported)); |
|
150 |
|
151 if(CMseng::IsInternalDrive(aFsSession, iCurrentScannedDrive)) |
|
152 { |
|
153 theReader.OpenLC( &aResFile, C_DIRECTORIES ); |
|
154 iDirArray = theReader.ReadDesCArrayL(); |
|
155 CleanupStack::PopAndDestroy( &theReader ); |
|
156 // |
|
157 theReader.OpenLC( &aResFile, C_EXCLUDED_DIRECTORIES ); |
|
158 iExcludedDirArray = theReader.ReadDesCArrayL(); |
|
159 CleanupStack::PopAndDestroy( &theReader ); |
|
160 // |
|
161 theReader.OpenLC( &aResFile, C_SPECIAL_DATADIRS ); |
|
162 // reading later... |
|
163 |
|
164 } |
|
165 else if(CMseng::IsRemovableDrive(aFsSession, iCurrentScannedDrive)) |
|
166 { |
|
167 theReader.OpenLC( &aResFile, E_DIRECTORIES ); |
|
168 iDirArray = theReader.ReadDesCArrayL(); |
|
169 CleanupStack::PopAndDestroy( &theReader ); |
|
170 // |
|
171 theReader.OpenLC( &aResFile, E_EXCLUDED_DIRECTORIES ); |
|
172 iExcludedDirArray = theReader.ReadDesCArrayL(); |
|
173 CleanupStack::PopAndDestroy( &theReader ); |
|
174 // |
|
175 theReader.OpenLC( &aResFile, E_SPECIAL_DATADIRS ); |
|
176 // reading later... |
|
177 |
|
178 } |
|
179 |
|
180 // Apply correct drive letter in directory array names |
|
181 TInt dirCount = iDirArray->Count(); |
|
182 for (TInt i=0; i<dirCount; i++) |
|
183 { |
|
184 HBufC* dirName = iDirArray->MdcaPoint(i).AllocLC(); |
|
185 TPtr ptrName = dirName->Des(); |
|
186 TBuf<1> drive; |
|
187 TChar ch; |
|
188 |
|
189 if ( RFs::DriveToChar( iCurrentScannedDrive, ch ) == KErrNone ) |
|
190 { |
|
191 drive.Append(ch); |
|
192 ptrName.Replace(0, drive.Length(), drive); |
|
193 } |
|
194 iDirArray->Delete(i); |
|
195 iDirArray->InsertL(i, ptrName); |
|
196 CleanupStack::PopAndDestroy(dirName); |
|
197 } |
|
198 |
|
199 // Apply correct drive letter in excluded directory array names |
|
200 TInt exDirCount = iExcludedDirArray->Count(); |
|
201 for (TInt i=0; i<exDirCount; i++) |
|
202 { |
|
203 HBufC* dirName = iExcludedDirArray->MdcaPoint(i).AllocLC(); |
|
204 TPtr ptrName = dirName->Des(); |
|
205 TBuf<1> drive; |
|
206 TChar ch; |
|
207 |
|
208 if ( RFs::DriveToChar( iCurrentScannedDrive, ch ) == KErrNone ) |
|
209 { |
|
210 drive.Append(ch); |
|
211 ptrName.Replace(0, drive.Length(), drive); |
|
212 } |
|
213 iExcludedDirArray->Delete(i); |
|
214 iExcludedDirArray->InsertL(i, ptrName); |
|
215 CleanupStack::PopAndDestroy(dirName); |
|
216 } |
|
217 |
|
218 //the first WORD contains the number of elements in the resource |
|
219 length = theReader.ReadInt16L(); |
|
220 |
|
221 // Create the arrays for special data dirs |
|
222 iDataDirArray = new (ELeave) CDesCArrayFlat(length); |
|
223 iDataDirGroupArray = new (ELeave) CArrayFixFlat<TInt>(length); |
|
224 iDataDirExclArray = new (ELeave) CArrayPtrFlat<CDesCArray>(length); |
|
225 |
|
226 // Read the array resource |
|
227 for(TInt i=0; i<length; i++) |
|
228 { |
|
229 TInt groupindex = theReader.ReadInt8L(); |
|
230 TChar ch; |
|
231 HBufC* name = theReader.ReadHBufCL(); |
|
232 CleanupStack::PushL(name); |
|
233 TPtr ptrName = name->Des(); |
|
234 TBuf<1> drive; |
|
235 TBool driveValid = EFalse; |
|
236 |
|
237 if ( RFs::DriveToChar( iCurrentScannedDrive, ch ) == KErrNone ) |
|
238 { |
|
239 driveValid = ETrue; |
|
240 drive.Append(ch); |
|
241 ptrName.Replace(0, drive.Length(), drive); |
|
242 } |
|
243 |
|
244 // Next WORD contains the number of excluded files |
|
245 TInt lengthExcl = theReader.ReadInt16L(); |
|
246 TBool folderExists = EFalse; |
|
247 |
|
248 // Add directory to the list to be scanned |
|
249 if(driveValid && BaflUtils::FolderExists(aFsSession, ptrName)) |
|
250 { |
|
251 folderExists = ETrue; |
|
252 iDataDirArray->AppendL(ptrName); |
|
253 iDataDirGroupArray->AppendL(groupindex); |
|
254 iDataDirExclArray->AppendL(NULL); |
|
255 |
|
256 CDesCArray* subarray = new (ELeave) CDesCArrayFlat( Max(lengthExcl, 1) ); |
|
257 const TInt dirCount = iDataDirExclArray->Count(); |
|
258 iDataDirExclArray->At(dirCount-1) = subarray; |
|
259 } |
|
260 |
|
261 for(TInt j=0; j<lengthExcl; j++) |
|
262 { |
|
263 TPtrC nameExcl = theReader.ReadTPtrCL(); |
|
264 |
|
265 // Append special file only if folder exists |
|
266 if(folderExists) |
|
267 { |
|
268 const TInt dirCount = iDataDirExclArray->Count(); |
|
269 iDataDirExclArray->At(dirCount-1)->AppendL( nameExcl ); |
|
270 } |
|
271 } |
|
272 |
|
273 // If there was an error, we can assume it was because |
|
274 // the folder does not exist, and ignore the error. |
|
275 CleanupStack::PopAndDestroy( name ); |
|
276 } |
|
277 CleanupStack::PopAndDestroy( &theReader ); |
|
278 |
|
279 #ifdef __SHOW_RDEBUG_PRINT_ |
|
280 RDebug::Print(_L("CMsengInfoArray constructed. Printing current configuration.\n Extensions:")); |
|
281 for(TInt j=0; j < Exts().Count(); j++) |
|
282 { |
|
283 HBufC* ext = Exts().MdcaPoint(j).AllocL(); |
|
284 RDebug::Print(_L(" %d: %S"), j, ext); |
|
285 delete ext; |
|
286 } |
|
287 RDebug::Print(_L(" UIDs:")); |
|
288 for(TInt k=0; k < Uids().Count(); k++) |
|
289 { |
|
290 TUidName uid; |
|
291 uid = Uids().At(k).Name(); |
|
292 RDebug::Print(_L(" %d: %S"), k, &uid); |
|
293 } |
|
294 #endif // __SHOW_RDEBUG_PRINT_ |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // CMsengInfoArray::~CMsengInfoArray() |
|
299 // |
|
300 // Destructor |
|
301 // --------------------------------------------------------------------------- |
|
302 CMsengInfoArray::~CMsengInfoArray() |
|
303 { |
|
304 // delete data structures |
|
305 delete iUidResultArray; |
|
306 delete iExtResultArray; |
|
307 delete iGroupResultArray; |
|
308 delete iUidArray; |
|
309 delete iExtArray; |
|
310 delete iDirArray; |
|
311 delete iExcludedDirArray; |
|
312 delete iDataDirArray; |
|
313 delete iDataDirGroupArray; |
|
314 if(iDataDirExclArray) |
|
315 { |
|
316 iDataDirExclArray->ResetAndDestroy(); |
|
317 } |
|
318 delete iDataDirExclArray; |
|
319 } |
|
320 |
|
321 // --------------------------------------------------------------------------- |
|
322 // CMsengInfoArray::IsExcludedDir() |
|
323 // |
|
324 // |
|
325 // --------------------------------------------------------------------------- |
|
326 TBool CMsengInfoArray::IsExcludedDir(const TDesC& aDirectory) const |
|
327 { |
|
328 TInt count = iExcludedDirArray->Count(); |
|
329 for(TInt i=0; i<count; i++) |
|
330 { |
|
331 if(aDirectory.FindF(iExcludedDirArray->MdcaPoint(i)) == 0) |
|
332 { |
|
333 return ETrue; |
|
334 } |
|
335 } |
|
336 |
|
337 return EFalse; |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // CMsengInfoArray::FolderExists() |
|
342 // |
|
343 // |
|
344 // --------------------------------------------------------------------------- |
|
345 TBool CMsengInfoArray::FolderExists(RFs& aFs, const TDesC& aPath) |
|
346 { |
|
347 TBool result = EFalse; |
|
348 |
|
349 if(BaflUtils::FolderExists(aFs, aPath)) |
|
350 { |
|
351 result = ETrue; |
|
352 } |
|
353 // BaflUtils::FolderExists return KErrBadName, if called with |
|
354 // only drive letter (like "c:\") |
|
355 else |
|
356 { |
|
357 TChar driveLetter; |
|
358 if( RFs::DriveToChar(CurrentDrive(), driveLetter) == KErrNone) |
|
359 { |
|
360 TBuf<1> driveName; |
|
361 driveName.Append(driveLetter); |
|
362 TInt cmp = aPath.CompareF(BaflUtils::RootFolderPath(driveName)); |
|
363 result = (cmp == 0); |
|
364 } |
|
365 } |
|
366 |
|
367 return result; |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // CMsengInfoArray::IsSpecialDir() |
|
372 // |
|
373 // |
|
374 // --------------------------------------------------------------------------- |
|
375 TBool CMsengInfoArray::IsSpecialDir(const TDesC& aDirectory) const |
|
376 { |
|
377 TInt count = iDataDirArray->Count(); |
|
378 for(TInt i=0; i<count; i++) |
|
379 { |
|
380 if(aDirectory.FindF(iDataDirArray->MdcaPoint(i)) == 0) |
|
381 { |
|
382 return ETrue; |
|
383 } |
|
384 } |
|
385 |
|
386 return EFalse; |
|
387 } |
|
388 |
|
389 // End of File |