|
1 // Copyright (c) 2006-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 "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 "cmtpfsexclusionmgr.h" |
|
17 |
|
18 #include <mtp/mmtpdataproviderframework.h> |
|
19 #include <mtp/mmtpstoragemgr.h> |
|
20 #include <mtp/cmtpstoragemetadata.h> |
|
21 #include <mtp/cmtpmetadata.h> |
|
22 #include <e32hashtab.h> |
|
23 |
|
24 //[SP-Format-0x3002] |
|
25 //The full path of DDISCVRY.DPS of PictBridge DP. |
|
26 _LIT(KFullNameOfPictBridgeDiscovery, "C:\\DATA\\DDISCVRY.DPS"); |
|
27 |
|
28 __FLOG_STMT(_LIT8(KComponent,"CMTPFSExclusionMgr");) |
|
29 |
|
30 EXPORT_C CMTPFSExclusionMgr::CMTPFSExclusionMgr(MMTPDataProviderFramework& aFramework) : |
|
31 iFramework(aFramework), iOrder(CMTPMetaData::CompareTPathHash) |
|
32 { |
|
33 __FLOG_OPEN(KMTPSubsystem, KComponent); |
|
34 } |
|
35 |
|
36 EXPORT_C CMTPFSExclusionMgr::~CMTPFSExclusionMgr() |
|
37 { |
|
38 __FLOG_CLOSE; |
|
39 } |
|
40 |
|
41 EXPORT_C TBool CMTPFSExclusionMgr::IsFolderAcceptedL(const TDesC& aPath, TUint32 aStorageId) const |
|
42 { |
|
43 return IsPathAcceptedL(aPath, aStorageId); |
|
44 } |
|
45 |
|
46 EXPORT_C TBool CMTPFSExclusionMgr::IsFileAcceptedL(const TDesC& aPath, TUint32 /*aStorageId*/) const |
|
47 { |
|
48 __FLOG(_L8("IsFileAcceptedL - Entry")); |
|
49 |
|
50 TBool accepted = ETrue; |
|
51 TParsePtrC parse(aPath); |
|
52 |
|
53 if (parse.ExtPresent()) |
|
54 { |
|
55 accepted = IsExtensionValid(parse.Ext().Mid(1)); |
|
56 __FLOG_VA((_L8("IsExtensionValid = %d"), accepted)); |
|
57 } |
|
58 |
|
59 //[SP-Format-0x3002] |
|
60 //They are used to exclude DDISCVRY.DPS from the process of file dp's enumeration. |
|
61 if(accepted) |
|
62 { |
|
63 TFileName tmp = aPath; |
|
64 tmp.UpperCase(); |
|
65 if( tmp == KFullNameOfPictBridgeDiscovery ) |
|
66 { |
|
67 accepted = EFalse; |
|
68 } |
|
69 } |
|
70 __FLOG_VA((_L8("Exit IsFileAcceptedL = %d"), accepted)); |
|
71 return accepted; |
|
72 } |
|
73 |
|
74 EXPORT_C TBool CMTPFSExclusionMgr::IsPathAcceptedL(const TDesC& aPath, TUint32 aStorageId) const |
|
75 { |
|
76 |
|
77 CMTPStorageMetaData* storageMetaData = (CMTPStorageMetaData *)& iFramework.StorageMgr().StorageL(aStorageId); |
|
78 TBool accepted = EFalse; |
|
79 |
|
80 if (storageMetaData->Uint(CMTPStorageMetaData::EStorageSystemType) == CMTPStorageMetaData::ESystemTypeDefaultFileSystem) |
|
81 { |
|
82 // Use Hash code to compare. |
|
83 const RArray<CMTPMetaData::TPathHash>& excludedHash = const_cast<CMTPStorageMetaData*>(storageMetaData)->GetHashPathArray(); |
|
84 // Calculate hash code for aPath, aPath is always a folder because for file, we only need to check extension |
|
85 CMTPMetaData::TPathHash PathHash; |
|
86 TFileName ex(aPath); |
|
87 ex.LowerCase(); |
|
88 PathHash.iHash = DefaultHash::Des16(ex); |
|
89 |
|
90 accepted = ETrue; |
|
91 TInt index = KErrNotFound; |
|
92 if ( (index = excludedHash.SpecificFindInOrder(PathHash, iOrder, EArrayFindMode_First)) != KErrNotFound ) |
|
93 { |
|
94 // double check if the path need be excluded in case of hash duplicated. |
|
95 const CDesCArray& excludedAreas = const_cast<CMTPStorageMetaData*>(storageMetaData)->DesCArray(CMTPStorageMetaData::EExcludedAreas); |
|
96 |
|
97 for(TInt i=index; (PathHash.iHash==excludedHash[i].iHash)&&(i<excludedHash.Count()); ++i) |
|
98 { |
|
99 if ((aPath.MatchF(excludedAreas[excludedHash[i].iIndex])) != KErrNotFound) |
|
100 { |
|
101 accepted = EFalse; |
|
102 break; |
|
103 } |
|
104 } |
|
105 } |
|
106 } |
|
107 |
|
108 return accepted; |
|
109 } |