|
1 /* |
|
2 * Copyright (c) 2006-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 |
|
19 #ifndef T_CATALOGSUTILS_H |
|
20 #define T_CATALOGSUTILS_H |
|
21 |
|
22 #include <badesca.h> |
|
23 #include <s32strm.h> |
|
24 #include <s32mem.h> |
|
25 #include <f32file.h> |
|
26 |
|
27 class RFs; |
|
28 class RWriteStream; |
|
29 class RReadStream; |
|
30 class MCatalogsBaseMessage; |
|
31 class RFile; |
|
32 |
|
33 /** |
|
34 * TVersion class has size restrictions and is not suitable to represent SIS |
|
35 * file versions. TCatalogsVersion has higher limits for the version values. |
|
36 */ |
|
37 class TCatalogsVersion |
|
38 { |
|
39 public: |
|
40 |
|
41 /** |
|
42 * Converts a descriptor to TCatalogsVersion |
|
43 * |
|
44 * @leave KErrArgument if at least major number is not in aVersion |
|
45 * @leave KErrGeneral if aVersion doesn't contain valid characters |
|
46 */ |
|
47 static void ConvertL( TCatalogsVersion& aTarget, const TDesC& aVersion ); |
|
48 |
|
49 /** |
|
50 * Converts a version string to a descriptor |
|
51 */ |
|
52 static HBufC* ConvertLC( const TCatalogsVersion& aSource ); |
|
53 |
|
54 /** |
|
55 * Initializes version to 0.0.0 |
|
56 */ |
|
57 TCatalogsVersion(); |
|
58 |
|
59 /** |
|
60 * Initializes version |
|
61 * |
|
62 * @param aMajor Major version number |
|
63 * @param aMinor Minor version number |
|
64 * @param aBuild Build version number |
|
65 * @return |
|
66 */ |
|
67 TCatalogsVersion( TUint16 aMajor, TUint16 aMinor, TUint32 aBuild ); |
|
68 |
|
69 /** |
|
70 * Comparison operator |
|
71 * |
|
72 * @aVersion Version to compare with |
|
73 * @param ETrue if the versions are equal |
|
74 */ |
|
75 TBool operator==( const TCatalogsVersion& aVersion ) const; |
|
76 |
|
77 /** |
|
78 * Greater than -operator |
|
79 * |
|
80 * @param aVersion Version to compare with |
|
81 * @return ETrue if the current version is greater than |
|
82 * the version given as a parameter |
|
83 */ |
|
84 TBool operator>( const TCatalogsVersion& aVersion ) const; |
|
85 |
|
86 /** |
|
87 * Equar or greater than -operator |
|
88 * |
|
89 * @param aVersion Version to compare with |
|
90 * @return ETrue if the current version is equal with or greater than |
|
91 * the version given as a parameter |
|
92 */ |
|
93 TBool operator>=( const TCatalogsVersion& aVersion ) const; |
|
94 |
|
95 |
|
96 inline TBool operator!=( const TCatalogsVersion& aVersion ) const |
|
97 { |
|
98 return !operator==( aVersion ); |
|
99 } |
|
100 |
|
101 public: |
|
102 TUint16 iMajor; |
|
103 TUint16 iMinor; |
|
104 TUint32 iBuild; |
|
105 }; |
|
106 |
|
107 |
|
108 #ifndef NCD_STORAGE_TESTING |
|
109 |
|
110 /** |
|
111 * Utility class for reading data from MCatalogsBaseMessages |
|
112 * |
|
113 * Use CleanupClosePushL when pushing this object to cleanupstack |
|
114 * |
|
115 * Basic usage: |
|
116 * |
|
117 * @code |
|
118 * void FunctionThatUsesAMessage( MCatalogsBaseMessage& aMessage ) |
|
119 * { |
|
120 * ... |
|
121 * RCatalogsMessageReader reader; |
|
122 * reader.OpenLC( aMessage ); |
|
123 * TInt32 intFromMessage = reader().ReadInt32(); |
|
124 * ... |
|
125 * CleanupStack::PopAndDestroy( &reader ); |
|
126 * ... |
|
127 * @endcode |
|
128 */ |
|
129 class RCatalogsMessageReader |
|
130 { |
|
131 public: |
|
132 |
|
133 /** |
|
134 * Constructor |
|
135 */ |
|
136 RCatalogsMessageReader(); |
|
137 |
|
138 /** |
|
139 * Opens the stream for reading. |
|
140 * |
|
141 * @param aMessage Message to read from |
|
142 * @note This object must be Closed when it's not used anymore |
|
143 */ |
|
144 void OpenL( MCatalogsBaseMessage& aMessage ); |
|
145 |
|
146 /** |
|
147 * Opens the stream for reading and pushes the reader to cleanupstack |
|
148 * |
|
149 * @param aMessage Message to read from |
|
150 */ |
|
151 void OpenLC( MCatalogsBaseMessage& aMessage ); |
|
152 |
|
153 /** |
|
154 * Closes the object |
|
155 */ |
|
156 void Close(); |
|
157 |
|
158 /** |
|
159 * Destructor |
|
160 */ |
|
161 virtual ~RCatalogsMessageReader(); |
|
162 |
|
163 /** |
|
164 * Stream getter |
|
165 */ |
|
166 RReadStream& operator()() |
|
167 { |
|
168 return iStream; |
|
169 } |
|
170 |
|
171 protected: |
|
172 |
|
173 |
|
174 RCatalogsMessageReader( const RCatalogsMessageReader& ); |
|
175 RCatalogsMessageReader& operator=( const RCatalogsMessageReader& ); |
|
176 |
|
177 private: |
|
178 |
|
179 RBuf8 iBuf; |
|
180 RDesReadStream iStream; |
|
181 |
|
182 }; |
|
183 |
|
184 #endif |
|
185 |
|
186 /** |
|
187 * Utility class for writing to a buffer |
|
188 * |
|
189 * Usage: |
|
190 * |
|
191 * @code |
|
192 * RCatalogsBufferWriter writer; |
|
193 * writer.OpenLC(); |
|
194 * writer().WriteInt32L( 64 ); |
|
195 * ExternalizeDesL( myDescriptor, writer() ); |
|
196 * ... |
|
197 * TPtr8 ptr( writer->PtrL() ); |
|
198 * // use the pointer |
|
199 * ... |
|
200 * CleanupStack::PopAndDestroy( &writer ); |
|
201 * @endcode |
|
202 */ |
|
203 class RCatalogsBufferWriter |
|
204 { |
|
205 public: |
|
206 |
|
207 /** |
|
208 * Constructor |
|
209 */ |
|
210 RCatalogsBufferWriter(); |
|
211 |
|
212 /** |
|
213 * Opens the stream for writing. |
|
214 * |
|
215 * @note This object must be Closed when it's not used anymore |
|
216 */ |
|
217 void OpenL(); |
|
218 |
|
219 /** |
|
220 * Opens the stream for writing and pushes the writer to cleanupstack |
|
221 * |
|
222 */ |
|
223 void OpenLC(); |
|
224 |
|
225 /** |
|
226 * Closes the object |
|
227 */ |
|
228 void Close(); |
|
229 |
|
230 /** |
|
231 * Destructor |
|
232 */ |
|
233 virtual ~RCatalogsBufferWriter(); |
|
234 |
|
235 /** |
|
236 * Stream getter |
|
237 */ |
|
238 RWriteStream& operator()() |
|
239 { |
|
240 return iStream; |
|
241 } |
|
242 |
|
243 |
|
244 /** |
|
245 * Written buffer |
|
246 */ |
|
247 TPtr8 PtrL() |
|
248 { |
|
249 iStream.CommitL(); |
|
250 return iBuf->Ptr( 0 ); |
|
251 } |
|
252 |
|
253 protected: |
|
254 |
|
255 |
|
256 RCatalogsBufferWriter( const RCatalogsBufferWriter& ); |
|
257 RCatalogsBufferWriter& operator=( const RCatalogsBufferWriter& ); |
|
258 |
|
259 private: |
|
260 |
|
261 CBufBase* iBuf; |
|
262 RBufWriteStream iStream; |
|
263 |
|
264 }; |
|
265 |
|
266 /** |
|
267 * Copies a descriptor to a heap descriptor. |
|
268 * |
|
269 * @param aDes Destination heap descriptor. |
|
270 * @param aSource Source descriptor. |
|
271 */ |
|
272 void AssignDesL( HBufC8*& aDes, const TDesC8& aSource ); |
|
273 |
|
274 /** |
|
275 * Copies a descriptor to a heap descriptor. |
|
276 * |
|
277 * @param aDes Destination heap descriptor. |
|
278 * @param aSource Source descriptor. |
|
279 */ |
|
280 void AssignDesL( HBufC16*& aDes, const TDesC16& aSource ); |
|
281 |
|
282 |
|
283 /** |
|
284 * Copies a UTF-8 descriptor to a unicode heap descriptor. |
|
285 * |
|
286 * @param aDes Destination heap descriptor. |
|
287 * @param aSource Source descriptor. |
|
288 */ |
|
289 void AssignDesL( HBufC16*& aDes, const TDesC8& aSource ); |
|
290 |
|
291 /** |
|
292 * Converts a utf8 descriptor into unicode. |
|
293 * |
|
294 * @param aUtfText Source data |
|
295 * @return HBufC16* Converted data |
|
296 */ |
|
297 HBufC16* ConvertUtf8ToUnicodeL( const TDesC8& aUtfText ); |
|
298 |
|
299 /** |
|
300 * Converts a unicode descriptor into utf8. |
|
301 * |
|
302 * @param aUnicodeText Source data |
|
303 * @return HBufC8* Converted data |
|
304 */ |
|
305 HBufC8* ConvertUnicodeToUtf8L( const TDesC16& aUnicodeText ); |
|
306 |
|
307 /** |
|
308 * Converts a 16-bit des to a 8-bit des by TRUNCATING(!) data. |
|
309 * Creates readable text: _L16("abc") -> _L8("abc") |
|
310 * |
|
311 * @param aDes Source data |
|
312 * @return HBufC8* Dynamically allocated buffer containing the converted data. |
|
313 */ |
|
314 HBufC8* Des16ToDes8LC( const TDesC16& aDes ); |
|
315 |
|
316 /** |
|
317 * Converts a 16-bit des to a 8-bit des by TRUNCATING(!) data. |
|
318 * Creates readable text: _L16("abc") -> _L8("abc") |
|
319 * |
|
320 * @param aDes Source data |
|
321 * @return HBufC8* Dynamically allocated buffer containing the converted data. |
|
322 */ |
|
323 HBufC8* Des16ToDes8L( const TDesC16& aDes ); |
|
324 |
|
325 /** |
|
326 * Converts a 8-bit des to a 16-bit des by adding empty 8 bits to every byte. |
|
327 * Creates readable text: _L8("abc") -> _L16("abc") |
|
328 * |
|
329 * @param aDes Source data |
|
330 * @return HBufC16* Dynamically allocated buffer containing the converted data. |
|
331 */ |
|
332 HBufC16* Des8ToDes16LC( const TDesC8& aDes ); |
|
333 |
|
334 /** |
|
335 * Converts a 8-bit des to a 16-bit des by adding empty 8 bits to every byte. |
|
336 * Creates readable text: _L8("abc") -> _L16("abc") |
|
337 * |
|
338 * @param aDes Source data |
|
339 * @return HBufC16* Dynamically allocated buffer containing the converted data. |
|
340 */ |
|
341 HBufC16* Des8ToDes16L( const TDesC8& aDes ); |
|
342 |
|
343 /** |
|
344 * Converts descriptor containing decimal number to an integer. |
|
345 * |
|
346 * @param aDes Descriptor representation of a decimal. |
|
347 * @return TInt Converted integer. |
|
348 */ |
|
349 TInt DesDecToIntL( const TDesC& aDes ); |
|
350 |
|
351 /** |
|
352 * Converts descriptor containing decimal number to an integer. |
|
353 * |
|
354 * @param aDes Descriptor containing the decimal number. |
|
355 * @param aValue Integer where the outcome is put. |
|
356 * @return Symbian error-code as a conversion outcome. |
|
357 */ |
|
358 TInt DesDecToInt( const TDesC8& aDes, TInt& aValue ); |
|
359 |
|
360 /** |
|
361 * Converts descriptor containing decimal number to an integer. |
|
362 * |
|
363 * @param aDes Descriptor containing the decimal number. |
|
364 * @param aValue Integer where the outcome is put. |
|
365 * @return Symbian error-code as a conversion outcome. |
|
366 */ |
|
367 TInt DesDecToInt( const TDesC16& aDes, TInt& aValue ); |
|
368 |
|
369 /** |
|
370 * Converts descriptor containing hexadecimal number to an integer. |
|
371 * Accepts "ABCD" and "0xABCD" format numbers. |
|
372 * Leaves if corrupt parameter. |
|
373 * @param aDes Descriptor representation of a hexadecimal. |
|
374 * @return TInt Converted integer. |
|
375 */ |
|
376 TInt DesHexToIntL( const TDesC& aDes ); |
|
377 |
|
378 /** |
|
379 * Converts the raw contents of a 8-bit descriptor into an integer. |
|
380 * |
|
381 * @param aDes Descriptor containing a raw number. |
|
382 * @return Int Converted number |
|
383 */ |
|
384 TInt Des8ToInt( const TDesC8& aDes ); |
|
385 |
|
386 /** |
|
387 * Converts the raw contents of a 8-bit descriptor into an unsigned integer. |
|
388 * |
|
389 * @param aDes Descriptor containing a raw number. |
|
390 * @return Uint Converted number |
|
391 */ |
|
392 TUint Des8ToUint( const TDesC8& aDes ); |
|
393 |
|
394 /** |
|
395 * Converts an integer into a 8-bit descriptor. |
|
396 * NOTE: the number will not be in text format. |
|
397 * |
|
398 * @param aInt Number to convert |
|
399 * @return Dynamically allocated buffer containing the data |
|
400 */ |
|
401 HBufC8* IntToDes8LC( TInt aInt ); |
|
402 |
|
403 /** |
|
404 * Converts an integer into a 8-bit descriptor. |
|
405 * NOTE: the number will not be in text format. |
|
406 * |
|
407 * @param aInt Number to convert |
|
408 * @return Dynamically allocated buffer containing the data |
|
409 */ |
|
410 HBufC8* IntToDes8L( TInt aInt ); |
|
411 |
|
412 /** |
|
413 * Converts an unsigned integer into a 8-bit descriptor. |
|
414 * NOTE: the number will not be in text format. |
|
415 * |
|
416 * @param aUint Number to convert |
|
417 * @return Dynamically allocated buffer containing the data |
|
418 */ |
|
419 HBufC8* UintToDes8LC( TUint aUint ); |
|
420 |
|
421 /** |
|
422 * Converts an unsigned integer into a 8-bit descriptor. |
|
423 * NOTE: the number will not be in text format. |
|
424 * |
|
425 * @param aUint Number to convert |
|
426 * @return Dynamically allocated buffer containing the data |
|
427 */ |
|
428 HBufC8* UintToDes8L( TUint aUint ); |
|
429 |
|
430 |
|
431 /** |
|
432 * Converts an integer into a 16-bit descriptor. |
|
433 * |
|
434 * The required length for the target descriptor depends on the used integer. |
|
435 * |
|
436 * For 8- and 16-bit integers the length of the descriptor must be at least 1 |
|
437 * For 32-bit integers the length of the descriptor must be at least 2 |
|
438 * and for 64-bit integers it must be at least 4. |
|
439 * |
|
440 * @note The number will not be in text format. |
|
441 * @note The number can be unsigned or signed and 8, 16, 32 or 64 bit. |
|
442 * |
|
443 * |
|
444 * @param aInt Number to convert. |
|
445 * @param aDes Target descriptor. Length must be at least |
|
446 */ |
|
447 template<typename T> |
|
448 void IntToDes16( const T& aInt, TDes& aDes ); |
|
449 |
|
450 |
|
451 template<> |
|
452 void IntToDes16<TInt64>( const TInt64& aInt, TDes& aDes ); |
|
453 |
|
454 |
|
455 /** |
|
456 * Converts the raw contents of a 16-bit descriptor into an integer. |
|
457 * @note The number will not be in text format. |
|
458 * @note The number can be unsigned or signed and 8, 16, 32 or 64 bit. |
|
459 * |
|
460 |
|
461 * @param aDes Source descriptor. Length must be at least 1 for 8 and 16-bit |
|
462 * integers, 2 for 32-bit integers and 4 for 64-bit integers. |
|
463 * @param aInt Number to convert. |
|
464 */ |
|
465 template<typename T> |
|
466 void Des16ToInt( const TDesC& aDes, T& aInt ); |
|
467 |
|
468 template<> |
|
469 void Des16ToInt<TInt64>( const TDesC& aDes, TInt64& aInt ); |
|
470 |
|
471 |
|
472 |
|
473 /** |
|
474 * Externalizes the descriptor to the stream with length information |
|
475 * |
|
476 * @param aDes Descriptor to externalize |
|
477 * @param aStream Target stream |
|
478 */ |
|
479 void ExternalizeDesL( const TDesC16& aDes, RWriteStream& aStream ); |
|
480 |
|
481 |
|
482 /** |
|
483 * Internalizes a descriptor written with ExternalizeDesL() from the stream |
|
484 * |
|
485 * @param Target descriptor pointer. Old descriptor is deleted if the read is |
|
486 * successful and the length of the data was > 0. |
|
487 * @param aStream Source stream |
|
488 * @return Length of the read data |
|
489 */ |
|
490 TInt InternalizeDesL( HBufC16*& aDes, RReadStream& aStream ); |
|
491 |
|
492 |
|
493 /** |
|
494 * Externalizes the descriptor to the stream with length information |
|
495 * |
|
496 * @param aDes Descriptor to externalize |
|
497 * @param aStream Target stream |
|
498 */ |
|
499 void ExternalizeDesL( const TDesC8& aDes, RWriteStream& aStream ); |
|
500 |
|
501 /** |
|
502 * Internalizes a descriptor written with ExternalizeDesL() from the stream |
|
503 * |
|
504 * @param Target descriptor pointer. Old descriptor is deleted if the read is |
|
505 * successful and the length of the data was > 0. |
|
506 * @param aStream Source stream |
|
507 * @return Length of the read data |
|
508 */ |
|
509 TInt InternalizeDesL( HBufC8*& aDes, RReadStream& aStream ); |
|
510 |
|
511 |
|
512 /** |
|
513 * Returns the path where the Engine data has been installed. |
|
514 * Examples: |
|
515 * c:\private\12345678\ |
|
516 * z:\private\DEADBEEF\ |
|
517 * |
|
518 * @return TPath Engine path. |
|
519 */ |
|
520 TPath EnginePathL( RFs& aFs ); |
|
521 |
|
522 |
|
523 /** |
|
524 * Returns the path where the Engine may write data. |
|
525 * Examples: |
|
526 * c:\private\12345678\ |
|
527 * |
|
528 * @return TPath Path where the engine may write data. |
|
529 */ |
|
530 TPath WritableEnginePathL( RFs& aFs ); |
|
531 |
|
532 /** |
|
533 * Searches for the given file from engine's private paths |
|
534 * |
|
535 * @param aFs File server session |
|
536 * @param aFilename File to search for |
|
537 * @return Path to the file |
|
538 * @leave KErrNotFound if the file was not found |
|
539 */ |
|
540 HBufC* FindEngineFileL( RFs& aFs, const TDesC& aFilename ); |
|
541 |
|
542 /** |
|
543 * Checks whether a drive is a rom drive, and thus not writable. |
|
544 * |
|
545 * @param aFs File server session |
|
546 * @param aDriveChar Drive to check, ie. C,D,E,..,Z |
|
547 * @return ETrue if drive is ROM. |
|
548 */ |
|
549 TBool IsRomDriveL( RFs& aFs, TChar aDriveChar ); |
|
550 |
|
551 |
|
552 /** |
|
553 * Converts a drive number into a drive letter. |
|
554 * |
|
555 * @param aDrive Drive number |
|
556 * @return TChar Drive letter |
|
557 */ |
|
558 TChar DriveToCharL( TInt aDrive ); |
|
559 |
|
560 |
|
561 /** |
|
562 * Gives the root path of a given drive. |
|
563 * |
|
564 * @param aFs File server session |
|
565 * @param aDriveChar Drive to check, ie. C,D,E,..,Z |
|
566 * @return HBufC* Root path of the drive. |
|
567 * (Notice, this is not necessarily C:\ but can be, for example, |
|
568 * C:\data.) |
|
569 */ |
|
570 HBufC* DriveRootPathLC( RFs& aFs, const TChar& aDriveLetter ); |
|
571 |
|
572 |
|
573 /** |
|
574 * Converts symbian language codes to java form (e.g. ELangEnglish -> "en-EN") |
|
575 * |
|
576 * @param aLang Language code |
|
577 * @return HBufC* Language string in java form. |
|
578 */ |
|
579 HBufC* LangCodeToDescLC( TLanguage aLang ); |
|
580 |
|
581 |
|
582 /** |
|
583 * Removes [ and ] from the UID name |
|
584 * |
|
585 * @param aUid UID |
|
586 * @return UID in a descriptor without [ and ] |
|
587 */ |
|
588 TUidName CleanUidName( const TUid& aUid ); |
|
589 |
|
590 |
|
591 /** |
|
592 * Encodes a filename so that it can safely be used within |
|
593 * the filesystem by replacing certain characters. |
|
594 * @param aFileName Filename to be encoded |
|
595 * @return HBufC* Encoded filename |
|
596 */ |
|
597 HBufC* EncodeFilenameLC( const TDesC& aFileName, RFs& aFs ); |
|
598 |
|
599 |
|
600 /** |
|
601 * Creates a private directory on the designated drive |
|
602 * @param aFs File server session |
|
603 * @param aDriveAndColon Drive letter and a colon, eg. "C:" |
|
604 * @param aPath Created directory path including drive |
|
605 */ |
|
606 void CreatePrivatePathL( RFs& aFs, const TDesC& aDriveAndColon, TDes& aPath ); |
|
607 |
|
608 |
|
609 /** |
|
610 * Returns maximum amount of free space on devices drive (flash or hd). |
|
611 * |
|
612 * @param aFs File server session |
|
613 * @param aDriveNumber Drive number. |
|
614 * @return TInt64 Amount of free space. |
|
615 */ |
|
616 TInt64 FreeDiskSpaceL( RFs& aFs, TInt aDriveNumber ); |
|
617 |
|
618 |
|
619 #ifndef USE_MMF_RESET_AND_DESTROY_PUSHL |
|
620 /** |
|
621 * A utility class used by the templated function CleanupResetAndDestroyPushL() |
|
622 * to create a TCleanupItem item that will perform a ResetAndDestroy type |
|
623 * operation on the class T type object. |
|
624 * |
|
625 * @see CleanupResetAndDestroyPushL() |
|
626 */ |
|
627 template <typename T> |
|
628 class CleanupResetAndDestroy |
|
629 { |
|
630 public: |
|
631 inline static void PushL(T& aRef); |
|
632 private: |
|
633 static void ResetAndDestroy(TAny *aPtr); |
|
634 }; |
|
635 |
|
636 |
|
637 /** |
|
638 * Pushes the given item to cleanupstack and calls ResetAndDestroy() to it |
|
639 * in PopAndDestroy or in case a leave occurs. |
|
640 */ |
|
641 template <typename T> |
|
642 inline void CleanupResetAndDestroyPushL(T& aRef); |
|
643 |
|
644 #endif // USE_MMF_RESET_AND_DESTROY_PUSHL |
|
645 |
|
646 /** |
|
647 * A utility class used by the templated function CleanupInternalReleasePushL() |
|
648 * to create a TCleanupItem item that will perform a InternalRelease operation |
|
649 * on th eclass T type object. |
|
650 * |
|
651 * @see CleanupInternalReleasePushL() |
|
652 */ |
|
653 template <typename T> |
|
654 class CleanupInternalRelease |
|
655 { |
|
656 public: |
|
657 inline static void PushL( T& aRef ); |
|
658 private: |
|
659 static void InternalRelease( TAny* aPtr ); |
|
660 }; |
|
661 |
|
662 /** |
|
663 * Pushes the given item to cleanupstack and calls InternalRelease() to it |
|
664 * in PopAndDestroy or in case a leave occurs. |
|
665 */ |
|
666 template <typename T> |
|
667 inline void CleanupInternalReleasePushL( T& aRef ); |
|
668 |
|
669 |
|
670 /** |
|
671 * Checks whether the given uri uses https shceme. |
|
672 * |
|
673 * @return ETrue if uri is https, EFalse if not. |
|
674 */ |
|
675 TBool IsHttpsUri( const TDesC& aUri ); |
|
676 |
|
677 |
|
678 /** |
|
679 * Retrieves the bytes allocated by the directory in the filesystem. |
|
680 * @param aFs File server session |
|
681 * @param aDir Directory |
|
682 * @return TInt Allocation in bytes. |
|
683 */ |
|
684 TInt FileSystemAllocationL( RFs& aFs, const TDesC& aDir ); |
|
685 |
|
686 /** |
|
687 * Reads a file to the 8-bit descriptor. |
|
688 * |
|
689 * @param aFs Reference to the fileserver session. |
|
690 * @param aFileName File name. |
|
691 * @return HBufC8* Dynamically allocated descriptor containing the file data. |
|
692 */ |
|
693 HBufC8* ReadFileL( RFs& aFs, const TDesC& aFileName ); |
|
694 |
|
695 |
|
696 /** |
|
697 * Reads a file to the 8-bit descriptor. |
|
698 * |
|
699 * @param aFile An opened file handle. Must be closed by the caller |
|
700 * @return HBufC8* Dynamically allocated descriptor containing the file data. |
|
701 */ |
|
702 HBufC8* ReadFileL( RFile& aFile ); |
|
703 |
|
704 |
|
705 /** |
|
706 * Checks if the disk space would go below critical if the given amount |
|
707 * of data was written to disk |
|
708 * |
|
709 * @param aPath Path to check (only drive letter is mandatory) |
|
710 * @param aFs File server session |
|
711 * @param aSpaceNeeded Needed space |
|
712 * @leave KErrDiskFull if there is not enough space |
|
713 */ |
|
714 void WouldDiskSpaceGoBelowCriticalLevelL( const TDesC& aPath, |
|
715 RFs& aFs, |
|
716 TInt aSpaceNeeded ); |
|
717 |
|
718 |
|
719 /** |
|
720 * Converts a version string of format "1.2.3" or "1.2" or "1" to version components. |
|
721 * |
|
722 * @param aStr Version string |
|
723 * @param aMajor On return contains the major version |
|
724 * @param aMinor On return contains the minor version or 0 it not available |
|
725 * @param aBuild On return contains the build number or 0 if not available. |
|
726 */ |
|
727 void DesToVersionL( const TDesC& aVersion, |
|
728 TUint16& aMajor, TUint16& aMinor, TUint32& aBuild ); |
|
729 |
|
730 /** |
|
731 * Function that calls close for each element of given array once. |
|
732 * In the end this function calls reset for the array. |
|
733 * |
|
734 */ |
|
735 template <typename T> |
|
736 void ResetAndCloseArray( RPointerArray<T>& aArray ); |
|
737 |
|
738 template <typename T> |
|
739 void ResetAndCloseArray( RArray<T>& aArray ); |
|
740 |
|
741 |
|
742 /** |
|
743 * Function that casts each element as T and then calls delete for it. |
|
744 * In the end this function calls reset for the array. |
|
745 */ |
|
746 template <typename Casted, typename T > |
|
747 void ResetAndDestroyWithCast( RPointerArray<T>& aArray ); |
|
748 |
|
749 |
|
750 template <typename T> |
|
751 void DeleteFromArray( RPointerArray<T>& aArray, TInt aIndex ); |
|
752 |
|
753 template <typename Casted, typename T> |
|
754 void DeleteFromArray( RPointerArray<T>& aArray, TInt aIndex ); |
|
755 |
|
756 |
|
757 /** |
|
758 * Internalizes an enumeration from the given stream |
|
759 * |
|
760 * @note Enumeration is read as a TInt32 |
|
761 */ |
|
762 template <typename EnumType> |
|
763 void InternalizeEnumL( EnumType& aTarget, RReadStream& aReadStream ); |
|
764 |
|
765 /** |
|
766 * Externalizes an enumeration to the given stream |
|
767 * |
|
768 * @note Enumeration is written as a TInt32 |
|
769 */ |
|
770 template <typename EnumType> |
|
771 void ExternalizeEnumL( const EnumType& aSource, RWriteStream& aWriteStream ); |
|
772 |
|
773 |
|
774 /** |
|
775 * Appends aRoot with aAppendPath and puts them to aPath |
|
776 * |
|
777 * @param aPath RBuf without any allocated memory. This is put to CleanupStack |
|
778 * @param aRoot First path. Should contain the path delimiter at the end. |
|
779 * @param aAppendPath Second path. Appended to aRoot |
|
780 */ |
|
781 void AppendPathsLC( |
|
782 RBuf& aPath, |
|
783 const TDesC& aRoot, |
|
784 const TDesC& aAppendPath ); |
|
785 |
|
786 /** |
|
787 * Helper methods that leave if aError != KErrNone and aError != aAcceptErr |
|
788 */ |
|
789 void LeaveIfNotErrorL( TInt aError, TInt aAcceptErr ); |
|
790 void LeaveIfNotErrorL( TInt aError, TInt aAcceptErr, TInt aAcceptErr2 ); |
|
791 void LeaveIfNotErrorL( TInt aError, TInt aAcceptErr, TInt aAcceptErr2, |
|
792 TInt aAcceptErr3 ); |
|
793 |
|
794 |
|
795 /** |
|
796 * Opens a file or creates it if it doesn't already exist |
|
797 */ |
|
798 void OpenOrCreateFileL( |
|
799 RFs& aFs, RFile& aFile, const TDesC& aFilePath, TUint aFileMode ); |
|
800 |
|
801 |
|
802 /** |
|
803 * Checks if aData == aComp1 or aData == aComp2 |
|
804 * Can be used for simplifying horrendous if-clauses |
|
805 */ |
|
806 template <typename T> |
|
807 TBool IsOneOf( const T& aData, const T& aComp1, const T& aComp2 ); |
|
808 |
|
809 template <typename T> |
|
810 TBool IsOneOf( const T& aData, const T& aComp1, const T& aComp2, const T& aComp3 ); |
|
811 |
|
812 template <typename T> |
|
813 TBool IsOneOf( const T& aData, const T& aComp1, const T& aComp2, |
|
814 const T& aComp3, const T& aComp4 ); |
|
815 |
|
816 |
|
817 /** |
|
818 * Releases the object and sets the pointer as NULL |
|
819 */ |
|
820 template <typename T> |
|
821 void ReleasePtr( T*& aObject ); |
|
822 |
|
823 |
|
824 /** |
|
825 * Closes the object and sets the pointer as NULL |
|
826 */ |
|
827 template <typename T> |
|
828 void ClosePtr( T*& aObject ); |
|
829 |
|
830 |
|
831 /** |
|
832 * Deletes the object and sets the pointer as NULL |
|
833 */ |
|
834 template <typename T> |
|
835 void DeletePtr( T*& aObject ); |
|
836 |
|
837 |
|
838 #include "catalogsutils.inl" |
|
839 |
|
840 #endif // T_CATALOGSUTILS_H |