|
1 /* |
|
2 * Copyright (c) 2007-2007 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: CIAUpdateParametersFileManager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <bautils.h> |
|
22 #include <s32file.h> |
|
23 #include <sysutil.h> |
|
24 #include <iaupdateparameters.h> |
|
25 |
|
26 #include "iaupdateparametersfilemanager.h" |
|
27 #include "iaupdatefileconsts.h" |
|
28 #include "iaupdatetools.h" |
|
29 #include "iaupdatedebug.h" |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 // This constant will be used to check if the IAD application |
|
38 // is using the same version of the file. If the versions |
|
39 // differ, then this may require additional checking in the future versions |
|
40 // when data is internalized. For example, IAD may give old version data |
|
41 // when self update is started and after update new version is used. |
|
42 const TInt KVersion( 1 ); |
|
43 |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CIAUpdateParametersFileManager::NewL |
|
47 // |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CIAUpdateParametersFileManager* CIAUpdateParametersFileManager::NewL() |
|
51 { |
|
52 CIAUpdateParametersFileManager* self = |
|
53 CIAUpdateParametersFileManager::NewLC(); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CIAUpdateParametersFileManager::NewLC |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CIAUpdateParametersFileManager* CIAUpdateParametersFileManager::NewLC() |
|
65 { |
|
66 CIAUpdateParametersFileManager* self = |
|
67 new( ELeave) CIAUpdateParametersFileManager(); |
|
68 CleanupStack::PushL( self ); |
|
69 self->ConstructL(); |
|
70 return self; |
|
71 } |
|
72 |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CIAUpdateParametersFileManager::CIAUpdateParametersFileManager |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 CIAUpdateParametersFileManager::CIAUpdateParametersFileManager() |
|
80 : CBase() |
|
81 { |
|
82 } |
|
83 |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CIAUpdateParametersFileManager::ConstructL |
|
87 // |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CIAUpdateParametersFileManager::ConstructL() |
|
91 { |
|
92 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::ConstructL start"); |
|
93 |
|
94 User::LeaveIfError( iFsSession.Connect() ); |
|
95 User::LeaveIfError( |
|
96 iFsSession.SetSessionToPrivate( |
|
97 IAUpdateFileConsts::KDrive ) ); |
|
98 User::LeaveIfError( iFsSession.SessionPath( iPath ) ); |
|
99 BaflUtils::EnsurePathExistsL( iFsSession, iPath ); |
|
100 iPath.Append( IAUpdateFileConsts::KParamsFile() ); |
|
101 |
|
102 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateParametersFileManager::ConstructL end: %S", &iPath); |
|
103 } |
|
104 |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CIAUpdateParametersFileManager::~CIAUpdateParametersFileManager |
|
108 // |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 CIAUpdateParametersFileManager::~CIAUpdateParametersFileManager() |
|
112 { |
|
113 iFsSession.Close(); |
|
114 } |
|
115 |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CIAUpdateParametersFileManager::ReadL |
|
119 // |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CIAUpdateParameters* CIAUpdateParametersFileManager::ReadL() |
|
123 { |
|
124 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateParametersFileManager::ReadDataL path: %S", &iPath); |
|
125 |
|
126 CIAUpdateParameters* params( NULL ); |
|
127 |
|
128 RFile file; |
|
129 TInt err( file.Open( iFsSession, iPath, EFileRead ) ); |
|
130 if ( err == KErrNotFound ) |
|
131 { |
|
132 IAUPDATE_TRACE("[IAUPDATE] Parameter file did not exist."); |
|
133 // File was not found. |
|
134 // So, return NULL. |
|
135 return params; |
|
136 } |
|
137 |
|
138 // If error occurred then leave. |
|
139 User::LeaveIfError( err ); |
|
140 |
|
141 CleanupClosePushL( file ); |
|
142 |
|
143 RFileReadStream stream( file, 0 ); |
|
144 CleanupClosePushL( stream ); |
|
145 |
|
146 params = InternalizeL( stream ); |
|
147 |
|
148 CleanupStack::PopAndDestroy( &stream ); |
|
149 CleanupStack::PopAndDestroy( &file ); |
|
150 |
|
151 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::ReadDataL end"); |
|
152 |
|
153 return params; |
|
154 } |
|
155 |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CIAUpdateParametersFileManager::WriteL |
|
159 // |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CIAUpdateParametersFileManager::WriteL( const CIAUpdateParameters& aParams ) |
|
163 { |
|
164 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateParametersFileManager::WriteDataL path: %S", &iPath); |
|
165 TInt sizeOfFile = sizeof( TInt ) //length integer in stream |
|
166 + sizeof( TInt ) //KVersion |
|
167 + sizeof( TInt ) * 5 //integers in externalised params |
|
168 + aParams.SearchCriteria().Size() |
|
169 + aParams.CommandLineExecutable().Size() |
|
170 + aParams.CommandLineArguments().Size(); |
|
171 |
|
172 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFsSession, |
|
173 sizeOfFile, |
|
174 IAUpdateFileConsts::KDrive ) ) |
|
175 { |
|
176 User::Leave( KErrDiskFull ); |
|
177 } |
|
178 |
|
179 RFile file; |
|
180 User::LeaveIfError( file.Replace( iFsSession, iPath, EFileWrite ) ); |
|
181 CleanupClosePushL( file ); |
|
182 |
|
183 RFileWriteStream stream( file, 0 ); |
|
184 CleanupClosePushL( stream ); |
|
185 |
|
186 ExternalizeL( stream, aParams ); |
|
187 stream.CommitL(); |
|
188 |
|
189 CleanupStack::PopAndDestroy( &stream ); |
|
190 CleanupStack::PopAndDestroy( &file ); |
|
191 |
|
192 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::WriteDataL end"); |
|
193 } |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // CIAUpdateParametersFileManager::RemoveFile |
|
198 // |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CIAUpdateParametersFileManager::RemoveFile() |
|
202 { |
|
203 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateParametersFileManager::RemoveFile path: %S", &iPath); |
|
204 |
|
205 // May either be a full path, or relative to the session path. |
|
206 // Even if session path has already been set in the ConstructL, |
|
207 // we do not use the relative path and only the hard coded filename here. |
|
208 // A new path may have been given by calling SetFilePathL. So, use that |
|
209 // value here. |
|
210 TInt errorCode( BaflUtils::DeleteFile( iFsSession, iPath ) ); |
|
211 |
|
212 IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateParametersFileManager::RemoveFile end: %d", errorCode); |
|
213 |
|
214 return errorCode; |
|
215 } |
|
216 |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CIAUpdateParametersFileManager::InternalizeL |
|
220 // |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 CIAUpdateParameters* CIAUpdateParametersFileManager::InternalizeL( RReadStream& aStream ) |
|
224 { |
|
225 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::InternalizeL start"); |
|
226 |
|
227 // If you make changes here, |
|
228 // remember to update ExternalizeL accordingly!!! |
|
229 |
|
230 TInt version( aStream.ReadInt32L() ); |
|
231 |
|
232 // Notice! In the future, some checking maybe required here |
|
233 // to be sure that file version is correct and the data can be |
|
234 // internalized correctly between different versions. |
|
235 if ( version != KVersion ) |
|
236 { |
|
237 // For now, just leave with the corrupt error. |
|
238 User::Leave( KErrCorrupt ); |
|
239 } |
|
240 |
|
241 CIAUpdateParameters* params( NULL ); |
|
242 |
|
243 HBufC8* data( NULL ); |
|
244 IAUpdateTools::InternalizeDes8L( data, aStream ); |
|
245 if ( data ) |
|
246 { |
|
247 IAUPDATE_TRACE("[IAUPDATE] Create parameters object"); |
|
248 params = CIAUpdateParameters::NewLC(); |
|
249 IAUpdateTools::InternalizeParametersL( *params, *data ); |
|
250 delete data; |
|
251 data = NULL; |
|
252 CleanupStack::Pop( params ); |
|
253 } |
|
254 |
|
255 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::InternalizeL end"); |
|
256 |
|
257 return params; |
|
258 } |
|
259 |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CIAUpdateParametersFileManager::ExternalizeL |
|
263 // |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CIAUpdateParametersFileManager::ExternalizeL( RWriteStream& aStream, |
|
267 const CIAUpdateParameters& aParams ) |
|
268 { |
|
269 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::ExternalizeL start"); |
|
270 |
|
271 // If you make changes here, |
|
272 // remember to update InternalizeL accordingly!!! |
|
273 |
|
274 aStream.WriteInt32L( KVersion ); |
|
275 |
|
276 // Write parameter data into the stream. |
|
277 HBufC8* data( NULL ); |
|
278 IAUpdateTools::ExternalizeParametersL( data, aParams ); |
|
279 if ( data ) |
|
280 { |
|
281 IAUPDATE_TRACE("[IAUPDATE] Externalize parameter data into the stream."); |
|
282 IAUpdateTools::ExternalizeDes8L( *data, aStream ); |
|
283 delete data; |
|
284 data = NULL; |
|
285 } |
|
286 |
|
287 IAUPDATE_TRACE("[IAUPDATE] CIAUpdateParametersFileManager::ExternalizeL start"); |
|
288 } |