browserutilities/downloadmgr/DownloadMgrServEng/Src/HttpStorage.cpp
changeset 0 dd21522fd290
child 36 0ed94ceaa377
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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 the License "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:  Implements storage functionality in the DownloadManager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <bldvariant.hrh>
       
    22 #include <Browser_platform_variant.hrh>
       
    23 
       
    24 #include "FileExt.h"
       
    25 #include "HttpClientApp.h"
       
    26 #include "HttpDownload.h"
       
    27 #include "HttpStorage.h"
       
    28 #include "HttpDownloadManagerServerEngine.h"
       
    29 #include "HttpDownloadMgrLogger.h"
       
    30 #include "HeaderField.h"
       
    31 #include "BuffStorage.h"
       
    32 
       
    33 #include <SysUtil.h>
       
    34 #include <DocumentHandler.h>
       
    35 #include <APMSTD.H>
       
    36 
       
    37 #ifdef __SYNCML_DM_FOTA
       
    38 #include <fotaengine.h>
       
    39 #endif
       
    40 
       
    41 #ifdef RD_MULTIPLE_DRIVE
       
    42 #include <driveinfo.h>
       
    43 #endif //RD_MULTIPLE_DRIVE
       
    44 
       
    45 // EXTERNAL DATA STRUCTURES
       
    46 //extern  ?external_data;
       
    47 
       
    48 // EXTERNAL FUNCTION PROTOTYPES  
       
    49 //extern ?external_function( ?arg_type,?arg_type );
       
    50 
       
    51 // CONSTANTS
       
    52 //const ?type ?constant_var = ?constant;
       
    53 const TInt KDefaultStorageBufferSize = 128 * 1024;
       
    54 const TInt KFileNameExtensionMaxSize = 5; // practical maximum length of filename extension for renamed downloads
       
    55 const TInt KDefaultStorageBufferSizePD = 16 * 1024;
       
    56 // MACROS
       
    57 //#define ?macro ?macro_def
       
    58 
       
    59 // LOCAL CONSTANTS AND MACROS
       
    60 //const ?type ?constant_var = ?constant;
       
    61 //#define ?macro_name ?macro_def
       
    62 
       
    63 // MODULE DATA STRUCTURES
       
    64 //enum ?declaration
       
    65 //typedef ?declaration
       
    66 
       
    67 // LOCAL FUNCTION PROTOTYPES
       
    68 //?type ?function_name( ?arg_type, ?arg_type );
       
    69 
       
    70 // FORWARD DECLARATIONS
       
    71 //class ?FORWARD_CLASSNAME;
       
    72 
       
    73 // ============================ MEMBER FUNCTIONS ===============================
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CHttpStorage::CHttpStorage
       
    77 // C++ default constructor can NOT contain any code, that
       
    78 // might leave.
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 CHttpStorage::CHttpStorage( CHttpDownload* aDownload )
       
    82     :iDownload( aDownload )
       
    83     ,iProgressiveDownload( EFalse )
       
    84     ,iLength( KDefaultContentLength )
       
    85     ,iStorageMethod( EStoreFile )
       
    86     ,iBufferingEnabled( EFalse )
       
    87     ,iBufferSize( KDefaultStorageBufferSize )
       
    88     ,iPartialLength( KDefaultContentLength )
       
    89     {
       
    90     CLOG_WRITE_1( "Storage created: 0x%x", this );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CHttpStorage::ConstructL
       
    95 // Symbian 2nd phase constructor can leave.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CHttpStorage::ConstructL()
       
    99     {
       
   100     iStorage = CBuffStorage::NewL(this);
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CHttpStorage::NewL
       
   105 // Two-phased constructor.
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 CHttpStorage* CHttpStorage::NewL( CHttpDownload* aDownload )
       
   109     {
       
   110     CHttpStorage* self = new( ELeave ) CHttpStorage( aDownload );
       
   111     
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     CleanupStack::Pop();
       
   115 
       
   116     return self;
       
   117     }
       
   118 
       
   119     
       
   120 // Destructor
       
   121 CHttpStorage::~CHttpStorage()
       
   122     {
       
   123     delete iLocalFilename;
       
   124     delete iDestFilename;
       
   125     delete iDdFilename;
       
   126     
       
   127     
       
   128 	if(iStorage)
       
   129 		{
       
   130 		delete iStorage;
       
   131 		iStorage = NULL;	
       
   132 		}
       
   133     if( iFile )
       
   134         {
       
   135         iFile->Close();
       
   136         delete iFile;
       
   137         }
       
   138         
       
   139 #ifdef __SYNCML_DM_FOTA        
       
   140     if( iFotaEngine )
       
   141         {
       
   142         iFotaEngine->UpdatePackageDownloadComplete( iDownload->iFotaPckgId);
       
   143         iFotaStream = NULL;
       
   144         iFotaEngine->Close();
       
   145         delete iFotaEngine; iFotaEngine = NULL;
       
   146         }
       
   147 #endif // __SYNCML_DM_FOTA
       
   148 
       
   149     CLOG_WRITE_1( "Storage destroy: (0x%x)", this );
       
   150     }
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // CHttpStorage::SetStorageMethod
       
   154 // 
       
   155 // iDownloadedSize comes from the destination file size.
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CHttpStorage::SetStorageMethod( TStorageMethod aMethod )
       
   159     {
       
   160     iStorageMethod = aMethod;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CHttpStorage::CheckContentFileIntegrityL
       
   165 // 
       
   166 // iDownloadedSize comes from the destination file size.
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 TBool CHttpStorage::CheckContentFileIntegrityL()
       
   170     {
       
   171     LOGGER_ENTERFN( "CheckContentFileIntegrityL" );
       
   172     TBool retVal = ETrue;
       
   173 
       
   174     if( iDestFilename && iDestFilename->Length() )
       
   175         {
       
   176         if( iDriveId == GetDestinationDriveId() )
       
   177             // this is not the same drive as where content file was
       
   178             // previously saved
       
   179             {
       
   180             TEntry entry;
       
   181             RFs& fs = iDownload->ClientApp()->Engine()->Fs();
       
   182 
       
   183             if( fs.Entry( *iDestFilename, entry ) == KErrNone )
       
   184                 {
       
   185                 //Check if PD was on and if the file was being downloaded to MMC when last time we exited the session
       
   186                 //Use the Downloaded size as stored in info file 
       
   187                 //because when we exited from prev session
       
   188                 //size was not set back to downloaded size from total size
       
   189                 //
       
   190                 
       
   191                 if( !iProgressiveDownload && !iDownload->iNoMedia)
       
   192                     {
       
   193                     iDownloadedSize = entry.iSize;
       
   194                     } 
       
   195                 else 
       
   196                     {
       
   197                     iFile = new (ELeave) RFile;
       
   198                     TInt err = iFile->Open( fs , 
       
   199                                           *iLocalFilename, 
       
   200                                           EFileShareAny | 
       
   201                                           EFileStream | 
       
   202                                            EFileWrite );
       
   203                     if( !err )
       
   204                         {
       
   205                         iFile->SetSize( iDownloadedSize );
       
   206                         iProgressiveDownload = EFalse; 
       
   207                         iFile->Close();
       
   208                         delete iFile; iFile = NULL;       
       
   209                         }
       
   210                         iDownload->iNoMedia = EFalse;
       
   211                     }                    
       
   212 
       
   213                 CLOG_WRITE_2( "Length: %d, size: %d", iLength, iDownloadedSize );
       
   214 
       
   215                 // if full size is unknown, we can't decide
       
   216                 // if the content file integrity is ok, or wrong.
       
   217                 // Let's assume that it is ok.
       
   218                 if( iLength != KDefaultContentLength )
       
   219                     // Full size is known
       
   220                     {
       
   221                     if( !((iDownload->iDlState == EHttpDlMultipleMOCompleted &&
       
   222                         (iDownload->iProgState == EHttpProgContentFileMoved || 
       
   223                         iDownload->iProgState == EHttpProgContentFileMovedAndDestFNChanged ||
       
   224                         iLength == iDownloadedSize)) ||
       
   225                         (iDownload->iDlState != EHttpDlMultipleMOCompleted &&
       
   226                         iLength > iDownloadedSize)) )
       
   227                         {
       
   228                         CLOG_WRITE8( "Wrong file size" );
       
   229                         retVal = EFalse;
       
   230                         }
       
   231                     }
       
   232                 }
       
   233             else
       
   234                 // Entry failed but we can still assume that there's no problem
       
   235                 {
       
   236                 CLOG_WRITE8( "Unknown size" );
       
   237                 }
       
   238             }
       
   239         else
       
   240             {
       
   241             CLOG_WRITE8_1( "Different drive: %d", iDriveId );
       
   242             // MMC removed.
       
   243             iDownload->MediaRemoved( (TUint)KErrNotFound, ETrue );
       
   244             }
       
   245         }
       
   246     else
       
   247         {
       
   248         CLOG_WRITE( "No dest filename");
       
   249          iDownload->iNoMedia = EFalse; 
       
   250         }
       
   251 
       
   252     return retVal;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CHttpStorage::CreateDestinationFileL
       
   257 // ?implementation_description
       
   258 // (other items were commented in a header).
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CHttpStorage::CreateDestinationFileL()
       
   262     {
       
   263     LOGGER_ENTERFN( "CreateDestinationFileL" );
       
   264 
       
   265     TInt err( KErrNone );
       
   266     
       
   267     if( iStorageMethod == EStoreFota )
       
   268         {
       
   269 #ifdef __SYNCML_DM_FOTA        
       
   270         iFotaEngine = new (ELeave) RFotaEngineSession;
       
   271         iFotaEngine->OpenL();
       
   272         User::LeaveIfError( iFotaEngine->OpenUpdatePackageStore( iDownload->iFotaPckgId, 
       
   273                                                                  iFotaStream ) );
       
   274         
       
   275         CLOG_WRITE( "FOTA -> no file" );
       
   276 #else   // __SYNCML_DM_FOTA
       
   277         DMPanic( KErrNotSupported );
       
   278 #endif  // __SYNCML_DM_FOTA   
       
   279         }
       
   280     else
       
   281         {
       
   282         if( iRFileSetByClient )
       
   283             {
       
   284             CLOG_WRITE( "RFile is adopted from client" );
       
   285             
       
   286             TBuf<KMaxFileName> tempFileName; 
       
   287             iFile->FullName(tempFileName);           
       
   288             ReallocateStringL( iLocalFilename, tempFileName, KMaxPath );
       
   289 
       
   290             TBuf8<KMaxContentTypeLength> contentType;
       
   291             contentType.Copy( *iDownload->iDDType );
       
   292 
       
   293             if( (0 == contentType.Compare( KCodMimeType() )) ||
       
   294             	(0 == contentType.Compare( KDdMimeType() ))	 ||
       
   295             	(0 == contentType.Compare( KDd2MimeType() )) ||
       
   296             	(0 == contentType.Compare( KMultiPartMimeType() )) )
       
   297             	{
       
   298             	iDdFilename = iLocalFilename->Des().AllocL();
       
   299             	}            
       
   300             
       
   301             
       
   302             // check how many bytes are already persisted
       
   303             iFile->Size( (TInt&)iDownloadedSize );
       
   304 
       
   305             CLOG_WRITE_1( "iDownloadedSize: %d", iDownloadedSize );
       
   306 
       
   307             return;
       
   308             }
       
   309 
       
   310         CLOG_WRITE8_1( "iDownloadedSize: %d", iDownloadedSize );
       
   311             
       
   312         __ASSERT_DEBUG( !iFile, DMPanic( KErrInUse) );
       
   313 
       
   314         CreateDestinationFilenameL();
       
   315 
       
   316         iFile = new (ELeave) RFile;
       
   317 
       
   318         for( TInt i = 0; i < 2; ++i )
       
   319             {
       
   320             if( !iDownloadedSize )
       
   321                 // nothing persisted yet. If there's a file with the same name,
       
   322                 // delete it.
       
   323                 {
       
   324                 err = iFile->Replace( iDownload->ClientApp()->Engine()->Fs(), 
       
   325                                        *iLocalFilename, 
       
   326                                        EFileShareAny | 
       
   327                                        EFileStream | 
       
   328 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
       
   329                                        EFileWrite |
       
   330                                        EFileWriteDirectIO );
       
   331 #else
       
   332                                        EFileWrite );
       
   333 #endif
       
   334                 }
       
   335             else
       
   336                 {
       
   337                 err = iFile->Open( iDownload->ClientApp()->Engine()->Fs(), 
       
   338                                    *iLocalFilename, 
       
   339                                    EFileShareAny | 
       
   340                                    EFileStream | 
       
   341 #ifdef BRDO_RFILE_WRITE_DIRECT_IO_FF
       
   342                                    EFileWrite |
       
   343                                    EFileWriteDirectIO );
       
   344 #else
       
   345                                    EFileWrite );
       
   346 #endif
       
   347 
       
   348                 if( !err )
       
   349                     {
       
   350                     // append new chunks to the file
       
   351                     TInt pos( 0 );
       
   352                     iFile->Seek( ESeekEnd, pos );
       
   353                     }
       
   354                 }
       
   355 
       
   356             if( err == KErrPathNotFound )
       
   357                 {
       
   358                 TPath folder;
       
   359 
       
   360                 folder.Copy( *iLocalFilename );
       
   361 
       
   362                 TInt slash = folder.LocateReverse( '\\' );
       
   363                 if( slash != KErrNotFound )
       
   364                     {
       
   365                     folder.SetLength( slash+1 );
       
   366                     iDownload->ClientApp()->Engine()->Fs().MkDirAll( folder );
       
   367                     }
       
   368                 }
       
   369             else 
       
   370                 {
       
   371                 break;
       
   372                 }
       
   373             }
       
   374         }
       
   375     CLOG_WRITE8_1( "CreateDestinationFileL: %d", err );
       
   376 
       
   377     if( !err )
       
   378         {
       
   379         if( iFile && iLength != KDefaultContentLength && iProgressiveDownload )
       
   380             {
       
   381             iFile->SetSize( iLength );
       
   382             }
       
   383         }
       
   384     else
       
   385         {
       
   386         iDownload->OnError( err, EDestFileInUse );
       
   387         User::Leave( err );
       
   388         }
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CHttpStorage::CloseDestinationFile
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 void CHttpStorage::CloseDestinationFile( TFileCloseOperation aOperation )
       
   396     {
       
   397     LOGGER_ENTERFN( "CloseDestinationFile" );
       
   398 
       
   399     CLOG_WRITE_2( "iFile: %x, iRFileSetByClient: %d", iFile, iRFileSetByClient );
       
   400     if( iFile )
       
   401         // RFile received from client is not close only in
       
   402         // destructor, because there's no way to reopen it.
       
   403         {
       
   404         CLOG_WRITE( "HttpStorage: Writing final data and deallocating buffer" );
       
   405         
       
   406         // Make sure everything is written on the file
       
   407         TRAP_IGNORE(iStorage->FlushBuffersL()); // Might be good to somehow relay error somewhere?
       
   408        
       
   409         if( iProgressiveDownload && iDownloadedSize >= 0 )
       
   410                 {
       
   411                 iFile->SetSize( iDownloadedSize );
       
   412                 }
       
   413 
       
   414         
       
   415         // Free up memory
       
   416         iStorage->ResetBuffers();
       
   417         iStorage->ClearErrors();
       
   418 
       
   419         if( iDownload->iDlState == EHttpDlMultipleMOCompleted || !iRFileSetByClient )
       
   420             // do not close file of a progressive download,
       
   421             // only on complete.
       
   422             {
       
   423             iFile->Close();
       
   424             delete iFile; iFile = NULL;
       
   425             }
       
   426         }
       
   427 
       
   428 #ifdef __SYNCML_DM_FOTA        
       
   429     if( iFotaEngine )
       
   430         {
       
   431         iFotaEngine->UpdatePackageDownloadComplete( iDownload->iFotaPckgId);
       
   432         iFotaStream = NULL;
       
   433         iFotaEngine->Close();
       
   434         delete iFotaEngine; iFotaEngine = NULL;
       
   435         }
       
   436 #endif  // __SYNCML_DM_FOTA
       
   437 
       
   438     if( iLocalFilename )
       
   439         {
       
   440         if( aOperation == EDeleteFile )
       
   441             {
       
   442             CLOG_WRITE_1( "Delete: %S", iLocalFilename );
       
   443             iDownload->ClientApp()->Engine()->Fs().Delete( *iLocalFilename );
       
   444             iDownloadedSize = 0;
       
   445             }
       
   446         else if( aOperation == EReplaceFile )
       
   447             {
       
   448             CLOG_WRITE_1( "Replace: %S", iLocalFilename );
       
   449             RFile file;
       
   450             file.Replace( iDownload->ClientApp()->Engine()->Fs(), *iLocalFilename, EFileWrite );
       
   451             file.Close();
       
   452             iDownloadedSize = 0;
       
   453             }
       
   454         }
       
   455         
       
   456     if( iDestFilename )
       
   457         {
       
   458         if( aOperation == EDeleteFile )
       
   459             {
       
   460             CLOG_WRITE_1( "Delete: %S", iDestFilename );
       
   461             iDownload->ClientApp()->Engine()->Fs().Delete( *iDestFilename );
       
   462             }
       
   463         else if( aOperation == EReplaceFile )
       
   464             {
       
   465             CLOG_WRITE_1( "Replace: %S", iDestFilename );
       
   466             RFile file;
       
   467             file.Replace( iDownload->ClientApp()->Engine()->Fs(), *iDestFilename, EFileWrite );
       
   468             file.Close();  
       
   469             }
       
   470         }
       
   471     }
       
   472 
       
   473 // -----------------------------------------------------------------------------
       
   474 // CHttpStorage::WriteOutNextBodyDataL
       
   475 // ?implementation_description
       
   476 // (other items were commented in a header).
       
   477 // -----------------------------------------------------------------------------
       
   478 //
       
   479 TBool CHttpStorage::WriteOutNextBodyDataL( const TDesC8& aBuf )
       
   480     {
       
   481 
       
   482     return iStorage->WriteOutNextBodyDataL(aBuf);
       
   483 
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CHttpStorage::OnComplete
       
   488 // -----------------------------------------------------------------------------
       
   489 //
       
   490 void CHttpStorage::OnComplete()
       
   491     {
       
   492     LOGGER_ENTERFN( "CHttpStorage::OnComplete()" );
       
   493 
       
   494     // If destination filename is not set by client app
       
   495     // here we have to update it with the local filename
       
   496     if( !iDestFNameSet && 
       
   497         !iRFileSetByClient && 
       
   498         iStorageMethod != EStoreFota )
       
   499         {
       
   500         TRAP_IGNORE( 
       
   501             ReallocateStringL( iDestFilename, *iLocalFilename, KMaxPath ) );
       
   502         }
       
   503 
       
   504     CloseDestinationFile( CHttpStorage::EKeepFile );
       
   505     }
       
   506 
       
   507 // -----------------------------------------------------------------------------
       
   508 // CHttpStorage::ResetAndDestroy
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 void CHttpStorage::ResetAndDestroy()
       
   512     {
       
   513     LOGGER_ENTERFN( "CHttpStorage::ResetAndDestroy()" );
       
   514 
       
   515     if( iFile && iRFileSetByClient )
       
   516         // do not delete or close this file, only set its size to 0.
       
   517         {
       
   518         iFile->SetSize( 0 );
       
   519         }
       
   520 
       
   521 #ifdef __SYNCML_DM_FOTA
       
   522     if( iFotaEngine )
       
   523         {
       
   524         iFotaEngine->UpdatePackageDownloadComplete( iDownload->iFotaPckgId);
       
   525         iFotaStream = NULL;
       
   526         iFotaEngine->Close();
       
   527         delete iFotaEngine; iFotaEngine = NULL;
       
   528         }
       
   529 #endif  // __SYNCML_DM_FOTA        
       
   530 
       
   531     CloseDestinationFile( EReplaceFile );
       
   532 
       
   533     iLength = KDefaultContentLength;
       
   534     iDownloadedSize = 0;
       
   535     iMoDownloadedSize = 0;
       
   536 
       
   537     iDriveId = (TUint)KErrNotFound;
       
   538 
       
   539     if( iLocalFilename )
       
   540         {
       
   541         iLocalFilename->Des().SetLength( 0 );
       
   542         }
       
   543 
       
   544     HBufC* destName = iDestFilename;
       
   545     if( destName && destName->Length() && !iDestFNameSet )
       
   546         {
       
   547         destName->Des().SetLength( 0 );
       
   548         }
       
   549     }
       
   550 
       
   551 // -----------------------------------------------------------------------------
       
   552 // CHttpStorage::AdoptFileHandleL
       
   553 // -----------------------------------------------------------------------------
       
   554 //
       
   555 void CHttpStorage::AdoptFileHandleL( RFile* aFile )
       
   556     {
       
   557     LOGGER_ENTERFN( "AdoptFileHandleL" );
       
   558     
       
   559     __ASSERT_DEBUG( !iRFileSetByClient, DMPanic( KErrInUse ) );
       
   560     __ASSERT_DEBUG( !iFile, DMPanic( KErrInUse ) );
       
   561 #ifdef __SYNCML_DM_FOTA
       
   562     if( iRFileSetByClient || iFile || iFotaEngine )
       
   563 #else
       
   564     if( iRFileSetByClient || iFile )
       
   565 #endif
       
   566         {
       
   567         CLOG_WRITE_2( "iRFileSetByClient: %d, iFile: %d", iRFileSetByClient, iFile );
       
   568         User::Leave( KErrInUse );
       
   569         }
       
   570 
       
   571     // forget any previously set filename
       
   572     delete iDestFilename; iDestFilename = NULL;
       
   573     delete iLocalFilename; iLocalFilename = NULL;
       
   574     iDestFNameSet = EFalse;
       
   575     
       
   576     iFile = aFile;
       
   577     
       
   578     // check how many bytes are already persisted
       
   579     iFile->Size( (TInt&)iDownloadedSize );
       
   580 
       
   581     CLOG_WRITE_1( "File size: %d", iDownloadedSize );
       
   582     
       
   583     iRFileSetByClient = ETrue;
       
   584     }
       
   585 
       
   586 // -----------------------------------------------------------------------------
       
   587 // CHttpStorage::SetProgressiveMode
       
   588 // -----------------------------------------------------------------------------
       
   589 //
       
   590 void CHttpStorage::SetProgressiveMode( TBool aValue )
       
   591     {
       
   592     iProgressiveDownload = aValue;
       
   593     if( iProgressiveDownload )
       
   594         {
       
   595         iBufferSize = KDefaultStorageBufferSizePD;
       
   596         }
       
   597     EnableBufferingL();    
       
   598       
       
   599     if( iFile )
       
   600         {
       
   601         if( iProgressiveDownload )
       
   602             {
       
   603             if( iLength != KDefaultContentLength )    
       
   604                 {
       
   605                 iFile->SetSize( iLength );
       
   606                 }
       
   607             }
       
   608         else
       
   609             {
       
   610             iFile->SetSize( iDownloadedSize );
       
   611             }
       
   612         }
       
   613     }
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // CHttpStorage::CheckFreeDiskSpaceL
       
   617 // ?implementation_description
       
   618 // (other items were commented in a header).
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 TInt CHttpStorage::CheckFreeDiskSpaceL()
       
   622     {
       
   623     LOGGER_ENTERFN( "CheckFreeDiskSpaceL" );
       
   624     TInt err( KErrNone );
       
   625     CHttpDownloadManagerServerEngine *DMSrvEngine = iDownload->ClientApp()->Engine();
       
   626     RFs& fs = DMSrvEngine->Fs();
       
   627     TInt bytesToWrite(0);
       
   628     
       
   629     if( iLength == KDefaultContentLength || iLength == 0 )
       
   630         // we don't know the size of the content -> no way to check that it can
       
   631         // fit into memory
       
   632         {
       
   633 #ifdef RD_MULTIPLE_DRIVE
       
   634         TVolumeInfo volInfoCurrent;
       
   635         TInt driveSpaceMax;
       
   636         TInt driveSpaceCurrent;
       
   637         TInt64 freeSpaceCurrent( 0 );
       
   638         TInt64 freeSpaceMax( 0 );
       
   639         TInt errDrvStat;
       
   640 
       
   641         // initializing Drive variables to Default System drive/memory
       
   642         User::LeaveIfError(
       
   643             DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, driveSpaceMax ) );
       
   644         driveSpaceCurrent = driveSpaceMax;
       
   645 
       
   646         HBufC8* drivesDynList = iDownload->ClientApp()->Engine()->QueryDynDriveListLC();
       
   647         TPtrC8 drives( *drivesDynList );
       
   648 
       
   649         // drive letters are separated by semicolons
       
   650         for( TInt i = 0; i < drives.Length(); i = i + 2 )
       
   651             {
       
   652             if( (err = fs.CharToDrive( drives[i], driveSpaceCurrent )) == KErrNone )
       
   653                 {
       
   654                 TUint status;
       
   655                 CLOG_WRITE_1( " Current Drive: %d", driveSpaceCurrent );
       
   656                 errDrvStat = DriveInfo::GetDriveStatus( fs, driveSpaceCurrent, status );
       
   657                 if ( errDrvStat == KErrNone )
       
   658                     {
       
   659                     if ( ( status & ( DriveInfo::EDriveUserVisible | DriveInfo::EDrivePresent ) ) )
       
   660                         {
       
   661                         CLOG_WRITE_1( "Drive %d is present and visible", driveSpaceCurrent);
       
   662                         TInt errVol = fs.Volume( volInfoCurrent, driveSpaceCurrent );
       
   663                         if (( errVol != KErrNone ) || ( volInfoCurrent.iDrive.iType <= EMediaUnknown)) 
       
   664                             {
       
   665                             CLOG_WRITE_1( " errVol: %d", errVol );
       
   666                             CLOG_WRITE_1( " Current Drive driveSpaceCurrent: %d", driveSpaceCurrent );
       
   667                             CLOG_WRITE_1( " volInfoCurrent.iDrive.iType: %d", volInfoCurrent.iDrive.iType );
       
   668                             continue;
       
   669                             }
       
   670                         else
       
   671                             {
       
   672                             CLOG_WRITE_1( " errVol: %d", errVol );
       
   673                             CLOG_WRITE_1( " Current Drive driveSpaceCurrent: %d", driveSpaceCurrent );
       
   674                             CLOG_WRITE_1( " volInfoCurrent.iDrive.iType: %d", volInfoCurrent.iDrive.iType );
       
   675                             CLOG_WRITE_1( "        volInfoCurrent.iFree: %Ld", volInfoCurrent.iFree );
       
   676                             freeSpaceCurrent = volInfoCurrent.iFree;
       
   677                             if ( freeSpaceCurrent > freeSpaceMax ) 
       
   678                                 {
       
   679                                 freeSpaceMax = freeSpaceCurrent;
       
   680                                 driveSpaceMax = driveSpaceCurrent;
       
   681                                 }
       
   682                             }
       
   683                         }
       
   684                     }
       
   685                 else
       
   686                     {
       
   687                     CLOG_WRITE_1( "GetDriveStatus return error code: %d", errDrvStat);
       
   688                     CLOG_WRITE_1( "Current Drive: %d", driveSpaceCurrent );
       
   689                     }
       
   690                 }
       
   691             else
       
   692                 {
       
   693                 CLOG_WRITE_1( "RFS::CharToDrive failed with %d", err );
       
   694                 CLOG_WRITE8_1( "Bad drive letter [%c]", drives[i] );
       
   695                 }            
       
   696             }
       
   697         CleanupStack::PopAndDestroy( drivesDynList );
       
   698         CLOG_WRITE_2( "Saving content to %d Drive with %d B free space", driveSpaceMax, freeSpaceMax );
       
   699         
       
   700         TDriveInfo driveInfo;
       
   701     
       
   702     	if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, driveSpaceMax) )
       
   703         	{
       
   704         	iRemovableDest = (driveInfo.iDriveAtt & KDriveAttRemovable);
       
   705         	CLOG_WRITE_1( "Removable: [%d]", iRemovableDest );
       
   706         	CLOG_WRITE_1( "driveInfo.iDriveAtt: [%d]", driveInfo.iDriveAtt );
       
   707         	}
       
   708     	else
       
   709         	{
       
   710         	CLOG_WRITE("DriveInfo failed");
       
   711         	}
       
   712         	
       
   713         return driveSpaceMax;
       
   714 #else
       
   715         // If no MMC is inserted, this will leave (and not set mmcOk).
       
   716         bytesToWrite = iLength;
       
   717         if (bytesToWrite < 0)
       
   718             bytesToWrite = 0;
       
   719         
       
   720         TBool mmcOk = EFalse;
       
   721         TRAP_IGNORE( mmcOk = !SysUtil::MMCSpaceBelowCriticalLevelL
       
   722         			       ( &fs, bytesToWrite ); )
       
   723         if(!mmcOk)
       
   724         	{
       
   725         	CLOG_WRITE( "no MMC present" );
       
   726         	return EDriveC;
       
   727         	}
       
   728         CLOG_WRITE( "MMC is present " );        
       
   729         TVolumeInfo volInfoC;
       
   730         TVolumeInfo volInfoE;
       
   731         fs.Volume(volInfoC,EDriveC);
       
   732         fs.Volume(volInfoE,EDriveE);
       
   733         TInt64 freeC = volInfoC.iFree;//free memory available in that drive
       
   734         TInt64 freeE = volInfoE.iFree;
       
   735         return  freeC>=freeE?EDriveC:EDriveE;//put the file in which ever drive has more memory
       
   736 #endif
       
   737         }
       
   738 
       
   739     // Destination is FFS in default
       
   740 #ifdef RD_MULTIPLE_DRIVE
       
   741     TInt drive;
       
   742     User::LeaveIfError(
       
   743         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive ) );
       
   744 #else
       
   745     TInt drive( EDriveC );
       
   746 #endif
       
   747 
       
   748 	TBool isSpace( EFalse );
       
   749 	
       
   750 	//Get size of currently ongoing downloads
       
   751 	TInt currentDownloadsLen (0);
       
   752 	
       
   753     if( iDestFilename && iDestFilename->Length() )
       
   754         // client app gave the destination filename -> only that drive needs
       
   755         // to be checked
       
   756         {
       
   757         CLOG_WRITE8( "cfds1" );
       
   758         if( (err = fs.CharToDrive( (*iDestFilename)[0], drive )) != KErrNone )
       
   759             {
       
   760             CLOG_WRITE8( "Bad drive letter" );
       
   761             iDownload->OnError( KErrUnknown, EWrongDestFilename );
       
   762             User::Leave( err );
       
   763             }
       
   764         else if( !fs.IsValidDrive( drive ) )
       
   765             // invalid drive letter in filename
       
   766             {
       
   767             CLOG_WRITE8( "Invalid drive" );
       
   768             iDownload->OnError( KErrUnknown, EWrongDestFilename );
       
   769             User::Leave( KErrBadName );
       
   770             }
       
   771         if( iPartialLength ==  KDefaultContentLength )
       
   772             //This is the case when web Server returns Partial Content Length 
       
   773             //Hence Disk Critical level should checked against partial Content Length
       
   774             {
       
   775             iPartialLength = iLength;
       
   776             }
       
   777             
       
   778         currentDownloadsLen = DMSrvEngine->AllDownloadsSizeInDriveL(iDownload, drive);
       
   779 
       
   780         // Check if there's enough memory in the phone
       
   781         bytesToWrite = iPartialLength + currentDownloadsLen;
       
   782         if (bytesToWrite < 0)
       
   783             bytesToWrite = 0;
       
   784         
       
   785 	    TRAP( err, isSpace = !SysUtil::DiskSpaceBelowCriticalLevelL(
       
   786                                                 &iDownload->ClientApp()->Engine()->Fs(),
       
   787 			                                    bytesToWrite,
       
   788                                                 drive ));
       
   789         }
       
   790     else
       
   791         {
       
   792 #ifdef RD_MULTIPLE_DRIVE
       
   793         HBufC8* drivesDynList = iDownload->ClientApp()->Engine()->QueryDynDriveListLC();
       
   794         TPtrC8 drives( *drivesDynList );
       
   795 #else
       
   796         TPtrC drives( iDownload->ClientApp()->Engine()->iDriveLettersCenRep );
       
   797 #endif
       
   798         
       
   799         // drive letters are separated by semicolons
       
   800         for( TInt i = 0; i < drives.Length() && (err || !isSpace); i = i + 2 )
       
   801             {
       
   802             if( (err = fs.CharToDrive( drives[i], drive )) == KErrNone )
       
   803                 {
       
   804                 currentDownloadsLen = DMSrvEngine->AllDownloadsSizeInDriveL(iDownload, drive);
       
   805 
       
   806                 // Check if there's enough memory in the phone
       
   807                 bytesToWrite = iLength + currentDownloadsLen;
       
   808                 if (bytesToWrite < 0)
       
   809                     bytesToWrite = 0;
       
   810                 
       
   811         	    TRAP( err, isSpace = !SysUtil::DiskSpaceBelowCriticalLevelL(
       
   812                                                         &fs,
       
   813         			                                    bytesToWrite,
       
   814                                                         drive ));
       
   815                 }
       
   816             else
       
   817                 {
       
   818                 CLOG_WRITE8_1( "Bad drive letter [%c]", drives[i] );
       
   819                 }            
       
   820             }
       
   821 #ifdef RD_MULTIPLE_DRIVE
       
   822         CleanupStack::PopAndDestroy( drivesDynList );
       
   823 #endif
       
   824         }	
       
   825 
       
   826     TDriveInfo driveInfo;
       
   827     
       
   828     if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, drive) )
       
   829         {
       
   830         iRemovableDest = (driveInfo.iDriveAtt & KDriveAttRemovable);
       
   831         CLOG_WRITE_1( "Removable: [%d]", iRemovableDest );
       
   832         }
       
   833     else
       
   834         {
       
   835         CLOG_WRITE("DriveInfo failed");
       
   836         }
       
   837 
       
   838     if( err || !isSpace )
       
   839         {
       
   840         CLOG_WRITE8( "OOD1" );
       
   841         iDownload->OnError( KErrDiskFull, EDiskFull );
       
   842         User::Leave( KErrDiskFull );
       
   843         }
       
   844 
       
   845     return drive;
       
   846     }
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // CHttpStorage::CreateDestinationFilenameL
       
   850 // ?implementation_description
       
   851 // (other items were commented in a header).
       
   852 // -----------------------------------------------------------------------------
       
   853 //
       
   854 void CHttpStorage::CreateDestinationFilenameL()
       
   855     {
       
   856     LOGGER_ENTERFN( "CreateDestinationFilenameL" );
       
   857 
       
   858     TInt drive = CheckFreeDiskSpaceL();
       
   859 
       
   860     if( iLocalFilename && iLocalFilename->Length() )
       
   861         // Destination filename is already created, or set
       
   862         // by client app -> nothing to do
       
   863         {
       
   864         CLOG_WRITE_1( "local: %S", iLocalFilename );
       
   865         return;
       
   866         }
       
   867 
       
   868     if( iDestFNameSet )
       
   869         // Use destination filename client app set
       
   870         {
       
   871         ReallocateStringL( iLocalFilename, *iDestFilename, KMaxPath );
       
   872         }
       
   873     else
       
   874         {
       
   875         TPath folder;
       
   876 
       
   877         iDownload->ClientApp()->Engine()->DownloadContentFolder( iDownload->ClientApp(),
       
   878                                                                  folder );
       
   879 
       
   880         delete iLocalFilename; iLocalFilename = NULL;
       
   881 
       
   882         TChar driveChar;
       
   883 
       
   884         // this is surely works because we got the driver letter
       
   885         // from the FS earlier
       
   886         iDownload->ClientApp()->Engine()->Fs().DriveToChar( drive, driveChar );
       
   887         // allocate filename buffer
       
   888         TInt pathLen = folder.Length();
       
   889         TInt dlNameLen = MIN( KDownloadNameMaxSize, iDownload->iDlName->Length() );
       
   890         iLocalFilename = HBufC::NewL( pathLen + dlNameLen + KFileNameExtensionMaxSize );
       
   891         TPtr locFilenamePtr = iLocalFilename->Des();
       
   892         // copy path and name to buffer
       
   893         locFilenamePtr.Copy( folder );
       
   894         locFilenamePtr.Append( iDownload->iDlName->Left( dlNameLen ) );
       
   895 
       
   896         // set drive letter
       
   897         locFilenamePtr[0] = (TUint16)TUint(driveChar);
       
   898 
       
   899         ReallocateStringL( iDestFilename, *iLocalFilename, KMaxPath );
       
   900 
       
   901         UpdateExtensionL();
       
   902 
       
   903 		// Below code is to update the destination file path with new destination file name.
       
   904 		// Check if the iDlName and filename in iLocalFileName are same. If not update the 
       
   905 		// iLocalFilename and iDestFilename with iDlName. Note that iDlName has an unique file name.
       
   906     	if( iLocalFilename->Des().Right( iDownload->iDlName->Length() ).CompareF( *iDownload->iDlName ) )
       
   907         {
       
   908         TInt slash = iLocalFilename->Des().LocateReverse( '/' );
       
   909 
       
   910         if( slash == KErrNotFound )
       
   911             {
       
   912             slash = iLocalFilename->Des().LocateReverse( '\\' );
       
   913             }
       
   914            
       
   915         if( slash != KErrNotFound )
       
   916             {
       
   917             TInt newDLNameLen = iDownload->iDlName->Length();
       
   918             TInt newLength = slash + newDLNameLen + 1;
       
   919             iLocalFilename = iLocalFilename->ReAllocL(newLength);
       
   920             iLocalFilename->Des().SetLength( newLength );
       
   921             iLocalFilename->Des().Replace( slash+1, newDLNameLen, iDownload->iDlName->Des() );            
       
   922 	        ReallocateStringL( iDestFilename, *iLocalFilename, KMaxPath );
       
   923             }
       
   924         }        
       
   925         
       
   926         }
       
   927 
       
   928 	TBuf8<KMaxContentTypeLength> contentType;
       
   929 	contentType.Copy( *iDownload->iDDType );
       
   930 	
       
   931 	if( (0 == contentType.Compare( KCodMimeType() )) ||
       
   932 		(0 == contentType.Compare( KDdMimeType() ))	 ||
       
   933 		(0 == contentType.Compare( KDd2MimeType() )) ||
       
   934 		(0 == contentType.Compare( KMultiPartMimeType() )) )
       
   935 		{
       
   936 		iDdFilename = iLocalFilename->Des().AllocL();
       
   937 		}
       
   938 
       
   939     iDriveId = GetDestinationDriveId();
       
   940     
       
   941     TText badChar( 32 );
       
   942     TBool isValid = iDownload->ClientApp()->Engine()->Fs().IsValidName( *iLocalFilename, badChar );
       
   943     
       
   944     CLOG_WRITE_1( "dest2: %S", iLocalFilename );
       
   945     CLOG_WRITE_2( "Valid: %d - %c", isValid, badChar );
       
   946     }
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // CHttpStorage::GetDestinationDriveId
       
   950 // ?implementation_description
       
   951 // (other items were commented in a header).
       
   952 // -----------------------------------------------------------------------------
       
   953 //
       
   954 TUint CHttpStorage::GetDestinationDriveId()
       
   955     {
       
   956     LOGGER_ENTERFN( "GetDestinationDriveId" );
       
   957     TUint retVal( (TUint)KErrNotFound );
       
   958 
       
   959     if( iDestFilename && iDestFilename->Length() )
       
   960         {
       
   961         TInt drive;
       
   962         iDownload->ClientApp()->Engine()->Fs().CharToDrive( 
       
   963                                                     (*iDestFilename)[0], drive );
       
   964 
       
   965         TVolumeInfo info;
       
   966 
       
   967         if( iDownload->ClientApp()->Engine()->Fs().Volume( info, drive ) 
       
   968                                                                 == KErrNone )
       
   969             {
       
   970             CLOG_WRITE_1( "Dest drive id: %x", info.iUniqueID );
       
   971 
       
   972             retVal = info.iUniqueID;
       
   973             }
       
   974         else
       
   975             {
       
   976             CLOG_WRITE( "Volume failed" );
       
   977             retVal = (TUint)KErrNotFound;
       
   978             }
       
   979         }
       
   980     CLOG_WRITE_1( " retVal: %d", retVal );
       
   981     return retVal;
       
   982     }
       
   983     
       
   984 // -----------------------------------------------------------------------------
       
   985 // CHttpStorage::UpdateDestinationFilenameL
       
   986 // ?implementation_description
       
   987 // (other items were commented in a header).
       
   988 // -----------------------------------------------------------------------------
       
   989 //
       
   990 void CHttpStorage::UpdateDestinationFilenameL( const TDesC16& aFilename, TBool aUserSet )
       
   991 	{
       
   992 	LOGGER_ENTERFN( "UpdateDestinationFilenameL" );
       
   993 	CLOG_WRITE_2( "FN: [%S], userSet: %d", &aFilename, aUserSet );
       
   994     TBufC<KMaxFileName> oldFileName;
       
   995 	if( iDestFilename )
       
   996 		{
       
   997 		oldFileName = *iDestFilename;
       
   998 		}
       
   999     ReallocateStringL( iDestFilename, aFilename, KMaxPath );
       
  1000     iDestFNameSet = aUserSet;
       
  1001     if ( aFilename.Length() == 0 )
       
  1002         {
       
  1003         return;
       
  1004         }
       
  1005         
       
  1006     iDriveId = GetDestinationDriveId();
       
  1007     TInt drive;
       
  1008     if( !iDownload->ClientApp()->Engine()->Fs().CharToDrive((*iDestFilename)[0], drive) )
       
  1009         {
       
  1010         TDriveInfo driveInfo;
       
  1011         if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, drive) )
       
  1012             {
       
  1013             iRemovableDest = (driveInfo.iDriveAtt & KDriveAttRemovable);
       
  1014             CLOG_WRITE_1( "Removable: [%d]", iRemovableDest );
       
  1015             }
       
  1016         else
       
  1017             {
       
  1018             CLOG_WRITE("DriveInfo failed");
       
  1019             }
       
  1020         }
       
  1021     else
       
  1022         {
       
  1023         CLOG_WRITE("CharToDrive failed");
       
  1024         }
       
  1025     
       
  1026 	}
       
  1027 
       
  1028 // -----------------------------------------------------------------------------
       
  1029 // CHttpStorage::AppendStorageInfoL
       
  1030 // ?implementation_description
       
  1031 // (other items were commented in a header).
       
  1032 // -----------------------------------------------------------------------------
       
  1033 //
       
  1034 void CHttpStorage::AppendStorageInfoL( TPtr8& aBuf ) const
       
  1035     {
       
  1036     AppendBufL( aBuf, iDestFilename );
       
  1037     APPEND_BUF_INT( aBuf, iDestFNameSet );
       
  1038     AppendBufL( aBuf, iLocalFilename );    
       
  1039     APPEND_BUF_INT( aBuf, iLength );
       
  1040     APPEND_BUF_INT( aBuf, iDriveId );
       
  1041     APPEND_BUF_INT( aBuf, iStorageMethod );
       
  1042     APPEND_BUF_INT( aBuf, iProgressiveDownload);
       
  1043     APPEND_BUF_INT( aBuf, iDownloadedSize);
       
  1044     AppendBufL( aBuf, iDdFilename );    
       
  1045     APPEND_BUF_INT( aBuf, iDownload->iMoLength );
       
  1046     APPEND_BUF_INT( aBuf, iRemovableDest );
       
  1047 
       
  1048     }
       
  1049 
       
  1050 // -----------------------------------------------------------------------------
       
  1051 // CHttpStorage::SaveStorageInfoL
       
  1052 // ?implementation_description
       
  1053 // (other items were commented in a header).
       
  1054 // -----------------------------------------------------------------------------
       
  1055 //
       
  1056 void CHttpStorage::LoadStorageInfoL( RFile& aInFile )
       
  1057     {
       
  1058     ReadHBufCL( aInFile, iDestFilename );
       
  1059     READ_INT_L( aInFile, iDestFNameSet );
       
  1060     ReadHBufCL( aInFile, iLocalFilename );    
       
  1061     READ_INT_L( aInFile, iLength );
       
  1062     READ_INT_L( aInFile, iDriveId );
       
  1063     READ_INT_L( aInFile, iStorageMethod );
       
  1064     READ_INT_L( aInFile, iProgressiveDownload);
       
  1065     READ_INT_L( aInFile, iDownloadedSize );
       
  1066     ReadHBufCL( aInFile, iDdFilename );
       
  1067     READ_INT_L( aInFile, iDownload->iMoLength  );
       
  1068     READ_INT_L( aInFile, iRemovableDest  );
       
  1069 
       
  1070     }
       
  1071 
       
  1072 // -----------------------------------------------------------------------------
       
  1073 // CHttpStorage::UpdateExtensionL
       
  1074 // ?implementation_description
       
  1075 // (other items were commented in a header).
       
  1076 // -----------------------------------------------------------------------------
       
  1077 //
       
  1078 void CHttpStorage::UpdateExtensionL()
       
  1079     {
       
  1080     LOGGER_ENTERFN( "UpdateExtensionL" );
       
  1081     
       
  1082     TPtr fileName( iDestFilename->Des() );
       
  1083     TBool toDelete;
       
  1084     const HBufC8* contentType = NULL;
       
  1085 
       
  1086 #ifdef DRM_EXTENSION_SPECIAL_CASE
       
  1087     // Check if we have the original DRM content-type    
       
  1088     const CArrayPtrFlat<CHeaderField>* resp = iDownload->ResponseHeaders();
       
  1089     
       
  1090     TInt index = iDownload->FindHeaderField( resp, KDRMOldContentType );
       
  1091     
       
  1092     if( index != KErrNotFound )
       
  1093         // Yes, we have it. Use the content-type set to this field.
       
  1094         {
       
  1095         CLOG_WRITE( "Old DRM content type" );
       
  1096         contentType = (*resp)[index]->FieldRawData();
       
  1097         }
       
  1098     else
       
  1099         {
       
  1100         contentType = iDownload->GetString8AttributeL( EDlAttrContentType, toDelete );
       
  1101         }
       
  1102 #else
       
  1103     contentType = iDownload->GetString8AttributeL( EDlAttrContentType, toDelete );
       
  1104 #endif        
       
  1105 
       
  1106     CLOG_WRITE8_1( "Content-Type: [%S]", contentType );
       
  1107     
       
  1108     TDataType dataType( *contentType );
       
  1109     
       
  1110     iDownload->ClientApp()->Engine()->DocHandler()->CheckFileNameExtension( fileName, dataType );
       
  1111 
       
  1112     ReallocateStringL( iLocalFilename, *iDestFilename, KMaxPath );
       
  1113     
       
  1114     CLOG_WRITE_1( "filename: [%S]", &fileName );
       
  1115     CLOG_WRITE_1( "DlName: [%S]", iDownload->iDlName );
       
  1116     
       
  1117     if( fileName.Right( iDownload->iDlName->Length() ).CompareF( *iDownload->iDlName ) )
       
  1118         {
       
  1119         CLOG_WRITE("Updating DlName");
       
  1120         TInt slash = fileName.LocateReverse( '/' );
       
  1121 
       
  1122         if( slash == KErrNotFound )
       
  1123             {
       
  1124             slash = fileName.LocateReverse( '\\' );
       
  1125             }
       
  1126            
       
  1127         if( slash != KErrNotFound )
       
  1128             {
       
  1129             iDownload->SetDownloadNameL( fileName.Right(fileName.Length()-slash-1) );
       
  1130             }
       
  1131         else
       
  1132             {
       
  1133             iDownload->SetDownloadNameL( fileName );
       
  1134             }
       
  1135         }
       
  1136     }
       
  1137 
       
  1138 // -----------------------------------------------------------------------------
       
  1139 // CHttpStorage::SetBufferSize
       
  1140 // set size of disk buffer: after this - call EnableBuffering() or buffering
       
  1141 // will be disabled.
       
  1142 // (other items were commented in a header).
       
  1143 // -----------------------------------------------------------------------------
       
  1144 //
       
  1145 void CHttpStorage::SetBufferSizeL( TInt aBufferSize )
       
  1146     {
       
  1147     DisableBufferingL();
       
  1148     iBufferSize = aBufferSize;
       
  1149     }
       
  1150 
       
  1151 // -----------------------------------------------------------------------------
       
  1152 // CHttpStorage::EnableBuffering
       
  1153 // turn on buffered writing of data to disk
       
  1154 // (other items were commented in a header).
       
  1155 // -----------------------------------------------------------------------------
       
  1156 //
       
  1157 void CHttpStorage::EnableBufferingL()
       
  1158     {
       
  1159     // first check if buffer exists, and if it does, has iBufferSize
       
  1160     // been changed since buffering was last enabled
       
  1161     
       
  1162     CLOG_WRITE("CHttpStorage::EnableBufferingL >>");
       
  1163     
       
  1164     if( iBufferingEnabled && iBufferSize != iStorage->CurrentBufferSize())
       
  1165         {
       
  1166         FlushL();
       
  1167         }
       
  1168 
       
  1169     iBufferingEnabled = ETrue;
       
  1170     
       
  1171     CLOG_WRITE("CHttpStorage::EnableBufferingL <<");
       
  1172     }
       
  1173 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // CHttpStorage::DisableBuffering
       
  1176 // turn off buffered writing of data to disk
       
  1177 // (other items were commented in a header).
       
  1178 // -----------------------------------------------------------------------------
       
  1179 //
       
  1180 void CHttpStorage::DisableBufferingL()
       
  1181     {
       
  1182     FlushL();
       
  1183     iBufferingEnabled = EFalse;
       
  1184     }
       
  1185 
       
  1186 // -----------------------------------------------------------------------------
       
  1187 // CHttpStorage::Flush
       
  1188 // Flush internal buffer to disk
       
  1189 // (other items were commented in a header).
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CHttpStorage::FlushL()
       
  1193     {
       
  1194     iStorage->FlushBuffersL();
       
  1195     iStorage->ResetBuffers();
       
  1196     }
       
  1197 
       
  1198 // -----------------------------------------------------------------------------
       
  1199 // CHttpStorage::SetLocalFilenameL
       
  1200 // -----------------------------------------------------------------------------
       
  1201 //
       
  1202 void CHttpStorage::SetLocalFilenameL(const TDesC16& aValue)
       
  1203 {
       
  1204     TBool isCodDownload;
       
  1205     iDownload->GetBoolAttributeL( EDlAttrCodDownload, isCodDownload );
       
  1206     // allow to set the local file name only for OMA downloads in case PDL
       
  1207 	// In this case the MP/VP is responsible for file move. This app should set 
       
  1208 	// dest and local file names before move.
       
  1209 	if (isCodDownload && iProgressiveDownload)
       
  1210 	{
       
  1211 	  TRAP_IGNORE(ReallocateStringL( iLocalFilename, aValue, KMaxPath ));
       
  1212 	}
       
  1213 }
       
  1214     
       
  1215 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1216 
       
  1217 //  End of File