|
1 /* |
|
2 * Copyright (c) 2005-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 |
|
20 /************************************************************************* |
|
21 * |
|
22 * System Includes |
|
23 * |
|
24 *************************************************************************/ |
|
25 |
|
26 #include <e32std.h> |
|
27 #include <e32base.h> |
|
28 #include <f32file.h> |
|
29 /************************************************************************* |
|
30 * |
|
31 * Local Includes |
|
32 * |
|
33 *************************************************************************/ |
|
34 |
|
35 #include "dataconsumer_file.h" |
|
36 #include "stat.h" |
|
37 /************************************************************************* |
|
38 * |
|
39 * Definitions |
|
40 * |
|
41 *************************************************************************/ |
|
42 _LIT( KTxtDiskError, "DiskError" ); |
|
43 |
|
44 /************************************************************************* |
|
45 * |
|
46 * CDataConsumerFile - Construction |
|
47 * |
|
48 *************************************************************************/ |
|
49 CDataConsumerFile *CDataConsumerFile::NewL() |
|
50 { |
|
51 CDataConsumerFile *self = new (ELeave) CDataConsumerFile(); |
|
52 |
|
53 CleanupStack::PushL(self); |
|
54 |
|
55 self->ConstructL(); |
|
56 |
|
57 CleanupStack::Pop(); |
|
58 |
|
59 return self; |
|
60 } |
|
61 |
|
62 CDataConsumerFile::CDataConsumerFile() |
|
63 { |
|
64 ; |
|
65 } |
|
66 |
|
67 void CDataConsumerFile::ConstructL( void ) |
|
68 { |
|
69 |
|
70 _LIT(KFileSrvDll, "efsrv.dll"); |
|
71 _LIT(KFileSeparator, "\\"); |
|
72 TBuf<8> systemDrive; |
|
73 |
|
74 iLock.CreateLocal( EOwnerProcess ); |
|
75 |
|
76 User::LeaveIfError( iFsSession.Connect( ) ); |
|
77 |
|
78 TDriveNumber defaultSysDrive(EDriveC); |
|
79 RLibrary pluginLibrary; |
|
80 TInt pluginErr = pluginLibrary.Load(KFileSrvDll); |
|
81 |
|
82 if (pluginErr == KErrNone) |
|
83 { |
|
84 typedef TDriveNumber(*fun1)(); |
|
85 fun1 sysdrive; |
|
86 |
|
87 #ifdef __EABI__ |
|
88 sysdrive = (fun1)pluginLibrary.Lookup(336); |
|
89 #else |
|
90 sysdrive = (fun1)pluginLibrary.Lookup(304); |
|
91 #endif |
|
92 |
|
93 if(sysdrive!=NULL) |
|
94 { |
|
95 defaultSysDrive = sysdrive(); |
|
96 } |
|
97 } |
|
98 pluginLibrary.Close(); |
|
99 |
|
100 systemDrive.Append(TDriveUnit(defaultSysDrive).Name()); |
|
101 systemDrive.Append(KFileSeparator); |
|
102 |
|
103 |
|
104 RFile file; |
|
105 |
|
106 TInt err = file.Temp( iFsSession, systemDrive,iFilePath, EFileShareExclusive ); |
|
107 |
|
108 file.Close( ); |
|
109 |
|
110 User::LeaveIfError( err ); |
|
111 } |
|
112 |
|
113 |
|
114 |
|
115 CDataConsumerFile::~CDataConsumerFile( ) |
|
116 { |
|
117 iLock.Wait( ); |
|
118 { |
|
119 iFsSession.Close(); |
|
120 |
|
121 iLock.Close( ); |
|
122 } |
|
123 } |
|
124 |
|
125 /************************************************************************* |
|
126 * |
|
127 * CDataConsumerFile - Public interface |
|
128 * |
|
129 *************************************************************************/ |
|
130 |
|
131 /************************************************************************* |
|
132 * |
|
133 * Delete |
|
134 * |
|
135 *************************************************************************/ |
|
136 |
|
137 void CDataConsumerFile::Delete( void ) |
|
138 { |
|
139 delete this; |
|
140 } |
|
141 |
|
142 /************************************************************************* |
|
143 * |
|
144 * GetTotalSize |
|
145 * |
|
146 *************************************************************************/ |
|
147 |
|
148 TInt CDataConsumerFile::GetTotalSize( TInt &aTotalSize ) |
|
149 { |
|
150 TInt err = KErrNone; |
|
151 TInt size = 0; |
|
152 |
|
153 iLock.Wait( ); |
|
154 { |
|
155 RFile file; |
|
156 |
|
157 err = file.Open( iFsSession, iFilePath, EFileRead | EFileStream | EFileShareReadersOnly ); |
|
158 |
|
159 if( err == KErrNone ) |
|
160 { |
|
161 err = file.Size( size ); |
|
162 |
|
163 if( err == KErrNone ) |
|
164 { |
|
165 aTotalSize = size; |
|
166 } |
|
167 |
|
168 file.Close( ); |
|
169 } |
|
170 |
|
171 iLock.Signal( ); |
|
172 } |
|
173 |
|
174 return ( err ); |
|
175 } |
|
176 |
|
177 /************************************************************************* |
|
178 * |
|
179 * AddData |
|
180 * |
|
181 *************************************************************************/ |
|
182 |
|
183 TInt CDataConsumerFile::AddData( const TDesC8 &aSource ) |
|
184 { |
|
185 TInt err = KErrNone; |
|
186 |
|
187 if( err == KErrNone ) |
|
188 { |
|
189 iLock.Wait( ); |
|
190 { |
|
191 RFile file; |
|
192 TInt shareMode = EFileWrite | EFileStream | EFileShareExclusive; |
|
193 |
|
194 err = file.Open( iFsSession, iFilePath, shareMode ); |
|
195 |
|
196 if( err == KErrNotFound ) |
|
197 { |
|
198 err = file.Create( iFsSession, iFilePath, shareMode ); |
|
199 } |
|
200 |
|
201 if( err == KErrNone ) |
|
202 { |
|
203 TInt pos = 0; |
|
204 err = file.Seek( ESeekEnd, pos ); |
|
205 |
|
206 if( err == KErrNone ) |
|
207 { |
|
208 err = file.Write( aSource ); |
|
209 } |
|
210 |
|
211 file.Flush( ); |
|
212 file.Close( ); |
|
213 } |
|
214 |
|
215 if( err != KErrNone ) |
|
216 { |
|
217 err = iFsSession.Delete(iFilePath); |
|
218 User::Panic(KTxtDiskError, err); |
|
219 } |
|
220 |
|
221 iLock.Signal( ); |
|
222 } |
|
223 } |
|
224 |
|
225 return ( err ); |
|
226 } |
|
227 |
|
228 /************************************************************************* |
|
229 * |
|
230 * GetData |
|
231 * |
|
232 *************************************************************************/ |
|
233 |
|
234 TInt CDataConsumerFile::GetData( HBufC8 & ) |
|
235 { |
|
236 return ( KErrNotSupported ); |
|
237 } |
|
238 |
|
239 /************************************************************************* |
|
240 * |
|
241 * SaveData |
|
242 * |
|
243 *************************************************************************/ |
|
244 |
|
245 TInt CDataConsumerFile::SaveData( const TDesC &filePath ) |
|
246 { |
|
247 TInt err = KErrNone; |
|
248 |
|
249 if( err == KErrNone ) |
|
250 { |
|
251 iLock.Wait( ); |
|
252 { |
|
253 |
|
254 CFileMan *theFile = CFileMan::NewL(iFsSession); |
|
255 CleanupStack::PushL(theFile); |
|
256 |
|
257 err = theFile->Copy( iFilePath, filePath ); |
|
258 |
|
259 if( err == KErrNone ) |
|
260 { |
|
261 err = theFile->Delete(iFilePath); |
|
262 } |
|
263 |
|
264 CleanupStack::PopAndDestroy(); |
|
265 |
|
266 iLock.Signal( ); |
|
267 } |
|
268 } |
|
269 |
|
270 return ( err ); |
|
271 } |
|
272 |
|
273 /************************************************************************* |
|
274 * |
|
275 * operator const TDesC8& |
|
276 * |
|
277 *************************************************************************/ |
|
278 |
|
279 CDataConsumerFile::operator const TDesC8&( void ) const |
|
280 { |
|
281 _LIT8( empty, "" ); |
|
282 return ( empty ); |
|
283 } |