|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Harvester Central Repository utility class* |
|
15 */ |
|
16 |
|
17 |
|
18 #include "harvestercenreputil.h" |
|
19 #include "centralrepository.h" |
|
20 #include "mdsutils.h" |
|
21 #include "mdeconstants.h" |
|
22 |
|
23 const TUid KHarvesterRepoUid = { 0x200009FE }; |
|
24 const TUint32 KSearchMask = 0xFFFF0000; |
|
25 const TUint32 KIgnorePathPartialKey = 0x00010000; |
|
26 const TUint32 KBootScanPartialKey = 0x00020000; |
|
27 const TUint32 KBootIgnorePartialKey = 0x00030000; |
|
28 const TUint32 KPartialRestorePartialKey = 0x00040000; |
|
29 const TUint32 KPartialRestoreIgnorePartialKey = 0x00050000; |
|
30 |
|
31 const TUint32 KRomScanEnabledKey = 0x00090000; |
|
32 |
|
33 const TInt32 KThumbnailManagerCenrepUID = 0x102830B0; // TNM cenrep uid |
|
34 const TUint32 KEnableDaemon = 0x300; // from TNM |
|
35 |
|
36 CHarvesterCenRepUtil::CHarvesterCenRepUtil() |
|
37 { |
|
38 // No implementation required |
|
39 } |
|
40 |
|
41 |
|
42 EXPORT_C CHarvesterCenRepUtil::~CHarvesterCenRepUtil() |
|
43 { |
|
44 iFspEngine.Close(); |
|
45 iFs.Close(); |
|
46 } |
|
47 |
|
48 EXPORT_C CHarvesterCenRepUtil* CHarvesterCenRepUtil::NewLC() |
|
49 { |
|
50 CHarvesterCenRepUtil* self = new (ELeave)CHarvesterCenRepUtil(); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 EXPORT_C CHarvesterCenRepUtil* CHarvesterCenRepUtil::NewL() |
|
57 { |
|
58 CHarvesterCenRepUtil* self=CHarvesterCenRepUtil::NewLC(); |
|
59 CleanupStack::Pop(); // self; |
|
60 return self; |
|
61 } |
|
62 |
|
63 void CHarvesterCenRepUtil::ConstructL() |
|
64 { |
|
65 User::LeaveIfError( iFs.Connect() ); |
|
66 User::LeaveIfError( iFspEngine.Open( iFs, KMdsFSPluginPosition ) ); |
|
67 } |
|
68 |
|
69 EXPORT_C RMdsFSPEngine& CHarvesterCenRepUtil::FspEngine() |
|
70 { |
|
71 return iFspEngine; |
|
72 } |
|
73 |
|
74 EXPORT_C void CHarvesterCenRepUtil::AddIgnorePathsToFspL( const TDesC& aDrivePrefix ) |
|
75 { |
|
76 AddOrRemoveIgnorePathsL( aDrivePrefix, ETrue, KNullDesC ); |
|
77 } |
|
78 |
|
79 EXPORT_C void CHarvesterCenRepUtil::AddIgnorePathsToFspL( const TDesC& aDrivePrefix, |
|
80 const TDesC& aFilterPrefix ) |
|
81 { |
|
82 AddOrRemoveIgnorePathsL( aDrivePrefix, ETrue, aFilterPrefix); |
|
83 } |
|
84 |
|
85 EXPORT_C void CHarvesterCenRepUtil::RemoveIgnorePathsFromFspL( const TDesC& aDrivePrefix ) |
|
86 { |
|
87 AddOrRemoveIgnorePathsL( aDrivePrefix, EFalse, KNullDesC ); |
|
88 } |
|
89 |
|
90 void CHarvesterCenRepUtil::AddOrRemoveIgnorePathsL( const TDesC& aDrivePrefix, |
|
91 TBool aAdd, |
|
92 const TDesC& aFilterPrefix ) |
|
93 { |
|
94 CRepository* repo = CRepository::NewLC( KHarvesterRepoUid ); |
|
95 RArray<TUint32> ignoredKeys; |
|
96 CleanupClosePushL( ignoredKeys ); |
|
97 TInt ret = repo->FindL( KIgnorePathPartialKey, KSearchMask, ignoredKeys ); |
|
98 |
|
99 TBuf<KMaxFileName> path; |
|
100 const TInt count = ignoredKeys.Count(); |
|
101 for( TInt i=0;i<count;i++ ) |
|
102 { |
|
103 const TInt error( repo->Get( ignoredKeys[i], path ) ); |
|
104 if( error != KErrNone ) |
|
105 { |
|
106 continue; |
|
107 } |
|
108 if( aFilterPrefix != KNullDesC ) |
|
109 { |
|
110 TPtrC pathStart = path.Left( aFilterPrefix.Length() ); |
|
111 if( MdsUtils::Compare( pathStart, aFilterPrefix ) != 0 ) |
|
112 { |
|
113 continue; |
|
114 } |
|
115 } |
|
116 HBufC* ignorePath = HBufC::NewL( aDrivePrefix.Length() + path.Length() ); |
|
117 TPtr ptr = ignorePath->Des(); |
|
118 ptr.Append( aDrivePrefix ); |
|
119 ptr.Append( path ); |
|
120 if( aAdd ) |
|
121 { |
|
122 iFspEngine.AddIgnorePath( *ignorePath ); |
|
123 } |
|
124 else |
|
125 { |
|
126 iFspEngine.RemoveIgnorePath( *ignorePath ); |
|
127 } |
|
128 delete ignorePath; |
|
129 ignorePath = NULL; |
|
130 } |
|
131 CleanupStack::PopAndDestroy( &ignoredKeys ); |
|
132 CleanupStack::PopAndDestroy( repo ); |
|
133 } |
|
134 |
|
135 EXPORT_C void CHarvesterCenRepUtil::GetIgnorePathL( |
|
136 RPointerArray<HBufC>& aIgnorePaths ) |
|
137 { |
|
138 GetPathsL( KIgnorePathPartialKey, aIgnorePaths ); |
|
139 } |
|
140 |
|
141 EXPORT_C void CHarvesterCenRepUtil::GetScanItemsL( |
|
142 RPointerArray<TScanItem>& aItems ) |
|
143 { |
|
144 GetItemsL( KBootScanPartialKey, aItems ); |
|
145 } |
|
146 |
|
147 EXPORT_C void CHarvesterCenRepUtil::GetIgnoredScanPathsL( |
|
148 RPointerArray<HBufC>& aIngorePaths ) |
|
149 { |
|
150 GetPathsL( KBootIgnorePartialKey, aIngorePaths ); |
|
151 } |
|
152 |
|
153 EXPORT_C void CHarvesterCenRepUtil::GetPartialRestorePathsL( |
|
154 RPointerArray<TScanItem>& aPaths ) |
|
155 { |
|
156 GetItemsL( KPartialRestorePartialKey, aPaths ); |
|
157 } |
|
158 |
|
159 EXPORT_C void CHarvesterCenRepUtil::GetIgnoredPartialRestorePathsL( |
|
160 RPointerArray<HBufC>& aIngorePaths ) |
|
161 { |
|
162 GetPathsL( KPartialRestoreIgnorePartialKey, aIngorePaths ); |
|
163 } |
|
164 |
|
165 EXPORT_C void CHarvesterCenRepUtil::IsRomScanEnabledL( TBool& aEnabled ) |
|
166 { |
|
167 CRepository* rep = CRepository::NewLC( KHarvesterRepoUid ); |
|
168 |
|
169 rep->Get( KRomScanEnabledKey, aEnabled ); |
|
170 |
|
171 CleanupStack::PopAndDestroy( rep ); |
|
172 } |
|
173 |
|
174 EXPORT_C void CHarvesterCenRepUtil::IsThumbnailDaemonEnabledL( TBool& aEnabled ) |
|
175 { |
|
176 CRepository* rep = CRepository::NewLC( TUid::Uid( KThumbnailManagerCenrepUID ) ); |
|
177 |
|
178 rep->Get( KEnableDaemon, aEnabled ); |
|
179 |
|
180 CleanupStack::PopAndDestroy( rep ); |
|
181 } |
|
182 |
|
183 void CHarvesterCenRepUtil::GetPathsL( TUint32 aPartialKey, RPointerArray<HBufC>& aPaths ) |
|
184 { |
|
185 CRepository* repo = CRepository::NewLC( KHarvesterRepoUid ); |
|
186 RArray<TUint32> scanPathKeys; |
|
187 CleanupClosePushL( scanPathKeys ); |
|
188 |
|
189 repo->FindL( aPartialKey, KSearchMask, scanPathKeys ); |
|
190 |
|
191 TBuf<KMaxFileName> path; |
|
192 const TInt count = scanPathKeys.Count(); |
|
193 aPaths.ReserveL( count ); |
|
194 for( TInt i = 0; i < count; i++ ) |
|
195 { |
|
196 const TInt error( repo->Get( scanPathKeys[i], path ) ); |
|
197 if( error != KErrNone ) |
|
198 { |
|
199 continue; |
|
200 } |
|
201 HBufC* pathBuf = path.AllocL(); |
|
202 aPaths.Append( pathBuf ); |
|
203 } |
|
204 |
|
205 CleanupStack::PopAndDestroy( &scanPathKeys ); |
|
206 CleanupStack::PopAndDestroy( repo ); |
|
207 } |
|
208 |
|
209 void CHarvesterCenRepUtil::GetItemsL( TUint32 aPartialKey, RPointerArray<TScanItem>& aItems ) |
|
210 { |
|
211 CRepository* repo = CRepository::NewLC( KHarvesterRepoUid ); |
|
212 RArray<TUint32> scanPathKeys; |
|
213 CleanupClosePushL( scanPathKeys ); |
|
214 |
|
215 repo->FindL( aPartialKey, KSearchMask, scanPathKeys ); |
|
216 |
|
217 TBuf<KMaxFileName> path; |
|
218 const TInt count = scanPathKeys.Count(); |
|
219 for( TInt i = 0; i < count; i++ ) |
|
220 { |
|
221 const TInt error( repo->Get( scanPathKeys[i], path ) ); |
|
222 if( error != KErrNone ) |
|
223 { |
|
224 continue; |
|
225 } |
|
226 TUint32 preinstalled = MdeConstants::MediaObject::ENotPreinstalled; |
|
227 if( path[ path.Length() - 1 ] != TChar('\\') ) |
|
228 { |
|
229 User::LeaveIfError( repo->GetMeta( scanPathKeys[i], preinstalled ) ); |
|
230 } |
|
231 TScanItem* item = new (ELeave) TScanItem(); |
|
232 CleanupStack::PushL( item ); |
|
233 item->iPath = path.AllocL(); |
|
234 item->iPreinstalled = preinstalled; |
|
235 CleanupStack::Pop( item ); |
|
236 aItems.Append( item ); // ownership is transferred |
|
237 } |
|
238 |
|
239 CleanupStack::PopAndDestroy( &scanPathKeys ); |
|
240 CleanupStack::PopAndDestroy( repo ); |
|
241 } |
|
242 |
|
243 // End of file |
|
244 |