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