1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "aprfndr.h" |
|
17 #include "APFDEF.H" |
|
18 #include "APFSTD.H" |
|
19 #include "../apgrfx/APGAIR.H" |
|
20 #include <apsserv.h> |
|
21 #include "../apgrfx/apprivate.h" |
|
22 #include <apsidchecker.h> |
|
23 |
|
24 ///////////////////////////// |
|
25 // CApaAppRegFinder |
|
26 ///////////////////////////// |
|
27 |
|
28 EXPORT_C CApaAppRegFinder* CApaAppRegFinder::NewL(const RFs& aFs) |
|
29 { |
|
30 CApaAppRegFinder* self=NewLC(aFs); |
|
31 CleanupStack::Pop(self); |
|
32 return self; |
|
33 } |
|
34 |
|
35 EXPORT_C CApaAppRegFinder* CApaAppRegFinder::NewLC(const RFs& aFs) |
|
36 { |
|
37 CApaAppRegFinder* self=new (ELeave) CApaAppRegFinder(aFs); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 CApaAppRegFinder::CApaAppRegFinder(const RFs& aFs) |
|
44 : iFs(aFs), |
|
45 iListOfFolders(2), |
|
46 iSidCheckerMap(CApaAppListServer::Self()?CApaAppListServer::Self()->RescanCallBack():TCallBack(NULL,NULL)) |
|
47 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
48 ,iRemovableMediaDriveScan(EFalse) |
|
49 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
50 |
|
51 { |
|
52 } |
|
53 |
|
54 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
55 CApaAppRegFinder::~CApaAppRegFinder() |
|
56 { |
|
57 iListOfFolders.ResetAndDestroy(); |
|
58 iListOfFolders.Close(); |
|
59 iListOfDrives.Close(); |
|
60 iSidCheckerMap.Close(); |
|
61 delete iFileList; // should already be deleted and NULL at this point |
|
62 } |
|
63 #else |
|
64 CApaAppRegFinder::~CApaAppRegFinder() |
|
65 { |
|
66 iListOfFolders.ResetAndDestroy(); |
|
67 iListOfFolders.Close(); |
|
68 if (iListOfDrives) |
|
69 { |
|
70 iListOfDrives->Close(); |
|
71 delete iListOfDrives; |
|
72 } |
|
73 iSidCheckerMap.Close(); |
|
74 |
|
75 delete iFileList; // should already be deleted and NULL at this point |
|
76 } |
|
77 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
78 |
|
79 void CApaAppRegFinder::ConstructL() |
|
80 { |
|
81 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
82 BuildDriveListL(); |
|
83 #else |
|
84 GetDriveListL(); |
|
85 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
86 GetFolderListL(); |
|
87 } |
|
88 |
|
89 #ifndef SYMBIAN_APPARC_APPINFO_CACHE |
|
90 void CApaAppRegFinder::GetDriveListL() |
|
91 { |
|
92 TDriveList driveList; |
|
93 User::LeaveIfError(iFs.DriveList(driveList)); |
|
94 iListOfDrives = new(ELeave) RArray<TDriveUnitInfo>(4); |
|
95 BuildDriveListL(iFs, driveList, *iListOfDrives); |
|
96 } |
|
97 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
98 |
|
99 _LIT(KAppRegRscSearchPath,"\\private\\10003a3f\\apps\\"); |
|
100 _LIT(KAppRegRscImportSearchPath,"\\private\\10003a3f\\import\\apps\\"); |
|
101 _LIT(KAppRegRscImportNonNativeSearchPath,"\\private\\10003a3f\\import\\apps\\NonNative\\Resource\\"); |
|
102 |
|
103 void CApaAppRegFinder::GetFolderListL() |
|
104 { |
|
105 TPtrC ptr(KAppRegRscSearchPath); |
|
106 HBufC* searchPath = ptr.AllocLC(); |
|
107 User::LeaveIfError(iListOfFolders.Append(searchPath)); |
|
108 CleanupStack::Pop(searchPath); |
|
109 searchPath = NULL; |
|
110 |
|
111 ptr.Set(KAppRegRscImportSearchPath); |
|
112 searchPath = ptr.AllocLC(); |
|
113 User::LeaveIfError(iListOfFolders.Append(searchPath)); |
|
114 CleanupStack::Pop(searchPath); |
|
115 |
|
116 ptr.Set(KAppRegRscImportNonNativeSearchPath); |
|
117 searchPath = ptr.AllocLC(); |
|
118 User::LeaveIfError(iListOfFolders.Append(searchPath)); |
|
119 CleanupStack::Pop(searchPath); |
|
120 } |
|
121 |
|
122 #ifndef SYMBIAN_APPARC_APPINFO_CACHE |
|
123 void CApaAppRegFinder::BuildDriveListL(const RFs& aFs, const TDriveList& aSourceDriveList, RArray<TDriveUnitInfo>& aDestDriveList) |
|
124 { // static |
|
125 TInt drive(EDriveY); |
|
126 TDriveUnitInfo driveUnitInfo; |
|
127 while(drive >= EDriveA) |
|
128 { |
|
129 if (aSourceDriveList[drive]!=KDriveAbsent) |
|
130 { |
|
131 TDriveInfo driveInfo; |
|
132 TInt ret = aFs.Drive(driveInfo,drive); |
|
133 if (ret==KErrNone) |
|
134 { |
|
135 if (driveInfo.iType!=EMediaNotPresent && driveInfo.iType!=EMediaRemote) |
|
136 { |
|
137 driveUnitInfo.iDriveUnit=drive; |
|
138 driveUnitInfo.iDriveAtt=driveInfo.iDriveAtt; |
|
139 User::LeaveIfError(aDestDriveList.Append(driveUnitInfo)); |
|
140 } |
|
141 } |
|
142 } |
|
143 --drive; |
|
144 } |
|
145 driveUnitInfo.iDriveUnit=EDriveZ; |
|
146 driveUnitInfo.iDriveAtt=KDriveAttRom; |
|
147 User::LeaveIfError(aDestDriveList.Append(driveUnitInfo)); |
|
148 } |
|
149 |
|
150 EXPORT_C void CApaAppRegFinder::FindAllAppsL() |
|
151 { |
|
152 delete iFileList; |
|
153 iFileList = NULL; |
|
154 if(iListOfDrives) |
|
155 { |
|
156 iListOfDrives->Close(); |
|
157 delete iListOfDrives; |
|
158 iListOfDrives = NULL; |
|
159 } |
|
160 GetDriveListL(); |
|
161 iCurrentIndexInDriveList=-1; |
|
162 iCurrentIndexInFolderList=0; |
|
163 iScanStage=EScanStageNonImportROM; |
|
164 iLastChkedApp = KNullUid; |
|
165 } |
|
166 |
|
167 #else |
|
168 void CApaAppRegFinder::BuildDriveListL() |
|
169 { |
|
170 TDriveList driveList; |
|
171 User::LeaveIfError(iFs.DriveList(driveList)); |
|
172 |
|
173 TInt drive(EDriveY); |
|
174 TDriveUnitInfo driveUnitInfo; |
|
175 while(drive >= EDriveA) |
|
176 { |
|
177 if (driveList[drive]!=KDriveAbsent) |
|
178 { |
|
179 TDriveInfo driveInfo; |
|
180 TInt ret = iFs.Drive(driveInfo,drive); |
|
181 if (ret==KErrNone) |
|
182 { |
|
183 if (iRemovableMediaDriveScan) |
|
184 {// iListOfDrives should have list of all the removable drives irrespective of presence of the media |
|
185 if ((driveInfo.iType != EMediaRemote) && (driveInfo.iDriveAtt & KDriveAttRemovable)) |
|
186 { |
|
187 driveUnitInfo.iDriveUnit=drive; |
|
188 driveUnitInfo.iDriveAtt=driveInfo.iDriveAtt; |
|
189 User::LeaveIfError(iListOfDrives.Append(driveUnitInfo)); |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 if (driveInfo.iType!=EMediaNotPresent && driveInfo.iType!=EMediaRemote) |
|
195 { |
|
196 driveUnitInfo.iDriveUnit=drive; |
|
197 driveUnitInfo.iDriveAtt=driveInfo.iDriveAtt; |
|
198 User::LeaveIfError(iListOfDrives.Append(driveUnitInfo)); |
|
199 } |
|
200 } |
|
201 } |
|
202 } |
|
203 --drive; |
|
204 } |
|
205 if (!iRemovableMediaDriveScan) |
|
206 { |
|
207 driveUnitInfo.iDriveUnit=EDriveZ; |
|
208 driveUnitInfo.iDriveAtt=KDriveAttRom; |
|
209 User::LeaveIfError(iListOfDrives.Append(driveUnitInfo)); |
|
210 } |
|
211 } |
|
212 |
|
213 EXPORT_C void CApaAppRegFinder::FindAllRemovableMediaAppsL() |
|
214 { |
|
215 iRemovableMediaDriveScan = ETrue; |
|
216 FindAllAppsL(); |
|
217 } |
|
218 |
|
219 EXPORT_C const RArray<TDriveUnitInfo>& CApaAppRegFinder::DriveList() const |
|
220 { |
|
221 return (iListOfDrives); |
|
222 } |
|
223 |
|
224 EXPORT_C void CApaAppRegFinder::FindAllAppsL() |
|
225 { |
|
226 delete iFileList; |
|
227 iFileList = NULL; |
|
228 iListOfDrives.Reset(); |
|
229 BuildDriveListL(); |
|
230 iCurrentIndexInDriveList=-1; |
|
231 iCurrentIndexInFolderList=0; |
|
232 iScanStage = EScanStageNonImportROM; |
|
233 iRemovableMediaDriveScan = EFalse; |
|
234 iLastChkedApp = KNullUid; |
|
235 } |
|
236 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
237 |
|
238 /** Scans the applications in following order: |
|
239 1. non-import y-a,z but only on ROM drives |
|
240 2. import on all non-ROM drives in the order y-a,z |
|
241 3. import on all ROM drives in the order y-a,z |
|
242 |
|
243 Upgrades of apparc server (via Software Install) are currently disallowed. |
|
244 This means it is not possible to install registration files to \private\10003a3f\apps |
|
245 (on any drive), so there is no need to scan \private\10003a3f\apps on non ROM based drives. |
|
246 */ |
|
247 EXPORT_C TBool CApaAppRegFinder::NextL(TApaAppEntry& aAppRegistrationEntry, const RPointerArray<HBufC>& aForcedRegistrations) |
|
248 { |
|
249 TBool entryFound = EFalse; |
|
250 while (DoNextL(aAppRegistrationEntry, aForcedRegistrations, entryFound)) |
|
251 { |
|
252 //do nothing. the point is to keep calling DoNextL |
|
253 } |
|
254 return entryFound; |
|
255 } |
|
256 |
|
257 TBool CApaAppRegFinder::DoNextL(TApaAppEntry& aAppRegistrationEntry, const RPointerArray<HBufC>& aForcedRegistrations, TBool& aEntryFound) |
|
258 { |
|
259 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
260 __ASSERT_ALWAYS(iListOfDrives.Count(),Panic(EPanicFindAllAppsNotCalled)); |
|
261 #else |
|
262 __ASSERT_ALWAYS(iListOfDrives,Panic(EPanicFindAllAppsNotCalled)); |
|
263 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
264 |
|
265 if (!iFileList) |
|
266 {// scan the next drive/dir |
|
267 iFileIndex = 0; |
|
268 while (GetNextDriveAndFolder()) |
|
269 { |
|
270 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
271 if (GetFileListL((iListOfDrives[iCurrentIndexInDriveList]).iDriveUnit, *iListOfFolders[iCurrentIndexInFolderList])==KErrNone) |
|
272 #else |
|
273 if (GetFileListL(((*iListOfDrives)[iCurrentIndexInDriveList]).iDriveUnit, *iListOfFolders[iCurrentIndexInFolderList])==KErrNone) |
|
274 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
275 { |
|
276 break; |
|
277 } |
|
278 } |
|
279 if (!iFileList) |
|
280 { |
|
281 aEntryFound = EFalse; |
|
282 return EFalse; // no more drives to scan |
|
283 } |
|
284 } |
|
285 // scan the file list |
|
286 while (iFileIndex<iFileList->Count()) |
|
287 { |
|
288 const TEntry& entry=(*iFileList)[iFileIndex++]; |
|
289 if (!ApaUtils::HandleAsRegistrationFile(entry.iType)) |
|
290 { |
|
291 continue; // only interested in app registration resource files |
|
292 } |
|
293 |
|
294 TParse parse; |
|
295 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
296 const TDriveName driveName = (iListOfDrives[iCurrentIndexInDriveList]).iDriveUnit.Name(); |
|
297 #else |
|
298 const TDriveName driveName = ((*iListOfDrives)[iCurrentIndexInDriveList]).iDriveUnit.Name(); |
|
299 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
300 parse.Set(entry.iName, iListOfFolders[iCurrentIndexInFolderList], &driveName); |
|
301 |
|
302 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
303 if (iListOfDrives[iCurrentIndexInDriveList].iDriveAtt&KDriveAttRemovable) |
|
304 #else |
|
305 if ((*iListOfDrives)[iCurrentIndexInDriveList].iDriveAtt&KDriveAttRemovable) |
|
306 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
307 { |
|
308 if (entry[2] != iLastChkedApp) //Check for validity only if it has not yet been checked |
|
309 { |
|
310 TUid appTypeUid; |
|
311 if(entry[0].iUid == KUidPrefixedNonNativeRegistrationResourceFile) |
|
312 { |
|
313 appTypeUid = entry[1]; |
|
314 } |
|
315 else |
|
316 { |
|
317 appTypeUid = KNullUid; |
|
318 } |
|
319 |
|
320 // Get the CAppSidChecker for this type of executable |
|
321 TBool validRegistration = ETrue; |
|
322 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
323 TRAPD(err, validRegistration = iSidCheckerMap.FindSidCheckerL(appTypeUid).AppRegisteredAt(entry[2], (iListOfDrives)[iCurrentIndexInDriveList].iDriveUnit)); |
|
324 #else |
|
325 TRAPD(err, validRegistration = iSidCheckerMap.FindSidCheckerL(appTypeUid).AppRegisteredAt(entry[2], (*iListOfDrives)[iCurrentIndexInDriveList].iDriveUnit)); |
|
326 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
327 iLastChkedApp = entry[2]; |
|
328 if(err == KErrNone) |
|
329 { |
|
330 if(!validRegistration) |
|
331 { |
|
332 // Check if this registration file should be included |
|
333 // despite not being officially reported as a valid registration |
|
334 HBufC* fullName = parse.FullName().AllocLC(); |
|
335 TInt pos = aForcedRegistrations.FindInOrder(fullName, TLinearOrder<HBufC>(CApaAppList::CompareStrings)); |
|
336 CleanupStack::PopAndDestroy(fullName); |
|
337 if (pos == KErrNotFound) |
|
338 { |
|
339 continue; |
|
340 } |
|
341 } |
|
342 } |
|
343 else if(err != KErrNotFound) |
|
344 { |
|
345 User::Leave(err); |
|
346 } |
|
347 } |
|
348 else |
|
349 { |
|
350 continue; |
|
351 } |
|
352 } |
|
353 aAppRegistrationEntry.iUidType = entry.iType; |
|
354 aAppRegistrationEntry.iFullName = parse.FullName(); |
|
355 aEntryFound = ETrue; // we found one |
|
356 return EFalse; |
|
357 } |
|
358 // current Drive has been exhausted |
|
359 delete iFileList; |
|
360 iFileList = NULL; |
|
361 return ETrue; // scan the next drive |
|
362 } |
|
363 |
|
364 TBool CApaAppRegFinder::GetNextDriveAndFolder() |
|
365 { |
|
366 TBool found=ETrue; |
|
367 TBool checkNextFolder=ETrue; |
|
368 TDriveUnitInfo driveUnitInfo; |
|
369 while (checkNextFolder) |
|
370 { |
|
371 // move to next folder |
|
372 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
373 if (++iCurrentIndexInDriveList>=iListOfDrives.Count()) |
|
374 #else |
|
375 if (++iCurrentIndexInDriveList>=iListOfDrives->Count()) |
|
376 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
377 { |
|
378 iCurrentIndexInDriveList=0; |
|
379 ++iScanStage; |
|
380 } |
|
381 |
|
382 //Get drive info |
|
383 #ifdef SYMBIAN_APPARC_APPINFO_CACHE |
|
384 driveUnitInfo=iListOfDrives[iCurrentIndexInDriveList]; |
|
385 #else |
|
386 driveUnitInfo=(*iListOfDrives)[iCurrentIndexInDriveList]; |
|
387 #endif // SYMBIAN_APPARC_APPINFO_CACHE |
|
388 //check folder |
|
389 switch (iScanStage) |
|
390 { |
|
391 case EScanStageNonImportROM: |
|
392 if (driveUnitInfo.iDriveAtt==KDriveAttRom) |
|
393 { |
|
394 iCurrentIndexInFolderList=0; |
|
395 checkNextFolder=EFalse; |
|
396 } |
|
397 break; |
|
398 case EScanStageImportNonROM: |
|
399 if (driveUnitInfo.iDriveAtt!=KDriveAttRom) |
|
400 { |
|
401 iCurrentIndexInFolderList=1; |
|
402 checkNextFolder=EFalse; |
|
403 } |
|
404 break; |
|
405 case EScanStageImportNonNativeResourceNonROM: |
|
406 if (driveUnitInfo.iDriveAtt!=KDriveAttRom) |
|
407 { |
|
408 iCurrentIndexInFolderList=2; |
|
409 checkNextFolder=EFalse; |
|
410 } |
|
411 break; |
|
412 case EScanStageImportROM: |
|
413 if (driveUnitInfo.iDriveAtt==KDriveAttRom) |
|
414 { |
|
415 iCurrentIndexInFolderList=1; |
|
416 checkNextFolder=EFalse; |
|
417 } |
|
418 break; |
|
419 case EScanStageImportNonNativeResourceROM: |
|
420 if (driveUnitInfo.iDriveAtt==KDriveAttRom) |
|
421 { |
|
422 iCurrentIndexInFolderList=2; |
|
423 checkNextFolder=EFalse; |
|
424 } |
|
425 break; |
|
426 case EScanStageComplete: |
|
427 checkNextFolder=EFalse; |
|
428 found=EFalse; |
|
429 break; |
|
430 default: |
|
431 break; |
|
432 } |
|
433 } |
|
434 return found; |
|
435 } |
|
436 |
|
437 _LIT(KAppRegRscSearchAnyFile,"*"); |
|
438 |
|
439 TInt CApaAppRegFinder::GetFileListL(TDriveUnit aDriveUnit, const TDesC& aPathName) |
|
440 { |
|
441 const TDriveName driveName=aDriveUnit.Name(); |
|
442 TParse parse; |
|
443 TInt error = parse.Set(KAppRegRscSearchAnyFile,&aPathName,&driveName); |
|
444 User::LeaveIfError(error); |
|
445 TInt ret = iFs.GetDir(parse.FullName(), KEntryAttAllowUid, ESortNone, iFileList); |
|
446 CheckErrorL(ret); |
|
447 return ret; |
|
448 } |
|
449 |
|
450 void CApaAppRegFinder::CheckErrorL(TInt aError) |
|
451 // static |
|
452 { |
|
453 if (aError!=KErrNone && aError!=KErrNotFound && aError!=KErrPathNotFound && aError!=KErrNotReady |
|
454 && aError!=KErrDisMounted && aError!=KErrCorrupt && aError!=KErrNotSupported && aError!=KErrBadName && aError!=KErrLocked) |
|
455 { |
|
456 User::Leave(aError); |
|
457 } |
|
458 } |
|