62
|
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 <e32wins.h>
|
|
17 |
|
|
18 |
#include "TMsvServerStoreManager.h"
|
|
19 |
#include "MSVUTILS.H"
|
|
20 |
#include "MSVSERV.H"
|
|
21 |
#include "MSVPANIC.H"
|
|
22 |
#include "MSVAPI.H"
|
|
23 |
#include "msvindexadapter.h"
|
|
24 |
#include "msvpreferreddrivelist.h"
|
|
25 |
|
|
26 |
TMsvServerStoreManager::TMsvServerStoreManager() : iMsvServer(NULL),iFs(NULL)
|
|
27 |
{
|
|
28 |
}
|
|
29 |
|
|
30 |
void TMsvServerStoreManager::SetMsvServerAndFileSession(CMsvServer& aMsvServer,RFs& aFs)
|
|
31 |
{
|
|
32 |
iMsvServer = &aMsvServer;
|
|
33 |
iFs = &aFs;
|
|
34 |
}
|
|
35 |
|
|
36 |
/** Gets the filepath for the storage of binary files associated with the context
|
|
37 |
|
|
38 |
If the directory specified in the context does not exist, it is created.
|
|
39 |
|
|
40 |
@param aEntryId index id of the entry whose filepath is requested
|
|
41 |
@param aDirectory On return, contains the binary file directory path
|
|
42 |
@return KErrNone - success;
|
|
43 |
@return The server was unable to create the directory.- failure */
|
|
44 |
TInt TMsvServerStoreManager::GetFilePath(TMsvId aEntryId, TFileName& aDirectory) const
|
|
45 |
{
|
|
46 |
__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
|
|
47 |
|
|
48 |
TMsvId owningService = KMsvNullIndexEntryId;
|
|
49 |
GetOwningServiceAndFilePath(aEntryId,aDirectory,owningService);
|
|
50 |
|
|
51 |
MsvUtils::ConstructEntryName(owningService, aEntryId, aDirectory, MsvUtils::EFolder);
|
|
52 |
TInt error = iMsvServer->FileSession().MkDirAll(aDirectory);
|
|
53 |
return (error==KErrAlreadyExists ? KErrNone : error);
|
|
54 |
}
|
|
55 |
|
|
56 |
/** Gets the filestore name associated with the context
|
|
57 |
|
|
58 |
@param aEntryId Index id of the entry whose store filename is requested
|
|
59 |
@param aFileName On return, contains the store file name for the context
|
|
60 |
*/
|
|
61 |
void TMsvServerStoreManager::GetStoreFileName(TMsvId aEntryId, TFileName& aFileName) const
|
|
62 |
{
|
|
63 |
__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
|
|
64 |
|
|
65 |
TMsvId owningService = KMsvNullIndexEntryId;
|
|
66 |
GetOwningServiceAndFilePath(aEntryId,aFileName,owningService);
|
|
67 |
|
|
68 |
MsvUtils::ConstructEntryName(owningService, aEntryId, aFileName, MsvUtils::EStore);
|
|
69 |
}
|
|
70 |
|
|
71 |
void TMsvServerStoreManager::GetOwningServiceAndFilePath(TMsvId aEntryId,TDes& aFilePath,TMsvId& aOwningService) const
|
|
72 |
{
|
|
73 |
__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
|
|
74 |
|
|
75 |
#if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)
|
|
76 |
//TUint driveId = MsvUtils::GetDriveId(aEntryId);
|
|
77 |
TUint driveId = GetDriveId(aEntryId);
|
|
78 |
TDriveNumber driveNum = EDriveC;
|
|
79 |
CMsvPreferredDriveList::GetDriveList()->GetDriveNumber(driveId, driveNum);
|
|
80 |
aFilePath.Zero();
|
|
81 |
aFilePath.Append(TDriveUnit(driveNum).Name());
|
|
82 |
TParse parse;
|
|
83 |
parse.Set(iMsvServer->Context().MessageFolder(), NULL, NULL);
|
|
84 |
aFilePath.Append(parse.Path());
|
|
85 |
#else
|
|
86 |
aFilePath = iMsvServer->Context().MessageFolder();
|
|
87 |
#endif
|
|
88 |
|
|
89 |
iMsvServer->IndexAdapter().OwningService(aEntryId, aOwningService);
|
|
90 |
}
|
|
91 |
|
|
92 |
/** Checks if the filename length is greater than KMaxFileName(256)
|
|
93 |
|
|
94 |
If the filename is greater than KMaxFileName then it truncates the filename
|
|
95 |
|
|
96 |
@param aFilePath file path where the file is being created.
|
|
97 |
@param aFileName name of the file whose length if being checked.
|
|
98 |
@return ETrue if the filename is changed.
|
|
99 |
*/
|
|
100 |
TBool TMsvServerStoreManager::CheckFileNameLengthAndTrimL(const TDesC& aFilePath,TDes& aFileName)
|
|
101 |
{
|
|
102 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
103 |
|
|
104 |
TParsePtrC filenamePPtr(aFileName);
|
|
105 |
TPtrC fileExtension(filenamePPtr.Ext());
|
|
106 |
|
|
107 |
#ifdef __WINS__
|
|
108 |
TFileName winsFileName;
|
|
109 |
TFileName mailStoreDrive;
|
|
110 |
TDriveUnit drive(MessageServer::CurrentDriveL(*iFs));
|
|
111 |
mailStoreDrive.Append(drive.Name());
|
|
112 |
mailStoreDrive.Append(KPathDelimiter);
|
|
113 |
MapEmulatedFileName(winsFileName, mailStoreDrive); // Ignoring return value
|
|
114 |
TInt KEpocBasePathLen = winsFileName.Length();
|
|
115 |
TInt maxFilenameLength = KMaxFileName-(aFilePath).Length()-fileExtension.Length()-KEpocBasePathLen;
|
|
116 |
#else
|
|
117 |
TInt maxFilenameLength = KMaxFileName-(aFilePath).Length()-fileExtension.Length();
|
|
118 |
#endif
|
|
119 |
TBool fileNameChanged = EFalse;
|
|
120 |
// Truncate filename if too long.
|
|
121 |
if (maxFilenameLength < aFileName.Length())
|
|
122 |
{
|
|
123 |
aFileName.SetLength(maxFilenameLength);
|
|
124 |
aFileName.Append(fileExtension);
|
|
125 |
|
|
126 |
fileNameChanged = ETrue;
|
|
127 |
}
|
|
128 |
return fileNameChanged;
|
|
129 |
}
|
|
130 |
|
|
131 |
TBool TMsvServerStoreManager::GenerateFileNameIfExistsL(TDes& aFileName)
|
|
132 |
{
|
|
133 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
134 |
|
|
135 |
TParse fileParser;
|
|
136 |
User::LeaveIfError(fileParser.Set(aFileName, NULL, NULL));
|
|
137 |
TInt fileNameGenerator = 1;
|
|
138 |
TBool fileNameChanged = EFalse;
|
|
139 |
CDir* dir;
|
|
140 |
TInt error = iFs->GetDir(fileParser.DriveAndPath(), KEntryAttNormal, ESortNone, dir);
|
|
141 |
if (error==KErrNone)
|
|
142 |
{
|
|
143 |
CleanupStack::PushL(dir);
|
|
144 |
TInt fileCount=dir->Count();
|
|
145 |
while(fileCount--)
|
|
146 |
{
|
|
147 |
TBool open;
|
|
148 |
TFileName filePath(aFileName);
|
|
149 |
TInt error = iFs->IsFileOpen(aFileName, open);
|
|
150 |
// file exists
|
|
151 |
if (error==KErrNone)
|
|
152 |
{
|
|
153 |
TFileName tempFileName(fileParser.DriveAndPath());
|
|
154 |
tempFileName.Append(fileParser.Name());
|
|
155 |
tempFileName.AppendNum(fileNameGenerator++);
|
|
156 |
tempFileName.Append(fileParser.Ext());
|
|
157 |
aFileName = tempFileName;
|
|
158 |
fileNameChanged = ETrue;
|
|
159 |
}
|
|
160 |
else if (error==KErrNotFound)
|
|
161 |
{
|
|
162 |
break;
|
|
163 |
}
|
|
164 |
else
|
|
165 |
{
|
|
166 |
User::Leave(error);
|
|
167 |
}
|
|
168 |
}
|
|
169 |
CleanupStack::PopAndDestroy(dir);
|
|
170 |
}
|
|
171 |
return fileNameChanged;
|
|
172 |
}
|
|
173 |
|
|
174 |
// from MMsvStoreManager
|
|
175 |
TBool TMsvServerStoreManager::CreateAttachmentForWriteL(TMsvId aEntryId, TDes& aFilename, RFile& aFile)
|
|
176 |
{
|
|
177 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
178 |
|
|
179 |
return CreateAttachmentL(aEntryId, aFilename, aFile, *iFs);
|
|
180 |
}
|
|
181 |
|
|
182 |
TBool TMsvServerStoreManager::CreateShareProtectedAttachmentForWriteL(TMsvId aEntryId, TDes& aFilename, RFile& aFile)
|
|
183 |
{
|
|
184 |
RFs fs;
|
|
185 |
User::LeaveIfError(fs.Connect());
|
|
186 |
User::LeaveIfError(fs.ShareProtected());
|
|
187 |
|
|
188 |
return CreateAttachmentL(aEntryId, aFilename, aFile, fs, ETrue);
|
|
189 |
}
|
|
190 |
|
|
191 |
TBool TMsvServerStoreManager::CreateAttachmentL(TMsvId aEntryId, TDes& aFilename, RFile& aFile, RFs& aFs,TBool aSharedAccess)
|
|
192 |
{
|
|
193 |
TFileName filePath;
|
|
194 |
GetFilePath(aEntryId,filePath);
|
|
195 |
TBool fileNameChanged = EFalse;
|
|
196 |
|
|
197 |
if(CheckFileNameLengthAndTrimL(filePath,(TDes&)aFilename))
|
|
198 |
{
|
|
199 |
fileNameChanged = ETrue;
|
|
200 |
}
|
|
201 |
|
|
202 |
//for handling TBuf desc overflow
|
|
203 |
RBuf newFilePath;
|
|
204 |
TInt error = KErrNone;
|
|
205 |
newFilePath.CreateL(KMaxPath);
|
|
206 |
newFilePath.CleanupClosePushL();
|
|
207 |
newFilePath.Copy(filePath);
|
|
208 |
if(aFilename.Length()+filePath.Length()>KMaxFileName)
|
|
209 |
{
|
|
210 |
newFilePath.ReAllocL(aFilename.Length()+filePath.Length());
|
|
211 |
}
|
|
212 |
newFilePath.Append(aFilename);
|
|
213 |
if (aSharedAccess)
|
|
214 |
{
|
|
215 |
//Shared access for reading and writing
|
|
216 |
error = aFile.Create(aFs,newFilePath,EFileShareAny|EFileWrite);
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
error = aFile.Create(aFs,newFilePath,EFileWrite);
|
|
221 |
}
|
|
222 |
|
|
223 |
if(error == KErrAlreadyExists)
|
|
224 |
{
|
|
225 |
if(GenerateFileNameIfExistsL(newFilePath))
|
|
226 |
{
|
|
227 |
fileNameChanged = ETrue;
|
|
228 |
}
|
|
229 |
if (aSharedAccess)
|
|
230 |
{
|
|
231 |
//Shared access for reading and writing
|
|
232 |
User::LeaveIfError(aFile.Create(aFs,newFilePath, EFileShareAny|EFileWrite));
|
|
233 |
}
|
|
234 |
else
|
|
235 |
{
|
|
236 |
User::LeaveIfError(aFile.Create(aFs,newFilePath,EFileWrite));
|
|
237 |
}
|
|
238 |
|
|
239 |
aFilename.Copy(newFilePath);
|
|
240 |
|
|
241 |
}
|
|
242 |
else
|
|
243 |
{
|
|
244 |
User::LeaveIfError(error);
|
|
245 |
// return if error = KErrNone
|
|
246 |
aFilename.Copy(newFilePath);
|
|
247 |
}
|
|
248 |
CleanupStack::PopAndDestroy(&newFilePath);//newFilePath destroy
|
|
249 |
return fileNameChanged;
|
|
250 |
}
|
|
251 |
|
|
252 |
void TMsvServerStoreManager::ReplaceAttachmentForWriteL(TMsvId aEntryId, TDes& aFilename, RFile& aFile)
|
|
253 |
{
|
|
254 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
255 |
|
|
256 |
TFileName filePath;
|
|
257 |
GetFilePath(aEntryId, filePath);
|
|
258 |
TParsePtrC fileName(aFilename);
|
|
259 |
filePath.Append(fileName.NameAndExt());
|
|
260 |
|
|
261 |
User::LeaveIfError(aFile.Replace(*iFs, filePath, EFileWrite));
|
|
262 |
|
|
263 |
aFilename = filePath;
|
|
264 |
}
|
|
265 |
|
|
266 |
void TMsvServerStoreManager::OpenAttachmentL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
|
|
267 |
{
|
|
268 |
__ASSERT_ALWAYS(iFs != NULL,PanicServer(EMsvFileSessionNotValid));
|
|
269 |
|
|
270 |
TFileName filePath;
|
|
271 |
GetFilePath(aEntryId,filePath);
|
|
272 |
TParsePtrC fileName(aFilePath);
|
|
273 |
filePath.Append(fileName.NameAndExt());
|
|
274 |
|
|
275 |
User::LeaveIfError(aFile.Open(*iFs,filePath,EFileRead|EFileShareReadersOnly));
|
|
276 |
}
|
|
277 |
|
|
278 |
void TMsvServerStoreManager::OpenAttachmentForWriteL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
|
|
279 |
{
|
|
280 |
__ASSERT_ALWAYS(iFs != NULL,PanicServer(EMsvFileSessionNotValid));
|
|
281 |
|
|
282 |
TFileName filePath;
|
|
283 |
GetFilePath(aEntryId,filePath);
|
|
284 |
TParsePtrC fileName(aFilePath);
|
|
285 |
filePath.Append(fileName.NameAndExt());
|
|
286 |
|
|
287 |
User::LeaveIfError(aFile.Open(*iFs,filePath,EFileWrite));
|
|
288 |
}
|
|
289 |
|
|
290 |
|
|
291 |
TInt TMsvServerStoreManager::DeleteAttachment(TMsvId aEntryId, const TDesC& aFilePath)
|
|
292 |
{
|
|
293 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
294 |
|
|
295 |
TFileName filePath;
|
|
296 |
GetFilePath(aEntryId,filePath);
|
|
297 |
TParsePtrC fileName(aFilePath);
|
|
298 |
filePath.Append(fileName.NameAndExt());
|
|
299 |
|
|
300 |
TInt error = iFs->Delete(filePath);
|
|
301 |
|
|
302 |
if(error == KErrNotFound || error == KErrPathNotFound)
|
|
303 |
return KErrNotFound;
|
|
304 |
|
|
305 |
return error;
|
|
306 |
}
|
|
307 |
|
|
308 |
TInt TMsvServerStoreManager::RenameAttachment(TMsvId aEntryId, const TDesC& aOldFilePath, const TDesC& aNewName)
|
|
309 |
{
|
|
310 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
311 |
|
|
312 |
TFileName filePath;
|
|
313 |
TInt err = GetFilePath(aEntryId, filePath);
|
|
314 |
|
|
315 |
TParsePtrC fileToRename(aOldFilePath);
|
|
316 |
if(err==KErrNone)
|
|
317 |
{
|
|
318 |
filePath.Append(fileToRename.NameAndExt());
|
|
319 |
TParse newPath;
|
|
320 |
err = newPath.Set(aNewName, &fileToRename.FullName(), NULL);
|
|
321 |
if( err==KErrNone )
|
|
322 |
{
|
|
323 |
err = iFs->Rename(filePath, newPath.FullName());
|
|
324 |
}
|
|
325 |
}
|
|
326 |
|
|
327 |
return err;
|
|
328 |
}
|
|
329 |
|
|
330 |
TBool TMsvServerStoreManager::FileExistsL(const TDesC& aFilePath)
|
|
331 |
{
|
|
332 |
// Use the Att method to check if file exists as it does change the
|
|
333 |
// file and is a light-weight call
|
|
334 |
TUint attValue = 0;
|
|
335 |
TInt err = iFs->Att(aFilePath, attValue);
|
|
336 |
|
|
337 |
TBool fileExists = EFalse;
|
|
338 |
if (err == KErrNotFound || err == KErrPathNotFound)
|
|
339 |
{
|
|
340 |
fileExists = EFalse;
|
|
341 |
}
|
|
342 |
else if (err == KErrNone)
|
|
343 |
{
|
|
344 |
fileExists = ETrue;
|
|
345 |
}
|
|
346 |
else
|
|
347 |
{
|
|
348 |
User::Leave(err);
|
|
349 |
}
|
|
350 |
|
|
351 |
return fileExists;
|
|
352 |
}
|
|
353 |
|
|
354 |
void TMsvServerStoreManager::AttachmentFilePathL(TMsvId aEntryId, TDes& aFilePath)
|
|
355 |
{
|
|
356 |
TFileName filePath;
|
|
357 |
User::LeaveIfError(GetFilePath(aEntryId, filePath));
|
|
358 |
|
|
359 |
aFilePath = filePath;
|
|
360 |
}
|
|
361 |
|
|
362 |
TInt TMsvServerStoreManager::OpenFileStoreForRead(TMsvId aEntryId, RFile& aFile)
|
|
363 |
{
|
|
364 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
365 |
|
|
366 |
TFileName filePathAndName;
|
|
367 |
GetStoreFileName(aEntryId,filePathAndName);
|
|
368 |
|
|
369 |
TInt error = aFile.Open(*iFs,filePathAndName,EFileRead|EFileShareAny);
|
|
370 |
if(error == KErrNotFound || error == KErrPathNotFound)
|
|
371 |
return KErrNotFound;
|
|
372 |
|
|
373 |
return error;
|
|
374 |
}
|
|
375 |
|
|
376 |
void TMsvServerStoreManager::OpenTempStoreFileL(TMsvId aEntryId, RFile& aFile)
|
|
377 |
{
|
|
378 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
379 |
|
|
380 |
TFileName tempFilePathAndName;
|
|
381 |
GetStoreFileName(aEntryId,tempFilePathAndName);
|
|
382 |
|
|
383 |
tempFilePathAndName.Append(KMsvUtilsNewExtension);
|
|
384 |
|
|
385 |
TInt error= aFile.Replace(*iFs,tempFilePathAndName,EFileShareExclusive|EFileWrite);
|
|
386 |
if (error==KErrPathNotFound)
|
|
387 |
{
|
|
388 |
//only create directory if not found
|
|
389 |
error=iFs->MkDirAll(tempFilePathAndName);
|
|
390 |
if (error==KErrNone)
|
|
391 |
error=aFile.Replace(*iFs,tempFilePathAndName,EFileShareExclusive|EFileWrite);
|
|
392 |
}
|
|
393 |
User::LeaveIfError(error);
|
|
394 |
|
|
395 |
}
|
|
396 |
|
|
397 |
void TMsvServerStoreManager::ReplaceFileStoreL(TMsvId aEntryId)
|
|
398 |
{
|
|
399 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
400 |
|
|
401 |
TFileName filePathAndName;
|
|
402 |
|
|
403 |
GetStoreFileName(aEntryId,filePathAndName);
|
|
404 |
TFileName tempFilePathAndName(filePathAndName);
|
|
405 |
|
|
406 |
tempFilePathAndName.Append(KMsvUtilsNewExtension);
|
|
407 |
|
|
408 |
TInt error = iFs->Replace(tempFilePathAndName,filePathAndName);
|
|
409 |
|
|
410 |
|
|
411 |
if(error !=KErrNone)
|
|
412 |
{
|
|
413 |
iFs->Delete(tempFilePathAndName);
|
|
414 |
User::Leave(error);
|
|
415 |
}
|
|
416 |
}
|
|
417 |
|
|
418 |
void TMsvServerStoreManager::DeleteFileStoreL(TMsvId aEntryId)
|
|
419 |
{
|
|
420 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
421 |
|
|
422 |
TFileName filePathAndName;
|
|
423 |
GetStoreFileName(aEntryId,filePathAndName);
|
|
424 |
|
|
425 |
TInt error = iFs->Delete(filePathAndName);
|
|
426 |
if(error != KErrNone && error != KErrNotFound && error != KErrPathNotFound)
|
|
427 |
User::Leave(error);
|
|
428 |
|
|
429 |
// Delete the temporary store file if it exists
|
|
430 |
filePathAndName.Append(KMsvUtilsNewExtension);
|
|
431 |
error = iFs->Delete(filePathAndName);
|
|
432 |
if(error != KErrNone && error != KErrNotFound && error != KErrPathNotFound)
|
|
433 |
User::Leave(error);
|
|
434 |
}
|
|
435 |
|
|
436 |
TBool TMsvServerStoreManager::FileStoreExistsL(TMsvId aEntryId) const
|
|
437 |
{
|
|
438 |
__ASSERT_ALWAYS(iMsvServer != NULL, PanicServer(EMsvServerNotValid));
|
|
439 |
|
|
440 |
TMsvId owningService = KMsvNullIndexEntryId;
|
|
441 |
TFileName filePathAndName;
|
|
442 |
GetOwningServiceAndFilePath(aEntryId,filePathAndName,owningService);
|
|
443 |
|
|
444 |
return User::LeaveIfError(MsvUtils::HasStore(iMsvServer->FileSession(),filePathAndName,owningService, aEntryId));
|
|
445 |
}
|
|
446 |
|
|
447 |
|
|
448 |
/**
|
|
449 |
Gets the path for the file in message store for which the message Id is passed.
|
|
450 |
@param aBodyTextId The Id of the body text for which the path is required.
|
|
451 |
@param aFilepath The output parameter which contains filepath.
|
|
452 |
@return none.
|
|
453 |
*/
|
|
454 |
void TMsvServerStoreManager::BodyTextFilePathL(TMsvId aBodyTextId, TDes& aFilePath)
|
|
455 |
{
|
|
456 |
TFileName filePath;
|
|
457 |
User::LeaveIfError(GetFilePath(aBodyTextId, filePath));
|
|
458 |
aFilePath = filePath;
|
|
459 |
}
|
|
460 |
|
|
461 |
/**
|
|
462 |
Opens the RFile for which the aFilepath is passed in read mode.
|
|
463 |
@param RFile Reference to RFile that needs to be opened.
|
|
464 |
@param aBodyTextId The Id of the bodytext.
|
|
465 |
@param aFilepath The path of the file to be opened.
|
|
466 |
@return none.
|
|
467 |
*/
|
|
468 |
void TMsvServerStoreManager::OpenBodyTextFileForReadL(RFile& aFile, TMsvId /*aBodyTextId*/, const TDesC& aFilePath)
|
|
469 |
{
|
|
470 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
471 |
|
|
472 |
User::LeaveIfError(aFile.Open(*iFs, aFilePath, EFileRead));
|
|
473 |
}
|
|
474 |
|
|
475 |
/**
|
|
476 |
Creates the RFile in the aFilepath is passed.
|
|
477 |
@param RFile Reference to RFile that will be created.
|
|
478 |
@param aBodyTextId The Id of the bodytext.
|
|
479 |
@return none.
|
|
480 |
*/
|
|
481 |
void TMsvServerStoreManager::CreatePlainTextFileL(RFile& aFile, TMsvId aBodyTextId)
|
|
482 |
{
|
|
483 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
484 |
|
|
485 |
TFileName filePathAndName;
|
|
486 |
GetFilePath(aBodyTextId, filePathAndName);
|
|
487 |
|
|
488 |
TBuf<KFileNameFixedWidth> fileName;
|
|
489 |
|
|
490 |
fileName.NumFixedWidth(aBodyTextId, EHex, KFileNameFixedWidth);
|
|
491 |
filePathAndName.Append(fileName);
|
|
492 |
|
|
493 |
TFileName tempFilePathAndName((filePathAndName));
|
|
494 |
tempFilePathAndName.Append(KMsvUtilsNewExtension);
|
|
495 |
User::LeaveIfError(aFile.Replace(*iFs, tempFilePathAndName, EFileShareExclusive|EFileWrite));
|
|
496 |
}
|
|
497 |
|
|
498 |
/**
|
|
499 |
Deletes the RFile in the aFilepath passed.
|
|
500 |
@param aBodyTextId The Id of the bodytext.
|
|
501 |
@return none.
|
|
502 |
*/
|
|
503 |
void TMsvServerStoreManager::DeletePlainTextFileL(TMsvId aBodyTextId)
|
|
504 |
{
|
|
505 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
506 |
TFileName filePathAndName;
|
|
507 |
GetFilePath(aBodyTextId, filePathAndName);
|
|
508 |
|
|
509 |
TBuf<KFileNameFixedWidth> fileName;
|
|
510 |
|
|
511 |
fileName.NumFixedWidth(aBodyTextId, EHex, KFileNameFixedWidth);
|
|
512 |
filePathAndName.Append(fileName);
|
|
513 |
|
|
514 |
TFileName tempFilePathAndName((filePathAndName));
|
|
515 |
tempFilePathAndName.Append(KMsvUtilsNewExtension);
|
|
516 |
// Remove the temporary file if it is there.
|
|
517 |
TInt err = iFs->Delete(tempFilePathAndName);
|
|
518 |
|
|
519 |
if (err != KErrNone && err != KErrNotFound)
|
|
520 |
{
|
|
521 |
User::Leave(err);
|
|
522 |
}
|
|
523 |
// There is no temporary file, delete the body text file.
|
|
524 |
if (err == KErrNotFound)
|
|
525 |
{
|
|
526 |
TInt error = iFs->Delete(filePathAndName);
|
|
527 |
if (error != KErrNone && error != KErrNotFound && error != KErrPathNotFound)
|
|
528 |
{
|
|
529 |
User::Leave(error);
|
|
530 |
}
|
|
531 |
}
|
|
532 |
}
|
|
533 |
|
|
534 |
/**
|
|
535 |
Replaces a temporary RFile with a new RFile.
|
|
536 |
@param aBodyTextId The Id of the bodytext.
|
|
537 |
@return none.
|
|
538 |
*/
|
|
539 |
void TMsvServerStoreManager::ReplacePlainTextFileL(TMsvId aBodyTextId)
|
|
540 |
{
|
|
541 |
__ASSERT_ALWAYS(iFs != NULL, PanicServer(EMsvFileSessionNotValid));
|
|
542 |
TFileName filePathAndName;
|
|
543 |
GetFilePath(aBodyTextId, filePathAndName);
|
|
544 |
|
|
545 |
TBuf<KFileNameFixedWidth> fileName;
|
|
546 |
|
|
547 |
fileName.NumFixedWidth(aBodyTextId, EHex, KFileNameFixedWidth);
|
|
548 |
filePathAndName.Append(fileName);
|
|
549 |
|
|
550 |
TFileName tempFilePathAndName((filePathAndName));
|
|
551 |
tempFilePathAndName.Append(KMsvUtilsNewExtension);
|
|
552 |
TInt err = iFs->Replace(tempFilePathAndName,filePathAndName);
|
|
553 |
if(err != KErrNone)
|
|
554 |
{
|
|
555 |
iFs->Delete(tempFilePathAndName);
|
|
556 |
User::Leave(err);
|
|
557 |
}
|
|
558 |
}
|
|
559 |
|
|
560 |
|
|
561 |
|
|
562 |
|
|
563 |
|
|
564 |
#if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
|
|
565 |
/**
|
|
566 |
* LoadHeaderL()
|
|
567 |
*
|
|
568 |
* @param aMtmId : a MTM id.
|
|
569 |
* @param aEntryId: Metadata entry Id of the message body.
|
|
570 |
* @param iFieldPairList: Array of header fields.
|
|
571 |
*/
|
|
572 |
|
|
573 |
void TMsvServerStoreManager::LoadHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, RPointerArray<CHeaderFields>& aFieldPairList)
|
|
574 |
{
|
|
575 |
iMsvServer->MessageDBAdapter().LoadHeaderEntryL(aMtmId,aEntryId,aFieldPairList);
|
|
576 |
}
|
|
577 |
|
|
578 |
/**
|
|
579 |
* DeleteHeaderL()
|
|
580 |
*
|
|
581 |
*
|
|
582 |
* @param aMtmId : a MTM id.
|
|
583 |
* @param aEntryId: Metadata entry Id of the message body.
|
|
584 |
*/
|
|
585 |
|
|
586 |
void TMsvServerStoreManager::DeleteHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId)
|
|
587 |
{
|
|
588 |
iMsvServer->MessageDBAdapter().DeleteHeaderEntryL(aMtmId,aEntryId);
|
|
589 |
}
|
|
590 |
|
|
591 |
|
|
592 |
/**
|
|
593 |
* UpdateHeaderL()
|
|
594 |
*
|
|
595 |
*
|
|
596 |
* @param aMtmId : a MTM id.
|
|
597 |
* @param aEntryId: Metadata entry Id of the message body.
|
|
598 |
* @param iFieldPairList: Array of header fields.
|
|
599 |
*/
|
|
600 |
|
|
601 |
void TMsvServerStoreManager::UpdateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
|
|
602 |
{
|
|
603 |
iMsvServer->MessageDBAdapter().UpdateHeaderEntryL(aMtmId,aEntryId,aFieldPairList);
|
|
604 |
}
|
|
605 |
|
|
606 |
/**
|
|
607 |
* CreateHeaderEntryL()
|
|
608 |
*
|
|
609 |
*
|
|
610 |
* @param aMtmId : a MTM id.
|
|
611 |
* @param aEntryId: Metadata entry Id of the message body.
|
|
612 |
* @param iFieldPairList: Array of header fields.
|
|
613 |
*/
|
|
614 |
|
|
615 |
void TMsvServerStoreManager::CreateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
|
|
616 |
{
|
|
617 |
iMsvServer->MessageDBAdapter().CreateHeaderEntryL(aMtmId,aEntryId,aFieldPairList);
|
|
618 |
}
|
|
619 |
|
|
620 |
|
|
621 |
|
|
622 |
TBool TMsvServerStoreManager::DoesAnyStoreExists(TMsvId aId, TUid aMtmId)
|
|
623 |
{
|
|
624 |
TBool isStoreExists = EFalse;
|
|
625 |
TRAPD(err, isStoreExists = iMsvServer->MessageDBAdapter().DoesAnyStoreExistsL(aId, aMtmId));
|
|
626 |
if(err)
|
|
627 |
{
|
|
628 |
return EFalse;
|
|
629 |
}
|
|
630 |
else
|
|
631 |
{
|
|
632 |
return isStoreExists;
|
|
633 |
}
|
|
634 |
|
|
635 |
}
|
|
636 |
|
|
637 |
TBool TMsvServerStoreManager::DoesHeaderTableExist(const TUid& aMtmId)
|
|
638 |
{
|
|
639 |
TBool doesTableExists = EFalse;
|
|
640 |
TRAPD(err, doesTableExists = iMsvServer->MessageDBAdapter().IsHeaderTableExistsL(aMtmId));
|
|
641 |
if(err)
|
|
642 |
{
|
|
643 |
return EFalse;
|
|
644 |
}
|
|
645 |
else
|
|
646 |
{
|
|
647 |
return doesTableExists;
|
|
648 |
}
|
|
649 |
|
|
650 |
}
|
|
651 |
|
|
652 |
|
|
653 |
|
|
654 |
|
|
655 |
|
|
656 |
|
|
657 |
#endif // #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
|