21
|
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 |
&& !CMseng::IsMassStorageDrive( aFsSession, iCurrentScannedDrive ) )
|
|
153 |
{
|
|
154 |
theReader.OpenLC( &aResFile, C_DIRECTORIES );
|
|
155 |
iDirArray = theReader.ReadDesCArrayL();
|
|
156 |
CleanupStack::PopAndDestroy( &theReader );
|
|
157 |
//
|
|
158 |
theReader.OpenLC( &aResFile, C_EXCLUDED_DIRECTORIES );
|
|
159 |
iExcludedDirArray = theReader.ReadDesCArrayL();
|
|
160 |
CleanupStack::PopAndDestroy( &theReader );
|
|
161 |
//
|
|
162 |
theReader.OpenLC( &aResFile, C_SPECIAL_DATADIRS );
|
|
163 |
// reading later...
|
|
164 |
|
|
165 |
}
|
|
166 |
else // other drives except Phone Memory should be scanned from root folder.
|
|
167 |
{
|
|
168 |
theReader.OpenLC( &aResFile, E_DIRECTORIES );
|
|
169 |
iDirArray = theReader.ReadDesCArrayL();
|
|
170 |
CleanupStack::PopAndDestroy( &theReader );
|
|
171 |
//
|
|
172 |
theReader.OpenLC( &aResFile, E_EXCLUDED_DIRECTORIES );
|
|
173 |
iExcludedDirArray = theReader.ReadDesCArrayL();
|
|
174 |
CleanupStack::PopAndDestroy( &theReader );
|
|
175 |
//
|
|
176 |
theReader.OpenLC( &aResFile, E_SPECIAL_DATADIRS );
|
|
177 |
// reading later...
|
|
178 |
|
|
179 |
}
|
|
180 |
|
|
181 |
// Apply correct drive letter in directory array names
|
|
182 |
TInt dirCount = iDirArray->Count();
|
|
183 |
for (TInt i=0; i<dirCount; i++)
|
|
184 |
{
|
|
185 |
HBufC* dirName = iDirArray->MdcaPoint(i).AllocLC();
|
|
186 |
TPtr ptrName = dirName->Des();
|
|
187 |
TBuf<1> drive;
|
|
188 |
TChar ch;
|
|
189 |
|
|
190 |
if ( RFs::DriveToChar( iCurrentScannedDrive, ch ) == KErrNone )
|
|
191 |
{
|
|
192 |
drive.Append(ch);
|
|
193 |
ptrName.Replace(0, drive.Length(), drive);
|
|
194 |
}
|
|
195 |
iDirArray->Delete(i);
|
|
196 |
iDirArray->InsertL(i, ptrName);
|
|
197 |
CleanupStack::PopAndDestroy(dirName);
|
|
198 |
}
|
|
199 |
|
|
200 |
// Apply correct drive letter in excluded directory array names
|
|
201 |
TInt exDirCount = iExcludedDirArray->Count();
|
|
202 |
for (TInt i=0; i<exDirCount; i++)
|
|
203 |
{
|
|
204 |
HBufC* dirName = iExcludedDirArray->MdcaPoint(i).AllocLC();
|
|
205 |
TPtr ptrName = dirName->Des();
|
|
206 |
TBuf<1> drive;
|
|
207 |
TChar ch;
|
|
208 |
|
|
209 |
if ( RFs::DriveToChar( iCurrentScannedDrive, ch ) == KErrNone )
|
|
210 |
{
|
|
211 |
drive.Append(ch);
|
|
212 |
ptrName.Replace(0, drive.Length(), drive);
|
|
213 |
}
|
|
214 |
iExcludedDirArray->Delete(i);
|
|
215 |
iExcludedDirArray->InsertL(i, ptrName);
|
|
216 |
CleanupStack::PopAndDestroy(dirName);
|
|
217 |
}
|
|
218 |
|
|
219 |
//the first WORD contains the number of elements in the resource
|
|
220 |
length = theReader.ReadInt16L();
|
|
221 |
|
|
222 |
// Create the arrays for special data dirs
|
|
223 |
iDataDirArray = new (ELeave) CDesCArrayFlat(length);
|
|
224 |
iDataDirGroupArray = new (ELeave) CArrayFixFlat<TInt>(length);
|
|
225 |
iDataDirExclArray = new (ELeave) CArrayPtrFlat<CDesCArray>(length);
|
|
226 |
|
|
227 |
// Read the array resource
|
|
228 |
for(TInt i=0; i<length; i++)
|
|
229 |
{
|
|
230 |
TInt groupindex = theReader.ReadInt8L();
|
|
231 |
TChar ch;
|
|
232 |
HBufC* name = theReader.ReadHBufCL();
|
|
233 |
CleanupStack::PushL(name);
|
|
234 |
TPtr ptrName = name->Des();
|
|
235 |
TBuf<1> drive;
|
|
236 |
TBool driveValid = EFalse;
|
|
237 |
|
|
238 |
if ( RFs::DriveToChar( iCurrentScannedDrive, ch ) == KErrNone )
|
|
239 |
{
|
|
240 |
driveValid = ETrue;
|
|
241 |
drive.Append(ch);
|
|
242 |
ptrName.Replace(0, drive.Length(), drive);
|
|
243 |
}
|
|
244 |
|
|
245 |
// Next WORD contains the number of excluded files
|
|
246 |
TInt lengthExcl = theReader.ReadInt16L();
|
|
247 |
TBool folderExists = EFalse;
|
|
248 |
|
|
249 |
// Add directory to the list to be scanned
|
|
250 |
if(driveValid && BaflUtils::FolderExists(aFsSession, ptrName))
|
|
251 |
{
|
|
252 |
folderExists = ETrue;
|
|
253 |
iDataDirArray->AppendL(ptrName);
|
|
254 |
iDataDirGroupArray->AppendL(groupindex);
|
|
255 |
iDataDirExclArray->AppendL(NULL);
|
|
256 |
|
|
257 |
CDesCArray* subarray = new (ELeave) CDesCArrayFlat( Max(lengthExcl, 1) );
|
|
258 |
const TInt dirCount = iDataDirExclArray->Count();
|
|
259 |
iDataDirExclArray->At(dirCount-1) = subarray;
|
|
260 |
}
|
|
261 |
|
|
262 |
for(TInt j=0; j<lengthExcl; j++)
|
|
263 |
{
|
|
264 |
TPtrC nameExcl = theReader.ReadTPtrCL();
|
|
265 |
|
|
266 |
// Append special file only if folder exists
|
|
267 |
if(folderExists)
|
|
268 |
{
|
|
269 |
const TInt dirCount = iDataDirExclArray->Count();
|
|
270 |
iDataDirExclArray->At(dirCount-1)->AppendL( nameExcl );
|
|
271 |
}
|
|
272 |
}
|
|
273 |
|
|
274 |
// If there was an error, we can assume it was because
|
|
275 |
// the folder does not exist, and ignore the error.
|
|
276 |
CleanupStack::PopAndDestroy( name );
|
|
277 |
}
|
|
278 |
CleanupStack::PopAndDestroy( &theReader );
|
|
279 |
|
|
280 |
#ifdef __SHOW_RDEBUG_PRINT_
|
|
281 |
RDebug::Print(_L("CMsengInfoArray constructed. Printing current configuration.\n Extensions:"));
|
|
282 |
for(TInt j=0; j < Exts().Count(); j++)
|
|
283 |
{
|
|
284 |
HBufC* ext = Exts().MdcaPoint(j).AllocL();
|
|
285 |
RDebug::Print(_L(" %d: %S"), j, ext);
|
|
286 |
delete ext;
|
|
287 |
}
|
|
288 |
RDebug::Print(_L(" UIDs:"));
|
|
289 |
for(TInt k=0; k < Uids().Count(); k++)
|
|
290 |
{
|
|
291 |
TUidName uid;
|
|
292 |
uid = Uids().At(k).Name();
|
|
293 |
RDebug::Print(_L(" %d: %S"), k, &uid);
|
|
294 |
}
|
|
295 |
#endif // __SHOW_RDEBUG_PRINT_
|
|
296 |
}
|
|
297 |
|
|
298 |
// ---------------------------------------------------------------------------
|
|
299 |
// CMsengInfoArray::~CMsengInfoArray()
|
|
300 |
//
|
|
301 |
// Destructor
|
|
302 |
// ---------------------------------------------------------------------------
|
|
303 |
CMsengInfoArray::~CMsengInfoArray()
|
|
304 |
{
|
|
305 |
// delete data structures
|
|
306 |
delete iUidResultArray;
|
|
307 |
delete iExtResultArray;
|
|
308 |
delete iGroupResultArray;
|
|
309 |
delete iUidArray;
|
|
310 |
delete iExtArray;
|
|
311 |
delete iDirArray;
|
|
312 |
delete iExcludedDirArray;
|
|
313 |
delete iDataDirArray;
|
|
314 |
delete iDataDirGroupArray;
|
|
315 |
if(iDataDirExclArray)
|
|
316 |
{
|
|
317 |
iDataDirExclArray->ResetAndDestroy();
|
|
318 |
}
|
|
319 |
delete iDataDirExclArray;
|
|
320 |
}
|
|
321 |
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
// CMsengInfoArray::IsExcludedDir()
|
|
324 |
//
|
|
325 |
//
|
|
326 |
// ---------------------------------------------------------------------------
|
|
327 |
TBool CMsengInfoArray::IsExcludedDir(const TDesC& aDirectory) const
|
|
328 |
{
|
|
329 |
TInt count = iExcludedDirArray->Count();
|
|
330 |
for(TInt i=0; i<count; i++)
|
|
331 |
{
|
|
332 |
if(aDirectory.FindF(iExcludedDirArray->MdcaPoint(i)) == 0)
|
|
333 |
{
|
|
334 |
return ETrue;
|
|
335 |
}
|
|
336 |
}
|
|
337 |
|
|
338 |
return EFalse;
|
|
339 |
}
|
|
340 |
|
|
341 |
// ---------------------------------------------------------------------------
|
|
342 |
// CMsengInfoArray::FolderExists()
|
|
343 |
//
|
|
344 |
//
|
|
345 |
// ---------------------------------------------------------------------------
|
|
346 |
TBool CMsengInfoArray::FolderExists(RFs& aFs, const TDesC& aPath)
|
|
347 |
{
|
|
348 |
TBool result = EFalse;
|
|
349 |
|
|
350 |
if(BaflUtils::FolderExists(aFs, aPath))
|
|
351 |
{
|
|
352 |
result = ETrue;
|
|
353 |
}
|
|
354 |
// BaflUtils::FolderExists return KErrBadName, if called with
|
|
355 |
// only drive letter (like "c:\")
|
|
356 |
else
|
|
357 |
{
|
|
358 |
TChar driveLetter;
|
|
359 |
if( RFs::DriveToChar(CurrentDrive(), driveLetter) == KErrNone)
|
|
360 |
{
|
|
361 |
TBuf<1> driveName;
|
|
362 |
driveName.Append(driveLetter);
|
|
363 |
TInt cmp = aPath.CompareF(BaflUtils::RootFolderPath(driveName));
|
|
364 |
result = (cmp == 0);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
|
|
368 |
return result;
|
|
369 |
}
|
|
370 |
|
|
371 |
// ---------------------------------------------------------------------------
|
|
372 |
// CMsengInfoArray::IsSpecialDir()
|
|
373 |
//
|
|
374 |
//
|
|
375 |
// ---------------------------------------------------------------------------
|
|
376 |
TBool CMsengInfoArray::IsSpecialDir(const TDesC& aDirectory) const
|
|
377 |
{
|
|
378 |
TInt count = iDataDirArray->Count();
|
|
379 |
for(TInt i=0; i<count; i++)
|
|
380 |
{
|
|
381 |
if(aDirectory.FindF(iDataDirArray->MdcaPoint(i)) == 0)
|
|
382 |
{
|
|
383 |
return ETrue;
|
|
384 |
}
|
|
385 |
}
|
|
386 |
|
|
387 |
return EFalse;
|
|
388 |
}
|
|
389 |
|
|
390 |
// End of File
|