|
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: Reads the VAS resource file and keeps the information in |
|
15 * member variables for later use. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <f32file.h> |
|
22 #include <barsc.h> |
|
23 #include <bautils.h> |
|
24 #include <barsread.h> |
|
25 #include <NssVasResource.rsg> |
|
26 #include "NssVasCVasDbSrvdef.h" |
|
27 #include "NssVasCResourceHandler.h" |
|
28 #include "RubyDebug.h" |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CNssVasResourceHandler::CNssVasResourceHandler |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CNssVasResourceHandler::CNssVasResourceHandler() : iDatabasePath( NULL ), |
|
39 iDatabaseName( NULL ) |
|
40 { |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CNssVasResourceHandler::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CNssVasResourceHandler::ConstructL() |
|
49 { |
|
50 ReadResourceFileL(); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CNssVasResourceHandler::NewL |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CNssVasResourceHandler* CNssVasResourceHandler::NewL() |
|
59 { |
|
60 CNssVasResourceHandler* self = new ( ELeave ) CNssVasResourceHandler(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop( self ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CNssVasResourceHandler::~CNssVasResourceHandler |
|
69 // Destructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CNssVasResourceHandler::~CNssVasResourceHandler() |
|
73 { |
|
74 delete iDatabasePath; |
|
75 delete iDatabaseName; |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CNssVasResourceHandler::ReadResourceFileL |
|
80 // Reads the data from the resource file. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CNssVasResourceHandler::ReadResourceFileL() |
|
84 { |
|
85 RUBY_DEBUG_BLOCK( "CVasResourceHandler::ReadResourceFileL" ); |
|
86 |
|
87 // letters for drives in search order |
|
88 const TBuf<2> KResourceDrives = _L("cz"); |
|
89 |
|
90 RFs fs; |
|
91 |
|
92 // start a file session |
|
93 User::LeaveIfError( fs.Connect() ); |
|
94 CleanupClosePushL ( fs ); |
|
95 |
|
96 // Declare a resource file |
|
97 RResourceFile resourceFile; |
|
98 |
|
99 TFileName name; |
|
100 TInt i( 0 ); |
|
101 // try to find from the first driver |
|
102 name.Append( KResourceDrives[i] ); |
|
103 name.Append( ':' ); |
|
104 name.Append( KDC_RESOURCE_FILES_DIR ); |
|
105 name.Append( KResourceFileName ); |
|
106 |
|
107 TBool found( EFalse ); |
|
108 |
|
109 while ( !found && i < KResourceDrives.Length() ) |
|
110 { |
|
111 name[0] = KResourceDrives[i++]; |
|
112 |
|
113 if ( BaflUtils::FileExists(fs, name) ) |
|
114 { |
|
115 // open resource |
|
116 resourceFile.OpenL( fs, name ); |
|
117 CleanupClosePushL( resourceFile ); |
|
118 found = ETrue; |
|
119 } |
|
120 } |
|
121 |
|
122 if ( !found ) |
|
123 { |
|
124 User::Leave( KErrNotFound ); |
|
125 } |
|
126 |
|
127 HBufC8* res = resourceFile.AllocReadLC(VASINFO); // Stack: file session, res file, res reader |
|
128 |
|
129 TResourceReader theReader; |
|
130 theReader.SetBuffer(res); |
|
131 |
|
132 // Get the name of the database file |
|
133 iDatabasePath = theReader.ReadHBufCL(); |
|
134 iDatabaseName = theReader.ReadHBufCL(); |
|
135 |
|
136 // Release resource reader |
|
137 // Close resource file |
|
138 // Close file session |
|
139 CleanupStack::PopAndDestroy( res ); |
|
140 CleanupStack::PopAndDestroy( &resourceFile ); |
|
141 CleanupStack::PopAndDestroy( &fs ); |
|
142 } |
|
143 |
|
144 // End of File |