114
|
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: Service for maintaining contents of the "themes" folder
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <s32file.h>
|
|
21 |
#include <s32mem.h>
|
|
22 |
#include <sysutil.h>
|
|
23 |
#include <bautils.h>
|
|
24 |
#include <centralrepository.h>
|
|
25 |
|
|
26 |
#include "hsps_builds_cfg.hrh"
|
|
27 |
|
|
28 |
#include "hspsthememanagement.h"
|
|
29 |
#include "hspsdefinitionrepository.h"
|
|
30 |
#include "hspsodt.h"
|
|
31 |
|
|
32 |
#ifdef HSPS_LOG_ACTIVE
|
|
33 |
#include <hspslogbus.h>
|
|
34 |
#endif
|
|
35 |
|
|
36 |
// CONSTANTS
|
|
37 |
const TInt KDefRepArrayGranularity = 5;
|
|
38 |
|
|
39 |
_LIT(KImportFolder, "import");
|
|
40 |
_LIT(KThemesFolder, "themes");
|
|
41 |
_LIT(KSourceFolder, "sources");
|
|
42 |
_LIT(KSourceFolderWithSeperators, "\\sources\\");
|
|
43 |
_LIT(KLocaleFolder, "locales");
|
|
44 |
_LIT(KBackupFolder, "backup");
|
|
45 |
|
|
46 |
|
|
47 |
_LIT(KDoubleBackSlash,"\\");
|
|
48 |
|
|
49 |
_LIT(KFolderFormat,"%d"); // folder format for localized resources
|
|
50 |
|
|
51 |
_LIT(KMatchAll, "*");
|
|
52 |
|
|
53 |
|
|
54 |
_LIT(KMatchSkeleton, ".o0000");
|
|
55 |
|
|
56 |
const TInt KTIntMahspsumbers( 11 );
|
|
57 |
|
|
58 |
_LIT_SECURITY_POLICY_C1( KPSReadPolicy, ECapabilityReadDeviceData );
|
|
59 |
_LIT_SECURITY_POLICY_C1( KPSWritePolicy, ECapabilityWriteDeviceData );
|
|
60 |
|
|
61 |
|
|
62 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
63 |
|
|
64 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
65 |
|
|
66 |
// -----------------------------------------------------------------------------
|
|
67 |
// ChspsDefinitionRepository::ChspsDefinitionRepository
|
|
68 |
// C++ default constructor can NOT contain any code, that
|
|
69 |
// might leave.
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
ChspsDefinitionRepository::ChspsDefinitionRepository(
|
|
73 |
CRepository& aCentralRepository ) :
|
|
74 |
iCacheLastODT( NULL ),
|
|
75 |
iCentralRepository( aCentralRepository )
|
|
76 |
{
|
|
77 |
}
|
|
78 |
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
// ChspsDefinitionRepository::ConstructL
|
|
81 |
// Symbian 2nd phase constructor can leave.
|
|
82 |
// -----------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
void ChspsDefinitionRepository::ConstructL()
|
|
85 |
{
|
|
86 |
// Setup RProperty keys for the client applications
|
|
87 |
SetupPropertiesL( KPropertyAI3Key );
|
|
88 |
SetupPropertiesL( KPropertyMTKey );
|
|
89 |
|
|
90 |
User::LeaveIfError( iFs.Connect() );
|
|
91 |
//Create private path if it doesn't exist already
|
|
92 |
TInt err = iFs.CreatePrivatePath(EDriveC);
|
|
93 |
if (err!=KErrNone && err!=KErrAlreadyExists)
|
|
94 |
{
|
|
95 |
User::Leave(err);
|
|
96 |
}
|
|
97 |
HBufC* path = HBufC::NewLC( KMaxFileName );
|
|
98 |
TPtr pathPtr = path->Des();
|
|
99 |
User::LeaveIfError( iFs.PrivatePath( pathPtr ));
|
|
100 |
AppendDesCIntoPathL( pathPtr, KImportFolder );
|
|
101 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
102 |
iFs.MkDir( pathPtr );
|
|
103 |
CleanupStack::PopAndDestroy( path );
|
|
104 |
User::LeaveIfError(iFs.SetSessionToPrivate(EDriveC));
|
|
105 |
iLicenseDefault = EFalse;
|
|
106 |
iLockSemaphore = 0;
|
|
107 |
|
|
108 |
iTempFileName1 = KNullDesC;
|
|
109 |
iTempFileName2 = KNullDesC;
|
|
110 |
}
|
|
111 |
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
// ChspsDefinitionRepository::NewL
|
|
114 |
// Two-phased constructor.
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
EXPORT_C ChspsDefinitionRepository* ChspsDefinitionRepository::NewL(
|
|
118 |
CRepository& aCentralRepository )
|
|
119 |
{
|
|
120 |
ChspsDefinitionRepository* self =
|
|
121 |
new( ELeave ) ChspsDefinitionRepository( aCentralRepository );
|
|
122 |
|
|
123 |
CleanupStack::PushL( self );
|
|
124 |
self->ConstructL();
|
|
125 |
CleanupStack::Pop( self );
|
|
126 |
|
|
127 |
return self;
|
|
128 |
}
|
|
129 |
|
|
130 |
// Destructor
|
|
131 |
ChspsDefinitionRepository::~ChspsDefinitionRepository()
|
|
132 |
{
|
|
133 |
iProperty.Close();
|
|
134 |
iFs.Close();
|
|
135 |
iRepositoryInfoQueue.Reset();
|
|
136 |
iRepositoryInfoQueue.Close();
|
|
137 |
iObservers.Reset();
|
|
138 |
iObservers.Close();
|
|
139 |
delete iPath;
|
|
140 |
|
|
141 |
delete iCacheLastODT;
|
|
142 |
|
|
143 |
iTempFileName1 = KNullDesC;
|
|
144 |
iTempFileName2 = KNullDesC;
|
|
145 |
}
|
|
146 |
|
|
147 |
// -----------------------------------------------------------------------------
|
|
148 |
// ChspsDefinitionRepository::SetupPropertiesL
|
|
149 |
// -----------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
void ChspsDefinitionRepository::SetupPropertiesL( const TUint aKey )
|
|
152 |
{
|
|
153 |
TInt err = RProperty::Define(
|
|
154 |
KPropertyHspsCat,
|
|
155 |
aKey,
|
|
156 |
RProperty::EInt,
|
|
157 |
KPSReadPolicy,
|
|
158 |
KPSWritePolicy );
|
|
159 |
if( err != KErrAlreadyExists && err != KErrNone )
|
|
160 |
{
|
|
161 |
User::LeaveIfError( err );
|
|
162 |
}
|
|
163 |
// Init
|
|
164 |
User::LeaveIfError(
|
|
165 |
RProperty::Set(
|
|
166 |
KPropertyHspsCat,
|
|
167 |
aKey,
|
|
168 |
KPropertyKeyDefault )
|
|
169 |
);
|
|
170 |
}
|
|
171 |
|
|
172 |
// -----------------------------------------------------------------------------
|
|
173 |
// ChspsDefinitionRepository::SetLocaleL
|
|
174 |
// Saves the dtd-file into the repository.
|
|
175 |
// (other items were commented in a header).
|
|
176 |
// -----------------------------------------------------------------------------
|
|
177 |
EXPORT_C TInt ChspsDefinitionRepository::SetLocaleL( ChspsODT& aODT, ChspsResource& aResource )
|
|
178 |
{
|
|
179 |
// Populate a path based on ODT attributes and file extension of the resource file
|
|
180 |
GetPathL( aODT, EResourceDTD );
|
|
181 |
|
|
182 |
// Results are in iPath, copy resouce file from temp path to a new path in the repository
|
|
183 |
TInt errorCode = CopyFileL( aResource.FileName() );
|
|
184 |
if ( !errorCode )
|
|
185 |
{
|
|
186 |
// Store the new path
|
|
187 |
aResource.SetFileNameL( iPath->Des() );
|
|
188 |
}
|
|
189 |
return errorCode;
|
|
190 |
}
|
|
191 |
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
// ChspsDefinitionRepository::MakeODTPathL
|
|
194 |
// Creates a path for given ODT.
|
|
195 |
// (other items were commented in a header).
|
|
196 |
// -----------------------------------------------------------------------------
|
|
197 |
EXPORT_C void ChspsDefinitionRepository::MakeODTPathL( ChspsODT& aODT, ChspsResource& aResource )
|
|
198 |
{
|
|
199 |
// make sure the temporary buffer is empty
|
|
200 |
iTempFileName1.Zero();
|
|
201 |
|
|
202 |
// get the path for ODT-resource to store
|
|
203 |
GetPathL( aODT, EResourceODT );
|
|
204 |
|
|
205 |
TPtr ptrPath = iPath->Des();
|
|
206 |
TParsePtr p( ptrPath );
|
|
207 |
aODT.SetThemeShortNameL(p.Name());
|
|
208 |
|
|
209 |
// iPath is modified
|
|
210 |
TPtrC pathPtr = iPath->Des();
|
|
211 |
iTempFileName1.Format( _L("%S%S"), &KCDrive, &pathPtr );
|
|
212 |
aResource.SetFileNameL( iTempFileName1 );
|
|
213 |
|
|
214 |
iTempFileName1.Zero();
|
|
215 |
}
|
|
216 |
|
|
217 |
|
|
218 |
// -----------------------------------------------------------------------------
|
|
219 |
// ChspsDefinitionRepository::SetOdtL
|
|
220 |
// Saves the odt-structure into the repository.
|
|
221 |
// (other items were commented in a header).
|
|
222 |
// -----------------------------------------------------------------------------
|
|
223 |
//
|
|
224 |
EXPORT_C TInt ChspsDefinitionRepository::SetOdtL( const ChspsODT &aODT )
|
|
225 |
{
|
|
226 |
TInt ret = KErrGeneral;
|
|
227 |
|
|
228 |
#ifdef HSPS_LOG_ACTIVE
|
|
229 |
if( iLogBus )
|
|
230 |
{
|
|
231 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::SetOdtL(): - rewriting the binary file." ) );
|
|
232 |
}
|
|
233 |
#endif
|
|
234 |
|
|
235 |
GetPathL( aODT, EResourceODT );
|
|
236 |
ret = WriteToFileL( aODT);
|
|
237 |
|
|
238 |
|
|
239 |
#ifdef HSPS_LOG_ACTIVE
|
|
240 |
if( iLogBus )
|
|
241 |
{
|
|
242 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::SetOdtL(): - rewriting done. return code: %d." ), ret );
|
|
243 |
}
|
|
244 |
#endif
|
|
245 |
|
|
246 |
if( aODT.ConfigurationType() == EhspsAppConfiguration )
|
|
247 |
{
|
|
248 |
delete iCacheLastODT;
|
|
249 |
iCacheLastODT = NULL;
|
|
250 |
iCacheLastODT = aODT.CloneL();
|
|
251 |
|
|
252 |
// Check whether we updated active application configuration
|
|
253 |
TInt configurationUid = -1;
|
|
254 |
User::LeaveIfError(
|
|
255 |
iCentralRepository.Get( iCacheLastODT->RootUid(), configurationUid )
|
|
256 |
);
|
|
257 |
if( configurationUid == aODT.ThemeUid() )
|
|
258 |
{
|
|
259 |
|
|
260 |
const TUint key = iCacheLastODT->RootUid();
|
|
261 |
|
|
262 |
// Get current value
|
|
263 |
TInt version( 0 );
|
|
264 |
User::LeaveIfError(
|
|
265 |
RProperty::Get(
|
|
266 |
KPropertyHspsCat,
|
|
267 |
key,
|
|
268 |
version )
|
|
269 |
);
|
|
270 |
|
|
271 |
// Increment the version, each client session should update the ODT copies
|
|
272 |
version++;
|
|
273 |
if( version < 1 )
|
|
274 |
{
|
|
275 |
version = 1;
|
|
276 |
}
|
|
277 |
User::LeaveIfError(
|
|
278 |
RProperty::Set(
|
|
279 |
KPropertyHspsCat,
|
|
280 |
key,
|
|
281 |
version )
|
|
282 |
);
|
|
283 |
}
|
|
284 |
}
|
|
285 |
|
|
286 |
return ret;
|
|
287 |
}
|
|
288 |
|
|
289 |
// -----------------------------------------------------------------------------
|
|
290 |
// ChspsDefinitionRepository::GetOdtL
|
|
291 |
// Retrieves the odt-structure from the repository as a reference.
|
|
292 |
// (other items were commented in a header).
|
|
293 |
// -----------------------------------------------------------------------------
|
|
294 |
//
|
|
295 |
EXPORT_C TInt ChspsDefinitionRepository::GetOdtL( ChspsODT& aODT )
|
|
296 |
{
|
|
297 |
TInt errorCode = KErrNone;
|
|
298 |
|
|
299 |
if ( aODT.Flags() & EhspsThemeStatusLicenceeDefault )
|
|
300 |
{
|
|
301 |
iLicenseDefault = ETrue;
|
|
302 |
}
|
|
303 |
else
|
|
304 |
{
|
|
305 |
iLicenseDefault = EFalse;
|
|
306 |
}
|
|
307 |
|
|
308 |
if( iCacheLastODT &&
|
|
309 |
iCacheLastODT->RootUid() == aODT.RootUid() &&
|
|
310 |
iCacheLastODT->ThemeUid() == aODT.ThemeUid() )
|
|
311 |
{
|
|
312 |
aODT.CloneL( *iCacheLastODT );
|
|
313 |
}
|
|
314 |
else
|
|
315 |
{
|
|
316 |
TRAP( errorCode, GetPathL( aODT, EResourceODT ));
|
|
317 |
if ( !errorCode )
|
|
318 |
{
|
|
319 |
errorCode = ReadFromFileL( *iPath, aODT );
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
iLicenseDefault = EFalse;
|
|
324 |
|
|
325 |
return errorCode;
|
|
326 |
}
|
|
327 |
|
|
328 |
// -----------------------------------------------------------------------------
|
|
329 |
// ChspsDefinitionRepository::GetOdtHeaderL
|
|
330 |
// Retrieves the odt-structure from the repository as a reference.
|
|
331 |
// (other items were commented in a header).
|
|
332 |
// -----------------------------------------------------------------------------
|
|
333 |
//
|
|
334 |
EXPORT_C TInt ChspsDefinitionRepository::GetOdtHeaderL( TDes& aPath, TLanguage /*aLang*/, ChspsODT& aODT )
|
|
335 |
{
|
|
336 |
TInt err( KErrNotFound );
|
|
337 |
|
|
338 |
CDesCArraySeg* themeList = new ( ELeave ) CDesCArraySeg( KDefRepArrayGranularity );
|
|
339 |
CleanupStack::PushL( themeList );
|
|
340 |
|
|
341 |
SelectFilesFromPathL( *themeList, aPath, ESortByDate, KMatchSkeleton );
|
|
342 |
|
|
343 |
if( themeList->MdcaCount() > 0 )
|
|
344 |
{
|
|
345 |
|
|
346 |
TPtrC name = themeList->MdcaPoint( 0 );
|
|
347 |
if ( name.FindF( KSourceFolderWithSeperators ) == KErrNotFound )
|
|
348 |
{
|
|
349 |
HBufC8* header( StreamHeaderFromFileL( name ) );
|
|
350 |
CleanupStack::PushL( header );
|
|
351 |
|
|
352 |
if( header )
|
|
353 |
{
|
|
354 |
aODT.UnMarshalHeaderL( *header );
|
|
355 |
err = KErrNone;
|
|
356 |
}
|
|
357 |
|
|
358 |
CleanupStack::PopAndDestroy( header );
|
|
359 |
}
|
|
360 |
}
|
|
361 |
|
|
362 |
CleanupStack::PopAndDestroy( themeList );
|
|
363 |
|
|
364 |
User::LeaveIfError( err );
|
|
365 |
|
|
366 |
return err;
|
|
367 |
}
|
|
368 |
|
|
369 |
// -----------------------------------------------------------------------------
|
|
370 |
// ChspsDefinitionRepository::GetODTPathL
|
|
371 |
// Retrieves the path of given ODT.
|
|
372 |
// (other items were commented in a header).
|
|
373 |
// -----------------------------------------------------------------------------
|
|
374 |
//
|
|
375 |
EXPORT_C void ChspsDefinitionRepository::GetResourcePathL( const ChspsODT& aODT, ThspsResourceType aResourceType, TDes& aFilePath )
|
|
376 |
{
|
|
377 |
// get the path for source resources to store
|
|
378 |
GetPathL( aODT, aResourceType );
|
|
379 |
TPtrC ptr = iPath->Des();
|
|
380 |
// modifying the resource file path on the resource
|
|
381 |
aFilePath.Format( _L("%S%S"), &KCDrive, &ptr );
|
|
382 |
}
|
|
383 |
|
|
384 |
|
|
385 |
// -----------------------------------------------------------------------------
|
|
386 |
// ChspsDefinitionRepository::GetThemePathListL
|
|
387 |
// Retrieves the list of installed themes.
|
|
388 |
// (other items were commented in a header).
|
|
389 |
// -----------------------------------------------------------------------------
|
|
390 |
EXPORT_C void ChspsDefinitionRepository::GetThemePathListL( CDesCArraySeg& aThemeList, const ChspsODT& aODT )
|
|
391 |
{
|
|
392 |
CDesCArraySeg* pathList = new( ELeave ) CDesCArraySeg(KDefRepArrayGranularity);
|
|
393 |
CleanupStack::PushL( pathList );
|
|
394 |
|
|
395 |
CDesCArraySeg* tempPathList = new( ELeave ) CDesCArraySeg(KDefRepArrayGranularity);
|
|
396 |
CleanupStack::PushL( tempPathList );
|
|
397 |
|
|
398 |
// The "themes" folder must exist at this point (C drive)
|
|
399 |
_LIT( KDriveC, "C:" );
|
|
400 |
TFileName themesPath;
|
|
401 |
User::LeaveIfError( iFs.PrivatePath( themesPath ));
|
|
402 |
HBufC* path = HBufC::NewLC( KMaxFileName );
|
|
403 |
TPtr pathPtr = path->Des();
|
|
404 |
AppendDesCIntoPathL( pathPtr, KDriveC );
|
|
405 |
AppendDesCIntoPathL( pathPtr, themesPath );
|
|
406 |
AppendDesCIntoPathL( pathPtr, KThemesFolder );
|
|
407 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
408 |
|
|
409 |
// Allocate memory for the folder name to be found (uid folder)
|
|
410 |
HBufC* match = HBufC::NewLC( KTIntMahspsumbers );
|
|
411 |
TPtr matchPtr = match->Des();
|
|
412 |
|
|
413 |
// Setup a mask from the search criterias
|
|
414 |
TInt8 rootUid = aODT.RootUid() ? 1 : 0;
|
|
415 |
TInt8 provUid = aODT.ProviderUid() ? 2 : 0;
|
|
416 |
TInt8 themeUid = aODT.ThemeUid() ? 4 : 0;
|
|
417 |
TInt8 mask = rootUid | provUid | themeUid;
|
|
418 |
|
|
419 |
TInt index( 0 );
|
|
420 |
|
|
421 |
switch ( mask )
|
|
422 |
{
|
|
423 |
case 0://No data in ODT.
|
|
424 |
{
|
|
425 |
MatchingFoldersFromAllDrivesL( KMatchAll, pathPtr, *pathList );
|
|
426 |
}
|
|
427 |
break;
|
|
428 |
case 1://AppUid given.
|
|
429 |
case 3://AppUid and ProviderUid given.
|
|
430 |
case 7://AppUid, ProviderUid and ThemeUid given.
|
|
431 |
{
|
|
432 |
if ( aODT.RootUid() )
|
|
433 |
{
|
|
434 |
AppendNumIntoPathL( pathPtr, aODT.RootUid() );
|
|
435 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
436 |
}
|
|
437 |
if ( aODT.ProviderUid() )
|
|
438 |
{
|
|
439 |
AppendNumIntoPathL( pathPtr, aODT.ProviderUid() );
|
|
440 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
441 |
}
|
|
442 |
if ( aODT.ThemeUid() )
|
|
443 |
{
|
|
444 |
AppendNumIntoPathL( pathPtr, aODT.ThemeUid() );
|
|
445 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
446 |
}
|
|
447 |
MatchingFoldersFromAllDrivesL( KMatchAll, pathPtr, *pathList );
|
|
448 |
}
|
|
449 |
break;
|
|
450 |
case 2://ProviderUid given.
|
|
451 |
{
|
|
452 |
MatchingFoldersFromAllDrivesL( KMatchAll, pathPtr, *tempPathList );
|
|
453 |
matchPtr.Zero();
|
|
454 |
matchPtr.AppendNum( aODT.ProviderUid() );
|
|
455 |
for ( index = 0; index < tempPathList->Count(); index++ )
|
|
456 |
{
|
|
457 |
MatchingFoldersL( *match, tempPathList->MdcaPoint( index ), *pathList );
|
|
458 |
}
|
|
459 |
}
|
|
460 |
break;
|
|
461 |
case 4://ThemeUid given.
|
|
462 |
{
|
|
463 |
MatchingFoldersFromAllDrivesL( KMatchAll, pathPtr, *pathList );
|
|
464 |
for ( index = 0; index < pathList->Count(); index++ )
|
|
465 |
{
|
|
466 |
MatchingFoldersL( *match, pathList->MdcaPoint( index ), *tempPathList );
|
|
467 |
}
|
|
468 |
matchPtr.Zero();
|
|
469 |
matchPtr.AppendNum( aODT.ThemeUid() );
|
|
470 |
pathList->Reset();
|
|
471 |
for ( index = 0; index < tempPathList->Count(); index++ )
|
|
472 |
{
|
|
473 |
MatchingFoldersL( *match, tempPathList->MdcaPoint( index ), *pathList );
|
|
474 |
}
|
|
475 |
}
|
|
476 |
break;
|
|
477 |
case 6://ProviderUid and ThemeUid given.
|
|
478 |
{
|
|
479 |
MatchingFoldersFromAllDrivesL( KMatchAll, pathPtr, *pathList );
|
|
480 |
matchPtr.Zero();
|
|
481 |
matchPtr.AppendNum( aODT.ProviderUid() );
|
|
482 |
for ( index = 0; index < pathList->Count(); index++ )
|
|
483 |
{
|
|
484 |
MatchingFoldersL( *match, pathList->MdcaPoint( index ), *tempPathList );
|
|
485 |
}
|
|
486 |
matchPtr.Zero();
|
|
487 |
matchPtr.AppendNum( aODT.ThemeUid() );
|
|
488 |
pathList->Reset();
|
|
489 |
for ( index = 0; index < tempPathList->Count(); index++ )
|
|
490 |
{
|
|
491 |
MatchingFoldersL( *match, tempPathList->MdcaPoint( index ), *pathList );
|
|
492 |
}
|
|
493 |
}
|
|
494 |
break;
|
|
495 |
case 5://AppUid and ThemeUid given.
|
|
496 |
{
|
|
497 |
// Get paths matching the 1st argument into pathList array
|
|
498 |
matchPtr.Zero();
|
|
499 |
matchPtr.AppendNum( aODT.RootUid() );
|
|
500 |
MatchingFoldersFromAllDrivesL( *match, pathPtr, *pathList );
|
|
501 |
// From previous results, match and store results into tempPathList array
|
|
502 |
matchPtr.Zero();
|
|
503 |
matchPtr = KMatchAll;
|
|
504 |
for ( index = 0; index < pathList->Count(); index++ )
|
|
505 |
{
|
|
506 |
MatchingFoldersL( *match, pathList->MdcaPoint( index ), *tempPathList );
|
|
507 |
}
|
|
508 |
// From previous results, find mathing plugins and store them back to the pathList
|
|
509 |
matchPtr.Zero();
|
|
510 |
matchPtr.AppendNum( aODT.ThemeUid() );
|
|
511 |
pathList->Reset();
|
|
512 |
for ( index = 0; index < tempPathList->Count(); index++ )
|
|
513 |
{
|
|
514 |
MatchingFoldersL( *match, tempPathList->MdcaPoint( index ), *pathList );
|
|
515 |
}
|
|
516 |
}
|
|
517 |
break;
|
|
518 |
default:
|
|
519 |
{
|
|
520 |
pathList->AppendL( pathPtr );
|
|
521 |
}
|
|
522 |
break;
|
|
523 |
}
|
|
524 |
|
|
525 |
TInt err( KErrNotFound );
|
|
526 |
for ( TInt i = 0; i < pathList->MdcaCount(); i++ )
|
|
527 |
{
|
|
528 |
err = MatchingFoldersL( KMatchAll, pathList->MdcaPoint(i), *pathList );
|
|
529 |
if ( err == KErrNotFound )
|
|
530 |
{
|
|
531 |
TPtrC pathPtr = pathList->MdcaPoint(i);
|
|
532 |
aThemeList.AppendL( pathPtr );
|
|
533 |
}
|
|
534 |
}
|
|
535 |
CleanupStack::PopAndDestroy( 4, pathList );//path, match, pathList, tempPathList
|
|
536 |
}
|
|
537 |
|
|
538 |
// -----------------------------------------------------------------------------
|
|
539 |
// ChspsDefinitionRepository::GetThemeListAsStreamL
|
|
540 |
// Retrieves the headers of installed themes as an array of streams.
|
|
541 |
// (other items were commented in a header).
|
|
542 |
// -----------------------------------------------------------------------------
|
|
543 |
//
|
|
544 |
EXPORT_C void ChspsDefinitionRepository::GetThemeListAsStreamL( CArrayPtrSeg<HBufC8>& aHeaderList, const ChspsODT& aODT )
|
|
545 |
{
|
|
546 |
CDesCArraySeg* pathList = new( ELeave ) CDesCArraySeg(KDefRepArrayGranularity);
|
|
547 |
CleanupStack::PushL( pathList );
|
|
548 |
GetThemePathListL( *pathList, aODT );
|
|
549 |
CDesCArraySeg* themeList = new( ELeave ) CDesCArraySeg(KDefRepArrayGranularity);
|
|
550 |
CleanupStack::PushL( themeList );
|
|
551 |
|
|
552 |
for ( TInt i = 0; i < pathList->MdcaCount(); i++ )
|
|
553 |
{
|
|
554 |
SelectFilesFromPathL( *themeList, pathList->MdcaPoint( i ), ESortByDate, KMatchSkeleton );
|
|
555 |
}
|
|
556 |
|
|
557 |
for ( TInt j = 0; j < themeList->MdcaCount(); j++ )
|
|
558 |
{
|
|
559 |
TPtrC ptr( themeList->MdcaPoint( j ) );
|
|
560 |
if ( ptr.FindF( KSourceFolderWithSeperators ) == KErrNotFound )
|
|
561 |
{
|
|
562 |
HBufC8* temp = StreamHeaderFromFileL( themeList->MdcaPoint( j ) );
|
|
563 |
if ( temp )
|
|
564 |
{
|
|
565 |
aHeaderList.AppendL( temp );
|
|
566 |
}
|
|
567 |
}
|
|
568 |
}
|
|
569 |
CleanupStack::PopAndDestroy( 2, pathList );//themeList, pathList
|
|
570 |
}
|
|
571 |
|
|
572 |
// -----------------------------------------------------------------------------
|
|
573 |
// ChspsDefinitionRepository::RemoveThemeL
|
|
574 |
// Removes the specified theme.
|
|
575 |
// (other items were commented in a header).
|
|
576 |
// -----------------------------------------------------------------------------
|
|
577 |
EXPORT_C void ChspsDefinitionRepository::RemoveThemeL( const ChspsODT& aODT )
|
|
578 |
{
|
|
579 |
GetPathL( aODT, EResourceNone );
|
|
580 |
RemoveDirectoryL();
|
|
581 |
// theme removal is not informed to the clients through RepositoryInfoArray
|
|
582 |
// because this function is used also by the theme server's clean up functions -
|
|
583 |
// and it not necessary inform about them.
|
|
584 |
// insteads, maintenance handler does inform the removal.
|
|
585 |
}
|
|
586 |
|
|
587 |
|
|
588 |
// -----------------------------------------------------------------------------
|
|
589 |
// ChspsDefinitionRepository::MakeResourcePathL
|
|
590 |
// Makes a path in the repository that can be used to store the resource file.
|
|
591 |
// The path is written back into aResource
|
|
592 |
// The path depends on the locale under which the resource belongs.
|
|
593 |
// The path information will be used to retrieve the source later.
|
|
594 |
// (other items were commented in a header).
|
|
595 |
// -----------------------------------------------------------------------------
|
|
596 |
EXPORT_C void ChspsDefinitionRepository::MakeResourcePathL( const ChspsODT& aODT, ChspsResource& aResource )
|
|
597 |
{
|
|
598 |
// get the path for source resources to store (results are stored into the iPath instance)
|
|
599 |
GetPathL( aODT, aResource.ResourceType() );
|
|
600 |
TPtr pathPtr = iPath->Des();
|
|
601 |
|
|
602 |
// If the resource is of type "Other" then skip renaming of the file extension
|
|
603 |
if ( aResource.ResourceType() == EResourceOther )
|
|
604 |
{
|
|
605 |
if ( aResource.Language() != ELangNone )
|
|
606 |
{
|
|
607 |
AddLocalePathL( pathPtr, aODT.OdtLanguage() );
|
|
608 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
609 |
}
|
|
610 |
|
|
611 |
// Append the iPath with the resource name
|
|
612 |
AppendDesCIntoPathL( pathPtr, aResource.ResourceId() );
|
|
613 |
|
|
614 |
// Append with original file extension or fix it
|
|
615 |
const TDesC& name = aResource.FileName();
|
|
616 |
TParsePtr parsePtr( (TDes&)name );
|
|
617 |
TPtrC fileExtension = parsePtr.Ext();
|
|
618 |
if ( fileExtension.Length() > 2 && fileExtension.Left(2).CompareF( _L(".o") ) == 0 )
|
|
619 |
{
|
|
620 |
// Strip the first letter
|
|
621 |
TInt odtIndex(0);
|
|
622 |
TLex lex( fileExtension.Mid(3) );
|
|
623 |
if ( lex.Val( odtIndex ) == KErrNone && odtIndex >= 0 )
|
|
624 |
{
|
|
625 |
fileExtension.Set( KMatchSkeleton );
|
|
626 |
}
|
|
627 |
}
|
|
628 |
AppendDesCIntoPathL( pathPtr, fileExtension );
|
|
629 |
}
|
|
630 |
else
|
|
631 |
{
|
|
632 |
// If replaceable resource
|
|
633 |
if ( aResource.LockingPolicy() == EhspsUnlocked )
|
|
634 |
{
|
|
635 |
AppendDesCIntoPathL( pathPtr, aResource.ResourceId() );
|
|
636 |
FileExtensionL( aResource.ResourceType(), aODT.OdtLanguage() );
|
|
637 |
}
|
|
638 |
else
|
|
639 |
{
|
|
640 |
// make phycical path
|
|
641 |
User::LeaveIfError(iFs.SetSessionToPrivate(EDriveC));
|
|
642 |
// create the directory structure on the path
|
|
643 |
TInt err = iFs.MkDirAll( *iPath );
|
|
644 |
if ( err != KErrNone && err != KErrAlreadyExists )
|
|
645 |
{
|
|
646 |
User::Leave( err );
|
|
647 |
}
|
|
648 |
AppendDesCIntoPathL( pathPtr, aResource.ResourceId() );
|
|
649 |
FileExtensionL( aResource.ResourceType(), aODT.OdtLanguage() );
|
|
650 |
}
|
|
651 |
}
|
|
652 |
aResource.SetFileNameL( iPath->Des() );
|
|
653 |
}
|
|
654 |
|
|
655 |
// -----------------------------------------------------------------------------
|
|
656 |
// ChspsDefinitionRepository::SetResourceListL
|
|
657 |
// Stores the resource list to the repository.
|
|
658 |
// (other items were commented in a header).
|
|
659 |
// -----------------------------------------------------------------------------
|
|
660 |
EXPORT_C TInt ChspsDefinitionRepository::SetResourceListL( ChspsODT& aODT, const CArrayPtrSeg<ChspsResource>& aResourceList )
|
|
661 |
{
|
|
662 |
// make sure the temporary buffers are empty.
|
|
663 |
iTempFileName1.Zero();
|
|
664 |
iTempFileName2.Zero();
|
|
665 |
|
|
666 |
TInt errorCode = KErrNone;
|
|
667 |
|
|
668 |
TInt tempLanguage = aODT.OdtLanguage();
|
|
669 |
|
|
670 |
// Loop provided resources and copy them to correct places in the repository
|
|
671 |
for ( TInt i=0; i<aResourceList.Count(); i++ )
|
|
672 |
{
|
|
673 |
ChspsResource* res = aResourceList.At(i);
|
|
674 |
|
|
675 |
aODT.SetOdtLanguage( res->Language() );
|
|
676 |
|
|
677 |
if ( res->ResourceType() == EResourceDTD )
|
|
678 |
{
|
|
679 |
SetLocaleL( aODT, *res );
|
|
680 |
}
|
|
681 |
else
|
|
682 |
{
|
|
683 |
// save source path because res->FileName() will be modified by MakeResourcePath but
|
|
684 |
// the original path is still needed
|
|
685 |
HBufC* fileName = HBufC::NewLC( KMaxFileName );
|
|
686 |
TPtr fileNamePtr = fileName->Des();
|
|
687 |
fileNamePtr.Append( res->FileName() );
|
|
688 |
|
|
689 |
// strip the extension temporarily
|
|
690 |
TParsePtr k( fileNamePtr );
|
|
691 |
TPtrC name = k.Name();
|
|
692 |
res->SetResourceIdL(name);
|
|
693 |
|
|
694 |
// copy a non-cacheable resource from its location into the repository
|
|
695 |
MakeResourcePathL( aODT, *res );
|
|
696 |
|
|
697 |
// restore the file extension
|
|
698 |
TPtrC nameAndExt = k.NameAndExt();
|
|
699 |
res->SetResourceIdL(nameAndExt);
|
|
700 |
|
|
701 |
// copy the resource file to the repository
|
|
702 |
errorCode = CopyFileL( *fileName, iPath->Des() );
|
|
703 |
if ( errorCode )
|
|
704 |
{
|
|
705 |
#ifdef HSPS_LOG_ACTIVE
|
|
706 |
if( iLogBus )
|
|
707 |
{
|
|
708 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::SetResourceListL() - resource copying failed" ) );
|
|
709 |
}
|
|
710 |
#endif
|
|
711 |
}
|
|
712 |
|
|
713 |
CleanupStack::PopAndDestroy( fileName );
|
|
714 |
|
|
715 |
// Set drive information
|
|
716 |
iTempFileName1.Format( _L("%S"), &res->FileName() );
|
|
717 |
TParsePtr f( iTempFileName1 );
|
|
718 |
TPtrC path = f.Path();
|
|
719 |
TPtrC file = f.NameAndExt();
|
|
720 |
iTempFileName2.Format(_L("%S%S%S"), &KCDrive, &path, &file );
|
|
721 |
res->SetFileNameL( iTempFileName2 );
|
|
722 |
}
|
|
723 |
aODT.AddResourceL( res );
|
|
724 |
}
|
|
725 |
|
|
726 |
aODT.SetOdtLanguage( tempLanguage );
|
|
727 |
iTempFileName1.Zero();
|
|
728 |
iTempFileName2.Zero();
|
|
729 |
|
|
730 |
return errorCode;
|
|
731 |
}
|
|
732 |
|
|
733 |
// -----------------------------------------------------------------------------
|
|
734 |
// ChspsDefinitionRepository::GetResourceListL
|
|
735 |
// Retrieves the resource list from the repository. ODT-header given is a search mask.
|
|
736 |
// (other items were commented in a header).
|
|
737 |
// -----------------------------------------------------------------------------
|
|
738 |
EXPORT_C TInt ChspsDefinitionRepository::GetResourceListL( const ChspsODT& aODT, CArrayPtrSeg<ChspsResource>& aResourceList )
|
|
739 |
{
|
|
740 |
TInt errorCode = KErrNone;
|
|
741 |
GetPathL( aODT, EResourceODT );
|
|
742 |
CFileStore* store = OpenFileStoreLC( *iPath );
|
|
743 |
|
|
744 |
if( !store )
|
|
745 |
{
|
|
746 |
errorCode = KErrNotFound;
|
|
747 |
}
|
|
748 |
// Construct and open the root stream which contains the representation of our objects.
|
|
749 |
if( !errorCode )
|
|
750 |
{
|
|
751 |
RStoreReadStream instream;
|
|
752 |
CleanupClosePushL( instream );
|
|
753 |
|
|
754 |
instream.OpenLC( *store, store->Root() );
|
|
755 |
|
|
756 |
ChspsODT* odt = ChspsODT::NewL();
|
|
757 |
CleanupStack::PushL( odt );
|
|
758 |
|
|
759 |
odt->InternalizeHeaderL( instream );
|
|
760 |
// consumes header delimiter
|
|
761 |
instream.ReadInt16L();
|
|
762 |
odt->InternalizeResourceListL( instream );
|
|
763 |
// destroy the direct file store object (closes the file)
|
|
764 |
for ( TInt i = 0; i < odt->ResourceCount(); i++ )
|
|
765 |
{
|
|
766 |
aResourceList.AppendL( odt->ResourceL( i ).CloneL());
|
|
767 |
}
|
|
768 |
|
|
769 |
CleanupStack::PopAndDestroy( odt );
|
|
770 |
|
|
771 |
// Destroy the stream object and close the intstream
|
|
772 |
CleanupStack::PopAndDestroy( 2, &instream );
|
|
773 |
|
|
774 |
// Destroy the direct file store object (closes the file)
|
|
775 |
CleanupStack::PopAndDestroy( store );
|
|
776 |
}
|
|
777 |
|
|
778 |
return errorCode;
|
|
779 |
}
|
|
780 |
|
|
781 |
// -----------------------------------------------------------------------------
|
|
782 |
// ChspsDefinitionRepository::GetRepositoryInfo
|
|
783 |
// Returns a refrence to a RArray-object containing changes in the repository system.
|
|
784 |
// It is a responsibilty of the caller to lock the repository for modifications.
|
|
785 |
// (other items were commented in a header).
|
|
786 |
// -----------------------------------------------------------------------------
|
|
787 |
EXPORT_C void ChspsDefinitionRepository::RegisterNotification( ThspsRepositoryInfo aRepositoryInfo )
|
|
788 |
{
|
|
789 |
iRepositoryInfoQueue.Append( aRepositoryInfo );
|
|
790 |
|
|
791 |
for ( TInt i=0; i < iRepositoryInfoQueue.Count(); i++ )
|
|
792 |
{
|
|
793 |
// take an info from the queue
|
|
794 |
ThspsRepositoryInfo info = iRepositoryInfoQueue[i];
|
|
795 |
TBool consumed = EFalse;
|
|
796 |
// notify the observers until someone consumes the info
|
|
797 |
for ( TInt j=0; !consumed && j < iObservers.Count(); j++ )
|
|
798 |
{
|
|
799 |
if ( iObservers[j]->HandleDefinitionRespositoryEvent( info ) )
|
|
800 |
{
|
|
801 |
// observer has handled the event, stop this loop
|
|
802 |
consumed = ETrue;
|
|
803 |
}
|
|
804 |
}
|
|
805 |
// delete info from the queue
|
|
806 |
iRepositoryInfoQueue.Remove( i );
|
|
807 |
}
|
|
808 |
iRepositoryInfoQueue.Compress();
|
|
809 |
}
|
|
810 |
|
|
811 |
// -----------------------------------------------------------------------------
|
|
812 |
// ChspsDefinitionRepository::RegisterObserverL
|
|
813 |
// Registers an observer. Observers will be notified when there are definition repository
|
|
814 |
// events available.
|
|
815 |
// (other items were commented in a header).
|
|
816 |
// -----------------------------------------------------------------------------
|
|
817 |
EXPORT_C void ChspsDefinitionRepository::RegisterObserverL
|
|
818 |
( const MhspsDefinitionRepositoryObserver& aObserver )
|
|
819 |
{
|
|
820 |
iObservers.Append( &aObserver );
|
|
821 |
}
|
|
822 |
|
|
823 |
// -----------------------------------------------------------------------------
|
|
824 |
// ChspsDefinitionRepository::UnregisterObserver
|
|
825 |
// When an observer stops observation of definition repository events, it must
|
|
826 |
// unregister itself.
|
|
827 |
// (other items were commented in a header).
|
|
828 |
// -----------------------------------------------------------------------------
|
|
829 |
EXPORT_C void ChspsDefinitionRepository::UnregisterObserver
|
|
830 |
( const MhspsDefinitionRepositoryObserver& aObserver )
|
|
831 |
{
|
|
832 |
TInt found = iObservers.Find( &aObserver );
|
|
833 |
if ( !( found == KErrNotFound ))
|
|
834 |
{
|
|
835 |
iObservers.Remove( found );
|
|
836 |
}
|
|
837 |
}
|
|
838 |
|
|
839 |
|
|
840 |
// -----------------------------------------------------------------------------
|
|
841 |
// ChspsDefinitionRepository::Lock
|
|
842 |
// (other items were commented in a header).
|
|
843 |
// -----------------------------------------------------------------------------
|
|
844 |
EXPORT_C void ChspsDefinitionRepository::Lock()
|
|
845 |
{
|
|
846 |
iLockSemaphore++;
|
|
847 |
|
|
848 |
#ifdef HSPS_LOG_ACTIVE
|
|
849 |
if( iLogBus )
|
|
850 |
{
|
|
851 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::Lock() - semaphore increased to %d" ),
|
|
852 |
iLockSemaphore );
|
|
853 |
}
|
|
854 |
#endif
|
|
855 |
}
|
|
856 |
|
|
857 |
// -----------------------------------------------------------------------------
|
|
858 |
// ChspsDefinitionRepository::Unlock
|
|
859 |
// (other items were commented in a header).
|
|
860 |
// -----------------------------------------------------------------------------
|
|
861 |
EXPORT_C void ChspsDefinitionRepository::Unlock()
|
|
862 |
{
|
|
863 |
if (iLockSemaphore )
|
|
864 |
{
|
|
865 |
iLockSemaphore--;
|
|
866 |
|
|
867 |
#ifdef HSPS_LOG_ACTIVE
|
|
868 |
if( iLogBus )
|
|
869 |
{
|
|
870 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::Unlock() - semaphore decreased to %d" ),
|
|
871 |
iLockSemaphore );
|
|
872 |
}
|
|
873 |
#endif
|
|
874 |
}
|
|
875 |
}
|
|
876 |
|
|
877 |
|
|
878 |
// -----------------------------------------------------------------------------
|
|
879 |
// ChspsDefinitionRepository::Locked
|
|
880 |
// (other items were commented in a header).
|
|
881 |
// -----------------------------------------------------------------------------
|
|
882 |
EXPORT_C TBool ChspsDefinitionRepository::Locked() const
|
|
883 |
{
|
|
884 |
return iLockSemaphore;
|
|
885 |
}
|
|
886 |
|
|
887 |
// -----------------------------------------------------------------------------
|
|
888 |
// ChspsDefinitionRepository::GetODTPathLC
|
|
889 |
// Creates a path from the theme header information.
|
|
890 |
// (other items were commented in a header).
|
|
891 |
// -----------------------------------------------------------------------------
|
|
892 |
EXPORT_C void ChspsDefinitionRepository::GetODTPathL( const ChspsODT& aODT, TDes& aPath )
|
|
893 |
{
|
|
894 |
GetPathL( aODT, EResourceODT );
|
|
895 |
if ( iPath )
|
|
896 |
{
|
|
897 |
aPath.Copy( iPath->Des() );
|
|
898 |
}
|
|
899 |
else
|
|
900 |
User::Leave( KErrNotFound );
|
|
901 |
}
|
|
902 |
|
|
903 |
// -----------------------------------------------------------------------------
|
|
904 |
// ChspsDefinitionRepository::SetLogBus
|
|
905 |
// Set log bus.
|
|
906 |
// -----------------------------------------------------------------------------
|
|
907 |
#ifdef HSPS_LOG_ACTIVE
|
|
908 |
EXPORT_C void ChspsDefinitionRepository::SetLogBus( void* aLogBus )
|
|
909 |
{
|
|
910 |
iLogBus = (ChspsLogBus*)aLogBus;
|
|
911 |
}
|
|
912 |
#else
|
|
913 |
EXPORT_C void ChspsDefinitionRepository::SetLogBus( void* /*aLogBus*/ )
|
|
914 |
{
|
|
915 |
}
|
|
916 |
#endif
|
|
917 |
|
|
918 |
// -----------------------------------------------------------------------------
|
|
919 |
// ChspsDefinitionRepository::GetPathL
|
|
920 |
// Creates a path from the theme header information.
|
|
921 |
// (other items were commented in a header).
|
|
922 |
// -----------------------------------------------------------------------------
|
|
923 |
void ChspsDefinitionRepository::GetPathL( const ChspsODT& aODT, ThspsResourceType aResourceType )
|
|
924 |
{
|
|
925 |
delete iPath;
|
|
926 |
iPath = NULL;
|
|
927 |
iPath = HBufC::NewL( KMaxFileName );
|
|
928 |
TPtr pathPtr = iPath->Des();
|
|
929 |
|
|
930 |
TInt rootUid( aODT.RootUid() );
|
|
931 |
TInt providerUid( aODT.ProviderUid() );
|
|
932 |
TInt themeUid( aODT.ThemeUid() );
|
|
933 |
|
|
934 |
const TDesC& providerName = aODT.ProviderName();
|
|
935 |
const TDesC& themeShortName = aODT.ThemeShortName();
|
|
936 |
const TDesC& fileVersion = aODT.ThemeVersion();
|
|
937 |
|
|
938 |
User::LeaveIfError( iFs.PrivatePath( pathPtr ));
|
|
939 |
|
|
940 |
AppendDesCIntoPathL( pathPtr, KThemesFolder );
|
|
941 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
942 |
|
|
943 |
if ( rootUid )
|
|
944 |
{
|
|
945 |
// Append root uid
|
|
946 |
AppendNumIntoPathL( pathPtr, rootUid );
|
|
947 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
948 |
}
|
|
949 |
if ( providerUid )
|
|
950 |
{
|
|
951 |
// Append provider uid
|
|
952 |
AppendNumIntoPathL( pathPtr, providerUid );
|
|
953 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
954 |
}
|
|
955 |
if ( themeUid )
|
|
956 |
{
|
|
957 |
// Append configuration uid
|
|
958 |
AppendNumIntoPathL( pathPtr, themeUid );
|
|
959 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
960 |
}
|
|
961 |
if ( fileVersion.Length() )
|
|
962 |
{
|
|
963 |
// Append version
|
|
964 |
AppendDesCIntoPathL( pathPtr, fileVersion );
|
|
965 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
966 |
}
|
|
967 |
|
|
968 |
// path for source files
|
|
969 |
if ( aResourceType > EResourceODT )
|
|
970 |
{
|
|
971 |
if ( aResourceType != EResourceXML )
|
|
972 |
{
|
|
973 |
if ( aResourceType == EResourceDTD )
|
|
974 |
{
|
|
975 |
// <ver> locales <language>
|
|
976 |
AppendDesCIntoPathL( pathPtr, KLocaleFolder );
|
|
977 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
978 |
AddLocalePathL( pathPtr, aODT.OdtLanguage() );
|
|
979 |
}
|
|
980 |
else
|
|
981 |
{
|
|
982 |
// <ver> sources
|
|
983 |
AppendDesCIntoPathL( pathPtr, KSourceFolder );
|
|
984 |
}
|
|
985 |
AppendDesCIntoPathL( pathPtr, KDoubleBackSlash );
|
|
986 |
}
|
|
987 |
|
|
988 |
}
|
|
989 |
|
|
990 |
// resource source files do not need full path and filename
|
|
991 |
// because they must be stored as is
|
|
992 |
if ( aResourceType > EResourceNone && aResourceType < EResourceRES )
|
|
993 |
{
|
|
994 |
if ( themeShortName.Length() )
|
|
995 |
{
|
|
996 |
// Append configuration name
|
|
997 |
AppendDesCIntoPathL( pathPtr, themeShortName );
|
|
998 |
}
|
|
999 |
else if ( themeUid )
|
|
1000 |
{
|
|
1001 |
AppendNumIntoPathL( pathPtr, themeUid );
|
|
1002 |
}
|
|
1003 |
|
|
1004 |
FileExtensionL( aResourceType, aODT.OdtLanguage() );
|
|
1005 |
}
|
|
1006 |
}
|
|
1007 |
|
|
1008 |
// -----------------------------------------------------------------------------
|
|
1009 |
// ChspsDefinitionRepository::AppendDesCIntoPathL
|
|
1010 |
// Appends a descriptor into path. Leaves if fails.
|
|
1011 |
// (other items were commented in a header).
|
|
1012 |
// -----------------------------------------------------------------------------
|
|
1013 |
void ChspsDefinitionRepository::AppendDesCIntoPathL( TDes& aPath, const TDesC& aText )
|
|
1014 |
{
|
|
1015 |
if ( ( KMaxFileName - aPath.Length() ) >= aText.Length() )
|
|
1016 |
{
|
|
1017 |
aPath.Append( aText );
|
|
1018 |
}
|
|
1019 |
else
|
|
1020 |
{
|
|
1021 |
User::Leave( KErrOverflow );
|
|
1022 |
}
|
|
1023 |
}
|
|
1024 |
|
|
1025 |
// -----------------------------------------------------------------------------
|
|
1026 |
// ChspsDefinitionRepository::AppendNumIntoPathL
|
|
1027 |
// Appends a number into path. Leaves if fails.
|
|
1028 |
// (other items were commented in a header).
|
|
1029 |
// -----------------------------------------------------------------------------
|
|
1030 |
void ChspsDefinitionRepository::AppendNumIntoPathL( TDes& aPath, const TUint aNum )
|
|
1031 |
{
|
|
1032 |
TInt len = 8;
|
|
1033 |
if ( ( KMaxFileName - aPath.Length() ) >= len )
|
|
1034 |
{
|
|
1035 |
aPath.AppendNum( aNum );
|
|
1036 |
}
|
|
1037 |
else
|
|
1038 |
{
|
|
1039 |
User::Leave( KErrOverflow );
|
|
1040 |
}
|
|
1041 |
}
|
|
1042 |
|
|
1043 |
// -----------------------------------------------------------------------------
|
|
1044 |
// ChspsDefinitionRepository::FileExtensionL
|
|
1045 |
// Returns a file extension for the given TDefRepFileExtension.
|
|
1046 |
// (other items were commented in a header).
|
|
1047 |
// -----------------------------------------------------------------------------
|
|
1048 |
void ChspsDefinitionRepository::FileExtensionL( ThspsResourceType aResourceType,
|
|
1049 |
TInt /*aLanguage*/ )
|
|
1050 |
{
|
|
1051 |
TPtr pathPtr = iPath->Des();
|
|
1052 |
switch ( aResourceType )
|
|
1053 |
{
|
|
1054 |
case EResourceNone:
|
|
1055 |
{
|
|
1056 |
}
|
|
1057 |
break;
|
|
1058 |
case EResourceODT:
|
|
1059 |
{
|
|
1060 |
TBuf<6> extension( KODTFileExtension );
|
|
1061 |
AppendDesCIntoPathL( pathPtr, extension );
|
|
1062 |
}
|
|
1063 |
break;
|
|
1064 |
case EResourceDTD:
|
|
1065 |
{
|
|
1066 |
AppendDesCIntoPathL( pathPtr, KDTDFileExtension );
|
|
1067 |
}
|
|
1068 |
break;
|
|
1069 |
case EResourceXML:
|
|
1070 |
{
|
|
1071 |
AppendDesCIntoPathL( pathPtr, KXMLFileExtension );
|
|
1072 |
}
|
|
1073 |
break;
|
|
1074 |
case EResourceDAT:
|
|
1075 |
{
|
|
1076 |
AppendDesCIntoPathL( pathPtr, KDATFileExtension );
|
|
1077 |
}
|
|
1078 |
break;
|
|
1079 |
default:
|
|
1080 |
{
|
|
1081 |
User::Leave( KErrArgument );
|
|
1082 |
}
|
|
1083 |
break;
|
|
1084 |
};
|
|
1085 |
}
|
|
1086 |
|
|
1087 |
// -----------------------------------------------------------------------------
|
|
1088 |
// ChspsDefinitionRepository::PathExtensionL
|
|
1089 |
// Returns a file extension for the given TDefRepFileExtension.
|
|
1090 |
// (other items were commented in a header).
|
|
1091 |
// -----------------------------------------------------------------------------
|
|
1092 |
void ChspsDefinitionRepository::AddLocalePathL( TDes& aPath, TInt aLanguage )
|
|
1093 |
{
|
|
1094 |
TBuf<6> extension;
|
|
1095 |
extension.AppendFormat( KFolderFormat, aLanguage );
|
|
1096 |
AppendDesCIntoPathL( aPath, extension );
|
|
1097 |
}
|
|
1098 |
|
|
1099 |
// -----------------------------------------------------------------------------
|
|
1100 |
// ChspsDefinitionRepository::WriteToFileL
|
|
1101 |
// Writes the ODT structure into file.
|
|
1102 |
// (other items were commented in a header).
|
|
1103 |
// -----------------------------------------------------------------------------
|
|
1104 |
TInt ChspsDefinitionRepository::WriteToFileL( const ChspsODT& aODT )
|
|
1105 |
{
|
|
1106 |
TInt errorCode = KErrNone;
|
|
1107 |
errorCode = iFs.SetSessionToPrivate( EDriveC );
|
|
1108 |
if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, 0, EDriveC ) )
|
|
1109 |
{
|
|
1110 |
errorCode = KErrDiskFull;
|
|
1111 |
|
|
1112 |
#ifdef HSPS_LOG_ACTIVE
|
|
1113 |
if( iLogBus )
|
|
1114 |
{
|
|
1115 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::WriteToFileL(): - disk full." ) );
|
|
1116 |
}
|
|
1117 |
#endif
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
if ( !errorCode )
|
|
1121 |
{
|
|
1122 |
// Create the directory structure
|
|
1123 |
if( !BaflUtils::FolderExists( iFs, *iPath ) )
|
|
1124 |
{
|
|
1125 |
TInt err = iFs.MkDirAll( *iPath );
|
|
1126 |
if ( err != KErrNone && err != KErrAlreadyExists )
|
|
1127 |
{
|
|
1128 |
errorCode = err;
|
|
1129 |
|
|
1130 |
#ifdef HSPS_LOG_ACTIVE
|
|
1131 |
if( iLogBus )
|
|
1132 |
{
|
|
1133 |
iLogBus->LogText( _L( "ChspsDefinitionRepository::WriteToFileL(): - error %d." ),
|
|
1134 |
err );
|
|
1135 |
}
|
|
1136 |
#endif
|
|
1137 |
}
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
if ( !errorCode )
|
|
1141 |
{
|
|
1142 |
// Create (replace) the direct file store
|
|
1143 |
CFileStore* store = CDirectFileStore::ReplaceLC( iFs, *iPath, EFileWrite);
|
|
1144 |
|
|
1145 |
// Must say what kind of file store.
|
|
1146 |
store->SetTypeL( KDirectFileStoreLayoutUid );
|
|
1147 |
|
|
1148 |
// Construct the output stream.
|
|
1149 |
RStoreWriteStream outstream;
|
|
1150 |
CleanupClosePushL( outstream );
|
|
1151 |
|
|
1152 |
TStreamId id = outstream.CreateLC(*store);
|
|
1153 |
|
|
1154 |
// Stream out the ChspsODT
|
|
1155 |
outstream << aODT;
|
|
1156 |
outstream.CommitL();
|
|
1157 |
|
|
1158 |
// Destroy the stream object and close the outstream
|
|
1159 |
CleanupStack::PopAndDestroy( 2, &outstream );
|
|
1160 |
|
|
1161 |
// Set this stream id as the root
|
|
1162 |
store->SetRootL(id);
|
|
1163 |
store->CommitL();
|
|
1164 |
|
|
1165 |
// Destroy the direct file store object (closes the file),
|
|
1166 |
CleanupStack::PopAndDestroy( store );
|
|
1167 |
}
|
|
1168 |
}
|
|
1169 |
return errorCode;
|
|
1170 |
}
|
|
1171 |
|
|
1172 |
// -----------------------------------------------------------------------------
|
|
1173 |
// ChspsDefinitionRepository::ReadFromFileL
|
|
1174 |
// Reads the ODT structure from the file.
|
|
1175 |
// (other items were commented in a header).
|
|
1176 |
// -----------------------------------------------------------------------------
|
|
1177 |
TInt ChspsDefinitionRepository::ReadFromFileL( const TDesC& aPath, ChspsODT& aODT )
|
|
1178 |
{
|
|
1179 |
TInt errorCode = KErrNone;
|
|
1180 |
CFileStore* store = OpenFileStoreLC( aPath );
|
|
1181 |
if ( !store )
|
|
1182 |
{
|
|
1183 |
errorCode = KErrNotFound;
|
|
1184 |
}
|
|
1185 |
// Construct and open the root stream which
|
|
1186 |
// contains the representation of our objects.
|
|
1187 |
if ( !errorCode )
|
|
1188 |
{
|
|
1189 |
RStoreReadStream instream;
|
|
1190 |
CleanupClosePushL( instream );
|
|
1191 |
|
|
1192 |
instream.OpenLC(*store,store->Root());
|
|
1193 |
|
|
1194 |
// Stream in the ODT
|
|
1195 |
instream >> aODT;
|
|
1196 |
|
|
1197 |
// Destroy the stream object and close the instream
|
|
1198 |
CleanupStack::PopAndDestroy( 2, &instream );
|
|
1199 |
|
|
1200 |
// Destroy the direct file store object (closes the file),
|
|
1201 |
CleanupStack::PopAndDestroy( store );
|
|
1202 |
}
|
|
1203 |
|
|
1204 |
return errorCode;
|
|
1205 |
}
|
|
1206 |
|
|
1207 |
// -----------------------------------------------------------------------------
|
|
1208 |
// ChspsDefinitionRepository::StreamHeaderFromFileL
|
|
1209 |
// Streams the ODT header from the file into descriptor.
|
|
1210 |
// (other items were commented in a header).
|
|
1211 |
// -----------------------------------------------------------------------------
|
|
1212 |
HBufC8* ChspsDefinitionRepository::StreamHeaderFromFileL( const TDesC& aPath )
|
|
1213 |
{
|
|
1214 |
HBufC8* dataStream( NULL );
|
|
1215 |
CFileStore* store( NULL );
|
|
1216 |
|
|
1217 |
store = OpenFileStoreLC( aPath );
|
|
1218 |
|
|
1219 |
if( store )
|
|
1220 |
{
|
|
1221 |
// Construct and open the root stream, which
|
|
1222 |
// contains the representation of our objects.
|
|
1223 |
RStoreReadStream instream;
|
|
1224 |
CleanupClosePushL( instream );
|
|
1225 |
|
|
1226 |
instream.OpenLC( *store, store->Root() );
|
|
1227 |
|
|
1228 |
ChspsODT* odt = ChspsODT::NewL();
|
|
1229 |
CleanupStack::PushL( odt );
|
|
1230 |
|
|
1231 |
odt->InternalizeHeaderL( instream );
|
|
1232 |
|
|
1233 |
|
|
1234 |
dataStream = odt->MarshalHeaderL();
|
|
1235 |
|
|
1236 |
CleanupStack::PopAndDestroy( odt );
|
|
1237 |
|
|
1238 |
// Destroy the stream object and close the instream
|
|
1239 |
CleanupStack::PopAndDestroy( 2, &instream );
|
|
1240 |
|
|
1241 |
// Destroy the direct file store object (closes the file)
|
|
1242 |
CleanupStack::PopAndDestroy( store );
|
|
1243 |
}
|
|
1244 |
|
|
1245 |
return dataStream;
|
|
1246 |
}
|
|
1247 |
|
|
1248 |
// -----------------------------------------------------------------------------
|
|
1249 |
// ChspsDefinitionRepository::OpenFileStoreLC
|
|
1250 |
// Searches and opens the CFileStore from the any drive.
|
|
1251 |
// (other items were commented in a header).
|
|
1252 |
// -----------------------------------------------------------------------------
|
|
1253 |
CFileStore* ChspsDefinitionRepository::OpenFileStoreLC( const TDesC& aPath )
|
|
1254 |
{
|
|
1255 |
RFile file;
|
|
1256 |
TDriveList drivelist;
|
|
1257 |
CFileStore* store = NULL;
|
|
1258 |
|
|
1259 |
TInt err( KErrNotFound );
|
|
1260 |
iFs.SetSessionToPrivate( EDriveC );
|
|
1261 |
err = file.Open(iFs, aPath, EFileShareReadersOnly );
|
|
1262 |
if ( !err )
|
|
1263 |
{
|
|
1264 |
// if the file is empty CDirectFileStore::FromLC leaves.
|
|
1265 |
TInt size(0);
|
|
1266 |
file.Size(size);
|
|
1267 |
if(size)
|
|
1268 |
{
|
|
1269 |
// Oownership of the file passes to the store
|
|
1270 |
store = CDirectFileStore::FromLC( file );
|
|
1271 |
}
|
|
1272 |
}
|
|
1273 |
|
|
1274 |
if( err || !store )
|
|
1275 |
{
|
|
1276 |
// Just for sanity
|
|
1277 |
file.Close();
|
|
1278 |
}
|
|
1279 |
|
|
1280 |
iLicenseDefault = EFalse;
|
|
1281 |
|
|
1282 |
return store;
|
|
1283 |
}
|
|
1284 |
|
|
1285 |
|
|
1286 |
// -----------------------------------------------------------------------------
|
|
1287 |
// ChspsDefinitionRepository::SelectFilesFromPathL
|
|
1288 |
// Retrieves all the files from the given path.
|
|
1289 |
// (other items were commented in a header).
|
|
1290 |
// -----------------------------------------------------------------------------
|
|
1291 |
void ChspsDefinitionRepository::SelectFilesFromPathL( CDesCArraySeg& aFileList, const TDesC& aPath,
|
|
1292 |
TEntryKey aSortFlag, const TDesC& aFileExtension )
|
|
1293 |
{
|
|
1294 |
CDir* dirList;
|
|
1295 |
User::LeaveIfError( iFs.GetDir( aPath, KEntryAttMaskSupported, aSortFlag, dirList ));
|
|
1296 |
for ( TInt i = 0; i < dirList->Count(); i++)
|
|
1297 |
{
|
|
1298 |
if ( !(*dirList)[i].IsDir() )
|
|
1299 |
{
|
|
1300 |
HBufC* path = HBufC::NewLC( aPath.Length() + (*dirList)[i].iName.Length() );
|
|
1301 |
TPtr pathPtr = path->Des();
|
|
1302 |
AppendDesCIntoPathL( pathPtr, aPath );
|
|
1303 |
AppendDesCIntoPathL( pathPtr, (*dirList)[i].iName );
|
|
1304 |
TParse p;
|
|
1305 |
p.Set(pathPtr,NULL,NULL);
|
|
1306 |
|
|
1307 |
// If the path is not pointing to the sources folder (e.g. is not a resource file)
|
|
1308 |
if ( pathPtr.FindF( KSourceFolderWithSeperators ) == KErrNotFound )
|
|
1309 |
{
|
|
1310 |
// If requested and parsed file extensions match
|
|
1311 |
if ( !p.Ext().CompareF( aFileExtension ) )
|
|
1312 |
{
|
|
1313 |
aFileList.AppendL( pathPtr );
|
|
1314 |
}
|
|
1315 |
}
|
|
1316 |
CleanupStack::PopAndDestroy( path );
|
|
1317 |
}
|
|
1318 |
}
|
|
1319 |
delete dirList;
|
|
1320 |
}
|
|
1321 |
|
|
1322 |
|
|
1323 |
// -----------------------------------------------------------------------------
|
|
1324 |
// ChspsDefinitionRepository::CopyFileL
|
|
1325 |
// Copies a file from the given location into path,
|
|
1326 |
// which is stored in the iPath member variable.
|
|
1327 |
// (other items were commented in a header).
|
|
1328 |
// -----------------------------------------------------------------------------
|
|
1329 |
TInt ChspsDefinitionRepository::CopyFileL( const TDesC& aSourceFile, const TDesC& aDestinationFile )
|
|
1330 |
{
|
|
1331 |
TInt errorCode = KErrNone;
|
|
1332 |
iFs.SetSessionToPrivate( EDriveC );
|
|
1333 |
// create the directory structure if one does not exist
|
|
1334 |
TInt err = iFs.MkDirAll( aDestinationFile );
|
|
1335 |
if ( err != KErrNone && err != KErrAlreadyExists )
|
|
1336 |
{
|
|
1337 |
errorCode = err;
|
|
1338 |
}
|
|
1339 |
if ( !errorCode )
|
|
1340 |
{
|
|
1341 |
|
|
1342 |
TEntry entry;
|
|
1343 |
errorCode = iFs.Entry( aSourceFile, entry );
|
|
1344 |
if ( !errorCode && SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, entry.iSize, EDriveC ) )
|
|
1345 |
{
|
|
1346 |
errorCode = KErrDiskFull;
|
|
1347 |
}
|
|
1348 |
|
|
1349 |
if ( !errorCode )
|
|
1350 |
{
|
|
1351 |
CFileMan* fileMan = CFileMan::NewL( iFs );
|
|
1352 |
CleanupStack::PushL( fileMan );
|
|
1353 |
errorCode = fileMan->Copy( aSourceFile, aDestinationFile, ( CFileMan::ERecurse | CFileMan::EOverWrite ) );
|
|
1354 |
errorCode = fileMan->Attribs( *iPath, KEntryAttNormal,
|
|
1355 |
KEntryAttReadOnly | KEntryAttHidden, TTime(0) );
|
|
1356 |
CleanupStack::PopAndDestroy( fileMan );
|
|
1357 |
}
|
|
1358 |
}
|
|
1359 |
return errorCode;
|
|
1360 |
}
|
|
1361 |
|
|
1362 |
// -----------------------------------------------------------------------------
|
|
1363 |
// ChspsDefinitionRepository::MatchingFoldersFromAllDrivesL
|
|
1364 |
// Retrieves all the matching folders from the given path from every drive.
|
|
1365 |
// (other items were commented in a header).
|
|
1366 |
// -----------------------------------------------------------------------------
|
|
1367 |
void ChspsDefinitionRepository::MatchingFoldersFromAllDrivesL( const TDesC& aWildName,
|
|
1368 |
const TDesC& aScanDir, CDesCArraySeg& aPathList )
|
|
1369 |
{
|
|
1370 |
TFindFile fileFinder( iFs );
|
|
1371 |
CDir* fileList;
|
|
1372 |
|
|
1373 |
// Exclude external and ROM drives from the following search
|
|
1374 |
fileFinder.SetFindMask( KDriveAttExclude | KDriveAttRemovable |KDriveAttRemote |KDriveAttRom );
|
|
1375 |
|
|
1376 |
// Searches, using wildcards, for one or more files/directories in a specified directory.
|
|
1377 |
// If no matching file is found in that directory, all available drives are searched in
|
|
1378 |
// descending alphabetical order, from Y: to A:, and ending with the Z: drive.
|
|
1379 |
// The search ends when one or more matching filenames are found, or when every available
|
|
1380 |
// drive has been unsuccessfully searched.
|
|
1381 |
// To begin searching again after a successful match has been made, use FindWild().
|
|
1382 |
TInt err = fileFinder.FindWildByDir( aWildName, aScanDir, fileList );
|
|
1383 |
while ( err == KErrNone )
|
|
1384 |
{
|
|
1385 |
TInt i;
|
|
1386 |
for ( i = 0; i < fileList->Count(); i++ )
|
|
1387 |
{
|
|
1388 |
TPtrC name( (*fileList)[i].iName );
|
|
1389 |
if( (*fileList)[i].IsDir()
|
|
1390 |
&& KSourceFolder().CompareF( name ) != 0
|
|
1391 |
&& KLocaleFolder().CompareF( name ) != 0 )
|
|
1392 |
{
|
|
1393 |
TParse fullentry;
|
|
1394 |
fullentry.Set( name, &fileFinder.File(), NULL);
|
|
1395 |
|
|
1396 |
HBufC* path = HBufC::NewLC( fullentry.FullName().Length() + KDoubleBackSlash().Length() );
|
|
1397 |
TPtr pathPtr = path->Des();
|
|
1398 |
pathPtr.Append( fullentry.FullName() );
|
|
1399 |
pathPtr.Append( KDoubleBackSlash );
|
|
1400 |
aPathList.AppendL( pathPtr );
|
|
1401 |
CleanupStack::PopAndDestroy( path );
|
|
1402 |
}
|
|
1403 |
}//for
|
|
1404 |
delete fileList;
|
|
1405 |
//Go trough all the drives a->z
|
|
1406 |
err = fileFinder.FindWild( fileList );
|
|
1407 |
}//while
|
|
1408 |
}
|
|
1409 |
|
|
1410 |
// -----------------------------------------------------------------------------
|
|
1411 |
// ChspsDefinitionRepository::MatchingFoldersL
|
|
1412 |
// Retrieves all the matching folders from the given path and drive.
|
|
1413 |
// (other items were commented in a header).
|
|
1414 |
// -----------------------------------------------------------------------------
|
|
1415 |
TInt ChspsDefinitionRepository::MatchingFoldersL( const TDesC& aWildName,
|
|
1416 |
const TDesC& aScanDir, CDesCArraySeg& aPathList )
|
|
1417 |
{
|
|
1418 |
TInt foldersExists( KErrCancel );
|
|
1419 |
TFindFile fileFinder( iFs );
|
|
1420 |
CDir* fileList;
|
|
1421 |
|
|
1422 |
TInt err = fileFinder.FindWildByDir( aWildName, aScanDir, fileList );
|
|
1423 |
if ( err == KErrNone )
|
|
1424 |
{
|
|
1425 |
TInt i;
|
|
1426 |
for ( i = 0; i < fileList->Count(); i++ )
|
|
1427 |
{
|
|
1428 |
TPtrC name( (*fileList)[i].iName );
|
|
1429 |
if( (*fileList)[i].IsDir()
|
|
1430 |
&& KSourceFolder().CompareF( name ) != 0
|
|
1431 |
&& KLocaleFolder().CompareF( name ) != 0 )
|
|
1432 |
{
|
|
1433 |
foldersExists = KErrNone;
|
|
1434 |
TParse fullentry;
|
|
1435 |
fullentry.Set( name, &fileFinder.File(), NULL);
|
|
1436 |
|
|
1437 |
HBufC* path = HBufC::NewLC( fullentry.FullName().Length() + KDoubleBackSlash().Length() );
|
|
1438 |
TPtr pathPtr = path->Des();
|
|
1439 |
pathPtr.Append( fullentry.FullName() );
|
|
1440 |
pathPtr.Append( KDoubleBackSlash );
|
|
1441 |
aPathList.AppendL( pathPtr );
|
|
1442 |
CleanupStack::PopAndDestroy( path );
|
|
1443 |
}
|
|
1444 |
else
|
|
1445 |
{
|
|
1446 |
foldersExists = KErrNotFound;
|
|
1447 |
}
|
|
1448 |
}//for
|
|
1449 |
delete fileList;
|
|
1450 |
}//if
|
|
1451 |
|
|
1452 |
return foldersExists;
|
|
1453 |
}
|
|
1454 |
|
|
1455 |
// -----------------------------------------------------------------------------
|
|
1456 |
// ChspsDefinitionRepository::CopyFileL
|
|
1457 |
// Copies a file from the given location into path,
|
|
1458 |
// which is stored in the iPath member variable.
|
|
1459 |
// (other items were commented in a header).
|
|
1460 |
// -----------------------------------------------------------------------------
|
|
1461 |
TInt ChspsDefinitionRepository::CopyFileL( const TDesC& aSourceFile )
|
|
1462 |
{
|
|
1463 |
TInt errorCode = KErrNone;
|
|
1464 |
iFs.SetSessionToPrivate( EDriveC );
|
|
1465 |
// create the directory structure if one does not exist
|
|
1466 |
TInt err = iFs.MkDirAll( *iPath );
|
|
1467 |
if ( err != KErrNone && err != KErrAlreadyExists )
|
|
1468 |
{
|
|
1469 |
errorCode = err;
|
|
1470 |
}
|
|
1471 |
if ( !errorCode )
|
|
1472 |
{
|
|
1473 |
TEntry entry;
|
|
1474 |
errorCode = iFs.Entry( aSourceFile, entry );
|
|
1475 |
if ( !errorCode && SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, entry.iSize, EDriveC ) )
|
|
1476 |
{
|
|
1477 |
errorCode = KErrDiskFull;
|
|
1478 |
}
|
|
1479 |
if ( !errorCode )
|
|
1480 |
{
|
|
1481 |
CFileMan* fileMan = CFileMan::NewL( iFs );
|
|
1482 |
CleanupStack::PushL( fileMan );
|
|
1483 |
errorCode = fileMan->Copy( aSourceFile, *iPath, CFileMan::EOverWrite );
|
|
1484 |
errorCode = fileMan->Attribs( *iPath, KEntryAttNormal,
|
|
1485 |
KEntryAttReadOnly | KEntryAttHidden, TTime(0) );
|
|
1486 |
CleanupStack::PopAndDestroy( fileMan );
|
|
1487 |
}
|
|
1488 |
}
|
|
1489 |
return errorCode;
|
|
1490 |
}
|
|
1491 |
|
|
1492 |
// -----------------------------------------------------------------------------
|
|
1493 |
// ChspsDefinitionRepository::RemoveDirectoryL
|
|
1494 |
// Deletes the files and folders beneath the path,
|
|
1495 |
// which is stored in the iPath member variable.
|
|
1496 |
// (other items were commented in a header).
|
|
1497 |
// -----------------------------------------------------------------------------
|
|
1498 |
void ChspsDefinitionRepository::RemoveDirectoryL()
|
|
1499 |
{
|
|
1500 |
TInt errorCode = KErrNone;
|
|
1501 |
iFs.SetSessionToPrivate( EDriveC );
|
|
1502 |
CFileMan* fileMan = CFileMan::NewL( iFs );
|
|
1503 |
CleanupStack::PushL( fileMan );
|
|
1504 |
TPtr pathPtr = iPath->Des();
|
|
1505 |
TInt err = fileMan->RmDir( pathPtr );
|
|
1506 |
if ( err != KErrNone && err != KErrPathNotFound )
|
|
1507 |
{
|
|
1508 |
errorCode = err; // probably KErrInUse
|
|
1509 |
}
|
|
1510 |
else
|
|
1511 |
{
|
|
1512 |
//If the folder is empty -> remove it
|
|
1513 |
TParsePtr path( pathPtr );
|
|
1514 |
TInt flag( ETrue );
|
|
1515 |
do
|
|
1516 |
{
|
|
1517 |
TInt err = path.PopDir();
|
|
1518 |
if ( !err )
|
|
1519 |
{
|
|
1520 |
CDir* dirList;
|
|
1521 |
err = iFs.GetDir( path.Path(), KEntryAttMaskSupported,ESortByName, dirList );
|
|
1522 |
if ( !err && dirList->Count() == 0 )
|
|
1523 |
{
|
|
1524 |
err = fileMan->RmDir( path.Path() );
|
|
1525 |
}
|
|
1526 |
else
|
|
1527 |
{
|
|
1528 |
flag = EFalse;
|
|
1529 |
}
|
|
1530 |
delete dirList;
|
|
1531 |
}
|
|
1532 |
}
|
|
1533 |
while ( flag );
|
|
1534 |
}
|
|
1535 |
CleanupStack::PopAndDestroy( fileMan );
|
|
1536 |
User::LeaveIfError( errorCode );
|
|
1537 |
}
|
|
1538 |
|
|
1539 |
|
|
1540 |
// -----------------------------------------------------------------------------
|
|
1541 |
// ChspsDefinitionRepository::RestoreBackupConfiguration
|
|
1542 |
// Restores defined configuration from backup folder
|
|
1543 |
// (other items were commented in a header).
|
|
1544 |
// -----------------------------------------------------------------------------
|
|
1545 |
EXPORT_C TInt ChspsDefinitionRepository::RestoreBackupConfiguration(
|
|
1546 |
const ChspsODT& /*aODT*/ )
|
|
1547 |
{
|
|
1548 |
TInt err( KErrNotFound );
|
|
1549 |
|
|
1550 |
return err;
|
|
1551 |
}
|
|
1552 |
|
|
1553 |
// -----------------------------------------------------------------------------
|
|
1554 |
// ChspsDefinitionRepository::BackupConfigurationL
|
|
1555 |
// Copies defined configuration to theme backup folder
|
|
1556 |
// (other items were commented in a header).
|
|
1557 |
// -----------------------------------------------------------------------------
|
|
1558 |
EXPORT_C void ChspsDefinitionRepository::BackupConfigurationL(
|
|
1559 |
const ChspsODT& aODT )
|
|
1560 |
{
|
|
1561 |
HBufC* backupPath = HBufC::NewL( KMaxFileName );
|
|
1562 |
CleanupStack::PushL( backupPath );
|
|
1563 |
TPtr backupPathPtr = backupPath->Des();
|
|
1564 |
|
|
1565 |
User::LeaveIfError( iFs.PrivatePath( backupPathPtr ));
|
|
1566 |
|
|
1567 |
AppendDesCIntoPathL( backupPathPtr, KBackupFolder );
|
|
1568 |
AppendDesCIntoPathL( backupPathPtr, KDoubleBackSlash );
|
|
1569 |
AppendDesCIntoPathL( backupPathPtr, KThemesFolder );
|
|
1570 |
AppendDesCIntoPathL( backupPathPtr, KDoubleBackSlash );
|
|
1571 |
|
|
1572 |
// Backup configuration file
|
|
1573 |
GetPathL( aODT, EResourceODT );
|
|
1574 |
CopyFileL( iPath->Des(), backupPathPtr );
|
|
1575 |
|
|
1576 |
CleanupStack::PopAndDestroy( backupPath );
|
|
1577 |
|
|
1578 |
}
|
|
1579 |
|
|
1580 |
// -----------------------------------------------------------------------------
|
|
1581 |
// ChspsDefinitionRepository::ClearBackupsL
|
|
1582 |
// Clears previous backup data
|
|
1583 |
// (other items were commented in a header).
|
|
1584 |
// -----------------------------------------------------------------------------
|
|
1585 |
EXPORT_C void ChspsDefinitionRepository::ClearBackupsL()
|
|
1586 |
{
|
|
1587 |
|
|
1588 |
HBufC* backupPath = HBufC::NewL( KMaxFileName );
|
|
1589 |
CleanupStack::PushL( backupPath );
|
|
1590 |
TPtr backupPathPtr = backupPath->Des();
|
|
1591 |
|
|
1592 |
User::LeaveIfError( iFs.PrivatePath( backupPathPtr ));
|
|
1593 |
|
|
1594 |
AppendDesCIntoPathL( backupPathPtr, KBackupFolder );
|
|
1595 |
AppendDesCIntoPathL( backupPathPtr, KDoubleBackSlash );
|
|
1596 |
|
|
1597 |
RemoveDirectoryL( backupPathPtr );
|
|
1598 |
|
|
1599 |
CleanupStack::PopAndDestroy( backupPath );
|
|
1600 |
|
|
1601 |
}
|
|
1602 |
|
|
1603 |
// -----------------------------------------------------------------------------
|
|
1604 |
// ChspsDefinitionRepository::GetOdtL
|
|
1605 |
// Retrieves the odt-structure from the repository as a reference.
|
|
1606 |
// (other items were commented in a header).
|
|
1607 |
// -----------------------------------------------------------------------------
|
|
1608 |
//
|
|
1609 |
EXPORT_C void ChspsDefinitionRepository::GetOdtL(
|
|
1610 |
const TDes& aPath,
|
|
1611 |
ChspsODT& aODT )
|
|
1612 |
{
|
|
1613 |
User::LeaveIfError( ReadFromFileL( aPath, aODT ) );
|
|
1614 |
}
|
|
1615 |
|
|
1616 |
// -----------------------------------------------------------------------------
|
|
1617 |
// ChspsDefinitionRepository::RemoveDirectoryL
|
|
1618 |
// Deletes the defined directory ( files and folders recursively )
|
|
1619 |
// (other items were commented in a header).
|
|
1620 |
// -----------------------------------------------------------------------------
|
|
1621 |
void ChspsDefinitionRepository::RemoveDirectoryL(
|
|
1622 |
TDesC& aDirPath )
|
|
1623 |
{
|
|
1624 |
|
|
1625 |
iFs.SetSessionToPrivate( EDriveC );
|
|
1626 |
CFileMan* fileMan = CFileMan::NewL( iFs );
|
|
1627 |
CleanupStack::PushL( fileMan );
|
|
1628 |
TInt err = fileMan->RmDir( aDirPath );
|
|
1629 |
CleanupStack::PopAndDestroy( fileMan );
|
|
1630 |
|
|
1631 |
}
|
|
1632 |
|
|
1633 |
// End of File
|