1 /* |
|
2 * Copyright (c) 2004-2006 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: This class reads the resource file and provides access to the |
|
15 * information read from the resource file to the controller. |
|
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 "siresourcehandler.h" |
|
26 #include <nsssisrscontrollerplugin.rsg> |
|
27 //*#include "SDConsoleTest.h" // Unit Test |
|
28 #include "nsssispeechrecognitiondatacommon.h" |
|
29 #include "nsssispeechrecognitiondatadevasr.h" |
|
30 #include "rubydebug.h" |
|
31 |
|
32 // LOCAL CONSTANTS AND MACROS |
|
33 _LIT( KResourceFileName, "\\nsssisrscontrollerplugin.rsc" ); |
|
34 _LIT( KResourceDir, "\\resource" ); |
|
35 |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSIResourceHandler::CSIResourceHandler |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CSIResourceHandler::CSIResourceHandler() |
|
46 { |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CSIResourceHandler::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CSIResourceHandler::ConstructL() |
|
55 { |
|
56 RUBY_DEBUG_BLOCK( "CSIResourceHandler::ConstructL" ); |
|
57 ReadResourceFileL(); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSIResourceHandler::NewL |
|
62 // Two-phased constructor. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CSIResourceHandler* CSIResourceHandler::NewL() |
|
66 { |
|
67 RUBY_DEBUG_BLOCK( "CSIResourceHandler::NewL" ); |
|
68 CSIResourceHandler* self = new(ELeave) CSIResourceHandler(); |
|
69 CleanupStack::PushL(self); |
|
70 self->ConstructL(); |
|
71 CleanupStack::Pop(); // self |
|
72 return self; |
|
73 } |
|
74 |
|
75 // Destructor |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CSIResourceHandler::CSIResourceHandler |
|
78 // Destructor |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CSIResourceHandler::~CSIResourceHandler() |
|
82 { |
|
83 delete iDbFileName; |
|
84 delete iDataFilenamePrefix; |
|
85 delete iDataFilenamePostfix; |
|
86 delete iDataFilenameSeperator; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CSIResourceHandler::ReadResourceFileL |
|
91 // Reads the data from the resource file. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 void CSIResourceHandler::ReadResourceFileL() |
|
95 { |
|
96 // letters for drives in search order |
|
97 const TBuf<2> KResourceDrivers = _L("cz"); |
|
98 |
|
99 // load resources |
|
100 RResourceFile resourceFile; |
|
101 RFs fs; |
|
102 User::LeaveIfError( fs.Connect() ); |
|
103 CleanupClosePushL( fs ); |
|
104 |
|
105 TFileName name; |
|
106 TInt i( 0 ); |
|
107 // try to find from the first driver |
|
108 name.Append( KResourceDrivers[i] ); |
|
109 name.Append( ':' ); |
|
110 name.Append( KResourceDir ); |
|
111 name.Append( KResourceFileName ); |
|
112 |
|
113 TBool found( EFalse ); |
|
114 |
|
115 while ( !found && i < KResourceDrivers.Length() ) |
|
116 { |
|
117 name[0] = KResourceDrivers[i++]; |
|
118 |
|
119 if ( BaflUtils::FileExists(fs, name) ) |
|
120 { |
|
121 // open resource |
|
122 resourceFile.OpenL( fs, name ); |
|
123 CleanupClosePushL( resourceFile ); |
|
124 found = ETrue; |
|
125 } |
|
126 } |
|
127 |
|
128 if ( !found ) |
|
129 { |
|
130 User::Leave( KErrNotFound ); |
|
131 } |
|
132 |
|
133 // Read Resource file according to it's structure defination |
|
134 HBufC8* res = resourceFile.AllocReadLC(SICONTROLLERINFO); |
|
135 |
|
136 TResourceReader reader; |
|
137 reader.SetBuffer(res); |
|
138 |
|
139 iMaxModelsPerBank = reader.ReadInt16(); |
|
140 iMaxModelsSystem = reader.ReadInt16(); |
|
141 |
|
142 // Plugin database file name |
|
143 iDbFileName = reader.ReadHBufCL(); |
|
144 |
|
145 // Language package data file path and prefix |
|
146 iDataFilenamePrefix = reader.ReadHBufCL(); |
|
147 |
|
148 // Language package data file postfix |
|
149 iDataFilenamePostfix = reader.ReadHBufCL(); |
|
150 |
|
151 // Language package data file name seperator |
|
152 iDataFilenameSeperator = reader.ReadHBufCL(); |
|
153 |
|
154 // Cleanup reader, resourceFile, and fs |
|
155 CleanupStack::PopAndDestroy(3); |
|
156 } |
|
157 // End of File |
|