|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <f32file.h> |
|
17 #include <f32file64.h> |
|
18 #include <e32std.h> |
|
19 #include <caf/attribute.h> |
|
20 #include <caf/bitset.h> |
|
21 #include <caf/content.h> |
|
22 #include <caf/data.h> |
|
23 using namespace ContentAccess; |
|
24 #include <f32file.h> |
|
25 |
|
26 #include "FileAccess.h" |
|
27 |
|
28 CF32File::~CF32File() |
|
29 { |
|
30 if (!iFileHandle) |
|
31 iFile.Close(); |
|
32 delete iFilePath; |
|
33 } |
|
34 |
|
35 CF32File* CF32File::NewL(RFs& aSession, TDesC& aFilePath, TUint aMode) |
|
36 { |
|
37 CF32File* self = new (ELeave) CF32File; |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(aSession, aFilePath, aMode); |
|
40 CleanupStack::Pop(self); |
|
41 return self; |
|
42 } |
|
43 |
|
44 |
|
45 void CF32File::ConstructL(RFs& aSession, TDesC& aPath, TUint aFileMode) |
|
46 { |
|
47 iSession = &aSession; |
|
48 iFilePath = aPath.AllocL(); |
|
49 TUint attributes = 0; |
|
50 TInt err = iSession->Att(*iFilePath, attributes); |
|
51 if (err == KErrNone) |
|
52 { |
|
53 if ( attributes & KEntryAttReadOnly ) |
|
54 User::LeaveIfError(iFile.Open(*iSession, *iFilePath, EFileShareReadersOnly )) ; |
|
55 else //if ( !( attributes & KEntryAttReadOnly ) ) |
|
56 User::LeaveIfError(iFile.Open(*iSession, *iFilePath, aFileMode)) ; |
|
57 } |
|
58 else if ((err == KErrNotFound) && (aFileMode & EFileWrite)) |
|
59 { |
|
60 User::LeaveIfError(iFile.Create(*iSession, *iFilePath, aFileMode )) ; |
|
61 } |
|
62 else |
|
63 { |
|
64 User::Leave(err); |
|
65 } |
|
66 } |
|
67 |
|
68 |
|
69 RFile& CF32File::FileL() |
|
70 { |
|
71 return iFile; |
|
72 } |
|
73 |
|
74 TInt CF32File::Data(CData*& /*aData*/) |
|
75 { |
|
76 return KErrNotSupported; |
|
77 } |
|
78 |
|
79 TInt CF32File::Seek(TSeek aSeekMode, TInt aPos) |
|
80 { |
|
81 return iFile.Seek(aSeekMode, aPos); |
|
82 } |
|
83 |
|
84 TInt CF32File::Read(TDes8& aDes,TInt aLength) |
|
85 { |
|
86 return iFile.Read(aDes, aLength); |
|
87 } |
|
88 |
|
89 void CF32File::Read(TDes8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
90 { |
|
91 iFile.Read(aDes, aLength, aStatus); |
|
92 } |
|
93 |
|
94 TInt CF32File::Write(const TDesC8& aDes,TInt aLength) |
|
95 { |
|
96 return iFile.Write(aDes, aLength); |
|
97 } |
|
98 |
|
99 void CF32File::Write(const TDesC8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
100 { |
|
101 iFile.Write(aDes, aLength, aStatus); |
|
102 } |
|
103 |
|
104 TInt CF32File::Size(TInt& aSize) |
|
105 { |
|
106 return iFile.Size(aSize); |
|
107 } |
|
108 |
|
109 TInt CF32File::SetSize(TInt aSize) |
|
110 { |
|
111 TInt err = iFile.SetSize(aSize); |
|
112 if(err == KErrNone) |
|
113 iFileSize = aSize; |
|
114 else |
|
115 iFileSize = -1; |
|
116 |
|
117 return err; |
|
118 } |
|
119 |
|
120 TInt CF32File::EvaluateIntent(TIntent /*aIntent*/) const |
|
121 { |
|
122 return KErrNone; |
|
123 } |
|
124 |
|
125 |
|
126 TInt CF32File::ExecuteIntent(TIntent /*aIntent*/) |
|
127 { |
|
128 return KErrNone; |
|
129 } |
|
130 |
|
131 TBool CF32File::IsProtected() const |
|
132 { |
|
133 return EFalse; |
|
134 } |
|
135 |
|
136 TInt CF32File::Read(TInt aPosition, TDes8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
137 { |
|
138 iFile.Read(aPosition, aDes, aLength, aStatus); |
|
139 return KErrNone; |
|
140 } |
|
141 |
|
142 TInt CF32File::SetAgentProperty(TAgentProperty /*aProperty*/, TInt /*aValue*/) |
|
143 { |
|
144 // not an error to set this if not supported, just wont do anything |
|
145 return KErrNone; |
|
146 } |
|
147 |
|
148 CContentFile::~CContentFile() |
|
149 { |
|
150 delete iData; |
|
151 |
|
152 iLegacyFile.Close(); |
|
153 iFile64.Close(); //For defect EASA-84ZC6J |
|
154 |
|
155 delete iFilePath; |
|
156 } |
|
157 |
|
158 |
|
159 CContentFile* CContentFile::NewL(RFs& aSession, const TDesC& aFilePath, const TDesC& aUniqueId, TUint aMode, TBool aEnableUI) |
|
160 { |
|
161 CContentFile* self = new (ELeave) CContentFile; |
|
162 CleanupStack::PushL(self); |
|
163 self->ConstructL(aSession, aFilePath, aUniqueId, aMode, aEnableUI); |
|
164 CleanupStack::Pop(self); |
|
165 return self; |
|
166 } |
|
167 |
|
168 void CContentFile::ConstructL(RFs& aSession, const TDesC& aPath, const TDesC& aUniqueId, TUint /*aMode*/, TBool aEnableUI) |
|
169 { |
|
170 iSession = &aSession; |
|
171 iFilePath = aPath.AllocL(); |
|
172 |
|
173 // Assume that we want the content to be shared and read-only. |
|
174 if (aUniqueId.Length() > 0) |
|
175 { |
|
176 iData = CData::NewL(TVirtualPathPtr(*iFilePath, aUniqueId), EContentShareReadWrite); |
|
177 } |
|
178 else |
|
179 { |
|
180 iData = CData::NewL(TVirtualPathPtr(*iFilePath), EContentShareReadWrite); |
|
181 } |
|
182 |
|
183 TInt err = iData->SetProperty(EAgentPropertyAgentUI, aEnableUI); |
|
184 if (err != KErrNone && err != KErrCANotSupported) |
|
185 { |
|
186 User::Leave(err); |
|
187 } |
|
188 User::LeaveIfError(iData->EvaluateIntent(EPeek)); |
|
189 } |
|
190 |
|
191 |
|
192 |
|
193 TInt CContentFile::EvaluateIntent(TIntent aIntent) const |
|
194 { |
|
195 ASSERT(iData); |
|
196 return iData->EvaluateIntent(aIntent); |
|
197 } |
|
198 |
|
199 |
|
200 TInt CContentFile::ExecuteIntent(TIntent aIntent) |
|
201 { |
|
202 ASSERT(iData); |
|
203 return iData->ExecuteIntent(aIntent); |
|
204 } |
|
205 |
|
206 TBool CContentFile::IsProtected() const |
|
207 { |
|
208 ASSERT(iData); |
|
209 TInt value = 0; |
|
210 TInt err =iData->GetAttribute(EIsProtected, value); |
|
211 return (err == KErrNone && value); |
|
212 } |
|
213 |
|
214 TInt CContentFile::SetAgentProperty(ContentAccess::TAgentProperty aProperty, TInt aValue) |
|
215 { |
|
216 ASSERT(iData); |
|
217 return iData->SetProperty(aProperty, aValue); |
|
218 } |
|
219 |
|
220 TInt CContentFile::Seek(TSeek aSeekMode, TInt aPos) |
|
221 { |
|
222 ASSERT(iData); |
|
223 return iData->Seek(aSeekMode, aPos); |
|
224 } |
|
225 |
|
226 TInt CContentFile::Read(TDes8& aDes,TInt aLength) |
|
227 { |
|
228 ASSERT(iData); |
|
229 return iData->Read(aDes,aLength); |
|
230 } |
|
231 |
|
232 void CContentFile::Read(TDes8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
233 { |
|
234 ASSERT(iData); |
|
235 iData->Read(aDes, aLength, aStatus); |
|
236 } |
|
237 |
|
238 TInt CContentFile::Write(const TDesC8& /*aDes*/,TInt /*aLength*/) |
|
239 { |
|
240 return KErrAccessDenied; |
|
241 } |
|
242 void CContentFile::Write(const TDesC8& /*aDes*/, TInt /*aLength*/, TRequestStatus& aStatus) |
|
243 { |
|
244 TRequestStatus* status = &aStatus; |
|
245 User::RequestComplete(status, KErrAccessDenied); |
|
246 } |
|
247 |
|
248 TInt CContentFile::SetSize(TInt /*aSize*/) |
|
249 { |
|
250 // Only a source is implemented, hence this cannot be allowed |
|
251 return KErrAccessDenied; |
|
252 } |
|
253 |
|
254 |
|
255 // Get the size of file |
|
256 // this method opens a new, read-only, RFile the first time this method is called |
|
257 |
|
258 TInt CContentFile::Size(TInt& aSize) |
|
259 { |
|
260 ASSERT(iData); |
|
261 TRAPD(err, iData->DataSizeL(aSize)); |
|
262 return err; |
|
263 } |
|
264 |
|
265 /** |
|
266 * return a RFile for the legacy RFile method |
|
267 * this method opens a new, read-only, RFile the first time this method is called |
|
268 * @internalTechnology |
|
269 * @return Reference to RFile handle to current file |
|
270 */ |
|
271 RFile& CContentFile::FileL() |
|
272 { |
|
273 if (!iLegacyFileOpen) |
|
274 {//For defect EASA-84ZC6J |
|
275 TInt error = iLegacyFile.Open(*iSession, *iFilePath, EFileRead | EFileStream | EFileShareReadersOrWriters); |
|
276 if ( error == KErrTooBig ) |
|
277 { |
|
278 User::LeaveIfError(iFile64.Open(*iSession, *iFilePath, EFileRead | EFileStream | EFileShareReadersOrWriters)); |
|
279 iLegacyFileOpen = ETrue; |
|
280 return iFile64; |
|
281 } |
|
282 |
|
283 else if (error == KErrNone) |
|
284 { |
|
285 iLegacyFileOpen = ETrue; |
|
286 return iLegacyFile; |
|
287 } |
|
288 |
|
289 else |
|
290 { |
|
291 User::Leave(error); |
|
292 } |
|
293 } |
|
294 if(iLegacyFile.SubSessionHandle()) |
|
295 { |
|
296 return iLegacyFile; |
|
297 } |
|
298 else |
|
299 { |
|
300 return iFile64; |
|
301 } |
|
302 } |
|
303 |
|
304 TInt CContentFile::Data(CData*& aData) |
|
305 { |
|
306 if (iData==NULL) |
|
307 { |
|
308 return KErrNotReady; |
|
309 } |
|
310 else |
|
311 { |
|
312 aData = iData; |
|
313 return KErrNone; |
|
314 } |
|
315 } |
|
316 |
|
317 CF32File* CF32File::NewL(RFile& aFile) |
|
318 { |
|
319 CF32File* self = new (ELeave) CF32File; |
|
320 CleanupStack::PushL(self); |
|
321 self->ConstructL(aFile); |
|
322 CleanupStack::Pop(self); |
|
323 return self; |
|
324 } |
|
325 |
|
326 void CF32File::ConstructL(RFile& aFile) |
|
327 { |
|
328 iFile = aFile; |
|
329 iFileHandle = ETrue; |
|
330 } |
|
331 |
|
332 CContentFile* CContentFile::NewL(RFile& aFile, const TDesC& aUniqueId, TBool aEnableUI) |
|
333 { |
|
334 CContentFile* self = new (ELeave) CContentFile; |
|
335 CleanupStack::PushL(self); |
|
336 self->ConstructL(aFile, aUniqueId, aEnableUI); |
|
337 CleanupStack::Pop(self); |
|
338 return self; |
|
339 } |
|
340 |
|
341 void CContentFile::ConstructL(RFile& aFile, const TDesC& aUniqueId, TBool aEnableUI) |
|
342 { |
|
343 iData = CData::NewL(aFile, aUniqueId); |
|
344 TInt err = iData->SetProperty(EAgentPropertyAgentUI, aEnableUI); |
|
345 if (err != KErrNone && err != KErrCANotSupported) |
|
346 { |
|
347 User::Leave(err); |
|
348 } |
|
349 User::LeaveIfError(iData->EvaluateIntent(EPeek)); |
|
350 } |
|
351 |
|
352 TInt CContentFile::Read(TInt aPosition, TDes8& aDes, TInt aLength, TRequestStatus& aStatus) |
|
353 { |
|
354 return iData->Read(aPosition, aDes, aLength, aStatus); |
|
355 } |