wvuing/Utils/CAVersion.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 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 "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:  Version provider for IM.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "CAVersion.h"
       
    20 #include "ChatDebugPrint.h"
       
    21 
       
    22 #include <f32file.h>
       
    23 #include <pathinfo.h>
       
    24 
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KChatVersionBuffer = 1024;
       
    28 const TInt KDriveAndColon = 2;
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // CAVersion::UpdateVersion
       
    32 // ---------------------------------------------------------
       
    33 //
       
    34 TInt CAVersion::UpdateVersion( RFs& aFs
       
    35                                , const TDesC& aOwnVersionFile
       
    36                                , const TDesC& aTargetFile )
       
    37     {
       
    38     CHAT_DP( D_CHAT_LIT( "CAVersion::UpdateVersion %S %S" ), &aOwnVersionFile,
       
    39              &aTargetFile );
       
    40 
       
    41     // Get ROM and C drives
       
    42     TBuf<KDriveAndColon> romDrive;
       
    43     TBuf<KDriveAndColon> cDrive;
       
    44     romDrive = PathInfo::RomRootPath().Left( KDriveAndColon );
       
    45     cDrive = PathInfo::PhoneMemoryRootPath().Left( KDriveAndColon );
       
    46 
       
    47     // Construct full path for private version file
       
    48     TFileName ownVersionFile;
       
    49     aFs.PrivatePath( ownVersionFile );
       
    50     ownVersionFile.Insert( 0, romDrive );
       
    51     ownVersionFile.Append( aOwnVersionFile );
       
    52 
       
    53     // Append drive to published version file
       
    54     TFileName targetFile;
       
    55     targetFile.Append( cDrive );
       
    56     targetFile.Append( aTargetFile );
       
    57 
       
    58     if ( ownVersionFile.Compare( targetFile ) == KErrNone )
       
    59         {
       
    60         //nothing to do
       
    61         return KErrNone;
       
    62         }
       
    63 
       
    64     TBuf8< KChatVersionBuffer > myBuffer;
       
    65     myBuffer.Zero();
       
    66 
       
    67     TInt err( KErrNone );
       
    68 
       
    69     RFile myInputFile;
       
    70     RFile myOutputFile;
       
    71 
       
    72     err = myInputFile.Open( aFs, ownVersionFile, EFileRead );
       
    73 
       
    74     if ( !err )
       
    75         {
       
    76         err = myOutputFile.Replace( aFs, targetFile, EFileWrite );
       
    77         }
       
    78 #ifdef _DEBUG
       
    79     else
       
    80         {
       
    81         CHAT_DP( D_CHAT_LIT( "CAVersion::UpdateVersion Open %d" ), err );
       
    82         }
       
    83 #endif
       
    84 
       
    85     if ( !err )
       
    86         {
       
    87         TBool more( ETrue );
       
    88         while ( !err && more )
       
    89             {
       
    90             err = myInputFile.Read( myBuffer, KChatVersionBuffer );
       
    91             if ( !myBuffer.Length() )
       
    92                 {
       
    93                 more = EFalse;
       
    94                 }
       
    95             if ( !err )
       
    96                 {
       
    97                 err = myOutputFile.Write( myBuffer );
       
    98                 }
       
    99 #ifdef _DEBUG
       
   100             else
       
   101                 {
       
   102                 CHAT_DP( D_CHAT_LIT( "CAVersion::UpdateVersion Read %d" ),
       
   103                          err );
       
   104                 }
       
   105 
       
   106             if ( err )
       
   107                 {
       
   108                 CHAT_DP( D_CHAT_LIT( "CAVersion::UpdateVersion Write %d" ),
       
   109                          err );
       
   110                 }
       
   111 #endif
       
   112             }
       
   113         }
       
   114 #ifdef _DEBUG
       
   115     else
       
   116         {
       
   117         CHAT_DP( D_CHAT_LIT( "CAVersion::UpdateVersion Replace %d" ), err );
       
   118         }
       
   119 #endif
       
   120 
       
   121     myInputFile.Close();
       
   122     myOutputFile.Close();
       
   123 
       
   124     return err;
       
   125     }
       
   126 
       
   127 // End of file