codhandler/codeng/src/FileSaver.cpp
branchRCL_3
changeset 94 919f36ff910f
parent 93 79859ed3eea9
equal deleted inserted replaced
93:79859ed3eea9 94:919f36ff910f
     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 
       
    21 // INCLUDE FILES
    20 // INCLUDE FILES
    22 //#include <platform/mw/Browser_platform_variant.hrh>
    21 #include <browser_platform_variant.hrh>
    23 #include <Browser_platform_variant.hrh>
       
    24 #include "FileSaver.h"
    22 #include "FileSaver.h"
    25 #include "CodBuffStorage.h"
    23 #include "CodBuffStorage.h"
    26 #include "CodLoadObserver.h"
    24 #include "CodLoadObserver.h"
    27 #include "RFeatMgr.h"
    25 #include "RFeatMgr.h"
    28 #include "CodUtil.h"
    26 #include "CodUtil.h"
    31 #include "CodPanic.h"
    29 #include "CodPanic.h"
    32 #include "DrmHandler.h"
    30 #include "DrmHandler.h"
    33 #include "CodData.h"
    31 #include "CodData.h"
    34 
    32 
    35 #include <f32file.h>
    33 #include <f32file.h>
    36 #include <HttpDownloadMgrCommon.h>
    34 #include <httpdownloadmgrcommon.h>
    37 #include <DocumentHandler.h>
    35 #include <DocumentHandler.h>
    38 #include <pathinfo.h>
    36 #include <pathinfo.h>
    39 
       
    40 // following one line is temporary: AVKON dependency removal
       
    41 #undef BRDO_APP_GALLERY_SUPPORTED_FF
       
    42 
    37 
    43 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    38 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
    44 #include <MGXFileManagerFactory.h>
    39 #include <MGXFileManagerFactory.h>
    45 #include <CMGXFileManager.h>
    40 #include <CMGXFileManager.h>
    46 #endif
    41 #endif
    47 
    42 
    48 #include <DcfEntry.h>
    43 #include <DcfEntry.h>
    49 #include <DcfRep.h>
    44 #include <DcfRep.h>
       
    45 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
    46 #include <DownloadPathHandler.h>
       
    47 #endif
    50 
    48 
    51 const TInt KDefaultStorageBufferSize = 128 * 1024;
    49 const TInt KDefaultStorageBufferSize = 128 * 1024;
    52 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
    50 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
    53 
       
    54 
    51 
    55 // ================= MEMBER FUNCTIONS =======================
    52 // ================= MEMBER FUNCTIONS =======================
    56 
    53 
    57 // ---------------------------------------------------------
    54 // ---------------------------------------------------------
    58 // CFileSaver::NewL()
    55 // CFileSaver::NewL()
    82 void CFileSaver::ConstructL()
    79 void CFileSaver::ConstructL()
    83     {
    80     {
    84     CCodSaver::ConstructL();
    81     CCodSaver::ConstructL();
    85     iBufferSize =  KDefaultStorageBufferSize ;
    82     iBufferSize =  KDefaultStorageBufferSize ;
    86     iProgressiveDownload = EFalse ;
    83     iProgressiveDownload = EFalse ;
    87 
    84     
    88     iStorage = CCodBuffStorage::NewL(this);
    85     iStorage = CCodBuffStorage::NewL(this);
    89     }
    86     }
    90 
    87 
    91 // ---------------------------------------------------------
    88 // ---------------------------------------------------------
    92 // CFileSaver::CFileSaver()
    89 // CFileSaver::CFileSaver()
   108   iRootPath( aRootPath ),
   105   iRootPath( aRootPath ),
   109   iFname( aFname)
   106   iFname( aFname)
   110     {
   107     {
   111     CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
   108     CLOG(( ECodEng, 2, _L("*** CFileSaver::CFileSaver") ));
   112     }
   109     }
   113 
   110   
   114 // ---------------------------------------------------------
   111 // ---------------------------------------------------------
   115 // CFileSaver::~CFileSaver()
   112 // CFileSaver::~CFileSaver()
   116 // ---------------------------------------------------------
   113 // ---------------------------------------------------------
   117 //
   114 //
   118 CFileSaver::~CFileSaver()
   115 CFileSaver::~CFileSaver()
   129 //
   126 //
   130 void CFileSaver::OpenStoreL()
   127 void CFileSaver::OpenStoreL()
   131     {
   128     {
   132     CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") ));
   129     CLOG(( ECodEng, 2, _L("CFileSaver::OpenStoreL") ));
   133     __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) );
   130     __ASSERT_DEBUG( iState == EInit, CodPanic( ECodInternal ) );
   134 
   131     
   135     // Store (temp file) is not opened now.
   132     // Store (temp file) is not opened now.
   136     // Opening is deferred until first data chunk arrives.
   133     // Opening is deferred until first data chunk arrives.
   137 
   134 
   138     TInt err = iFile.Open(  iFs,
   135     TInt err = iFile.Open(  iFs, 
   139                             iFname,
   136                             iFname, 
   140                             EFileShareAny |
   137                             EFileShareAny | 
   141                             EFileStream |
   138                             EFileStream | 
   142 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   139 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   143                             EFileWrite |
   140                             EFileWrite |
   144                             EFileWriteDirectIO );
   141                             EFileWriteDirectIO );
   145 #else
   142 #else                            
   146                             EFileWrite );
   143                             EFileWrite );
   147 #endif
   144 #endif                            
   148 
   145                        
   149 	if(err == KErrNotFound)
   146 	if(err == KErrNotFound)                               
   150 	    {
   147 	    {
   151         err = iFile.Replace( iFs,
   148         err = iFile.Replace( iFs, 
   152                            iFname,
   149                            iFname, 
   153                            EFileShareAny |
   150                            EFileShareAny | 
   154                            EFileStream |
   151                            EFileStream | 
   155 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   152 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
   156                                        EFileWrite |
   153                                        EFileWrite |
   157                                        EFileWriteDirectIO );
   154                                        EFileWriteDirectIO );
   158 #else
   155 #else                           
   159                            EFileWrite );
   156                            EFileWrite );
   160 #endif
   157 #endif                           
   161 
   158 
   162 	    }
   159 	    }
   163 
   160 
   164     if( !err )
   161     if( !err )
   165         {
   162         {
   167         iFile.Seek( ESeekEnd, pos );
   164         iFile.Seek( ESeekEnd, pos );
   168         }
   165         }
   169     iSize = 0;
   166     iSize = 0;
   170     iState = EStoreOpen;
   167     iState = EStoreOpen;
   171     }
   168     }
   172 
   169     
   173 // ---------------------------------------------------------
   170 // ---------------------------------------------------------
   174 // CFileSaver::AppendData()
   171 // CFileSaver::AppendData()
   175 // ---------------------------------------------------------
   172 // ---------------------------------------------------------
   176 //
   173 //
   177 TInt CFileSaver::AppendData( const TDesC8& aData )
   174 TInt CFileSaver::AppendData( const TDesC8& aData )
   187 
   184 
   188         /*if( !iPausable )
   185         /*if( !iPausable )
   189             {
   186             {
   190             // nothing persisted yet. If there's a file with the same name,
   187             // nothing persisted yet. If there's a file with the same name,
   191             // delete it.
   188             // delete it.
   192             err = iFile.Replace( iFs,
   189             err = iFile.Replace( iFs, 
   193                                    iFname,
   190                                    iFname, 
   194                                    EFileShareAny |
   191                                    EFileShareAny | 
   195                                    EFileStream |
   192                                    EFileStream | 
   196                                    EFileWrite );
   193                                    EFileWrite );
   197             }
   194             }
   198         else*/
   195         else*/
   199 
   196 
   200         }
   197         }
   201     if ( !err )
   198     if ( !err )
   202         {
   199         {
   203         err = iStorage->WriteOutNextBodyDataL(aData );
   200         err = iStorage->WriteOutNextBodyDataL(aData );
   204         }
   201         }
   205 
   202     
   206     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
   203     CLOG(( EHttpLoad, 2, _L("<- CFileSaver::AppendData returns (%d)"), err ));
   207     return err;
   204     return err;
   208     }
   205     }
   209 
   206 
   210 // ---------------------------------------------------------
   207 // ---------------------------------------------------------
   248     // The transport size may also be different, if compression or some
   245     // The transport size may also be different, if compression or some
   249     // packaging format is used."
   246     // packaging format is used."
   250     //
   247     //
   251     // There is a safety upper bound on the transaction size, that is already
   248     // There is a safety upper bound on the transaction size, that is already
   252     // applied. See SetMaxSize().
   249     // applied. See SetMaxSize().
   253 
   250     
   254     TDataType drm( KOma1DrmMessageContentType );
   251     TDataType drm( KOma1DrmMessageContentType );
   255     TDataType dcf( KOma1DcfContentType );
   252     TDataType dcf( KOma1DcfContentType );
   256 
   253 
   257     if ( iType == drm )
   254     if ( iType == drm )
   258         {
   255         {
   285             }
   282             }
   286         }
   283         }
   287     else
   284     else
   288         {
   285         {
   289         // Other than DRM stuff arrived. Proper check for MIME type.
   286         // Other than DRM stuff arrived. Proper check for MIME type.
   290         if( !(*aData[aData.ActiveDownload()]).HasType( iType.Des8() ) )
   287         if( !(*aData[aData.ActiveDownload()]).HasType( iType.Des8() ) && ! iDocHandler.CanSaveL(iType) )
   291             {
   288             {
   292             CLOG(( ECodEng, 4, _L("  mismatch") ));
   289             CLOG(( ECodEng, 4, _L("  mismatch") ));
   293             User::Leave( KErrCodAttributeMismatch );
   290             User::Leave( KErrCodAttributeMismatch );
   294             }
   291             }
   295         }
   292         }
   312 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   309 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   313    In this case leave and go to the next state.
   310    In this case leave and go to the next state.
   314 */
   311 */
   315     if (!aAttached)
   312     if (!aAttached)
   316 	    {
   313 	    {
   317 #if 0
   314 #if 0 
   318         RFs fs;
   315         RFs fs;
   319         TInt err( KErrNone );
   316         TInt err( KErrNone );
   320         HBufC* filename = HBufC::NewLC(KMaxFileName);
   317         HBufC* filename = HBufC::NewLC(KMaxFileName);
   321         TPtr filenamePtr = filename->Des();
   318         TPtr filenamePtr = filename->Des();
   322         filenamePtr = iRootPath;
   319         filenamePtr = iRootPath;
   326         CFileMan* file=CFileMan::NewL(fs);
   323         CFileMan* file=CFileMan::NewL(fs);
   327         CleanupStack::PushL(file);
   324         CleanupStack::PushL(file);
   328         TInt error = fs.MkDirAll(filenamePtr);
   325         TInt error = fs.MkDirAll(filenamePtr);
   329         if (error!=KErrNone && error!=KErrAlreadyExists)
   326         if (error!=KErrNone && error!=KErrAlreadyExists)
   330            {
   327            {
   331             User::Leave(error);
   328             User::Leave(error);   
   332            }
   329            }
   333 
   330    
   334         // Find a unique name to avoid any conflict.
   331         // Find a unique name to avoid any conflict.
   335         // Here iFname has full path of current location of file
   332         // Here iFname has full path of current location of file
   336         // and filename has destination path.
   333         // and filename has destination path.
   337         FindUniqueDestinationFileNameL( iFname, filename );
   334         FindUniqueDestinationFileNameL( iFname, filename );
   338 
   335         
   339         filenamePtr = filename->Des();
   336         filenamePtr = filename->Des();     
   340 
   337                
   341         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   338         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   342 
   339     
   343         if(err != KErrNone)
   340         if(err != KErrNone)
   344            {
   341            {
   345            User::Leave(err);
   342            User::Leave(err);
   346            }
   343            }
   347 
   344        
   348         iFname = filenamePtr;
   345         iFname = filenamePtr;              
   349         NotifyMediaGalleryL( filenamePtr );
   346         NotifyMediaGalleryL( filenamePtr );        
   350         CleanupStack::PopAndDestroy(file);
   347         CleanupStack::PopAndDestroy(file);
   351         CleanupStack::PopAndDestroy(&fs);
   348         CleanupStack::PopAndDestroy(&fs);
   352         CleanupStack::PopAndDestroy(filename);
   349         CleanupStack::PopAndDestroy(filename);
   353 #else
   350 #else
   354         RFs fs;
   351         RFs fs;
   355         User::LeaveIfError( fs.Connect() );
   352         User::LeaveIfError( fs.Connect() );
   356         CleanupClosePushL(fs);
   353         CleanupClosePushL(fs);
   357         CFileMan* file=CFileMan::NewL(fs);
   354         CFileMan* file=CFileMan::NewL(fs);
   358         CleanupStack::PushL(file);
   355         CleanupStack::PushL(file);
   359 
   356 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
   360 
   357         CDownloadPathHandler* downloadPathPlugin = NULL;
       
   358 
       
   359         if ( aData.Count() )
       
   360             {
       
   361             // Get the mime type of the first media object
       
   362             TPtrC8 mimeType = (*aData[1]).Type();
       
   363             downloadPathPlugin = GetDownloadPathPluginInstanceL( mimeType );
       
   364 
       
   365             if( downloadPathPlugin )
       
   366                 {
       
   367                 CleanupStack::PushL( downloadPathPlugin );
       
   368                 }
       
   369             }
       
   370 #endif
   361         for( TInt i = 1; i <= aData.Count() ; ++i )
   371         for( TInt i = 1; i <= aData.Count() ; ++i )
   362             {
   372             {
   363             HBufC* filename = HBufC::NewLC(KMaxFileName);
   373             HBufC* filename = HBufC::NewLC(KMaxFileName);
   364             TPtr filenamePtr = filename->Des();
   374             TPtr filenamePtr = filename->Des();
   365             filenamePtr = (*aData[i]).iRootPath;
   375             filenamePtr = (*aData[i]).iRootPath;
   366 
   376             
   367             filenamePtr.Append(_L("download\\"));
   377 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   378             if( downloadPathPlugin )
       
   379                 {
       
   380                 TFileName iTempFlName = (*aData[i]).iFullName->Des();
       
   381                 GetUpdatedPathFromPluginL( downloadPathPlugin,iTempFlName, filenamePtr );
       
   382                 }
       
   383             else
       
   384                 {
       
   385                 filenamePtr.Append( _L( "download\\" ) );
       
   386                 }
       
   387 #else
       
   388             filenamePtr.Append( _L( "download\\" ) );
       
   389                 
       
   390 #endif
       
   391             
   368             TInt error = fs.MkDirAll(filenamePtr);
   392             TInt error = fs.MkDirAll(filenamePtr);
   369             if (error!=KErrNone && error!=KErrAlreadyExists)
   393             if (error!=KErrNone && error!=KErrAlreadyExists)
   370                {
   394                {
   371                 User::Leave(error);
   395                 User::Leave(error);   
   372                }
   396                }
   373             iFname = (*aData[i]).iFullName->Des();
   397             iFname = (*aData[i]).iFullName->Des();
   374 
   398             
   375             // Find a unique name to avoid any conflict.
   399             // Find a unique name to avoid any conflict.
   376             // Here iFname has full path of current location of file
   400             // Here iFname has full path of current location of file
   377             // and filename has destination path.
   401             // and filename has destination path.
   378             FindUniqueDestinationFileNameL( iFname, filename );
   402             FindUniqueDestinationFileNameL( iFname, filename );
   379 
   403             
   380             filenamePtr = filename->Des();
   404             filenamePtr = filename->Des();
   381             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   405             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   382             if(err != KErrNone)
   406             if(err != KErrNone)
   383             	{
   407             	{
   384             	User::LeaveIfError(err);
   408             	User::LeaveIfError(err);
   385             	}
   409             	}
   386             iFname = filenamePtr;
   410             iFname = filenamePtr;              
   387             NotifyMediaGalleryL( filenamePtr );
   411             NotifyMediaGalleryL( filenamePtr );
   388 
   412 
   389             (*aData[i]).iFileName = iFname;
   413             (*aData[i]).iFileName = iFname;
   390             (*aData[i]).iFullName = NameL();
   414             (*aData[i]).iFullName = NameL();
   391             CleanupStack::PopAndDestroy(filename);
   415             CleanupStack::PopAndDestroy(filename);
   392             }
   416             }
       
   417 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   418         if( downloadPathPlugin )
       
   419             {
       
   420             CleanupStack::PopAndDestroy( downloadPathPlugin );
       
   421             }
       
   422 #endif
   393         CleanupStack::PopAndDestroy(file);
   423         CleanupStack::PopAndDestroy(file);
   394         CleanupStack::PopAndDestroy(&fs);
   424         CleanupStack::PopAndDestroy(&fs);
   395 
   425 
   396 #endif // RD_MULTIPLE_DRIVE
   426 #endif // RD_MULTIPLE_DRIVE
   397     // TODO set iType to that of the packaged object (??)
   427     // TODO set iType to that of the packaged object (??)
   423 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   453 /* check if the PD app has been started (PD appl is responsible for file moving after play is done)
   424    In this case leave and go to the next state.
   454    In this case leave and go to the next state.
   425 */
   455 */
   426     if (!aAttached)
   456     if (!aAttached)
   427 	    {
   457 	    {
   428 #ifdef RD_MULTIPLE_DRIVE
   458 #ifdef RD_MULTIPLE_DRIVE 
   429         RFs fs;
   459         RFs fs;
   430         TInt err( KErrNone );
   460         TInt err( KErrNone );
   431         HBufC* filename = HBufC::NewLC(KMaxFileName);
   461         HBufC* filename = HBufC::NewLC(KMaxFileName);
   432         TPtr filenamePtr = filename->Des();
   462         TPtr filenamePtr = filename->Des();
   433         filenamePtr = iRootPath;
   463         filenamePtr = iRootPath;
   434         filenamePtr.Append(_L("download\\"));
   464 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   465         // Get the mime type of the content
       
   466         TPtrC8 mimeType( iType.Des8() );
       
   467         CDownloadPathHandler* downloadPathPlugin = NULL;
       
   468         downloadPathPlugin = GetDownloadPathPluginInstanceL( mimeType );
       
   469 
       
   470         if( downloadPathPlugin )
       
   471             {
       
   472             CleanupStack::PushL( downloadPathPlugin );
       
   473             GetUpdatedPathFromPluginL( downloadPathPlugin,iFname, filenamePtr );
       
   474             CleanupStack::PopAndDestroy( downloadPathPlugin );
       
   475             }
       
   476         else
       
   477             {
       
   478             filenamePtr.Append( _L( "download\\" ) );
       
   479             }
       
   480 #else
       
   481             filenamePtr.Append( _L( "download\\" ) );
       
   482             
       
   483 #endif
   435         User::LeaveIfError( fs.Connect() );
   484         User::LeaveIfError( fs.Connect() );
   436         CleanupClosePushL(fs);
   485         CleanupClosePushL(fs);
   437         CFileMan* file=CFileMan::NewL(fs);
   486         CFileMan* file=CFileMan::NewL(fs);
   438         CleanupStack::PushL(file);
   487         CleanupStack::PushL(file);
   439         TInt error = fs.MkDirAll(filenamePtr);
   488         TInt error = fs.MkDirAll(filenamePtr);
   440         if (error!=KErrNone && error!=KErrAlreadyExists)
   489         if (error!=KErrNone && error!=KErrAlreadyExists)
   441            {
   490            {
   442             User::Leave(error);
   491             User::Leave(error);   
   443            }
   492            }
   444 
   493    
   445         // Find a unique name to avoid any conflict.
   494         // Find a unique name to avoid any conflict.
   446         // Here iFname has full path of current location of file
   495         // Here iFname has full path of current location of file
   447         // and filename has destination path.
   496         // and filename has destination path.
   448         FindUniqueDestinationFileNameL( iFname, filename );
   497         FindUniqueDestinationFileNameL( iFname, filename );
   449 
   498         
   450         filenamePtr = filename->Des();
   499         filenamePtr = filename->Des();     
   451 
   500                
   452         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   501         err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   453 
   502     
   454         if(err != KErrNone)
   503         if(err != KErrNone)
   455            {
   504            {
   456            User::Leave(err);
   505            User::Leave(err);
   457            }
   506            }
   458 
   507        
   459         iFname = filenamePtr;
   508         iFname = filenamePtr;              
   460         NotifyMediaGalleryL( filenamePtr );
   509         NotifyMediaGalleryL( filenamePtr );        
   461         CleanupStack::PopAndDestroy(file);
   510         CleanupStack::PopAndDestroy(file);
   462         CleanupStack::PopAndDestroy(&fs);
   511         CleanupStack::PopAndDestroy(&fs);
   463         CleanupStack::PopAndDestroy(filename);
   512         CleanupStack::PopAndDestroy(filename);
   464 #else
   513 #else
   465             RFs fs;
   514             RFs fs;
   473             CFileMan* file=CFileMan::NewL(fs);
   522             CFileMan* file=CFileMan::NewL(fs);
   474             CleanupStack::PushL(file);
   523             CleanupStack::PushL(file);
   475             TInt error = fs.MkDirAll(filenamePtr);
   524             TInt error = fs.MkDirAll(filenamePtr);
   476             if (error!=KErrNone && error!=KErrAlreadyExists)
   525             if (error!=KErrNone && error!=KErrAlreadyExists)
   477                {
   526                {
   478                 User::Leave(error);
   527                 User::Leave(error);   
   479                }
   528                }
   480 
   529 
   481             // Find a unique name to avoid any conflict.
   530             // Find a unique name to avoid any conflict.
   482             // Here iFname has full path of current location of file
   531             // Here iFname has full path of current location of file
   483             // and filename has destination path.
   532             // and filename has destination path.
   484             FindUniqueDestinationFileNameL( iFname, filename );
   533             FindUniqueDestinationFileNameL( iFname, filename );
   485 
   534             
   486             filenamePtr = filename->Des();
   535             filenamePtr = filename->Des();
   487             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   536             TInt err = file->Move(iFname, filenamePtr, CFileMan::EOverWrite);
   488 
   537         
   489             if(err != KErrNone)
   538             if(err != KErrNone)
   490                {
   539                {
   491                User::Leave(err);
   540                User::Leave(err);
   492                 }
   541                 }
   493             iFname = filenamePtr;
   542             iFname = filenamePtr;              
   494             NotifyMediaGalleryL( filenamePtr );
   543             NotifyMediaGalleryL( filenamePtr );
   495             CleanupStack::PopAndDestroy(file);
   544             CleanupStack::PopAndDestroy(file);
   496             CleanupStack::PopAndDestroy(&fs);
   545             CleanupStack::PopAndDestroy(&fs);
   497             CleanupStack::PopAndDestroy(filename);
   546             CleanupStack::PopAndDestroy(filename);
   498 #endif // RD_MULTIPLE_DRIVE
   547 #endif // RD_MULTIPLE_DRIVE
   558     CLOG(( ECodEng, 2, _L("-> CFileSaver::Cleanup") ));
   607     CLOG(( ECodEng, 2, _L("-> CFileSaver::Cleanup") ));
   559     // Clean up the temporary file, ignore errors.
   608     // Clean up the temporary file, ignore errors.
   560     // Expected error: KErrNotFound (if there is no temp file).
   609     // Expected error: KErrNotFound (if there is no temp file).
   561     // Unexpected error: all the rest -> nothing we can do with them.
   610     // Unexpected error: all the rest -> nothing we can do with them.
   562     CloseStore();
   611     CloseStore();
   563 
   612     
   564 	if( aDeleteFile )
   613 	if( aDeleteFile )
   565 	    {
   614 	    {
   566 #ifdef __TEST_COD_LOG
   615 #ifdef __TEST_COD_LOG
   567         TInt err =  // ('Log-only' variable.)
   616         TInt err =  // ('Log-only' variable.)
   568 #endif /* def __TEST_COD_LOG */
   617 #endif /* def __TEST_COD_LOG */
   582         }
   631         }
   583     iState = EInit;
   632     iState = EInit;
   584     CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") ));
   633     CLOG(( ECodEng, 2, _L("<- CFileSaver::Cleanup") ));
   585     }
   634     }
   586 
   635 
   587 
   636   
   588 // ---------------------------------------------------------
   637 // ---------------------------------------------------------
   589 // CFileSaver::UpdateDCFRepositoryL()
   638 // CFileSaver::UpdateDCFRepositoryL()
   590 // Update saved file to DCFRepository
   639 // Update saved file to DCFRepository  
   591 // ---------------------------------------------------------
   640 // ---------------------------------------------------------
   592 //
   641 // 
   593 void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName )
   642 void CFileSaver::UpdateDCFRepositoryL( const TDesC& aFileName )
   594     {
   643     {
   595     CDcfEntry* dcfEntry = NULL;
   644     CDcfEntry* dcfEntry = NULL;
   596     dcfEntry = CDcfEntry::NewL();
   645     dcfEntry = CDcfEntry::NewL();    
   597     CleanupStack::PushL( dcfEntry );
   646     CleanupStack::PushL( dcfEntry );
   598 
   647     
   599     CDcfRep* dcfRep = NULL;
   648     CDcfRep* dcfRep = NULL;
   600     dcfRep = CDcfRep::NewL();
   649     dcfRep = CDcfRep::NewL();
   601     CleanupStack::PushL( dcfRep );
   650     CleanupStack::PushL( dcfRep );
   602 
   651 
   603     dcfEntry->SetLocationL( aFileName, 0 );
   652     dcfEntry->SetLocationL( aFileName, 0 );    
   604     dcfRep->UpdateL( dcfEntry );
   653     dcfRep->UpdateL( dcfEntry );
   605     CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
   654     CleanupStack::PopAndDestroy(2); // dcfEntry, dcfRep
   606     }
   655     }   
   607 
   656     
   608 // ---------------------------------------------------------
   657 // ---------------------------------------------------------
   609 // CFileSaver::UpdateMediaGalleryIfNeededL()
   658 // CFileSaver::UpdateMediaGalleryIfNeededL()
   610 // Calls MediaGallery Update method so that media gallery
   659 // Calls MediaGallery Update method so that media gallery
   611 // knows update its view.
   660 // knows update its view.
   612 // ---------------------------------------------------------
   661 // ---------------------------------------------------------
   613 //
   662 // 
   614 
   663 
   615 
   664 
   616 void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName )
   665 void CFileSaver::UpdateMediaGalleryIfNeededL( const TDesC& aFileName )
   617     {
   666     {
   618 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
   667 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF           
   619     CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs );
   668     CMGXFileManager* fm = MGXFileManagerFactory::NewFileManagerL( iFs );
   620     CleanupStack::PushL(fm);
   669     CleanupStack::PushL(fm);
   621     fm->UpdateL(aFileName);
   670     fm->UpdateL(aFileName);
   622     CleanupStack::PopAndDestroy(); // fm
   671     CleanupStack::PopAndDestroy(); // fm
   623 #endif
   672 #endif    
   624     }
   673     }
   625 // ---------------------------------------------------------
   674 // ---------------------------------------------------------
   626 // CFileSaver::NotifyMediaGalleryL()
   675 // CFileSaver::NotifyMediaGalleryL()
   627 // Notify media gallery about the new file.
   676 // Notify media gallery about the new file.
   628 // ---------------------------------------------------------
   677 // ---------------------------------------------------------
   629 //
   678 // 
   630 void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName )
   679 void CFileSaver::NotifyMediaGalleryL( const TDesC& aFileName )
   631     {
   680     {
   632 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF
   681 #ifdef BRDO_APP_GALLERY_SUPPORTED_FF    
   633 
   682     
   634     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs );
   683     CMGXFileManager* mgFileManager = MGXFileManagerFactory::NewFileManagerL( iFs );
   635     CleanupStack::PushL( mgFileManager );
   684     CleanupStack::PushL( mgFileManager );
   636 
   685 
   637     TRAP_IGNORE( mgFileManager->UpdateL() );
   686     TRAP_IGNORE( mgFileManager->UpdateL() );
   638     CleanupStack::PopAndDestroy( mgFileManager );
   687     CleanupStack::PopAndDestroy( mgFileManager );
   639 
   688 
   640     // Notify Media Gallery
   689     // Notify Media Gallery
   641     TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) );
   690     TRAP_IGNORE( UpdateMediaGalleryIfNeededL( aFileName ) );
   642 
   691 
   643 #endif
   692 #endif
   644 
   693     
   645 
   694     
   646     // Notify DCF repository
   695     // Notify DCF repository
   647     TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
   696     TRAP_IGNORE( UpdateDCFRepositoryL( aFileName ) );
   648     }
   697     }
   649 // ---------------------------------------------------------
   698 // ---------------------------------------------------------
   650 // CFileSaver::DownloadedFileSize()
   699 // CFileSaver::DownloadedFileSize()
   653 TInt CFileSaver::DownloadedFileSize()
   702 TInt CFileSaver::DownloadedFileSize()
   654     {
   703     {
   655     // check how many bytes are already persisted
   704     // check how many bytes are already persisted
   656     TInt DownloadedSize(0);
   705     TInt DownloadedSize(0);
   657     TInt err = iFile.Size( (TInt&)DownloadedSize );
   706     TInt err = iFile.Size( (TInt&)DownloadedSize );
   658 
   707     
   659     CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize  Downloaded size = %d  error = %d"), \
   708     CLOG(( ECodStorage, 2, _L("CFileSaver::DownloadedFileSize  Downloaded size = %d  error = %d"), \
   660                DownloadedSize,err ));
   709                DownloadedSize,err ));
   661 
   710 
   662     if(err != KErrNone)
   711     if(err != KErrNone)
   663         return err;
   712         return err;
   664     return DownloadedSize;
   713     return DownloadedSize;
   665     }
   714     }
   666 
   715     
   667 
   716     
   668 /**
   717 /**
   669 * Discard the old contents
   718 * Discard the old contents
   670 */
   719 */        
   671 void CFileSaver::ResetL()
   720 void CFileSaver::ResetL()
   672     {
   721     {
   673 
   722     
   674 
   723     
   675     iFile.Close();
   724     iFile.Close();
   676 
   725     
   677     User::LeaveIfError( iFile.Replace(  iFs,
   726     User::LeaveIfError( iFile.Replace(  iFs, 
   678                                         iFname,
   727                                         iFname, 
   679                                         EFileShareAny |
   728                                         EFileShareAny | 
   680                                         EFileStream |
   729                                         EFileStream | 
   681                                         EFileWrite ) );
   730                                         EFileWrite ) );
   682     }
   731     }
   683 
   732 
   684 
   733 
   685 // -----------------------------------------------------------------------------
   734 // -----------------------------------------------------------------------------
   691     iProgressiveDownload = aValue;
   740     iProgressiveDownload = aValue;
   692     if( iProgressiveDownload )
   741     if( iProgressiveDownload )
   693         {
   742         {
   694         iBufferSize = KDefaultStorageBufferSizePD;
   743         iBufferSize = KDefaultStorageBufferSizePD;
   695         }
   744         }
   696 
   745     
   697 
   746     
   698     if( iBufferSize != iStorage->CurrentBufferSize())
   747     if( iBufferSize != iStorage->CurrentBufferSize())
   699         {
   748         {
   700         FlushL();
   749         FlushL();
   701         }
   750         }
   702 
   751 
   703     if ( iFile.SubSessionHandle() )
   752     if ( iFile.SubSessionHandle() )
   704         {
   753         {
   705 
   754      	
   706         if( iProgressiveDownload )
   755         if( iProgressiveDownload )
   707             {
   756             {
   708             if( iLength != KDefaultContentLength )
   757             if( iLength != KDefaultContentLength )    
   709                 {
   758                 {
   710                 iFile.SetSize( iLength );
   759                 iFile.SetSize( iLength );
   711                 }
   760                 }
   712             }
   761             }
   713         else
   762         else
   739 // Called if download completed.
   788 // Called if download completed.
   740 // -----------------------------------------------------------------------------
   789 // -----------------------------------------------------------------------------
   741 //
   790 //
   742 void CFileSaver::OnComplete()
   791 void CFileSaver::OnComplete()
   743     {
   792     {
   744     CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));
   793     CLOG(( ECodEng, 2, _L("-> CFileSaver::OnComplete") ));    
   745     FlushL();
   794     FlushL();
   746     iStorage->ClearErrors();
   795     iStorage->ClearErrors();
   747     iFile.Close();
   796     iFile.Close();
   748     CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));
   797     CLOG(( ECodEng, 2, _L("<- CFileSaver::OnComplete") ));     
   749     }
   798     }
   750 
   799 
   751 
   800 
   752 
   801 
   753 
   802 
   756 // ---------------------------------------------------------
   805 // ---------------------------------------------------------
   757 HBufC* CFileSaver::NameL() const
   806 HBufC* CFileSaver::NameL() const
   758     {
   807     {
   759     return iFname.AllocL();
   808     return iFname.AllocL();
   760     }
   809     }
       
   810 #ifdef DOWNLOADMGR_PATH_PLUGIN_ENABLED_FF
       
   811 
       
   812 // ---------------------------------------------------------
       
   813 // CFileSaver::GetDownloadPathPluginInstanceL
       
   814 // ---------------------------------------------------------
       
   815 CDownloadPathHandler* CFileSaver::GetDownloadPathPluginInstanceL(TPtrC8& mimetype )
       
   816     {
       
   817     CDownloadPathHandler* downloadPathPlugin = NULL;
       
   818     TRAPD( kErr, downloadPathPlugin = CDownloadPathHandler::NewL( mimetype ) );
       
   819     if( kErr != KErrNone )
       
   820         {
       
   821         downloadPathPlugin = NULL;
       
   822         }
       
   823     return downloadPathPlugin;
       
   824     }
       
   825 
       
   826 // ---------------------------------------------------------
       
   827 // CFileSaver::GetUpdatedPathFromPluginL
       
   828 // ---------------------------------------------------------
       
   829 void CFileSaver::GetUpdatedPathFromPluginL(CDownloadPathHandler* downloadPathPlugin,TFileName& fname, TPtr& fileNamePtr)
       
   830     {
       
   831     TRAPD( kErr, downloadPathPlugin->GetUpdatedPathL( fname, fileNamePtr ) );
       
   832     if( kErr == KErrNone )
       
   833         {
       
   834         fileNamePtr.Append( _L( "\\" ) );
       
   835         }
       
   836     else
       
   837         {
       
   838         fileNamePtr.Append( _L( "download\\" ) );
       
   839         }
       
   840     }
       
   841 #endif
       
   842 
       
   843 //EOF