1 /* |
|
2 * Copyright (c) 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 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include <ecom/implementationproxy.h> |
|
21 #include <sacls.h> |
|
22 |
|
23 #include "chfactorysettingsinstallnotifier.h" |
|
24 #include "cpdebug.h" |
|
25 #include "chdbstatehandler.h" |
|
26 #include "chfactorysettingsdomparser.h" |
|
27 #include "chfactorysettingsplugin.h" |
|
28 |
|
29 // LOCAL CONSTANTS AND MACROS |
|
30 const TInt KADatFactorySettingsServerPluginUid( 0x102830EF); |
|
31 // Dynamically loaded data storage handler |
|
32 |
|
33 const TInt KDefaultGranularity = 5; |
|
34 |
|
35 _LIT( KDirFSNew, "import\\fs\\" ); |
|
36 _LIT( KParsedDir, "parsed\\fs\\" ); |
|
37 _LIT( KParsed, "parsed\\" ); |
|
38 _LIT( KFs, "fs\\" ); |
|
39 |
|
40 _LIT( KDriveC, "C:" ); |
|
41 _LIT( KColen, ":" ); |
|
42 |
|
43 // Map the interface UIDs to implementation factory functions |
|
44 const TImplementationProxy ImplementationTable[] = |
|
45 { |
|
46 { |
|
47 { |
|
48 KADatFactorySettingsServerPluginUid |
|
49 }, ( TProxyNewLPtr )CCHFactorySettings::NewL |
|
50 } |
|
51 }; |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // ImplementationGroupProxy |
|
55 // Exported proxy for instantiation method resolution |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 EXPORT_C const TImplementationProxy* |
|
59 ImplementationGroupProxy( TInt& aTableCount ) |
|
60 { |
|
61 aTableCount = sizeof( ImplementationTable ) / |
|
62 sizeof( TImplementationProxy ); |
|
63 return ImplementationTable; |
|
64 } |
|
65 |
|
66 // ============================ MEMBER FUNCTIONS =============================== |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CCHFactorySettings::CCHFactorySettings |
|
70 // C++ default constructor can NOT contain any code, that |
|
71 // might leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CCHFactorySettings::CCHFactorySettings() |
|
75 { |
|
76 |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CCHFactorySettings::ConstructL |
|
81 // Symbian 2nd phase constructor can leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CCHFactorySettings::ConstructL( MLiwInterface* aInterface ) |
|
85 { |
|
86 CP_DEBUG(_L8("CCHFactorySettings::ConstructL" )); |
|
87 iCPSInterface = aInterface; |
|
88 iFileNewList = new (ELeave) CDesCArrayFlat(KDefaultGranularity); |
|
89 User::LeaveIfError( iFs.Connect( ) ); |
|
90 iInstallNotifier = CCHFactorySettingsInstallNotifier::NewL( this, |
|
91 KUidSystemCategory, KSAUidSoftwareInstallKeyValue ); |
|
92 |
|
93 iParser = CCHFactorySettingsDOMParser::NewL( iCPSInterface, iFs ); // mw |
|
94 |
|
95 iFileMan = CFileMan::NewL( iFs ); |
|
96 iFilePath.CreateL( KMaxPath ); |
|
97 |
|
98 iFs.CreatePrivatePath( EDriveC ); |
|
99 User::LeaveIfError( iFs.PrivatePath( iFilePath ) ); |
|
100 |
|
101 //create "parsed" directory if it doesn't exist yet; |
|
102 RBuf filePath; |
|
103 filePath.CreateL( KMaxPath ); |
|
104 filePath.Append( KDriveC ); |
|
105 filePath.Append( iFilePath ); |
|
106 filePath.Append( KParsed ); |
|
107 iFs.MkDir( filePath ); |
|
108 filePath.Append( KFs ); |
|
109 iFs.MkDir( filePath ); |
|
110 filePath.Close( ); |
|
111 iDBStateHandler = CCHDbStateHandler::NewL( this ); |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CCHFactorySettings::NewL |
|
116 // Two-phased constructor. |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 CCHFactorySettings* CCHFactorySettings::NewL( MLiwInterface* aInterface ) |
|
120 { |
|
121 CCHFactorySettings* self = NewLC( aInterface ); |
|
122 CleanupStack::Pop( self ); |
|
123 return self; |
|
124 } |
|
125 |
|
126 // ----------------------------------------------------------------------------- |
|
127 // CCHFactorySettings::NewLC |
|
128 // Two-phased constructor. |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 CCHFactorySettings* CCHFactorySettings::NewLC( MLiwInterface* aInterface ) |
|
132 { |
|
133 CCHFactorySettings* self = new( ELeave ) CCHFactorySettings(); |
|
134 CleanupStack::PushL( self ); |
|
135 self->ConstructL( aInterface ); |
|
136 return self; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // Destructor |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 CCHFactorySettings::~CCHFactorySettings() |
|
144 { |
|
145 delete iFileNewList; |
|
146 delete iInstallNotifier; |
|
147 delete iFileMan; |
|
148 delete iParser; |
|
149 iFs.Close( ); |
|
150 iFilePath.Close( ); |
|
151 delete iDBStateHandler; |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // CCHFactorySettings::UpdateL |
|
156 // |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 void CCHFactorySettings::UpdateL() |
|
160 { |
|
161 CP_DEBUG(_L8("CCHFactorySettings::UpdateL" )); |
|
162 CheckDrivesL( ); // fill in list with file names from all drives |
|
163 AddNewL( ); // if any of them isn't added to db then add |
|
164 UnInstallL( ); // if any of files from any drive was removed remove data |
|
165 // from DB |
|
166 |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CCHFactorySettings::AddNewL |
|
171 // Add new entries after sis intallation. |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 void CCHFactorySettings::AddNewL() |
|
175 { |
|
176 CP_DEBUG(_L8("CCHFactorySettings::AddNewL" )); |
|
177 CDir* fileListInstalled= NULL; |
|
178 RBuf filePath; |
|
179 filePath.CreateL( KMaxPath ); |
|
180 CleanupClosePushL( filePath ); |
|
181 filePath.Append( KDriveC ); |
|
182 filePath.Append( iFilePath ); |
|
183 filePath.Append( KParsedDir ); |
|
184 iFs.GetDir( filePath, KEntryAttMaskSupported, ESortByName, |
|
185 fileListInstalled ); |
|
186 CleanupStack::PushL( fileListInstalled ); |
|
187 |
|
188 for ( TInt i(0); i<iFileNewList->Count( ); i++ ) |
|
189 { |
|
190 TBool parse(ETrue); |
|
191 TPtrC fileNewName = |
|
192 (*iFileNewList)[i].Mid( (*iFileNewList)[i].LocateReverse( '\\' ) + 1 ); |
|
193 TInt count = fileListInstalled->Count( ); |
|
194 for ( TInt j(0); j< count; j++ ) |
|
195 { |
|
196 TPtrC existingFile = (*fileListInstalled)[j].iName; |
|
197 if ( fileNewName.Compare( existingFile ) ) |
|
198 { |
|
199 parse = ETrue; |
|
200 } |
|
201 else |
|
202 { |
|
203 parse = EFalse; |
|
204 break; |
|
205 } |
|
206 } |
|
207 if ( parse ) |
|
208 { |
|
209 //file wasn't found in afterinstallation dir |
|
210 //so should be copied and entries install |
|
211 TBool fileOpened(ETrue); |
|
212 iFs.IsFileOpen( (*iFileNewList)[i], fileOpened ); |
|
213 |
|
214 if ( !fileOpened ) |
|
215 { |
|
216 TInt error = iParser->Restore( (*iFileNewList)[i], EFalse ); |
|
217 if ( error == KErrNone ) |
|
218 { |
|
219 iFileMan->Copy( (*iFileNewList)[i], filePath ); |
|
220 } |
|
221 } |
|
222 |
|
223 } |
|
224 } |
|
225 CleanupStack::PopAndDestroy( fileListInstalled ); |
|
226 CleanupStack::PopAndDestroy( &filePath ); |
|
227 } |
|
228 |
|
229 // ---------------------------------------------------------------------------- |
|
230 // CCHFactorySettings::UnInstallL |
|
231 // Removes entries after uninstallation. |
|
232 // ---------------------------------------------------------------------------- |
|
233 // |
|
234 void CCHFactorySettings::UnInstallL() |
|
235 { |
|
236 CP_DEBUG(_L8("CCHFactorySettings::UnInstallL" )); |
|
237 TBool found(EFalse); |
|
238 CDir* fileListInstalled= NULL; |
|
239 RBuf filePath; |
|
240 filePath.CreateL( KMaxPath ); |
|
241 CleanupClosePushL( filePath ); |
|
242 filePath.Append( KDriveC ); |
|
243 filePath.Append( iFilePath ); |
|
244 filePath.Append( KParsedDir ); |
|
245 iFs.GetDir( filePath, KEntryAttMaskSupported, ESortByName, |
|
246 fileListInstalled ); |
|
247 CleanupStack::PushL( fileListInstalled ); |
|
248 |
|
249 for ( TInt i(0); i<fileListInstalled->Count( ); i++ ) |
|
250 { |
|
251 TPtrC fileInstalledName = (*fileListInstalled)[i].iName; |
|
252 found = EFalse; |
|
253 for ( TInt j(0); j<iFileNewList->Count( ); j++ ) |
|
254 { |
|
255 TPtrC fileNewPath = (*iFileNewList)[j]; |
|
256 TPtrC fileNewName = |
|
257 (*iFileNewList)[j].Mid( (*iFileNewList)[j].LocateReverse( '\\' ) + 1 ); |
|
258 if ( fileInstalledName.Compare( fileNewName )==0 ) |
|
259 { |
|
260 if ( !(*fileListInstalled)[i].IsDir( ) ) |
|
261 { |
|
262 found = ETrue; |
|
263 break; |
|
264 } |
|
265 } |
|
266 } |
|
267 if ( !found ) //this file should be removed also entries from database |
|
268 { |
|
269 filePath.Zero( ); |
|
270 filePath.Append( KDriveC ); |
|
271 filePath.Append( iFilePath ); |
|
272 filePath.Append( KParsedDir ); |
|
273 filePath.Append( fileInstalledName ); |
|
274 |
|
275 iParser->Restore( filePath, ETrue ); |
|
276 iFileMan->Delete( filePath ); |
|
277 } |
|
278 } |
|
279 CleanupStack::PopAndDestroy( fileListInstalled ); |
|
280 CleanupStack::PopAndDestroy( &filePath ); |
|
281 } |
|
282 |
|
283 // ---------------------------------------------------------------------------- |
|
284 // CCHFactorySettings::CheckDrivesL |
|
285 // |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 void CCHFactorySettings::CheckDrivesL() |
|
289 { |
|
290 CP_DEBUG(_L8("CCHFactorySettings::CheckDrivesL" )); |
|
291 iFileNewList->Reset( ); |
|
292 TDriveList driveList; |
|
293 TChar driveLetter; |
|
294 User::LeaveIfError( iFs.DriveList( driveList ) ); |
|
295 for ( TInt driveNumber=EDriveA; driveNumber <= EDriveZ; driveNumber++ ) |
|
296 { |
|
297 if ( driveList[driveNumber] ) |
|
298 { |
|
299 User::LeaveIfError( iFs.DriveToChar( driveNumber, driveLetter ) ); |
|
300 RBuf filePath; |
|
301 filePath.CreateL( KMaxPath ); |
|
302 CleanupClosePushL( filePath ); |
|
303 filePath.Append( driveLetter ); |
|
304 filePath.Append( KColen ); |
|
305 filePath.Append( iFilePath ); |
|
306 filePath.Append( KDirFSNew ); |
|
307 CDir* fileList; |
|
308 iFs.GetDir( filePath, KEntryAttMaskSupported, ESortByName, |
|
309 fileList ); |
|
310 CleanupStack::PopAndDestroy( &filePath ); |
|
311 if ( fileList ) |
|
312 { |
|
313 CleanupStack::PushL( fileList ); |
|
314 for ( TInt i(0); i<fileList->Count( ); i++ ) |
|
315 { |
|
316 RBuf fullFileName; |
|
317 fullFileName.CreateL( KMaxPath ); |
|
318 CleanupClosePushL( fullFileName ); |
|
319 fullFileName.Append( driveLetter ); |
|
320 fullFileName.Append( KColen ); |
|
321 fullFileName.Append( iFilePath ); |
|
322 fullFileName.Append( KDirFSNew ) ; |
|
323 fullFileName.Append( (*fileList)[i].iName ); |
|
324 if ( !(*fileList)[i].IsDir( ) ) |
|
325 { |
|
326 //check if already exist |
|
327 iFileNewList->AppendL( fullFileName ); |
|
328 } |
|
329 CleanupStack::PopAndDestroy( &fullFileName ); |
|
330 } |
|
331 CleanupStack::PopAndDestroy( fileList ); |
|
332 } |
|
333 } |
|
334 } |
|
335 } |
|
336 |
|
337 // end of file |
|