codhandler/codeng/src/FileSaver.cpp
changeset 65 5bfc169077b2
parent 37 cb62a4f66ebe
equal deleted inserted replaced
42:d39add9822e2 65:5bfc169077b2
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description: 
    14 * Description:
    15 *      Implementation of class CFileSaver.   
    15 *      Implementation of class CFileSaver.
    16 *      
    16 *
    17 *
    17 *
    18 */
    18 */
    19 
    19 
       
    20 
    20 // INCLUDE FILES
    21 // INCLUDE FILES
    21 #include <browser_platform_variant.hrh>
    22 //#include <platform/mw/Browser_platform_variant.hrh>
       
    23 #include <Browser_platform_variant.hrh>
    22 #include "FileSaver.h"
    24 #include "FileSaver.h"
    23 #include "CodBuffStorage.h"
    25 #include "CodBuffStorage.h"
    24 #include "CodLoadObserver.h"
    26 #include "CodLoadObserver.h"
    25 #include "RFeatMgr.h"
    27 #include "RFeatMgr.h"
    26 #include "CodUtil.h"
    28 #include "CodUtil.h"
    29 #include "CodPanic.h"
    31 #include "CodPanic.h"
    30 #include "DrmHandler.h"
    32 #include "DrmHandler.h"
    31 #include "CodData.h"
    33 #include "CodData.h"
    32 
    34 
    33 #include <f32file.h>
    35 #include <f32file.h>
    34 #include <httpdownloadmgrcommon.h>
    36 #include <HttpDownloadMgrCommon.h>
    35 #include <DocumentHandler.h>
    37 #include <DocumentHandler.h>
    36 #include <pathinfo.h>
    38 #include <pathinfo.h>
       
    39 
       
    40 // following one line is temporary: AVKON dependency removal
       
    41 #undef BRDO_APP_GALLERY_SUPPORTED_FF
    37 
    42 
    38 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    43 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    39 #include <MGXFileManagerFactory.h>
    44 #include <MGXFileManagerFactory.h>
    40 #include <CMGXFileManager.h>
    45 #include <CMGXFileManager.h>
    41 #endif
    46 #endif
    43 #include <DcfEntry.h>
    48 #include <DcfEntry.h>
    44 #include <DcfRep.h>
    49 #include <DcfRep.h>
    45 
    50 
    46 const TInt KDefaultStorageBufferSize = 128 * 1024;
    51 const TInt KDefaultStorageBufferSize = 128 * 1024;
    47 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
    52 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
       
    53 
    48 
    54 
    49 // ================= MEMBER FUNCTIONS =======================
    55 // ================= MEMBER FUNCTIONS =======================
    50 
    56 
    51 // ---------------------------------------------------------
    57 // ---------------------------------------------------------
    52 // CFileSaver::NewL()
    58 // CFileSaver::NewL()
    76 void CFileSaver::ConstructL()
    82 void CFileSaver::ConstructL()
    77     {
    83     {
    78     CCodSaver::ConstructL();
    84     CCodSaver::ConstructL();
    79     iBufferSize =  KDefaultStorageBufferSize ;
    85     iBufferSize =  KDefaultStorageBufferSize ;
    80     iProgressiveDownload = EFalse ;
    86     iProgressiveDownload = EFalse ;
    81     
    87 
    82     iStorage = CCodBuffStorage::NewL(this);
    88     iStorage = CCodBuffStorage::NewL(this);
    83     }
    89     }
    84 
    90 
    85 // ---------------------------------------------------------
    91 // ---------------------------------------------------------
    86 // CFileSaver::CFileSaver()
    92 // CFileSaver::CFileSaver()
   102   iRootPath( aRootPath ),
   108   iRootPath( aRootPath ),
   103   iFname( aFname)
   109   iFname( aFname)
   104     {
   110     {
   105     CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
   111     CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
   106     }
   112     }
   107   
   113 
   108 // ---------------------------------------------------------
   114 // ---------------------------------------------------------
   109 // CFileSaver::~CFileSaver()
   115 // CFileSaver::~CFileSaver()
   110 // ---------------------------------------------------------
   116 // ---------------------------------------------------------
   111 //
   117 //
   112 CFileSaver::~CFileSaver()
   118 CFileSaver::~CFileSaver()
   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         {
   161         iFile.Seek( ESeekEnd, pos );
   167         iFile.Seek( ESeekEnd, pos );
   162         }
   168         }
   163     iSize = 0;
   169     iSize = 0;
   164     iState = EStoreOpen;
   170     iState = EStoreOpen;
   165     }
   171     }
   166     
   172 
   167 // ---------------------------------------------------------
   173 // ---------------------------------------------------------
   168 // CFileSaver::AppendData()
   174 // CFileSaver::AppendData()
   169 // ---------------------------------------------------------
   175 // ---------------------------------------------------------
   170 //
   176 //
   171 TInt CFileSaver::AppendData( const TDesC8& aData )
   177 TInt CFileSaver::AppendData( const TDesC8& aData )
   181 
   187 
   182         /*if( !iPausable )
   188         /*if( !iPausable )
   183             {
   189             {
   184             // nothing persisted yet. If there's a file with the same name,
   190             // nothing persisted yet. If there's a file with the same name,
   185             // delete it.
   191             // delete it.
   186             err = iFile.Replace( iFs, 
   192             err = iFile.Replace( iFs,
   187                                    iFname, 
   193                                    iFname,
   188                                    EFileShareAny | 
   194                                    EFileShareAny |
   189                                    EFileStream | 
   195                                    EFileStream |
   190                                    EFileWrite );
   196                                    EFileWrite );
   191             }
   197             }
   192         else*/
   198         else*/
   193 
   199 
   194         }
   200         }
   195     if ( !err )
   201     if ( !err )
   196         {
   202         {
   197         err = iStorage->WriteOutNextBodyDataL(aData );
   203         err = iStorage->WriteOutNextBodyDataL(aData );
   198         }
   204         }
   199     
   205 
   200     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
   206     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
   201     return err;
   207     return err;
   202     }
   208     }
   203 
   209 
   204 // ---------------------------------------------------------
   210 // ---------------------------------------------------------
   242     // The transport size may also be different, if compression or some
   248     // The transport size may also be different, if compression or some
   243     // packaging format is used."
   249     // packaging format is used."
   244     //
   250     //
   245     // There is a safety upper bound on the transaction size, that is already
   251     // There is a safety upper bound on the transaction size, that is already
   246     // applied. See SetMaxSize().
   252     // applied. See SetMaxSize().
   247     
   253 
   248     TDataType drm( KOma1DrmMessageContentType );
   254     TDataType drm( KOma1DrmMessageContentType );
   249     TDataType dcf( KOma1DcfContentType );
   255     TDataType dcf( KOma1DcfContentType );
   250 
   256 
   251     if ( iType == drm )
   257     if ( iType == drm )
   252         {
   258         {
   306 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   312 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   307    In this case leave and go to the next state.
   313    In this case leave and go to the next state.
   308 */
   314 */
   309     if (!aAttached)
   315     if (!aAttached)
   310 	    {
   316 	    {
   311 #if 0 
   317 #if 0
   312         RFs fs;
   318         RFs fs;
   313         TInt err( KErrNone );
   319         TInt err( KErrNone );
   314         HBufC* filename = HBufC::NewLC(KMaxFileName);
   320         HBufC* filename = HBufC::NewLC(KMaxFileName);
   315         TPtr filenamePtr = filename->Des();
   321         TPtr filenamePtr = filename->Des();
   316         filenamePtr = iRootPath;
   322         filenamePtr = iRootPath;
   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);
   417 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   423 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   418    In this case leave and go to the next state.
   424    In this case leave and go to the next state.
   419 */
   425 */
   420     if (!aAttached)
   426     if (!aAttached)
   421 	    {
   427 	    {
   422 #ifdef RD_MULTIPLE_DRIVE 
   428 #ifdef RD_MULTIPLE_DRIVE
   423         RFs fs;
   429         RFs fs;
   424         TInt err( KErrNone );
   430         TInt err( KErrNone );
   425         HBufC* filename = HBufC::NewLC(KMaxFileName);
   431         HBufC* filename = HBufC::NewLC(KMaxFileName);
   426         TPtr filenamePtr = filename->Des();
   432         TPtr filenamePtr = filename->Des();
   427         filenamePtr = iRootPath;
   433         filenamePtr = iRootPath;
   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
   552     CLOG(( ECodEng, 2, _L("-> CFileSaver::Cleanup") ));
   558     CLOG(( ECodEng, 2, _L("-> CFileSaver::Cleanup") ));
   553     // Clean up the temporary file, ignore errors.
   559     // Clean up the temporary file, ignore errors.
   554     // Expected error: KErrNotFound (if there is no temp file).
   560     // Expected error: KErrNotFound (if there is no temp file).
   555     // Unexpected error: all the rest -> nothing we can do with them.
   561     // Unexpected error: all the rest -> nothing we can do with them.
   556     CloseStore();
   562     CloseStore();
   557     
   563 
   558 	if( aDeleteFile )
   564 	if( aDeleteFile )
   559 	    {
   565 	    {
   560 #ifdef __TEST_COD_LOG
   566 #ifdef __TEST_COD_LOG
   561         TInt err =  // ('Log-only' variable.)
   567         TInt err =  // ('Log-only' variable.)
   562 #endif /* def __TEST_COD_LOG */
   568 #endif /* def __TEST_COD_LOG */
   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 // -----------------------------------------------------------------------------
   685     iProgressiveDownload = aValue;
   691     iProgressiveDownload = aValue;
   686     if( iProgressiveDownload )
   692     if( iProgressiveDownload )
   687         {
   693         {
   688         iBufferSize = KDefaultStorageBufferSizePD;
   694         iBufferSize = KDefaultStorageBufferSizePD;
   689         }
   695         }
   690     
   696 
   691     
   697 
   692     if( iBufferSize != iStorage->CurrentBufferSize())
   698     if( iBufferSize != iStorage->CurrentBufferSize())
   693         {
   699         {
   694         FlushL();
   700         FlushL();
   695         }
   701         }
   696 
   702 
   697     if ( iFile.SubSessionHandle() )
   703     if ( iFile.SubSessionHandle() )
   698         {
   704         {
   699      	
   705 
   700         if( iProgressiveDownload )
   706         if( iProgressiveDownload )
   701             {
   707             {
   702             if( iLength != KDefaultContentLength )    
   708             if( iLength != KDefaultContentLength )
   703                 {
   709                 {
   704                 iFile.SetSize( iLength );
   710                 iFile.SetSize( iLength );
   705                 }
   711                 }
   706             }
   712             }
   707         else
   713         else
   733 // Called if download completed.
   739 // Called if download completed.
   734 // -----------------------------------------------------------------------------
   740 // -----------------------------------------------------------------------------
   735 //
   741 //
   736 void CFileSaver::OnComplete()
   742 void CFileSaver::OnComplete()
   737     {
   743     {
   738     CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));    
   744     CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));
   739     FlushL();
   745     FlushL();
   740     iStorage->ClearErrors();
   746     iStorage->ClearErrors();
   741     iFile.Close();
   747     iFile.Close();
   742     CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));     
   748     CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));
   743     }
   749     }
   744 
   750 
   745 
   751 
   746 
   752 
   747 
   753