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 |
* Scanner class used to scan file system by filename extensions.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// USER INCLUDES
|
|
21 |
#include "msengfileextscanner.h"
|
|
22 |
#include "msenguihandler.h"
|
|
23 |
|
|
24 |
|
|
25 |
// ================= MEMBER FUNCTIONS ========================================
|
|
26 |
|
|
27 |
// ---------------------------------------------------------------------------
|
|
28 |
// CMsengFileExtScanner::CMsengFileExtScanner()
|
|
29 |
//
|
|
30 |
// C++ default constructor. Can NOT contain any code, that might leave.
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
CMsengFileExtScanner::CMsengFileExtScanner(MMsengScannerObserver& aObserver,
|
|
33 |
CMsengInfoArray& aScanArray,
|
|
34 |
RFs& aFsSession)
|
|
35 |
: CMsengFileScanner(aObserver, aScanArray, aFsSession), iMoveToNextDirectory(ETrue)
|
|
36 |
{
|
|
37 |
}
|
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// CMsengFileExtScanner::NewL()
|
|
41 |
//
|
|
42 |
// Two-phased constructor
|
|
43 |
// ---------------------------------------------------------------------------
|
|
44 |
CMsengFileExtScanner* CMsengFileExtScanner::NewL(MMsengScannerObserver& aObserver,
|
|
45 |
CMsengInfoArray& aScanArray,
|
|
46 |
RFs& aFsSession)
|
|
47 |
{
|
|
48 |
CMsengFileExtScanner* self =
|
|
49 |
new (ELeave) CMsengFileExtScanner(aObserver, aScanArray, aFsSession);
|
|
50 |
return self;
|
|
51 |
}
|
|
52 |
|
|
53 |
// ---------------------------------------------------------------------------
|
|
54 |
// CMsengFileExtScanner::~CMsengFileExtScanner()
|
|
55 |
//
|
|
56 |
// Destructor
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
CMsengFileExtScanner::~CMsengFileExtScanner()
|
|
59 |
{
|
|
60 |
}
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
// ---------------------------------------------------------------------------
|
|
66 |
// CMsengFileExtScanner::FindFilesL()
|
|
67 |
//
|
|
68 |
// ---------------------------------------------------------------------------
|
|
69 |
//
|
|
70 |
CDir* CMsengFileExtScanner::FindFilesL(const TDesC& aDirectory, TBool& aMoveToNextDirectory)
|
|
71 |
{
|
|
72 |
|
|
73 |
// iMoveToNextDirectory is true only when starting to handle the
|
|
74 |
// current directory. Reset iCurrentExtensionIndex.
|
|
75 |
if(iMoveToNextDirectory)
|
|
76 |
{
|
|
77 |
iCurrentExtensionIndex = -1;
|
|
78 |
iMoveToNextDirectory = EFalse;
|
|
79 |
#ifdef __SHOW_RDEBUG_PRINT_
|
|
80 |
RDebug::Print(_L("Entering directory:"));
|
|
81 |
RDebug::Print(_L("%S"), &aDirectory);
|
|
82 |
#endif // __SHOW_RDEBUG_PRINT_
|
|
83 |
}
|
|
84 |
|
|
85 |
// This function performs a search for each file in the directory by extension.
|
|
86 |
iCurrentExtensionIndex++;
|
|
87 |
const TPtrC pCurrentExtension(InfoArray().Exts()[iCurrentExtensionIndex]);
|
|
88 |
|
|
89 |
#ifdef __SHOW_RDEBUG_PRINT_
|
|
90 |
RDebug::Print(_L("Searching files with extension %d"), iCurrentExtensionIndex);
|
|
91 |
#endif // __SHOW_RDEBUG_PRINT_
|
|
92 |
|
|
93 |
// Get a list of results for this directory
|
|
94 |
CDir* results = NULL;
|
|
95 |
TParse parse;
|
|
96 |
TInt error;
|
|
97 |
|
|
98 |
const TInt pathlength = pCurrentExtension.Length() + aDirectory.Length();
|
|
99 |
if ( pathlength > KMaxFileName )
|
|
100 |
{
|
|
101 |
error = KErrNotFound;
|
|
102 |
#ifdef __SHOW_RDEBUG_PRINT_
|
|
103 |
RDebug::Print(_L("Path too long, files with extension %d do not fit to directory"),
|
|
104 |
iCurrentExtensionIndex);
|
|
105 |
#endif // __SHOW_RDEBUG_PRINT_
|
|
106 |
}
|
|
107 |
|
|
108 |
else
|
|
109 |
{
|
|
110 |
FsSession().Parse(pCurrentExtension, aDirectory, parse);
|
|
111 |
error = FsSession().GetDir(parse.FullName(), KEntryAttMaskSupported|KEntryAttAllowUid,
|
|
112 |
ESortNone, results);
|
|
113 |
}
|
|
114 |
|
|
115 |
if (error == KErrNotFound)
|
|
116 |
{
|
|
117 |
results = NULL;
|
|
118 |
}
|
|
119 |
|
|
120 |
// Should we move onto searching the next directory
|
|
121 |
// Yes, if this was the last extension.
|
|
122 |
const TInt extensionCount = InfoArray().Exts().Count();
|
|
123 |
iMoveToNextDirectory = (iCurrentExtensionIndex >= extensionCount-1);
|
|
124 |
aMoveToNextDirectory = iMoveToNextDirectory;
|
|
125 |
|
|
126 |
// Return populated (or potentially NULL) list.
|
|
127 |
return results;
|
|
128 |
}
|
|
129 |
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
// CMsengFileExtScanner::HandleLocatedEntryL()
|
|
132 |
//
|
|
133 |
//
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
CMsengFileScanner::TLocationResponse CMsengFileExtScanner::HandleLocatedEntryL(
|
|
137 |
const TDesC& aFullFileNameAndPath, const TEntry& aEntry)
|
|
138 |
{
|
|
139 |
TLocationResponse response = EEntryWasDiscarded;
|
|
140 |
const TInt KUidLocation = 2;
|
|
141 |
TUid fileUid = aEntry[KUidLocation];
|
|
142 |
|
|
143 |
if ( fileUid == KNullUid )
|
|
144 |
{
|
|
145 |
// Check whether extension found in special data dir
|
|
146 |
TBool addSize( ETrue );
|
|
147 |
TInt dataDirCount = InfoArray().DataDirs().Count();
|
|
148 |
for(TInt i=0; i < dataDirCount; i++)
|
|
149 |
{
|
|
150 |
TPtrC dataDirPath = InfoArray().DataDirs().MdcaPoint(i);
|
|
151 |
|
|
152 |
if(aFullFileNameAndPath.Length() >= dataDirPath.Length())
|
|
153 |
{
|
|
154 |
TFileName currentPath;
|
|
155 |
currentPath.Copy(aFullFileNameAndPath.Left(dataDirPath.Length()));
|
|
156 |
|
|
157 |
// Compare whether folder matches
|
|
158 |
if(!currentPath.CompareF(dataDirPath))
|
|
159 |
{
|
|
160 |
addSize = EFalse;
|
|
161 |
break;
|
|
162 |
}
|
|
163 |
}
|
|
164 |
}
|
|
165 |
|
|
166 |
if( addSize )
|
|
167 |
{
|
|
168 |
// Add size of object
|
|
169 |
InfoArray().AddSizeByExtL(iCurrentExtensionIndex, aEntry.FileSize() );
|
|
170 |
|
|
171 |
#ifdef __SHOW_RDEBUG_PRINT_
|
|
172 |
const TInt pathlength = aFullFileNameAndPath.Length();
|
|
173 |
|
|
174 |
if ( pathlength < KMaxFileName )
|
|
175 |
{
|
|
176 |
RDebug::Print(_L("File: %S, extension number: %d, size: %d"),
|
|
177 |
&aFullFileNameAndPath, iCurrentExtensionIndex, aEntry.FileSize());
|
|
178 |
}
|
|
179 |
else
|
|
180 |
{
|
|
181 |
RDebug::Print(_L("File: see next line, extension number: %d, size: %d"),
|
|
182 |
iCurrentExtensionIndex, aEntry.FileSize() );
|
|
183 |
RDebug::Print(_L("Can not print %d characters long file name"), pathlength );
|
|
184 |
}
|
|
185 |
#endif // __SHOW_RDEBUG_PRINT_
|
|
186 |
|
|
187 |
// We processed this one
|
|
188 |
response = EEntryWasProcessed;
|
|
189 |
}
|
|
190 |
}
|
|
191 |
else
|
|
192 |
{
|
|
193 |
#ifdef __SHOW_RDEBUG_PRINT_
|
|
194 |
RDebug::Print(_L("Handling file: %S, file Uid: 0x%x"),
|
|
195 |
&aFullFileNameAndPath, fileUid.iUid);
|
|
196 |
#endif // __SHOW_RDEBUG_PRINT_
|
|
197 |
|
|
198 |
// Make sure other than native applications are not calculated
|
|
199 |
if( iCurrentExtensionIndex == EExtSis || iCurrentExtensionIndex == EExtSisx )
|
|
200 |
{
|
|
201 |
InfoArray().AddSizeByExtL(iCurrentExtensionIndex, aEntry.FileSize() );
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
return response;
|
|
206 |
}
|
|
207 |
|
|
208 |
// End of File
|