123 // |
129 // |
124 void CFileSaver::OpenStoreL() |
130 void CFileSaver::OpenStoreL() |
125 { |
131 { |
126 CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") )); |
132 CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") )); |
127 __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) ); |
133 __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) ); |
128 |
134 |
129 // Store (temp file) is not opened now. |
135 // Store (temp file) is not opened now. |
130 // Opening is deferred until first data chunk arrives. |
136 // Opening is deferred until first data chunk arrives. |
131 |
137 |
132 TInt err = iFile.Open( iFs, |
138 TInt err = iFile.Open( iFs, |
133 iFname, |
139 iFname, |
134 EFileShareAny | |
140 EFileShareAny | |
135 EFileStream | |
141 EFileStream | |
136 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF |
142 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF |
137 EFileWrite | |
143 EFileWrite | |
138 EFileWriteDirectIO ); |
144 EFileWriteDirectIO ); |
139 #else |
145 #else |
140 EFileWrite ); |
146 EFileWrite ); |
141 #endif |
147 #endif |
142 |
148 |
143 if(err == KErrNotFound) |
149 if(err == KErrNotFound) |
144 { |
150 { |
145 err = iFile.Replace( iFs, |
151 err = iFile.Replace( iFs, |
146 iFname, |
152 iFname, |
147 EFileShareAny | |
153 EFileShareAny | |
148 EFileStream | |
154 EFileStream | |
149 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF |
155 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF |
150 EFileWrite | |
156 EFileWrite | |
151 EFileWriteDirectIO ); |
157 EFileWriteDirectIO ); |
152 #else |
158 #else |
153 EFileWrite ); |
159 EFileWrite ); |
154 #endif |
160 #endif |
155 |
161 |
156 } |
162 } |
157 |
163 |
158 if( !err ) |
164 if( !err ) |
159 { |
165 { |
320 CFileMan* file=CFileMan::NewL(fs); |
326 CFileMan* file=CFileMan::NewL(fs); |
321 CleanupStack::PushL(file); |
327 CleanupStack::PushL(file); |
322 TInt error = fs.MkDirAll(filenamePtr); |
328 TInt error = fs.MkDirAll(filenamePtr); |
323 if (error!=KErrNone && error!=KErrAlreadyExists) |
329 if (error!=KErrNone && error!=KErrAlreadyExists) |
324 { |
330 { |
325 User::Leave(error); |
331 User::Leave(error); |
326 } |
332 } |
327 |
333 |
328 // Find a unique name to avoid any conflict. |
334 // Find a unique name to avoid any conflict. |
329 // Here iFname has full path of current location of file |
335 // Here iFname has full path of current location of file |
330 // and filename has destination path. |
336 // and filename has destination path. |
331 FindUniqueDestinationFileNameL( iFname, filename ); |
337 FindUniqueDestinationFileNameL( iFname, filename ); |
332 |
338 |
333 filenamePtr = filename->Des(); |
339 filenamePtr = filename->Des(); |
334 |
340 |
335 err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
341 err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
336 |
342 |
337 if(err != KErrNone) |
343 if(err != KErrNone) |
338 { |
344 { |
339 User::Leave(err); |
345 User::Leave(err); |
340 } |
346 } |
341 |
347 |
342 iFname = filenamePtr; |
348 iFname = filenamePtr; |
343 NotifyMediaGalleryL( filenamePtr ); |
349 NotifyMediaGalleryL( filenamePtr ); |
344 CleanupStack::PopAndDestroy(file); |
350 CleanupStack::PopAndDestroy(file); |
345 CleanupStack::PopAndDestroy(&fs); |
351 CleanupStack::PopAndDestroy(&fs); |
346 CleanupStack::PopAndDestroy(filename); |
352 CleanupStack::PopAndDestroy(filename); |
347 #else |
353 #else |
348 RFs fs; |
354 RFs fs; |
349 User::LeaveIfError( fs.Connect() ); |
355 User::LeaveIfError( fs.Connect() ); |
350 CleanupClosePushL(fs); |
356 CleanupClosePushL(fs); |
351 CFileMan* file=CFileMan::NewL(fs); |
357 CFileMan* file=CFileMan::NewL(fs); |
352 CleanupStack::PushL(file); |
358 CleanupStack::PushL(file); |
353 |
359 |
354 |
360 |
355 for( TInt i = 1; i <= aData.Count() ; ++i ) |
361 for( TInt i = 1; i <= aData.Count() ; ++i ) |
356 { |
362 { |
357 HBufC* filename = HBufC::NewLC(KMaxFileName); |
363 HBufC* filename = HBufC::NewLC(KMaxFileName); |
358 TPtr filenamePtr = filename->Des(); |
364 TPtr filenamePtr = filename->Des(); |
359 filenamePtr = (*aData[i]).iRootPath; |
365 filenamePtr = (*aData[i]).iRootPath; |
360 |
366 |
361 filenamePtr.Append(_L("download\\")); |
367 filenamePtr.Append(_L("download\\")); |
362 TInt error = fs.MkDirAll(filenamePtr); |
368 TInt error = fs.MkDirAll(filenamePtr); |
363 if (error!=KErrNone && error!=KErrAlreadyExists) |
369 if (error!=KErrNone && error!=KErrAlreadyExists) |
364 { |
370 { |
365 User::Leave(error); |
371 User::Leave(error); |
366 } |
372 } |
367 iFname = (*aData[i]).iFullName->Des(); |
373 iFname = (*aData[i]).iFullName->Des(); |
368 |
374 |
369 // Find a unique name to avoid any conflict. |
375 // Find a unique name to avoid any conflict. |
370 // Here iFname has full path of current location of file |
376 // Here iFname has full path of current location of file |
371 // and filename has destination path. |
377 // and filename has destination path. |
372 FindUniqueDestinationFileNameL( iFname, filename ); |
378 FindUniqueDestinationFileNameL( iFname, filename ); |
373 |
379 |
374 filenamePtr = filename->Des(); |
380 filenamePtr = filename->Des(); |
375 TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
381 TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
376 if(err != KErrNone) |
382 if(err != KErrNone) |
377 { |
383 { |
378 User::LeaveIfError(err); |
384 User::LeaveIfError(err); |
379 } |
385 } |
380 iFname = filenamePtr; |
386 iFname = filenamePtr; |
381 NotifyMediaGalleryL( filenamePtr ); |
387 NotifyMediaGalleryL( filenamePtr ); |
382 |
388 |
383 (*aData[i]).iFileName = iFname; |
389 (*aData[i]).iFileName = iFname; |
384 (*aData[i]).iFullName = NameL(); |
390 (*aData[i]).iFullName = NameL(); |
385 CleanupStack::PopAndDestroy(filename); |
391 CleanupStack::PopAndDestroy(filename); |
431 CFileMan* file=CFileMan::NewL(fs); |
437 CFileMan* file=CFileMan::NewL(fs); |
432 CleanupStack::PushL(file); |
438 CleanupStack::PushL(file); |
433 TInt error = fs.MkDirAll(filenamePtr); |
439 TInt error = fs.MkDirAll(filenamePtr); |
434 if (error!=KErrNone && error!=KErrAlreadyExists) |
440 if (error!=KErrNone && error!=KErrAlreadyExists) |
435 { |
441 { |
436 User::Leave(error); |
442 User::Leave(error); |
437 } |
443 } |
438 |
444 |
439 // Find a unique name to avoid any conflict. |
445 // Find a unique name to avoid any conflict. |
440 // Here iFname has full path of current location of file |
446 // Here iFname has full path of current location of file |
441 // and filename has destination path. |
447 // and filename has destination path. |
442 FindUniqueDestinationFileNameL( iFname, filename ); |
448 FindUniqueDestinationFileNameL( iFname, filename ); |
443 |
449 |
444 filenamePtr = filename->Des(); |
450 filenamePtr = filename->Des(); |
445 |
451 |
446 err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
452 err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
447 |
453 |
448 if(err != KErrNone) |
454 if(err != KErrNone) |
449 { |
455 { |
450 User::Leave(err); |
456 User::Leave(err); |
451 } |
457 } |
452 |
458 |
453 iFname = filenamePtr; |
459 iFname = filenamePtr; |
454 NotifyMediaGalleryL( filenamePtr ); |
460 NotifyMediaGalleryL( filenamePtr ); |
455 CleanupStack::PopAndDestroy(file); |
461 CleanupStack::PopAndDestroy(file); |
456 CleanupStack::PopAndDestroy(&fs); |
462 CleanupStack::PopAndDestroy(&fs); |
457 CleanupStack::PopAndDestroy(filename); |
463 CleanupStack::PopAndDestroy(filename); |
458 #else |
464 #else |
459 RFs fs; |
465 RFs fs; |
467 CFileMan* file=CFileMan::NewL(fs); |
473 CFileMan* file=CFileMan::NewL(fs); |
468 CleanupStack::PushL(file); |
474 CleanupStack::PushL(file); |
469 TInt error = fs.MkDirAll(filenamePtr); |
475 TInt error = fs.MkDirAll(filenamePtr); |
470 if (error!=KErrNone && error!=KErrAlreadyExists) |
476 if (error!=KErrNone && error!=KErrAlreadyExists) |
471 { |
477 { |
472 User::Leave(error); |
478 User::Leave(error); |
473 } |
479 } |
474 |
480 |
475 // Find a unique name to avoid any conflict. |
481 // Find a unique name to avoid any conflict. |
476 // Here iFname has full path of current location of file |
482 // Here iFname has full path of current location of file |
477 // and filename has destination path. |
483 // and filename has destination path. |
478 FindUniqueDestinationFileNameL( iFname, filename ); |
484 FindUniqueDestinationFileNameL( iFname, filename ); |
479 |
485 |
480 filenamePtr = filename->Des(); |
486 filenamePtr = filename->Des(); |
481 TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
487 TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite); |
482 |
488 |
483 if(err != KErrNone) |
489 if(err != KErrNone) |
484 { |
490 { |
485 User::Leave(err); |
491 User::Leave(err); |
486 } |
492 } |
487 iFname = filenamePtr; |
493 iFname = filenamePtr; |
488 NotifyMediaGalleryL( filenamePtr ); |
494 NotifyMediaGalleryL( filenamePtr ); |
489 CleanupStack::PopAndDestroy(file); |
495 CleanupStack::PopAndDestroy(file); |
490 CleanupStack::PopAndDestroy(&fs); |
496 CleanupStack::PopAndDestroy(&fs); |
491 CleanupStack::PopAndDestroy(filename); |
497 CleanupStack::PopAndDestroy(filename); |
492 #endif // RD_MULTIPLE_DRIVE |
498 #endif // RD_MULTIPLE_DRIVE |
576 } |
582 } |
577 iState = EInit; |
583 iState = EInit; |
578 CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") )); |
584 CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") )); |
579 } |
585 } |
580 |
586 |
581 |
587 |
582 // --------------------------------------------------------- |
588 // --------------------------------------------------------- |
583 // CFileSaver::UpdateDCFRepositoryL() |
589 // CFileSaver::UpdateDCFRepositoryL() |
584 // Update saved file to DCFRepository |
590 // Update saved file to DCFRepository |
585 // --------------------------------------------------------- |
591 // --------------------------------------------------------- |
586 // |
592 // |
587 void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName ) |
593 void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName ) |
588 { |
594 { |
589 CDcfEntry* dcfEntry = NULL; |
595 CDcfEntry* dcfEntry = NULL; |
590 dcfEntry = CDcfEntry::NewL(); |
596 dcfEntry = CDcfEntry::NewL(); |
591 CleanupStack::PushL( dcfEntry ); |
597 CleanupStack::PushL( dcfEntry ); |
592 |
598 |
593 CDcfRep* dcfRep = NULL; |
599 CDcfRep* dcfRep = NULL; |
594 dcfRep = CDcfRep::NewL(); |
600 dcfRep = CDcfRep::NewL(); |
595 CleanupStack::PushL( dcfRep ); |
601 CleanupStack::PushL( dcfRep ); |
596 |
602 |
597 dcfEntry->SetLocationL( aFileName, 0 ); |
603 dcfEntry->SetLocationL( aFileName, 0 ); |
598 dcfRep->UpdateL( dcfEntry ); |
604 dcfRep->UpdateL( dcfEntry ); |
599 CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep |
605 CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep |
600 } |
606 } |
601 |
607 |
602 // --------------------------------------------------------- |
608 // --------------------------------------------------------- |
603 // CFileSaver::UpdateMediaGalleryIfNeededL() |
609 // CFileSaver::UpdateMediaGalleryIfNeededL() |
604 // Calls MediaGallery Update method so that media gallery |
610 // Calls MediaGallery Update method so that media gallery |
605 // knows update its view. |
611 // knows update its view. |
606 // --------------------------------------------------------- |
612 // --------------------------------------------------------- |
607 // |
613 // |
608 |
614 |
609 |
615 |
610 void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName ) |
616 void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName ) |
611 { |
617 { |
612 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF |
618 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF |
613 CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs ); |
619 CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs ); |
614 CleanupStack::PushL(fm); |
620 CleanupStack::PushL(fm); |
615 fm->UpdateL(aFileName); |
621 fm->UpdateL(aFileName); |
616 CleanupStack::PopAndDestroy(); // fm |
622 CleanupStack::PopAndDestroy(); // fm |
617 #endif |
623 #endif |
618 } |
624 } |
619 // --------------------------------------------------------- |
625 // --------------------------------------------------------- |
620 // CFileSaver::NotifyMediaGalleryL() |
626 // CFileSaver::NotifyMediaGalleryL() |
621 // Notify media gallery about the new file. |
627 // Notify media gallery about the new file. |
622 // --------------------------------------------------------- |
628 // --------------------------------------------------------- |
623 // |
629 // |
624 void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName ) |
630 void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName ) |
625 { |
631 { |
626 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF |
632 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF |
627 |
633 |
628 CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs ); |
634 CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs ); |
629 CleanupStack::PushL( mgFileManager ); |
635 CleanupStack::PushL( mgFileManager ); |
630 |
636 |
631 TRAP_IGNORE( mgFileManager->UpdateL() ); |
637 TRAP_IGNORE( mgFileManager->UpdateL() ); |
632 CleanupStack::PopAndDestroy( mgFileManager ); |
638 CleanupStack::PopAndDestroy( mgFileManager ); |
633 |
639 |
634 // Notify Media Gallery |
640 // Notify Media Gallery |
635 TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) ); |
641 TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) ); |
636 |
642 |
637 #endif |
643 #endif |
638 |
644 |
639 |
645 |
640 // Notify DCF repository |
646 // Notify DCF repository |
641 TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) ); |
647 TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) ); |
642 } |
648 } |
643 // --------------------------------------------------------- |
649 // --------------------------------------------------------- |
644 // CFileSaver::DownloadedFileSize() |
650 // CFileSaver::DownloadedFileSize() |
647 TInt CFileSaver::DownloadedFileSize() |
653 TInt CFileSaver::DownloadedFileSize() |
648 { |
654 { |
649 // check how many bytes are already persisted |
655 // check how many bytes are already persisted |
650 TInt DownloadedSize(0); |
656 TInt DownloadedSize(0); |
651 TInt err = iFile.Size( (TInt&)DownloadedSize ); |
657 TInt err = iFile.Size( (TInt&)DownloadedSize ); |
652 |
658 |
653 CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize Downloaded size = %d error = %d"), \ |
659 CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize Downloaded size = %d error = %d"), \ |
654 DownloadedSize,err )); |
660 DownloadedSize,err )); |
655 |
661 |
656 if(err != KErrNone) |
662 if(err != KErrNone) |
657 return err; |
663 return err; |
658 return DownloadedSize; |
664 return DownloadedSize; |
659 } |
665 } |
660 |
666 |
661 |
667 |
662 /** |
668 /** |
663 * Discard the old contents |
669 * Discard the old contents |
664 */ |
670 */ |
665 void CFileSaver::ResetL() |
671 void CFileSaver::ResetL() |
666 { |
672 { |
667 |
673 |
668 |
674 |
669 iFile.Close(); |
675 iFile.Close(); |
670 |
676 |
671 User::LeaveIfError( iFile.Replace( iFs, |
677 User::LeaveIfError( iFile.Replace( iFs, |
672 iFname, |
678 iFname, |
673 EFileShareAny | |
679 EFileShareAny | |
674 EFileStream | |
680 EFileStream | |
675 EFileWrite ) ); |
681 EFileWrite ) ); |
676 } |
682 } |
677 |
683 |
678 |
684 |
679 // ----------------------------------------------------------------------------- |
685 // ----------------------------------------------------------------------------- |