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: File Transfer Controller implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <stringresourcereader.h> |
|
21 #include <sconftp.rsg> |
|
22 #include <pathinfo.h> |
|
23 #include <connect/sbdefs.h> // to get backup/restore mode |
|
24 #include <driveinfo.h> |
|
25 #include <bautils.h> |
|
26 #include <sysutil.h> |
|
27 #include <CDirectoryLocalizer.h> |
|
28 |
|
29 #include "sconfshandler.h" |
|
30 #include "sconconsts.h" |
|
31 #include "irmcconsts.h" |
|
32 #include "cntparserclient.h" |
|
33 #include "cntparserinfolog.h" |
|
34 #include "debug.h" |
|
35 |
|
36 _LIT(KPhoneBookIrMCL2Request,"telecom/pb.vcf"); |
|
37 _LIT(KInfoLogIrMCL2Request,"telecom/pb/info.log"); |
|
38 _LIT(KInfoLogIrMCL2File,"IrMC\\info.log"); |
|
39 _LIT(KInfoLogPathAndFileName,"c:\\IrMC\\info.log"); |
|
40 _LIT(KPbPathAndFileName,"c:\\IrMC\\pb.vcf"); |
|
41 |
|
42 // ============================= MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CSConFsHandler::NewL() |
|
46 // Two-phase constructor |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CSConFsHandler* CSConFsHandler::NewL( RFs& aFs ) |
|
50 { |
|
51 TRACE_FUNC_ENTRY; |
|
52 CSConFsHandler* self = new (ELeave) CSConFsHandler( aFs ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL(); |
|
55 CleanupStack::Pop( self ); |
|
56 TRACE_FUNC_EXIT; |
|
57 return self; |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSConFsHandler::~CSConFsHandler() |
|
62 // Destructor |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CSConFsHandler::~CSConFsHandler() |
|
66 { |
|
67 TRACE_FUNC_ENTRY; |
|
68 delete iLocalizer; |
|
69 TRACE_FUNC_EXIT; |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CSConFsHandler::ParseFolderListL( CBufFlat* aBuffer, const TPtrC aPathName |
|
74 // , const TInt aMemNumber ) |
|
75 // Parses folder and file listing from specified directory |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 TInt CSConFsHandler::ParseFolderListL( CBufFlat* aBuffer, const TPtrC aPathName, |
|
79 const TInt aMemNumber ) |
|
80 { |
|
81 TRACE_FUNC_ENTRY; |
|
82 LOGGER_WRITE_1( "CSConFsHandler::ParseFolderListL aPathName = %S", &aPathName ); |
|
83 if( aPathName.Length() == 0 ) |
|
84 { |
|
85 LOGGER_WRITE( "CSConFsHandler::ParseFolderListL( CBufFlat* aBuffer, const TPtrC aPathName ) : No path" ); |
|
86 return KErrArgument; |
|
87 } |
|
88 |
|
89 if( aPathName.Length() > KDriveLength && !BaflUtils::FolderExists( iFs, aPathName ) ) |
|
90 { |
|
91 LOGGER_WRITE( "CSConFsHandler::ParseFolderListL( CBufFlat* aBuffer, const TPtrC aPathName ) : Current folder doesn't exist any more" ); |
|
92 return KErrNotFound; |
|
93 } |
|
94 |
|
95 TInt driveNumber; |
|
96 TInt err = iFs.CharToDrive(aPathName[0], driveNumber); |
|
97 if( err ) |
|
98 { |
|
99 LOGGER_WRITE_1( "CSConFsHandler::ParseFolderListL : CharToDrive err: %d", err ); |
|
100 return KErrNotFound; |
|
101 } |
|
102 TUint driveStatus; |
|
103 err = DriveInfo::GetDriveStatus( iFs, driveNumber, driveStatus); |
|
104 if( err ) |
|
105 { |
|
106 LOGGER_WRITE_1( "CSConFsHandler::ParseFolderListL : DriveInfo::GetDriveStatus err: %d", err ); |
|
107 return KErrNotFound; |
|
108 } |
|
109 |
|
110 // check mem type (DEV, DEV2, MMC, MMC2..) |
|
111 TBuf8<KSConMemTypeMaxLength> memType; |
|
112 if( driveStatus & DriveInfo::EDriveInternal ) |
|
113 { |
|
114 memType.Copy( KSConMemoryTypeDev ); |
|
115 if( aMemNumber > 1 ) |
|
116 { |
|
117 memType.AppendNum(aMemNumber); |
|
118 } |
|
119 } |
|
120 else if( driveStatus & DriveInfo::EDriveRemovable ) |
|
121 { |
|
122 memType.Copy( KSConMemoryTypeMmc ); |
|
123 if( aMemNumber > 1 ) |
|
124 { |
|
125 memType.AppendNum(aMemNumber); |
|
126 } |
|
127 } |
|
128 |
|
129 CDir *entryList = 0; |
|
130 CDir *dirList = 0; |
|
131 |
|
132 // show only normal files and folders |
|
133 TUint entryAttMask = KEntryAttNormal; |
|
134 |
|
135 |
|
136 // get folders and files |
|
137 err = iFs.GetDir( aPathName, entryAttMask, ESortByName, |
|
138 entryList, dirList ); |
|
139 |
|
140 if ( err ) |
|
141 { |
|
142 LOGGER_WRITE_1( "ParseFolderListL GetDir returned: %d", err ); |
|
143 return err; |
|
144 } |
|
145 |
|
146 CleanupStack::PushL( entryList ); |
|
147 CleanupStack::PushL( dirList ); |
|
148 |
|
149 TInt offset = 0; |
|
150 |
|
151 LOGGER_WRITE( "CSConFsHandler::ParseFolderList XML creation" ); |
|
152 //Create folder XML |
|
153 aBuffer->ResizeL( KSConXmlDocBegin().Length() ); |
|
154 aBuffer->Write( offset, KSConXmlDocBegin ); |
|
155 offset += KSConXmlDocBegin().Length(); |
|
156 |
|
157 aBuffer->ExpandL( offset, KSConXmlParentFolder().Length() ); |
|
158 aBuffer->Write( offset, KSConXmlParentFolder ); |
|
159 offset += KSConXmlParentFolder().Length(); |
|
160 |
|
161 HBufC* fullNameBuf = HBufC::NewLC( KMaxPath ); |
|
162 TPtr fullName = fullNameBuf->Des(); |
|
163 |
|
164 // Print folders to folder listing object |
|
165 for( TInt i = 0; i < dirList->Count(); i++ ) |
|
166 { |
|
167 const TEntry entry = ( *dirList )[i]; |
|
168 |
|
169 fullName.Copy( aPathName ); |
|
170 fullName.Append( entry.iName ); |
|
171 fullName.Append( KPathDelimiter ); |
|
172 |
|
173 // show path if not exluded |
|
174 TBool proceed = !IsExludedPath( fullName ); |
|
175 if ( proceed ) |
|
176 { |
|
177 PrintFolderL( aBuffer, offset, fullName, memType, entry ); |
|
178 } |
|
179 } |
|
180 CleanupStack::PopAndDestroy( fullNameBuf ); |
|
181 CleanupStack::PopAndDestroy( dirList ); |
|
182 |
|
183 LOGGER_WRITE("Print files"); |
|
184 // Print files to folder listing object |
|
185 for( TInt j = 0; j < entryList->Count(); j++ ) |
|
186 { |
|
187 const TEntry entry = ( *entryList )[j]; |
|
188 PrintFileL( aBuffer, offset, entry ); |
|
189 } |
|
190 LOGGER_WRITE("files printed"); |
|
191 //Write the end of XML |
|
192 aBuffer->ExpandL( offset, KSConXmlFolderListEnd().Length() ); |
|
193 aBuffer->Write( offset, KSConXmlFolderListEnd ); |
|
194 aBuffer->Compress(); |
|
195 |
|
196 CleanupStack::PopAndDestroy( entryList ); |
|
197 |
|
198 LOGGER_WRITE_1( "CSConFsHandler::ParseFolderListL() : returned %d", err ); |
|
199 return err; |
|
200 } |
|
201 |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CSConFsHandler::PrintFolderL |
|
205 // Prints folder entry to folder listing object |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CSConFsHandler::PrintFolderL( CBufFlat* aBuffer, TInt& aOffset, const TDesC& aFullPath, |
|
209 const TDesC8& aMemType, const TEntry& aFolderEntry ) |
|
210 { |
|
211 TRACE_FUNC_ENTRY; |
|
212 // initialize Localizer |
|
213 iLocalizer->SetFullPath( aFullPath ); |
|
214 |
|
215 TBool dataPath( EFalse ); |
|
216 if ( aFullPath.CompareF( PathInfo::PhoneMemoryRootPath() ) == 0 ) // datapath |
|
217 { |
|
218 // printable folder is C:\Data (Localized) |
|
219 dataPath = ETrue; |
|
220 } |
|
221 |
|
222 // print foldername |
|
223 aBuffer->ExpandL( aOffset, KSConXmlFolderNameBegin().Length() ); |
|
224 aBuffer->Write( aOffset, KSConXmlFolderNameBegin ); |
|
225 aOffset += KSConXmlFolderNameBegin().Length(); |
|
226 |
|
227 HBufC8* folderBuf = HBufC8::NewLC( KMaxFileName ); |
|
228 TPtr8 folderName = folderBuf->Des(); |
|
229 User::LeaveIfError( |
|
230 CnvUtfConverter::ConvertFromUnicodeToUtf8( folderName, aFolderEntry.iName ) ); |
|
231 |
|
232 //Replace special characters |
|
233 ReplaceSpecialChars( folderName ); |
|
234 |
|
235 aBuffer->ExpandL( aOffset, folderName.Length() ); |
|
236 aBuffer->Write( aOffset, folderName ); |
|
237 aOffset += folderName.Length(); |
|
238 |
|
239 CleanupStack::PopAndDestroy( folderBuf ); |
|
240 |
|
241 // print modified time |
|
242 TBuf<KSConDateMaxLength> modifiedTime; |
|
243 TTime time = aFolderEntry.iModified; |
|
244 time.FormatL( modifiedTime, KSConXmlDate ); |
|
245 |
|
246 TBuf8<KSConDateMaxLength> modifiedTime8; |
|
247 User::LeaveIfError( |
|
248 CnvUtfConverter::ConvertFromUnicodeToUtf8( modifiedTime8, modifiedTime ) ); |
|
249 |
|
250 aBuffer->ExpandL( aOffset, KSConXmlModified().Length() ); |
|
251 aBuffer->Write( aOffset, KSConXmlModified ); |
|
252 aOffset += KSConXmlModified().Length(); |
|
253 |
|
254 aBuffer->ExpandL( aOffset, modifiedTime8.Length() ); |
|
255 aBuffer->Write( aOffset, modifiedTime8 ); |
|
256 aOffset += modifiedTime8.Length(); |
|
257 |
|
258 // print attributes |
|
259 aBuffer->ExpandL( aOffset, KSConXmlUserAttributes().Length() ); |
|
260 aBuffer->Write( aOffset, KSConXmlUserAttributes ); |
|
261 aOffset += KSConXmlUserAttributes().Length(); |
|
262 |
|
263 // Add user-perm info |
|
264 if( aFolderEntry.IsReadOnly() ) |
|
265 { |
|
266 aBuffer->ExpandL( aOffset, |
|
267 KSConXmlUserEntryReadOnly().Length() ); |
|
268 aBuffer->Write( aOffset, KSConXmlUserEntryReadOnly ); |
|
269 aOffset += KSConXmlUserEntryReadOnly().Length(); |
|
270 } |
|
271 else if( iLocalizer->IsLocalized() || dataPath ) // delete disabled |
|
272 { |
|
273 aBuffer->ExpandL( aOffset, |
|
274 KSConXmlUserEntryDrive().Length() ); |
|
275 aBuffer->Write( aOffset, KSConXmlUserEntryDrive ); |
|
276 aOffset += KSConXmlUserEntryDrive().Length(); |
|
277 } |
|
278 else |
|
279 { |
|
280 aBuffer->ExpandL( aOffset, |
|
281 KSConXmlUserEntryArchive().Length() ); |
|
282 aBuffer->Write( aOffset, KSConXmlUserEntryArchive ); |
|
283 aOffset += KSConXmlUserEntryArchive().Length(); |
|
284 } |
|
285 |
|
286 |
|
287 // print memory type |
|
288 aBuffer->ExpandL( aOffset, KSConXmlMemoryType().Length() ); |
|
289 aBuffer->Write( aOffset, KSConXmlMemoryType ); |
|
290 aOffset += KSConXmlMemoryType().Length(); |
|
291 |
|
292 aBuffer->ExpandL( aOffset, aMemType.Length() ); |
|
293 aBuffer->Write( aOffset, aMemType ); |
|
294 aOffset += aMemType.Length(); |
|
295 |
|
296 // print label if exists |
|
297 if( iLocalizer->IsLocalized() ) |
|
298 { |
|
299 //get localized folder name |
|
300 HBufC8* labelBuf = |
|
301 CnvUtfConverter::ConvertFromUnicodeToUtf8L( iLocalizer->LocalizedName() ); |
|
302 CleanupStack::PushL( labelBuf ); |
|
303 TPtrC8 label = labelBuf->Des(); |
|
304 //memory label |
|
305 aBuffer->ExpandL( aOffset, |
|
306 KSConXmlMemoryLabel().Length() ); |
|
307 aBuffer->Write( aOffset, KSConXmlMemoryLabel ); |
|
308 aOffset += KSConXmlMemoryLabel().Length(); |
|
309 |
|
310 aBuffer->ExpandL( aOffset, label.Length() ); |
|
311 aBuffer->Write( aOffset, label ); |
|
312 aOffset += label.Length(); |
|
313 |
|
314 CleanupStack::PopAndDestroy( labelBuf ); |
|
315 } |
|
316 if ( dataPath ) // datapath |
|
317 { |
|
318 //memory label |
|
319 aBuffer->ExpandL( aOffset, |
|
320 KSConXmlMemoryLabel().Length() ); |
|
321 aBuffer->Write( aOffset, KSConXmlMemoryLabel ); |
|
322 aOffset += KSConXmlMemoryLabel().Length(); |
|
323 |
|
324 aBuffer->ExpandL( aOffset, iDataPathName.Length() ); |
|
325 aBuffer->Write( aOffset, iDataPathName ); |
|
326 aOffset += iDataPathName.Length(); |
|
327 } |
|
328 // print ending |
|
329 aBuffer->ExpandL( aOffset, KSConXmlFileEnd().Length() ); |
|
330 aBuffer->Write( aOffset, KSConXmlFileEnd ); |
|
331 aOffset += KSConXmlFileEnd().Length(); |
|
332 TRACE_FUNC_EXIT; |
|
333 } |
|
334 |
|
335 // ----------------------------------------------------------------------------- |
|
336 // CSConFsHandler::PrintFileL |
|
337 // Prints file entry to folder listing object |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CSConFsHandler::PrintFileL( CBufFlat* aBuffer, TInt& aOffset, const TEntry& aFileEntry ) |
|
341 { |
|
342 LOGGER_WRITE_1("CSConFsHandler::PrintFileL, filename: %S", &aFileEntry.iName ); |
|
343 HBufC8* fileBuf = HBufC8::NewLC( KMaxFileName ); |
|
344 TPtr8 fileName = fileBuf->Des(); |
|
345 |
|
346 User::LeaveIfError( |
|
347 CnvUtfConverter::ConvertFromUnicodeToUtf8( fileName, aFileEntry.iName ) ); |
|
348 |
|
349 //Replace special characters |
|
350 ReplaceSpecialChars( fileName ); |
|
351 |
|
352 // print filename |
|
353 aBuffer->ExpandL( aOffset, KSConXmlFileNameBegin().Length() ); |
|
354 aBuffer->Write( aOffset, KSConXmlFileNameBegin ); |
|
355 aOffset += KSConXmlFileNameBegin().Length(); |
|
356 |
|
357 aBuffer->ExpandL( aOffset, fileName.Length() ); |
|
358 aBuffer->Write( aOffset, fileName ); |
|
359 aOffset += fileName.Length(); |
|
360 |
|
361 // print size |
|
362 aBuffer->ExpandL( aOffset, KSConXmlSize().Length() ); |
|
363 aBuffer->Write( aOffset, KSConXmlSize ); |
|
364 aOffset += KSConXmlSize().Length(); |
|
365 |
|
366 fileName.Delete( 0, fileName.Length() ); // re-use fileName descriptor |
|
367 fileName.AppendNum( aFileEntry.iSize ); |
|
368 aBuffer->ExpandL( aOffset, fileName.Length() ); |
|
369 aBuffer->Write( aOffset, fileName ); |
|
370 aOffset += fileName.Length(); |
|
371 |
|
372 CleanupStack::PopAndDestroy( fileBuf ); |
|
373 |
|
374 // print modified |
|
375 TBuf<KSConDateMaxLength> modifiedTime; |
|
376 TTime time = aFileEntry.iModified; |
|
377 time.FormatL( modifiedTime, KSConXmlDate ); |
|
378 |
|
379 TBuf8<KSConDateMaxLength> modifiedTime8; |
|
380 User::LeaveIfError( |
|
381 CnvUtfConverter::ConvertFromUnicodeToUtf8( modifiedTime8, modifiedTime ) ); |
|
382 |
|
383 |
|
384 aBuffer->ExpandL( aOffset, KSConXmlModified().Length() ); |
|
385 aBuffer->Write( aOffset, KSConXmlModified ); |
|
386 aOffset += KSConXmlModified().Length(); |
|
387 |
|
388 aBuffer->ExpandL( aOffset, modifiedTime8.Length() ); |
|
389 aBuffer->Write( aOffset, modifiedTime8 ); |
|
390 aOffset += modifiedTime8.Length(); |
|
391 |
|
392 // attributes |
|
393 aBuffer->ExpandL( aOffset, KSConXmlUserAttributes().Length() ); |
|
394 aBuffer->Write( aOffset, KSConXmlUserAttributes ); |
|
395 aOffset += KSConXmlUserAttributes().Length(); |
|
396 |
|
397 if( aFileEntry.IsSystem() ) |
|
398 { |
|
399 aBuffer->ExpandL( aOffset, |
|
400 KSConXmlUserEntryReadOnly().Length() ); |
|
401 aBuffer->Write( aOffset, KSConXmlUserEntryReadOnly ); |
|
402 aOffset += KSConXmlUserEntryReadOnly().Length(); |
|
403 } |
|
404 else if( aFileEntry.IsReadOnly() ) |
|
405 { |
|
406 LOGGER_WRITE("was readonly" ); |
|
407 aBuffer->ExpandL( aOffset, |
|
408 KSConXmlUserEntryReadOnly().Length() ); |
|
409 aBuffer->Write( aOffset, KSConXmlUserEntryReadOnly ); |
|
410 aOffset += KSConXmlUserEntryReadOnly().Length(); |
|
411 } |
|
412 else |
|
413 { |
|
414 aBuffer->ExpandL( aOffset, |
|
415 KSConXmlUserEntryArchive().Length() ); |
|
416 aBuffer->Write( aOffset, KSConXmlUserEntryArchive ); |
|
417 aOffset += KSConXmlUserEntryArchive().Length(); |
|
418 } |
|
419 |
|
420 |
|
421 //Word document |
|
422 if ( aFileEntry.iType.IsPresent( KSConWordUid ) || |
|
423 aFileEntry.iName.Find( KSConEpocWordExt ) == aFileEntry.iName.Length() - 4 ) |
|
424 { |
|
425 aBuffer->ExpandL( aOffset, KSConXmlType().Length() ); |
|
426 aBuffer->Write( aOffset, KSConXmlType ); |
|
427 aOffset += KSConXmlType().Length(); |
|
428 |
|
429 aBuffer->ExpandL( aOffset, KSConXmlTypeWord().Length() ); |
|
430 aBuffer->Write( aOffset, KSConXmlTypeWord ); |
|
431 aOffset += KSConXmlTypeWord().Length(); |
|
432 } |
|
433 //Sheet document |
|
434 else if ( aFileEntry.iType.IsPresent( KSConSheetUid ) || |
|
435 aFileEntry.iName.Find( KSConEpocSheetExt ) == aFileEntry.iName.Length() - 4 ) |
|
436 { |
|
437 aBuffer->ExpandL( aOffset, KSConXmlType().Length() ); |
|
438 aBuffer->Write( aOffset, KSConXmlType ); |
|
439 aOffset += KSConXmlType().Length(); |
|
440 |
|
441 aBuffer->ExpandL( aOffset, KSConXmlTypeSheet().Length() ); |
|
442 aBuffer->Write( aOffset, KSConXmlTypeSheet ); |
|
443 aOffset += KSConXmlTypeSheet().Length(); |
|
444 } |
|
445 |
|
446 aBuffer->ExpandL( aOffset, KSConXmlFileEnd().Length() ); |
|
447 aBuffer->Write( aOffset, KSConXmlFileEnd ); |
|
448 aOffset += KSConXmlFileEnd().Length(); |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // CSConFsHandler::GetFileObjectL( CObexFileObject*& aFileObject, |
|
453 // const TPtrC aPathName, const TPtrC aFileName ) |
|
454 // Gets a file object |
|
455 // ----------------------------------------------------------------------------- |
|
456 // |
|
457 TInt CSConFsHandler::GetFileObjectL( CObexFileObject*& aFileObject, |
|
458 const TPtrC aPathName, const TPtrC aFileName ) |
|
459 { |
|
460 TRACE_FUNC_ENTRY; |
|
461 LOGGER_WRITE_2( "CSConFsHandler::GetFileObjectL aFileName = %S aPathName = %S", &aFileName, &aPathName ); |
|
462 |
|
463 TInt ret( KErrNone ); |
|
464 |
|
465 if( ( aPathName.Length() == 0 || aFileName.Length() == 0 ) && |
|
466 !( aFileName==KPhoneBookIrMCL2Request || |
|
467 aFileName==KInfoLogIrMCL2Request ) ) |
|
468 { |
|
469 return KErrArgument; |
|
470 } |
|
471 |
|
472 if( aPathName.Length() + aFileName.Length() > KMaxFileName ) |
|
473 { |
|
474 return KErrAbort; |
|
475 } |
|
476 |
|
477 HBufC* pathBuf = HBufC::NewLC( KMaxFileName ); |
|
478 TPtr pathBufPtr = pathBuf->Des(); |
|
479 |
|
480 /*These modifiactions are mean to catch an IrMC L2 request. |
|
481 If the request is made, then the requested phonebook file and |
|
482 info log -file are created. Path and filename is also changed |
|
483 to point to these created files.*/ |
|
484 if( aFileName == KPhoneBookIrMCL2Request || |
|
485 aFileName == KInfoLogIrMCL2Request ) |
|
486 { |
|
487 LOGGER_WRITE( "CSConFsHandler: IrMC L2 request!" ); |
|
488 TInt err; |
|
489 TInt status; |
|
490 TInt contactsSaved = 0; |
|
491 RCntParserServer cntParserServer; |
|
492 |
|
493 err = cntParserServer.Connect(); |
|
494 if( err != KErrNone ) |
|
495 { |
|
496 LOGGER_WRITE( "CSConFsHandler: Cannot connect to the cntparserserver, ABORT!" ); |
|
497 |
|
498 CleanupStack::PopAndDestroy( pathBuf ); |
|
499 return KErrAbort; |
|
500 } |
|
501 |
|
502 LOGGER_WRITE( "CSConFsHandler: Time to call CreateIrMCL2PhoneBook" ); |
|
503 TBool force = ( aFileName == KInfoLogIrMCL2Request ); |
|
504 status=cntParserServer.CreateIrMCL2PhoneBook( KMaximumNumberOfContacts, |
|
505 force ); |
|
506 LOGGER_WRITE_1( "CntParserServer.CreateIrMCL2PhoneBook returned %d", status ); |
|
507 |
|
508 //Check how many vcards were saved |
|
509 contactsSaved = cntParserServer.ContactsSaved(); |
|
510 LOGGER_WRITE_1( "CntParserServer.ContactsSaved returned %d", contactsSaved ); |
|
511 |
|
512 err = cntParserServer.Disconnect(); |
|
513 LOGGER_WRITE_1( "CntParserServer.Disconnect() %d", err ); |
|
514 if( err != KErrNone ) |
|
515 { |
|
516 CleanupStack::PopAndDestroy( pathBuf ); |
|
517 return KErrAbort; |
|
518 } |
|
519 //save info.log, if pb.vcf has changed (Note: KPBNotUpdated is returned |
|
520 // if no changes made to pb.vcf) |
|
521 if( status == KErrNone ) |
|
522 { |
|
523 LOGGER_WRITE( "CSConFsHandler: Create info.log" ); |
|
524 |
|
525 CCntParserInfoLog* infoLog=CCntParserInfoLog::NewL(); |
|
526 CleanupStack::PushL( infoLog ); |
|
527 //see KMaximumNumberOfContacts for more details |
|
528 infoLog->SetMaximumRecords( contactsSaved ); |
|
529 infoLog->SetTotalRecords( contactsSaved ); |
|
530 TFileName privatepath( K_C_ROOT ); |
|
531 privatepath.Append( KInfoLogIrMCL2File ); |
|
532 infoLog->SaveToFileL( privatepath ); |
|
533 CleanupStack::PopAndDestroy( infoLog ); |
|
534 } |
|
535 |
|
536 if( aFileName == KInfoLogIrMCL2Request ) |
|
537 { |
|
538 //Changes filename and path to info.log |
|
539 pathBufPtr.Copy( KInfoLogPathAndFileName ); |
|
540 } |
|
541 else |
|
542 { |
|
543 //Changes filename and path to pb.vcf |
|
544 pathBufPtr.Copy( KPbPathAndFileName ); |
|
545 } |
|
546 } |
|
547 else |
|
548 { |
|
549 pathBufPtr.Copy( aPathName ); |
|
550 pathBufPtr.Append( aFileName ); |
|
551 } |
|
552 |
|
553 LOGGER_WRITE( "CSConFsHandler::GetFileObjectL() : aFileObject->InitFromFileL( pathBufPtr )" ); |
|
554 TRAP( ret, aFileObject->InitFromFileL( pathBufPtr ) ); |
|
555 LOGGER_WRITE( "CSConFsHandler::GetFileObjectL() : aFileObject->InitFromFileL( pathBufPtr ) ok" ); |
|
556 |
|
557 CleanupStack::PopAndDestroy( pathBuf ); |
|
558 |
|
559 LOGGER_WRITE_1( "CSConFsHandler::GetFileObjectL( CObexFileObject*& aFileObject, const TPtrC aPathName, const TPtrC aFileName ) : returned %d", ret ); |
|
560 return ret; |
|
561 } |
|
562 |
|
563 // ----------------------------------------------------------------------------- |
|
564 // CSConFsHandler::SaveFileObjectL( const TPtrC aFullPathName, const TTime aTime, |
|
565 // const TPtrC aTempFileName ) |
|
566 // Stores a file object |
|
567 // ----------------------------------------------------------------------------- |
|
568 // |
|
569 TInt CSConFsHandler::SaveFileObjectL( const TPtrC aFullPathName, |
|
570 const TTime aTime, const TPtrC aTempFileName ) |
|
571 { |
|
572 TRACE_FUNC_ENTRY; |
|
573 LOGGER_WRITE_2( "CSConFsHandler::SaveFileObjectL aFullPathName = %S aTempFileName = %S", &aFullPathName, &aTempFileName ); |
|
574 |
|
575 TInt ret( KErrNone ); |
|
576 |
|
577 if( aFullPathName.Length() == 0 ) |
|
578 { |
|
579 iFs.Delete( aTempFileName ); |
|
580 return KErrPathNotFound; |
|
581 } |
|
582 |
|
583 ret = ValidateFileName( aFullPathName ); |
|
584 |
|
585 if( ret == KErrNone ) |
|
586 { |
|
587 TUint attr; |
|
588 TInt err = iFs.Att( BaflUtils::DriveAndPathFromFullName(aFullPathName), attr ); |
|
589 if ( err == KErrNone && attr & KEntryAttReadOnly ) |
|
590 { |
|
591 // folder is read only, permission denied |
|
592 iFs.Delete( aTempFileName ); |
|
593 ret = KErrAccessDenied; |
|
594 } |
|
595 else if( !BaflUtils::FileExists( iFs, aFullPathName ) ) |
|
596 { |
|
597 // file does not exist, rename. |
|
598 ret = iFs.Rename( aTempFileName, aFullPathName ); |
|
599 |
|
600 if( ret == KErrNone ) |
|
601 { |
|
602 ret = iFs.SetModified( aFullPathName, aTime ); |
|
603 ret = KErrNone; |
|
604 } |
|
605 else |
|
606 { |
|
607 iFs.Delete( aTempFileName ); |
|
608 } |
|
609 } |
|
610 else |
|
611 { |
|
612 LOGGER_WRITE( "CSConFsHandler::SaveFileObjectL() file exists. replace" ); |
|
613 // file exists. Replace if not read-only file. |
|
614 TUint attr; |
|
615 ret = iFs.Att( aFullPathName, attr ); |
|
616 // Check permissions |
|
617 if( ret == KErrNone && ( attr == KEntryAttNormal || |
|
618 attr == KEntryAttArchive ) && !(attr & KEntryAttReadOnly) ) |
|
619 { |
|
620 ret = iFs.Replace( aTempFileName, aFullPathName ); |
|
621 LOGGER_WRITE_1( "CSConFsHandler::SaveFileObjectL() iFs.Replace ret %d", ret); |
|
622 //Set correct time stamp |
|
623 if( ret == KErrNone ) |
|
624 { |
|
625 ret = iFs.SetModified( aFullPathName, aTime ); |
|
626 ret = KErrNone; |
|
627 } |
|
628 else |
|
629 { |
|
630 iFs.Delete( aTempFileName ); |
|
631 } |
|
632 } |
|
633 else |
|
634 { |
|
635 LOGGER_WRITE( "CSConFsHandler::SaveFileObjectL() no permissions" ); |
|
636 iFs.Delete( aTempFileName ); |
|
637 ret = KErrAccessDenied; |
|
638 } |
|
639 } |
|
640 } |
|
641 else |
|
642 { |
|
643 iFs.Delete( aTempFileName ); |
|
644 } |
|
645 |
|
646 LOGGER_WRITE_1( "CSConFsHandler::SaveFileObjectL() : returned %d", ret ); |
|
647 return ret; |
|
648 } |
|
649 |
|
650 // ----------------------------------------------------------------------------- |
|
651 // CSConFsHandler::ValidateFileName( const TPtrC aName ) |
|
652 // Validates the file name |
|
653 // ----------------------------------------------------------------------------- |
|
654 // |
|
655 TInt CSConFsHandler::ValidateFileName( const TPtrC aName ) |
|
656 { |
|
657 TInt ret( KErrNone ); |
|
658 |
|
659 if( !iFs.IsValidName( aName ) ) |
|
660 { |
|
661 ret = KErrBadName; |
|
662 } |
|
663 |
|
664 LOGGER_WRITE_1( "CSConFsHandler::ValidateFileName( const TPtrC aName ) : returned %d", ret ); |
|
665 return ret; |
|
666 } |
|
667 |
|
668 // ----------------------------------------------------------------------------- |
|
669 // CSConFsHandler::CreateFolderL( const TPtrC aFolderPath ) |
|
670 // Creates a folder |
|
671 // ----------------------------------------------------------------------------- |
|
672 // |
|
673 TInt CSConFsHandler::CreateFolderL( const TPtrC aFolderPath ) |
|
674 { |
|
675 TRACE_FUNC_ENTRY; |
|
676 |
|
677 TInt ret( KErrNone ); |
|
678 |
|
679 if( aFolderPath.Length() == 0 ) |
|
680 { |
|
681 return KErrArgument; |
|
682 } |
|
683 if( aFolderPath.Length() > KMaxPath ) |
|
684 { |
|
685 return KErrAbort; |
|
686 } |
|
687 if( BaflUtils::PathExists( iFs, aFolderPath ) ) |
|
688 { |
|
689 return KErrAlreadyExists; |
|
690 } |
|
691 // get restore mode |
|
692 TBool restoreInProgress( EFalse ); |
|
693 RProperty backupProperty; |
|
694 TInt burState( 0 ); |
|
695 TInt burErr = backupProperty.Get( KUidSystemCategory, conn::KUidBackupRestoreKey, burState ); |
|
696 const conn::TBURPartType partType = |
|
697 static_cast< conn::TBURPartType >( burState & conn::KBURPartTypeMask ); |
|
698 if( burErr == KErrNone && |
|
699 ( partType == conn::EBURRestorePartial || partType == conn::EBURRestoreFull ) ) |
|
700 { |
|
701 // restore mode |
|
702 LOGGER_WRITE( "CSConFsHandler::CreateFolderL() restore mode" ); |
|
703 restoreInProgress = ETrue; |
|
704 } |
|
705 |
|
706 // check permissions if not restore mode |
|
707 if ( !restoreInProgress ) |
|
708 { |
|
709 if ( IsExludedPath( aFolderPath ) ) |
|
710 { |
|
711 // user has no access to this folder |
|
712 LOGGER_WRITE( "CSConFsHandler::CreateFolderL() KErrAccessDenied" ); |
|
713 return KErrAccessDenied; |
|
714 } |
|
715 |
|
716 // user can create whole folder path at once and we need to check that |
|
717 // user has permission to create folders. We need to find first folder that |
|
718 // should be created, and see if parent folder has read-only permission. |
|
719 |
|
720 HBufC* fullPath = HBufC::NewLC( KMaxFileName ); |
|
721 TPtr fullPathPtr = fullPath->Des(); |
|
722 |
|
723 fullPathPtr.Copy(aFolderPath); |
|
724 TBool parentFound(EFalse); |
|
725 LOGGER_WRITE( "CSConFsHandler::CreateFolder() start loop" ); |
|
726 TInt err(KErrNone); |
|
727 while (!parentFound && err==KErrNone) |
|
728 { |
|
729 err = GetParentFolder( fullPathPtr, fullPathPtr ); |
|
730 if( err == KErrNone ) |
|
731 { |
|
732 if (BaflUtils::PathExists( iFs, fullPathPtr )) |
|
733 { |
|
734 parentFound = ETrue; |
|
735 TUint attr; |
|
736 ret = iFs.Att( fullPathPtr, attr ); |
|
737 if ( ret == KErrNone && (attr & KEntryAttReadOnly || attr & KEntryAttSystem) ) |
|
738 { |
|
739 // parent folder is read-only |
|
740 LOGGER_WRITE( "CSConFsHandler::CreateFolderL() KErrAccessDenied" ); |
|
741 err = KErrAccessDenied; |
|
742 } |
|
743 } |
|
744 } |
|
745 } |
|
746 |
|
747 CleanupStack::PopAndDestroy( fullPath ); |
|
748 if ( err == KErrAccessDenied ) |
|
749 { |
|
750 return KErrAccessDenied; |
|
751 } |
|
752 } |
|
753 |
|
754 ret = iFs.MkDirAll( aFolderPath ); |
|
755 LOGGER_WRITE_1( "CSConFsHandler::CreateFolderL( const TPtrC aFolderPath ) : returned %d", ret ); |
|
756 return ret; |
|
757 } |
|
758 |
|
759 // ----------------------------------------------------------------------------- |
|
760 // CSConFsHandler::DeleteObjectL( const TPtrC aFullPath ) |
|
761 // Removes a folder or a file |
|
762 // ----------------------------------------------------------------------------- |
|
763 // |
|
764 TInt CSConFsHandler::DeleteObjectL( const TPtrC aFullPath ) |
|
765 { |
|
766 TRACE_FUNC_ENTRY; |
|
767 LOGGER_WRITE_1("aFullPath: %S", &aFullPath); |
|
768 TInt ret( KErrNone ); |
|
769 |
|
770 if( aFullPath.Length() == 0 ) |
|
771 { |
|
772 return KErrArgument; |
|
773 } |
|
774 |
|
775 if( aFullPath.Length() > KMaxFileName ) |
|
776 { |
|
777 return KErrAbort; |
|
778 } |
|
779 |
|
780 TUint attr; |
|
781 // get source folder permissions. |
|
782 ret = iFs.Att( BaflUtils::DriveAndPathFromFullName(aFullPath), attr ); |
|
783 if ( ret == KErrNone && (attr & KEntryAttReadOnly || attr & KEntryAttSystem ) ) |
|
784 { |
|
785 return KErrAccessDenied; |
|
786 } |
|
787 |
|
788 |
|
789 // Check file/folder permissions |
|
790 ret = iFs.Att( aFullPath, attr ); |
|
791 if ( ret == KErrNone && ( attr & KEntryAttReadOnly || attr & KEntryAttSystem ) ) |
|
792 { |
|
793 return KErrAccessDenied; |
|
794 } |
|
795 |
|
796 TBool isFolder(EFalse); |
|
797 ret = BaflUtils::IsFolder( iFs, aFullPath, isFolder ); |
|
798 |
|
799 if( isFolder && ret == KErrNone ) |
|
800 { |
|
801 HBufC* fullPath = HBufC::NewLC( KMaxFileName ); |
|
802 TPtr fullPathPtr = fullPath->Des(); |
|
803 |
|
804 fullPathPtr.Copy( aFullPath ); |
|
805 //check if there is a slash at the end |
|
806 if( fullPathPtr.LocateReverse( KPathDelimiter ) != fullPathPtr.Length()-1 ) |
|
807 { |
|
808 fullPathPtr.Append( KPathDelimiter ); |
|
809 } |
|
810 |
|
811 if ( !IsFolderVisible( fullPathPtr ) ) |
|
812 { |
|
813 LOGGER_WRITE("folder was not visible"); |
|
814 CleanupStack::PopAndDestroy( fullPath ); |
|
815 return KErrNotFound; |
|
816 } |
|
817 else if ( !IsFolderDeletable( fullPathPtr ) ) |
|
818 { |
|
819 LOGGER_WRITE("folder was not deletable"); |
|
820 CleanupStack::PopAndDestroy( fullPath ); |
|
821 return KErrAccessDenied; |
|
822 } |
|
823 |
|
824 ret = iFs.RmDir( fullPathPtr ); |
|
825 LOGGER_WRITE_1("iFs.RmDir err: %d", ret); |
|
826 //delete non-empty folder |
|
827 if( ret != KErrNone ) |
|
828 { |
|
829 CFileMan* fileMan = CFileMan::NewL( iFs ); |
|
830 CleanupStack::PushL( fileMan ); |
|
831 // if directory contains read-only files, those files are not deleted |
|
832 // and KErrAccessDenied is returned. |
|
833 ret = fileMan->RmDir( fullPathPtr ); |
|
834 LOGGER_WRITE_1("fileMan->RmDir err: %d", ret); |
|
835 CleanupStack::PopAndDestroy( fileMan ); //fileman |
|
836 } |
|
837 if( ret == KErrNone ) |
|
838 { |
|
839 // check is delete operation really succesfully completed |
|
840 if( BaflUtils::PathExists( iFs, fullPathPtr ) ) |
|
841 { |
|
842 // Folder still exist, return error |
|
843 // KErrBadName mapped to precondition failed error. |
|
844 ret = KErrBadName; |
|
845 } |
|
846 } |
|
847 CleanupStack::PopAndDestroy( fullPath ); //fullPath |
|
848 } |
|
849 else if (ret == KErrNone) |
|
850 { |
|
851 // deleting file |
|
852 if ( IsExludedPath( aFullPath ) ) |
|
853 { |
|
854 LOGGER_WRITE("Cannot delete from specified folder, return KErrAccessDenied"); |
|
855 ret = KErrAccessDenied; |
|
856 } |
|
857 else |
|
858 { |
|
859 ret = iFs.Delete( aFullPath ); |
|
860 } |
|
861 } |
|
862 |
|
863 |
|
864 |
|
865 LOGGER_WRITE_1( "CSConFsHandler::DeleteObjectL() : returned %d", ret ); |
|
866 return ret; |
|
867 } |
|
868 |
|
869 |
|
870 // ----------------------------------------------------------------------------- |
|
871 // CSConFsHandler::CopyOrMoveFile() |
|
872 // Copy or Move file/folder. |
|
873 // ----------------------------------------------------------------------------- |
|
874 // |
|
875 void CSConFsHandler::DoCopyOrMoveFileL( const TDesC& aSource, const TDesC& aTarget, |
|
876 const TBool aUseCopyCommand) |
|
877 { |
|
878 TRACE_FUNC_ENTRY; |
|
879 TInt lastError(KErrNone); |
|
880 TBool isFolder; |
|
881 |
|
882 if( !iFs.IsValidName( aSource ) || !iFs.IsValidName( aTarget ) ) |
|
883 { |
|
884 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Not valid name" ); |
|
885 User::Leave( KErrBadName ); |
|
886 } |
|
887 |
|
888 // will leave if source (file/folder) does not exists. |
|
889 User::LeaveIfError( BaflUtils::IsFolder(iFs, aSource, isFolder ) ); |
|
890 |
|
891 // Check source file/folder permissions |
|
892 TUint attr; |
|
893 User::LeaveIfError( iFs.Att( aSource, attr ) ); |
|
894 if ( !aUseCopyCommand && (attr & KEntryAttReadOnly || attr & KEntryAttSystem ) ) |
|
895 { |
|
896 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : no permissions, abort" ); |
|
897 User::Leave( KErrAccessDenied ); |
|
898 } |
|
899 |
|
900 HBufC* sourceFolderBuf = HBufC::NewLC( KMaxFileName ); |
|
901 TPtr sourceFolder = sourceFolderBuf->Des(); |
|
902 HBufC* targetFolderBuf = HBufC::NewLC( KMaxFileName ); |
|
903 TPtr targetFolder = targetFolderBuf->Des(); |
|
904 |
|
905 sourceFolder.Copy( BaflUtils::DriveAndPathFromFullName(aSource) ); |
|
906 targetFolder.Copy( BaflUtils::DriveAndPathFromFullName(aTarget) ); |
|
907 |
|
908 |
|
909 // check disk space |
|
910 TInt driveNumber; |
|
911 |
|
912 User::LeaveIfError( iFs.CharToDrive(targetFolder[0], driveNumber) ); |
|
913 |
|
914 TVolumeInfo volumeInfo; |
|
915 TInt err = iFs.Volume(volumeInfo, driveNumber); |
|
916 if( err != KErrNone ) |
|
917 { |
|
918 LOGGER_WRITE_1( "CSConFsHandler::DoCopyOrMoveFileL : iFs.Volume err %d", err ); |
|
919 User::Leave( KErrNotFound ); |
|
920 } |
|
921 |
|
922 if( !isFolder ) |
|
923 { |
|
924 // file handling routines |
|
925 if( !IsFolderVisible( aSource ) ) |
|
926 { |
|
927 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Current folder doesn't exist" ); |
|
928 User::Leave( KErrNotFound ); |
|
929 } |
|
930 else if( !aUseCopyCommand && IsFolderReadOnly( sourceFolder ) ) |
|
931 { |
|
932 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : folder read only, abort" ); |
|
933 User::Leave( KErrAccessDenied ); |
|
934 } |
|
935 |
|
936 // source file is ok, check target |
|
937 |
|
938 if( !IsFolderVisible( targetFolder ) ) |
|
939 { |
|
940 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Current target file/folder doesn't exist" ); |
|
941 User::Leave( KErrNotFound ); |
|
942 } |
|
943 else if( IsFolderReadOnly( targetFolder ) ) |
|
944 { |
|
945 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : folder read only, abort" ); |
|
946 User::Leave( KErrAccessDenied ); |
|
947 } |
|
948 else |
|
949 { |
|
950 TBool diskFull( EFalse ); |
|
951 TEntry fileEntry; |
|
952 User::LeaveIfError( iFs.Entry( aSource, fileEntry ) ); |
|
953 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, fileEntry.iSize, driveNumber ) ) |
|
954 { |
|
955 diskFull = ETrue; |
|
956 } |
|
957 |
|
958 // target ok, ready to copy or move |
|
959 CFileMan* fileMan=CFileMan::NewL(iFs); |
|
960 CleanupStack::PushL(fileMan); |
|
961 |
|
962 if( aUseCopyCommand ) |
|
963 { |
|
964 if( diskFull ) |
|
965 { |
|
966 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : disk full" ); |
|
967 User::Leave( KErrDiskFull ); |
|
968 } |
|
969 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Copy file" ); |
|
970 User::LeaveIfError( fileMan->Copy( aSource, aTarget, 0 ) ); |
|
971 } |
|
972 else |
|
973 { |
|
974 if( aSource.Find( aTarget.Left(2) ) == KErrNone) |
|
975 { |
|
976 // same drive |
|
977 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Rename file" ); |
|
978 User::LeaveIfError( fileMan->Rename( aSource, aTarget, 0 ) ); |
|
979 } |
|
980 else |
|
981 { |
|
982 // different drive |
|
983 if( diskFull ) |
|
984 { |
|
985 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : disk full" ); |
|
986 User::Leave( KErrDiskFull ); |
|
987 } |
|
988 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : copy file" ); |
|
989 User::LeaveIfError( fileMan->Copy( aSource, aTarget, 0 ) ); |
|
990 |
|
991 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : delete original" ); |
|
992 User::LeaveIfError( fileMan->Delete( aSource, 0 ) ); |
|
993 } |
|
994 } |
|
995 CleanupStack::PopAndDestroy( fileMan ); // fileMan |
|
996 } |
|
997 } |
|
998 else |
|
999 { |
|
1000 // set trailing backslash after the final directory name |
|
1001 HBufC* tmpSourceBuf = HBufC::NewLC( KMaxFileName ); |
|
1002 TPtr tmpSourcePtr = tmpSourceBuf->Des(); |
|
1003 HBufC* tmpTargetBuf = HBufC::NewLC( KMaxFileName ); |
|
1004 TPtr tmpTargetPtr = tmpTargetBuf->Des(); |
|
1005 |
|
1006 tmpSourcePtr.Copy( aSource ); |
|
1007 if( tmpSourcePtr.LocateReverse( KPathDelimiter ) != tmpSourcePtr.Length()-1 ) |
|
1008 { |
|
1009 tmpSourcePtr.Append( KPathDelimiter ); |
|
1010 } |
|
1011 |
|
1012 tmpTargetPtr.Copy( aTarget ); |
|
1013 if( tmpTargetPtr.LocateReverse( KPathDelimiter ) != tmpTargetPtr.Length()-1 ) |
|
1014 { |
|
1015 tmpTargetPtr.Append( KPathDelimiter ); |
|
1016 } |
|
1017 |
|
1018 if( !IsFolderVisible( tmpSourcePtr ) ) |
|
1019 { |
|
1020 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Current folder doesn't exist" ); |
|
1021 User::Leave( KErrNotFound ); |
|
1022 } |
|
1023 else if( !aUseCopyCommand && IsFolderReadOnly( sourceFolder ) ) |
|
1024 { |
|
1025 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : sourcefolder read only, abort" ); |
|
1026 User::Leave( KErrAccessDenied ); |
|
1027 } |
|
1028 else if( !aUseCopyCommand && !IsFolderDeletable( tmpSourcePtr ) ) |
|
1029 { |
|
1030 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : source folder read only, abort" ); |
|
1031 User::Leave( KErrAccessDenied ); |
|
1032 } |
|
1033 else if( !IsFolderVisible( targetFolder ) ) |
|
1034 { |
|
1035 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Current target base-folder doesn't exist" ); |
|
1036 User::Leave( KErrNotFound ); |
|
1037 } |
|
1038 else if( IsFolderReadOnly( targetFolder) ) |
|
1039 { |
|
1040 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : target folder read only, abort" ); |
|
1041 User::Leave( KErrAccessDenied ); |
|
1042 } |
|
1043 else if( BaflUtils::FolderExists(iFs, tmpTargetPtr ) ) |
|
1044 { |
|
1045 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : target folder exist, abort" ); |
|
1046 User::Leave( KErrAlreadyExists ); |
|
1047 } |
|
1048 else if ( tmpTargetPtr.Find( tmpSourcePtr ) == KErrNone ) |
|
1049 { |
|
1050 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : conflict, abort" ); |
|
1051 User::Leave( KErrInUse ); |
|
1052 } |
|
1053 else |
|
1054 { |
|
1055 // is folder empty |
|
1056 TBool emptyFolder( ETrue ); |
|
1057 CDir *entryList = 0; |
|
1058 CDir *dirList = 0; |
|
1059 |
|
1060 User::LeaveIfError( iFs.GetDir( tmpSourcePtr, KEntryAttNormal, EDirsAnyOrder, |
|
1061 entryList, dirList ) ); |
|
1062 if( entryList->Count() > 0 || dirList->Count() > 0 ) |
|
1063 { |
|
1064 emptyFolder = EFalse; |
|
1065 } |
|
1066 |
|
1067 delete entryList; |
|
1068 delete dirList; |
|
1069 |
|
1070 // get folder size |
|
1071 TBool diskFull( EFalse ); |
|
1072 if( !emptyFolder ) |
|
1073 { |
|
1074 TInt64 folderSize = GetFolderSizeL(tmpSourcePtr); |
|
1075 LOGGER_WRITE_1( "CSConFsHandler::DoCopyOrMoveFileL : folderSize: %d", folderSize ); |
|
1076 if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, folderSize, driveNumber ) ) |
|
1077 { |
|
1078 diskFull = ETrue; |
|
1079 } |
|
1080 } |
|
1081 |
|
1082 |
|
1083 CFileMan* fileMan = CFileMan::NewL(iFs); |
|
1084 CleanupStack::PushL(fileMan); |
|
1085 |
|
1086 // ready to copy or move |
|
1087 if( aUseCopyCommand ) |
|
1088 { |
|
1089 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Copy folder" ); |
|
1090 if( emptyFolder ) |
|
1091 { |
|
1092 // folder is empty, can't copy folder. Create new empty folder. |
|
1093 User::LeaveIfError( iFs.MkDir( tmpTargetPtr ) ); |
|
1094 } |
|
1095 else |
|
1096 { |
|
1097 // folder not empty |
|
1098 if( diskFull ) |
|
1099 { |
|
1100 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : disk full" ); |
|
1101 User::Leave( KErrDiskFull ); |
|
1102 } |
|
1103 |
|
1104 User::LeaveIfError( |
|
1105 fileMan->Copy( aSource, aTarget, CFileMan::ERecurse ) ); |
|
1106 if( lastError == KErrNone ) |
|
1107 { |
|
1108 lastError = fileMan->GetLastError(); |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 TUint attr; |
|
1113 TInt err = iFs.Att( tmpSourcePtr, attr ); |
|
1114 if ( err == KErrNone && (attr & KEntryAttReadOnly ) ) |
|
1115 { |
|
1116 //set read only attribute |
|
1117 err = iFs.SetAtt( tmpTargetPtr, KEntryAttReadOnly, KEntryAttArchive ); |
|
1118 if (err != KErrNone) |
|
1119 { |
|
1120 // can't set attribute |
|
1121 LOGGER_WRITE_1( "CSConFsHandler::DoCopyOrMoveFileL : iFs.SetAtt err: %d",err ); |
|
1122 } |
|
1123 } |
|
1124 } |
|
1125 else |
|
1126 { |
|
1127 if( aSource.FindF( aTarget.Left(2) ) == KErrNone) |
|
1128 { |
|
1129 // same drive |
|
1130 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Rename folder" ); |
|
1131 User::LeaveIfError( fileMan->Rename( aSource, aTarget, 0 ) ); |
|
1132 } |
|
1133 else |
|
1134 { |
|
1135 // different drive |
|
1136 if( diskFull ) |
|
1137 { |
|
1138 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : disk full" ); |
|
1139 User::Leave( KErrDiskFull ); |
|
1140 } |
|
1141 |
|
1142 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : Copy folder" ); |
|
1143 if( emptyFolder ) |
|
1144 { |
|
1145 // folder is empty, can't copy empty folder. Create empty folder. |
|
1146 User::LeaveIfError( iFs.MkDir( tmpTargetPtr ) ); |
|
1147 } |
|
1148 else |
|
1149 { |
|
1150 User::LeaveIfError( |
|
1151 fileMan->Copy( aSource, aTarget, CFileMan::ERecurse ) ); |
|
1152 } |
|
1153 // copy completed, delete original folder. |
|
1154 LOGGER_WRITE( "CSConFsHandler::DoCopyOrMoveFileL : delete original" ); |
|
1155 User::LeaveIfError( fileMan->RmDir( tmpSourcePtr ) ); |
|
1156 // check was delete operation succesfully completed |
|
1157 if( BaflUtils::PathExists( iFs, tmpSourcePtr ) ) |
|
1158 { |
|
1159 // Folder still exist, return error |
|
1160 lastError = KErrAccessDenied; |
|
1161 } |
|
1162 } |
|
1163 } |
|
1164 CleanupStack::PopAndDestroy(fileMan); // fileMan |
|
1165 } |
|
1166 CleanupStack::PopAndDestroy(tmpTargetBuf); // tmpTargetBuf |
|
1167 CleanupStack::PopAndDestroy(tmpSourceBuf); // tmpSourceBuf |
|
1168 } |
|
1169 |
|
1170 CleanupStack::PopAndDestroy( targetFolderBuf ); |
|
1171 CleanupStack::PopAndDestroy( sourceFolderBuf ); |
|
1172 |
|
1173 if( lastError != KErrNone ) |
|
1174 { |
|
1175 LOGGER_WRITE_1( "CSConFTP::DoCopyOrMoveFileL() : lastError: %d", lastError ); |
|
1176 User::Leave( lastError ); |
|
1177 } |
|
1178 |
|
1179 TRACE_FUNC_EXIT; |
|
1180 } |
|
1181 |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // CSConFsHandler::IsFolderVisible() |
|
1184 // Check if folder can be showed |
|
1185 // ----------------------------------------------------------------------------- |
|
1186 // |
|
1187 TBool CSConFsHandler::IsFolderVisible( const TDesC& aFullPath ) |
|
1188 { |
|
1189 TRACE_FUNC_ENTRY; |
|
1190 LOGGER_WRITE_1( "aFullPath: %S", &aFullPath ); |
|
1191 TBool visible(EFalse); |
|
1192 |
|
1193 if( !BaflUtils::FolderExists( iFs, aFullPath ) ) |
|
1194 { |
|
1195 LOGGER_WRITE( "CSConFsHandler::IsFolderVisible() notExist ret EFalse" ); |
|
1196 return EFalse; |
|
1197 } |
|
1198 |
|
1199 // don't show if folder is exluded |
|
1200 visible = !IsExludedPath( aFullPath ); |
|
1201 LOGGER_WRITE_1( "CSConFsHandler::IsFolderVisible() : end, ret %d", (TInt)visible ); |
|
1202 return visible; |
|
1203 } |
|
1204 |
|
1205 // ----------------------------------------------------------------------------- |
|
1206 // CSConFsHandler::IsFolderReadOnly() |
|
1207 // Check if folder is read only (system folder) |
|
1208 // ----------------------------------------------------------------------------- |
|
1209 // |
|
1210 TBool CSConFsHandler::IsFolderReadOnly( const TDesC& aFullPath ) const |
|
1211 { |
|
1212 TRACE_FUNC_ENTRY; |
|
1213 LOGGER_WRITE_1( "aFullPath: %S", &aFullPath ); |
|
1214 TBool readOnly(EFalse); |
|
1215 |
|
1216 // C-drive root is read only, but there are some exceptions |
|
1217 |
|
1218 readOnly = IsExludedPath( aFullPath ); |
|
1219 |
|
1220 if ( aFullPath.CompareF( K_C_ROOT ) == 0 ) |
|
1221 { |
|
1222 // Root of C-drive is read-only |
|
1223 LOGGER_WRITE("Root of C-Drive is read only"); |
|
1224 readOnly = ETrue; |
|
1225 } |
|
1226 |
|
1227 // Check folder permissions |
|
1228 TUint attr; |
|
1229 TInt err = iFs.Att( aFullPath, attr ); |
|
1230 LOGGER_WRITE_1("iFs.Att err: %d", err); |
|
1231 if ( err == KErrNone && (attr & KEntryAttReadOnly || attr & KEntryAttSystem ) ) |
|
1232 { |
|
1233 LOGGER_WRITE("Folder is readonly"); |
|
1234 readOnly = ETrue; |
|
1235 } |
|
1236 |
|
1237 LOGGER_WRITE_1( "CSConFsHandler::IsFolderReadOnly() : end, ret %d", (TInt)readOnly ); |
|
1238 return readOnly; |
|
1239 } |
|
1240 |
|
1241 // ----------------------------------------------------------------------------- |
|
1242 // CSConFsHandler::IsFolderDeletable() |
|
1243 // Check if folder can be deleted. Localized folders cannot delete. |
|
1244 // In C-drive folders can be deleted only from under C:\\Data\\ |
|
1245 // ----------------------------------------------------------------------------- |
|
1246 // |
|
1247 TBool CSConFsHandler::IsFolderDeletable( const TDesC& aFullPath ) const |
|
1248 { |
|
1249 TRACE_FUNC_ENTRY; |
|
1250 LOGGER_WRITE_1( "aFullPath: %S", &aFullPath ); |
|
1251 TBool deleteAllowed(ETrue); |
|
1252 TPath PhoneMem( PathInfo::PhoneMemoryRootPath() ); // "C:\\Data\\" |
|
1253 |
|
1254 if ( aFullPath.CompareF( PhoneMem ) == 0 ) |
|
1255 { |
|
1256 // C:\\Data\\ |
|
1257 LOGGER_WRITE( "CSConFsHandler::IsFolderDeletable() datapath, ret EFalse" ); |
|
1258 deleteAllowed = EFalse; |
|
1259 } |
|
1260 else if ( IsExludedPath( aFullPath ) ) |
|
1261 { |
|
1262 deleteAllowed = EFalse; |
|
1263 } |
|
1264 |
|
1265 iLocalizer->SetFullPath( aFullPath ); |
|
1266 if ( iLocalizer->IsLocalized() ) // delete disabled |
|
1267 { |
|
1268 // Cannot delete localized paths (default paths) |
|
1269 deleteAllowed = EFalse; |
|
1270 } |
|
1271 |
|
1272 LOGGER_WRITE_1( "CSConFsHandler::IsFolderDeletable() : end, ret %d", (TInt)deleteAllowed ); |
|
1273 return deleteAllowed; |
|
1274 } |
|
1275 |
|
1276 // ----------------------------------------------------------------------------- |
|
1277 // CSConFsHandler::GetParentFolder( const TPtrC aFullPath, TDes& aParent) |
|
1278 // Get parent folder |
|
1279 // ----------------------------------------------------------------------------- |
|
1280 // |
|
1281 TInt CSConFsHandler::GetParentFolder( const TDesC& aFullPath, TDes& aParent) |
|
1282 { |
|
1283 TRACE_FUNC_ENTRY; |
|
1284 if (aFullPath.LocateReverse(KPathDelimiter) == aFullPath.Length()-1 ) |
|
1285 { |
|
1286 // remove backlash |
|
1287 aParent.Copy(aFullPath.Left(aFullPath.Length()-1)); |
|
1288 } |
|
1289 else |
|
1290 { |
|
1291 aParent.Copy(aFullPath); |
|
1292 } |
|
1293 |
|
1294 TInt pos = aParent.LocateReverse(KPathDelimiter); |
|
1295 if (pos != KErrNotFound) |
|
1296 { |
|
1297 aParent.Copy(aParent.Left(pos+1)); |
|
1298 LOGGER_WRITE( "CSConFsHandler::GetParentFolder : end KErrNone" ); |
|
1299 return KErrNone; |
|
1300 } |
|
1301 else |
|
1302 { |
|
1303 LOGGER_WRITE_1( "CSConFsHandler::GetParentFolder : end err %d", pos); |
|
1304 return pos; |
|
1305 } |
|
1306 } |
|
1307 |
|
1308 // ----------------------------------------------------------------------------- |
|
1309 // CSConFsHandler::CSConFsHandler() |
|
1310 // Constructor |
|
1311 // ----------------------------------------------------------------------------- |
|
1312 // |
|
1313 CSConFsHandler::CSConFsHandler( RFs& aFs ) : iFs(aFs) |
|
1314 { |
|
1315 TRACE_FUNC; |
|
1316 } |
|
1317 |
|
1318 // ----------------------------------------------------------------------------- |
|
1319 // CSConFsHandler::ConstructL() |
|
1320 // Initializes member data |
|
1321 // ----------------------------------------------------------------------------- |
|
1322 // |
|
1323 void CSConFsHandler::ConstructL() |
|
1324 { |
|
1325 TRACE_FUNC_ENTRY; |
|
1326 iLocalizer = CDirectoryLocalizer::NewL(); |
|
1327 |
|
1328 GetDataPathNameL(); |
|
1329 TRACE_FUNC_EXIT; |
|
1330 } |
|
1331 |
|
1332 // ----------------------------------------------------------------------------- |
|
1333 // CSConFsHandler::GetDataPathNameL() |
|
1334 // Updates the name of the data folder from a localized string |
|
1335 // ----------------------------------------------------------------------------- |
|
1336 // |
|
1337 void CSConFsHandler::GetDataPathNameL() |
|
1338 { |
|
1339 TRACE_FUNC_ENTRY; |
|
1340 //Read memory string and convert it |
|
1341 TFileName file( KSConResourceName ); |
|
1342 |
|
1343 BaflUtils::NearestLanguageFile( iFs, file ); |
|
1344 |
|
1345 CStringResourceReader* reader = CStringResourceReader::NewL( file ); |
|
1346 CleanupStack::PushL( reader ); |
|
1347 |
|
1348 CnvUtfConverter::ConvertFromUnicodeToUtf8( iDataPathName, |
|
1349 reader->ReadResourceString( R_SECON_DATA_FOLDER ) ); |
|
1350 |
|
1351 CleanupStack::PopAndDestroy( reader ); |
|
1352 TRACE_FUNC_EXIT; |
|
1353 } |
|
1354 |
|
1355 // ----------------------------------------------------------------------------- |
|
1356 // CSConFsHandler::GetFolderSizeL() |
|
1357 // Get folder (and subfolders) size |
|
1358 // ----------------------------------------------------------------------------- |
|
1359 // |
|
1360 TInt64 CSConFsHandler::GetFolderSizeL( const TDesC& aFullPath ) |
|
1361 { |
|
1362 TRACE_FUNC_ENTRY; |
|
1363 LOGGER_WRITE_1( "aFullPath: %S", &aFullPath ); |
|
1364 TInt64 totalSize(0); |
|
1365 CDir* dir( NULL ); |
|
1366 |
|
1367 User::LeaveIfError( iFs.GetDir(aFullPath, KEntryAttMatchMask, ESortByName, dir) ); |
|
1368 CleanupStack::PushL(dir); |
|
1369 for( TInt i=0; i<dir->Count(); ++i ) |
|
1370 { |
|
1371 TEntry entry = (*dir)[i]; |
|
1372 if( !entry.IsDir() ) |
|
1373 { |
|
1374 // file |
|
1375 totalSize += entry.iSize; |
|
1376 } |
|
1377 else |
|
1378 { |
|
1379 // folder |
|
1380 HBufC* subfolderBuf = HBufC::NewLC( KMaxPath ); |
|
1381 TPtr subfolderPtr = subfolderBuf->Des(); |
|
1382 |
|
1383 subfolderPtr.Copy(aFullPath); |
|
1384 subfolderPtr.Append(entry.iName); |
|
1385 subfolderPtr.Append( KPathDelimiter ); |
|
1386 |
|
1387 LOGGER_WRITE( "CSConFsHandler::GetFolderSizeL() : get subfolder size" ); |
|
1388 totalSize += GetFolderSizeL( subfolderPtr ); |
|
1389 CleanupStack::PopAndDestroy( subfolderBuf ); |
|
1390 } |
|
1391 } |
|
1392 CleanupStack::PopAndDestroy(dir); |
|
1393 TRACE_FUNC_EXIT; |
|
1394 return totalSize; |
|
1395 } |
|
1396 |
|
1397 // ----------------------------------------------------------------------------- |
|
1398 // CSConFsHandler::ReplaceSpecialChars() |
|
1399 // Replace special characters to xml compliant |
|
1400 // ----------------------------------------------------------------------------- |
|
1401 // |
|
1402 void CSConFsHandler::ReplaceSpecialChars( TDes8& aDes ) |
|
1403 { |
|
1404 for( TInt i = 0; i < aDes.Length(); i++ ) |
|
1405 { |
|
1406 switch( aDes[i] ) |
|
1407 { |
|
1408 case '&': |
|
1409 aDes.Delete( i, 1 ); |
|
1410 aDes.Insert( i, KReplace1 ); |
|
1411 break; |
|
1412 case '<': |
|
1413 aDes.Delete( i, 1 ); |
|
1414 aDes.Insert( i, KReplace2 ); |
|
1415 break; |
|
1416 case '>': |
|
1417 aDes.Delete( i, 1 ); |
|
1418 aDes.Insert( i, KReplace3 ); |
|
1419 break; |
|
1420 case '"': |
|
1421 aDes.Delete( i, 1 ); |
|
1422 aDes.Insert( i, KReplace4 ); |
|
1423 break; |
|
1424 case '\'': |
|
1425 aDes.Delete( i, 1 ); |
|
1426 aDes.Insert( i, KReplace5 ); |
|
1427 break; |
|
1428 default: |
|
1429 break; |
|
1430 } |
|
1431 } |
|
1432 } |
|
1433 |
|
1434 // ----------------------------------------------------------------------------- |
|
1435 // CSConFsHandler::IsExludedPath() |
|
1436 // Some folders are exluded from user access |
|
1437 // ----------------------------------------------------------------------------- |
|
1438 // |
|
1439 TBool CSConFsHandler::IsExludedPath( const TDesC& aFullPath ) const |
|
1440 { |
|
1441 TInt exluded(ETrue); |
|
1442 LOGGER_WRITE_1( "aFullPath: %S", &aFullPath ); |
|
1443 TPath mmcRoot( PathInfo::MemoryCardRootPath() ); |
|
1444 if ( aFullPath.Length() == KDriveLength ) |
|
1445 { |
|
1446 // root paths not exluded |
|
1447 exluded = EFalse; |
|
1448 } |
|
1449 else if ( aFullPath.FindF( K_C_ROOT ) == 0 ) |
|
1450 { |
|
1451 if ( aFullPath.FindF( PathInfo::PhoneMemoryRootPath() ) == 0 ) |
|
1452 { |
|
1453 // C:\\Data is visible, not exluded |
|
1454 exluded = EFalse; |
|
1455 } |
|
1456 else { |
|
1457 // other paths on C-drive are exluded |
|
1458 LOGGER_WRITE_1("CSConFsHandler::IsExludedPath() Path '%S' is not visible to user", &aFullPath); |
|
1459 exluded = ETrue; |
|
1460 } |
|
1461 } |
|
1462 // hide undesired folders from E: root level |
|
1463 else if( aFullPath.CompareF( mmcRoot ) == 0 ) |
|
1464 { |
|
1465 if ( aFullPath.FindF( KSConSys ) == KDriveLength ) |
|
1466 { |
|
1467 LOGGER_WRITE( "hiding mmcRoot KSConSys" ); |
|
1468 exluded = ETrue; |
|
1469 } |
|
1470 else if( aFullPath.FindF( KSConResource ) == KDriveLength ) |
|
1471 { |
|
1472 LOGGER_WRITE( "hiding mmcRoot KSConResource" ); |
|
1473 exluded = ETrue; |
|
1474 } |
|
1475 else if( aFullPath.FindF( KSConPrivate ) == KDriveLength ) |
|
1476 { |
|
1477 LOGGER_WRITE( "mmcRoot KSConPrivate" ); |
|
1478 exluded = ETrue; |
|
1479 } |
|
1480 else if( aFullPath.FindF( KSConSystem ) == KDriveLength ) |
|
1481 { |
|
1482 LOGGER_WRITE( "hiding mmcRoot KSConSystem" ); |
|
1483 exluded = ETrue; |
|
1484 } |
|
1485 } |
|
1486 // end of E: root level handling |
|
1487 else |
|
1488 { |
|
1489 // don't exlude paths from other drives |
|
1490 exluded = EFalse; |
|
1491 } |
|
1492 return exluded; |
|
1493 } |
|
1494 |
|
1495 // End of file |
|
1496 |
|
1497 |
|