|
1 /* |
|
2 * Copyright (c) 2005 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: Simplified interface to resource files |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "EPos_CPosLmResourceReader.h" |
|
22 |
|
23 // ============================ MEMBER FUNCTIONS =============================== |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CPosLmResourceReader::CPosLmResourceReader |
|
27 // C++ default constructor can NOT contain any code, that |
|
28 // might leave. |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CPosLmResourceReader::CPosLmResourceReader() |
|
32 :iFileSession(), |
|
33 iResourceFile(), |
|
34 iResourceBuffer(NULL) |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CPosLmResourceReader::ConstructL |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 void CPosLmResourceReader::ConstructL(const TDesC& aPath) |
|
44 { |
|
45 User::LeaveIfError(iFileSession.Connect()); |
|
46 |
|
47 TFindFile* filefinder = new (ELeave) TFindFile(iFileSession); |
|
48 CleanupStack::PushL(filefinder); |
|
49 |
|
50 TParse* fileparser = new (ELeave) TParse; |
|
51 CleanupStack::PushL(fileparser); |
|
52 fileparser->Set(aPath, NULL, NULL); |
|
53 |
|
54 User::LeaveIfError(filefinder->FindByDir(fileparser->NameAndExt(), |
|
55 fileparser->DriveAndPath())); |
|
56 |
|
57 iResourceFile.OpenL(iFileSession, filefinder->File()); |
|
58 iResourceFile.ConfirmSignatureL(0); |
|
59 |
|
60 CleanupStack::PopAndDestroy(2, filefinder); // fileparser |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CPosLmResourceReader::NewLC |
|
65 // Two-phased constructor. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C CPosLmResourceReader* CPosLmResourceReader::NewLC(const TDesC& aPath) |
|
69 { |
|
70 CPosLmResourceReader* self = new (ELeave) CPosLmResourceReader; |
|
71 CleanupStack::PushL( self ); |
|
72 self->ConstructL(aPath); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // Destructor |
|
77 EXPORT_C CPosLmResourceReader::~CPosLmResourceReader() |
|
78 { |
|
79 delete iResourceBuffer; |
|
80 iResourceFile.Close(); |
|
81 iFileSession.Close(); |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // CPosLmResourceReader::ReadHBufCL |
|
86 // (other items were commented in a header). |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 EXPORT_C HBufC* CPosLmResourceReader::ReadHBufCL(TInt aResourceId) |
|
90 { |
|
91 LoadResourceL(aResourceId); |
|
92 return iResourceReader.ReadHBufCL(); |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CPosLmResourceReader::ReadInt16L |
|
97 // (other items were commented in a header). |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C TInt CPosLmResourceReader::ReadInt16L(TInt aResourceId) |
|
101 { |
|
102 LoadResourceL(aResourceId); |
|
103 return iResourceReader.ReadInt16(); |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CPosLmResourceReader::ReadInt32L |
|
108 // (other items were commented in a header). |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 EXPORT_C TInt CPosLmResourceReader::ReadInt32L(TInt aResourceId) |
|
112 { |
|
113 LoadResourceL(aResourceId); |
|
114 return iResourceReader.ReadInt32(); |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CPosLmResourceReader::LoadResourceL |
|
119 // (other items were commented in a header). |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 EXPORT_C void CPosLmResourceReader::LoadResourceL(TInt aResourceId) |
|
123 { |
|
124 if (iResourceBuffer) |
|
125 { |
|
126 delete iResourceBuffer; |
|
127 iResourceBuffer = NULL; |
|
128 } |
|
129 iResourceBuffer = iResourceFile.AllocReadL(aResourceId); |
|
130 iResourceReader.SetBuffer(iResourceBuffer); |
|
131 } |
|
132 |
|
133 // End of File |