|
1 /* |
|
2 * Copyright (c) 2009 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 #include <bautils.h> |
|
20 #include <s32file.h> |
|
21 #include <sysversioninfo.h> |
|
22 #include "iaupdatefwversionfilehandler.h" |
|
23 #include "iaupdatedebug.h" |
|
24 |
|
25 |
|
26 // Constants to create the file. |
|
27 _LIT( KFile, "fwversion"); |
|
28 const TInt KDrive( EDriveC ); |
|
29 |
|
30 |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CIAUpdateFwVersionFileHandler::NewL |
|
34 // |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 CIAUpdateFwVersionFileHandler* CIAUpdateFwVersionFileHandler::NewL() |
|
38 { |
|
39 CIAUpdateFwVersionFileHandler* self = |
|
40 CIAUpdateFwVersionFileHandler::NewLC(); |
|
41 CleanupStack::Pop( self ); |
|
42 return self; |
|
43 } |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CIAUpdateFwVersionFileHandler::NewLC |
|
48 // |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CIAUpdateFwVersionFileHandler* CIAUpdateFwVersionFileHandler::NewLC() |
|
52 { |
|
53 CIAUpdateFwVersionFileHandler* self = |
|
54 new( ELeave) CIAUpdateFwVersionFileHandler(); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CIAUpdateFwVersionFileHandler::CIAUpdateFwVersionFileHandler |
|
63 // |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CIAUpdateFwVersionFileHandler::CIAUpdateFwVersionFileHandler() |
|
67 : iFwVersion( NULL ) |
|
68 { |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CIAUpdateFwVersionFileHandler::ConstructL |
|
73 // |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 void CIAUpdateFwVersionFileHandler::ConstructL() |
|
77 { |
|
78 User::LeaveIfError( iFsSession.Connect() ); |
|
79 User::LeaveIfError( iFsSession.SetSessionToPrivate( KDrive ) ); |
|
80 |
|
81 User::LeaveIfError( iFsSession.SessionPath( iPath ) ); |
|
82 BaflUtils::EnsurePathExistsL( iFsSession, iPath ); |
|
83 iPath.Append( KFile ); |
|
84 |
|
85 } |
|
86 |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CIAUpdateFwVersionFileHandler::~CIAUpdateFwVersionFileHandler |
|
90 // |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CIAUpdateFwVersionFileHandler::~CIAUpdateFwVersionFileHandler() |
|
94 { |
|
95 iFsSession.Close(); |
|
96 delete iFwVersion; |
|
97 } |
|
98 |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CIAUpdateFwVersionFileHandler::ReadControllerDataL |
|
102 // |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CIAUpdateFwVersionFileHandler::ReadControllerDataL() |
|
106 { |
|
107 RFile file; |
|
108 TInt err = file.Open( iFsSession, iPath, EFileRead|EFileShareAny ); |
|
109 if ( err == KErrNotFound ) |
|
110 { |
|
111 // File did not exist. |
|
112 // So, nothing to do here anymore. |
|
113 return; |
|
114 } |
|
115 User::LeaveIfError( err ); |
|
116 CleanupClosePushL( file ); |
|
117 |
|
118 RFileReadStream stream( file, 0 ); |
|
119 CleanupClosePushL( stream ); |
|
120 |
|
121 InternalizeL( stream ); |
|
122 |
|
123 CleanupStack::PopAndDestroy( &stream ); |
|
124 CleanupStack::PopAndDestroy( &file ); |
|
125 } |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CIAUpdateFwVersionFileHandler::WriteControllerDataL |
|
130 // |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CIAUpdateFwVersionFileHandler::WriteControllerDataL() |
|
134 { |
|
135 RFile file; |
|
136 User::LeaveIfError( file.Replace( iFsSession, iPath, EFileWrite|EFileShareAny ) ); |
|
137 CleanupClosePushL( file ); |
|
138 |
|
139 RFileWriteStream stream( file, 0 ); |
|
140 CleanupClosePushL( stream ); |
|
141 |
|
142 ExternalizeL( stream ); |
|
143 |
|
144 stream.CommitL(); |
|
145 |
|
146 CleanupStack::PopAndDestroy( &stream ); |
|
147 CleanupStack::PopAndDestroy( &file ); |
|
148 } |
|
149 |
|
150 |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CIAUpdateFwVersionFileHandler::FwVersionL |
|
154 // |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 HBufC* CIAUpdateFwVersionFileHandler::FwVersionL() |
|
158 { |
|
159 if ( iFwVersion ) |
|
160 { |
|
161 delete iFwVersion; |
|
162 iFwVersion = NULL; |
|
163 } |
|
164 iFwVersion = HBufC::NewL( KSysVersionInfoTextLength ); |
|
165 // Read data from the file if the file exists. |
|
166 // Otherwise, let default values remain. |
|
167 ReadControllerDataL(); |
|
168 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateFwVersionFileHandler::FwVersionL() Stored firmware version: %S", iFwVersion ); |
|
169 return iFwVersion; |
|
170 } |
|
171 |
|
172 |
|
173 // ---------------------------------------------------------- |
|
174 // CIAUpdateFwVersionFileHandler::SetFwVersionL() |
|
175 // ---------------------------------------------------------- |
|
176 void CIAUpdateFwVersionFileHandler::SetFwVersionL( const TDesC& aFwVersion ) |
|
177 { |
|
178 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateFwVersionFileHandler::SetFwVersionL() New firmware version: %S", &aFwVersion ); |
|
179 if ( iFwVersion ) |
|
180 { |
|
181 delete iFwVersion; |
|
182 iFwVersion = NULL; |
|
183 } |
|
184 iFwVersion = HBufC::NewL( aFwVersion.Length() ); |
|
185 TPtr fwptr = iFwVersion->Des(); |
|
186 fwptr.Copy( aFwVersion ); |
|
187 WriteControllerDataL(); |
|
188 } |
|
189 |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CIAUpdateFwVersionFileHandler::InternalizeL |
|
193 // |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CIAUpdateFwVersionFileHandler::InternalizeL( RReadStream& aStream ) |
|
197 { |
|
198 // If you make changes here, |
|
199 // remember to update ExternalizeL accordingly!!! |
|
200 //read the length of fw version string |
|
201 TInt fwlength ( aStream.ReadUint8L() ); |
|
202 |
|
203 //read string of fw version |
|
204 TPtr fwVer = iFwVersion->Des(); |
|
205 aStream.ReadL( fwVer, fwlength ); |
|
206 } |
|
207 |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CIAUpdateFwVersionFileHandler::ExternalizeL |
|
211 // |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CIAUpdateFwVersionFileHandler::ExternalizeL( RWriteStream& aStream ) |
|
215 { |
|
216 // If you make changes here, |
|
217 // remember to update InternalizeL accordingly!!! |
|
218 |
|
219 //write length of fw string |
|
220 aStream.WriteUint8L( iFwVersion->Length() ); |
|
221 // write string of fw version |
|
222 aStream.WriteL( *iFwVersion ); |
|
223 } |
|
224 |
|
225 //EOF |