1 /* |
|
2 * Copyright (c) 2007-2008 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 module contains the implementation of CIAUpdateFirstTimeDateFile |
|
15 * class member functions. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include <bautils.h> |
|
23 #include <s32file.h> |
|
24 #include <sysutil.h> |
|
25 |
|
26 #include "iaupdatefirsttimedatefile.h" |
|
27 |
|
28 |
|
29 const TInt KDrive( EDriveC ); |
|
30 const TInt KSizeOfFile( 8 ); |
|
31 |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CIAUpdateFirstTimeDateFile::NewL |
|
35 // |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CIAUpdateFirstTimeDateFile* CIAUpdateFirstTimeDateFile::NewL( |
|
39 const TDesC& aFile ) |
|
40 { |
|
41 CIAUpdateFirstTimeDateFile* self = |
|
42 CIAUpdateFirstTimeDateFile::NewLC( aFile ); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 |
|
48 // ----------------------------------------------------------------------------- |
|
49 // CIAUpdateFirstTimeDateFile::NewLC |
|
50 // |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 CIAUpdateFirstTimeDateFile* CIAUpdateFirstTimeDateFile::NewLC( |
|
54 const TDesC& aFile ) |
|
55 { |
|
56 CIAUpdateFirstTimeDateFile* self = |
|
57 new( ELeave) CIAUpdateFirstTimeDateFile(); |
|
58 CleanupStack::PushL( self ); |
|
59 self->ConstructL( aFile ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CIAUpdateFirstTimeDateFile::CIAUpdateFirstTimeDateFile |
|
66 // |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CIAUpdateFirstTimeDateFile::CIAUpdateFirstTimeDateFile() |
|
70 : CBase(), |
|
71 iFirstTime( 0 ) |
|
72 { |
|
73 } |
|
74 |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CIAUpdateFirstTimeDateFile::ConstructL |
|
78 // |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CIAUpdateFirstTimeDateFile::ConstructL( const TDesC& aFile ) |
|
82 { |
|
83 User::LeaveIfError( iFsSession.Connect() ); |
|
84 User::LeaveIfError( |
|
85 iFsSession.SetSessionToPrivate( KDrive ) ); |
|
86 |
|
87 User::LeaveIfError( iFsSession.SessionPath( iPath ) ); |
|
88 BaflUtils::EnsurePathExistsL( iFsSession, iPath ); |
|
89 iPath.Append( aFile ); |
|
90 |
|
91 // Read data from the file if the file exists. |
|
92 // Otherwise, let default values remain. |
|
93 ReadDataL(); |
|
94 } |
|
95 |
|
96 |
|
97 // ----------------------------------------------------------------------------- |
|
98 // CIAUpdateFirstTimeDateFile::~CIAUpdateFirstTimeDateFile |
|
99 // |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 CIAUpdateFirstTimeDateFile::~CIAUpdateFirstTimeDateFile() |
|
103 { |
|
104 iFsSession.Close(); |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CIAUpdateFirstTimeDateFile::ReadDataL |
|
110 // |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TBool CIAUpdateFirstTimeDateFile::ReadDataL() |
|
114 { |
|
115 RFile file; |
|
116 TInt err = file.Open( iFsSession, iPath, EFileRead|EFileShareAny ); |
|
117 if ( err == KErrNotFound ) |
|
118 { |
|
119 // File did not exist. |
|
120 // So, nothing to do here anymore. |
|
121 return EFalse; |
|
122 } |
|
123 User::LeaveIfError( err ); |
|
124 |
|
125 CleanupClosePushL( file ); |
|
126 |
|
127 RFileReadStream stream( file, 0 ); |
|
128 CleanupClosePushL( stream ); |
|
129 |
|
130 InternalizeL( stream ); |
|
131 |
|
132 CleanupStack::PopAndDestroy( &stream ); |
|
133 CleanupStack::PopAndDestroy( &file ); |
|
134 |
|
135 return ETrue; |
|
136 } |
|
137 |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CIAUpdateFirstTimeDateFile::WriteDataL |
|
141 // |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CIAUpdateFirstTimeDateFile::WriteDataL() |
|
145 { |
|
146 TDriveUnit driveUnit( KDrive ); |
|
147 if ( SysUtil::DiskSpaceBelowCriticalLevelL( |
|
148 &iFsSession, KSizeOfFile, driveUnit ) ) |
|
149 { |
|
150 User::Leave( KErrDiskFull ); |
|
151 } |
|
152 |
|
153 RFile file; |
|
154 User::LeaveIfError( |
|
155 file.Replace( iFsSession, iPath, EFileWrite|EFileShareAny ) ); |
|
156 CleanupClosePushL( file ); |
|
157 |
|
158 RFileWriteStream stream( file, 0 ); |
|
159 CleanupClosePushL( stream ); |
|
160 |
|
161 ExternalizeL( stream ); |
|
162 |
|
163 stream.CommitL(); |
|
164 |
|
165 CleanupStack::PopAndDestroy( &stream ); |
|
166 CleanupStack::PopAndDestroy( &file ); |
|
167 } |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CIAUpdateFirstTimeDateFile::FirstTime |
|
172 // |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 const TTime& CIAUpdateFirstTimeDateFile::FirstTime() const |
|
176 { |
|
177 return iFirstTime; |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CIAUpdateFirstTimeDateFile::SetCurrentFirstTime |
|
183 // |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CIAUpdateFirstTimeDateFile::SetCurrentFirstTime() |
|
187 { |
|
188 TTime universalTime; |
|
189 universalTime.UniversalTime(); |
|
190 iFirstTime = universalTime; |
|
191 } |
|
192 |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CIAUpdateFirstTimeDateFile::InternalizeL |
|
196 // |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CIAUpdateFirstTimeDateFile::InternalizeL( RReadStream& aStream ) |
|
200 { |
|
201 // If you make changes here, |
|
202 // remember to update ExternalizeL accordingly!!! |
|
203 |
|
204 TInt64 firstTime( 0 ); |
|
205 aStream >> firstTime; |
|
206 iFirstTime = firstTime; |
|
207 } |
|
208 |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CIAUpdateFirstTimeDateFile::ExternalizeL |
|
212 // |
|
213 // ----------------------------------------------------------------------------- |
|
214 // |
|
215 void CIAUpdateFirstTimeDateFile::ExternalizeL( RWriteStream& aStream ) |
|
216 { |
|
217 // If you make changes here, |
|
218 // remember to update InternalizeL accordingly!!! |
|
219 |
|
220 TInt64 firstTime( FirstTime().Int64() ); |
|
221 aStream << firstTime; |
|
222 } |
|