filemanager/bkupengine/src/CMMCScBkupIndexPublicDataFiles.cpp
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2005 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: CMMCScBkupIndexPublicDataFiles implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupIndexPublicDataFiles.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMMCScBkupArchiveDataInterface.h"
       
    23 #include "CMMCScBkupFileInfo.h"
       
    24 #include "CMMCScBkupFileListCollection.h"
       
    25 
       
    26 
       
    27     /**
       
    28      * Public File Data
       
    29      * ================
       
    30      * 
       
    31      * This is the format of the data written by the
       
    32      * CMMCScBkupStateArchiveOpPublicDataFiles object
       
    33      * 
       
    34      *  PUB FILE DATA for file 0
       
    35      *  PUB FILE DATA for file 1
       
    36      *  PUB FILE DATA for file n
       
    37      * 
       
    38      * Public File Data Index
       
    39      * ======================
       
    40      * 
       
    41      * This is the format of the data written by this object.
       
    42      * The format allows the possibility of a future partial
       
    43      * restore (hopefully).
       
    44      * 
       
    45      *  4 bytes = count of data owners
       
    46      *
       
    47      *  FOR EACH PUBLIC FILE
       
    48      *  {
       
    49      *      externalised CMMCScBkupFileInfo object
       
    50      *      externalised TMMCScBkupArchiveVector (offset & compressed size) object
       
    51      *  }
       
    52      *
       
    53      **/
       
    54 
       
    55 
       
    56 
       
    57 // ========================= MEMBER FUNCTIONS ================================
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CMMCScBkupIndexPublicDataFiles::CMMCScBkupIndexPublicDataFiles()
       
    61 // 
       
    62 // C++ constructor.
       
    63 // ---------------------------------------------------------------------------
       
    64 CMMCScBkupIndexPublicDataFiles::CMMCScBkupIndexPublicDataFiles()
       
    65 :   CMMCScBkupIndexBase( EMMCScBkupOwnerDataTypePublicData )
       
    66     {
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CMMCScBkupIndexPublicDataFiles::~CMMCScBkupIndexPublicDataFiles()
       
    72 // 
       
    73 // Destructor.
       
    74 // ---------------------------------------------------------------------------
       
    75 CMMCScBkupIndexPublicDataFiles::~CMMCScBkupIndexPublicDataFiles()
       
    76     {
       
    77     iEntries.Close();
       
    78     }
       
    79 
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CMMCScBkupIndexPublicDataFiles::NewLC()
       
    83 // 
       
    84 // 
       
    85 // ---------------------------------------------------------------------------
       
    86 CMMCScBkupIndexPublicDataFiles* CMMCScBkupIndexPublicDataFiles::NewLC()
       
    87     {
       
    88     CMMCScBkupIndexPublicDataFiles* self = new(ELeave) CMMCScBkupIndexPublicDataFiles();
       
    89     CleanupStack::PushL(self);
       
    90     self->ConstructL();
       
    91     return self;
       
    92     }
       
    93 
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CMMCScBkupIndexPublicDataFiles::AddIndexRecordL()
       
    97 // 
       
    98 // 
       
    99 // ---------------------------------------------------------------------------
       
   100 void CMMCScBkupIndexPublicDataFiles::AddIndexRecordL( const TMMCScBkupArchiveVector& aInfo, const CMMCScBkupFileInfo& aFile )
       
   101     {
       
   102     // Create new entry
       
   103     TMMCScBkupPublicFileEntry entry( aInfo, aFile );
       
   104 
       
   105     // Add it to our index
       
   106     iEntries.AppendL( entry );
       
   107     }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CMMCScBkupIndexPublicDataFiles::At()
       
   112 // 
       
   113 // 
       
   114 // ---------------------------------------------------------------------------
       
   115 const CMMCScBkupFileInfo& CMMCScBkupIndexPublicDataFiles::At( TInt aIndex, TMMCScBkupArchiveVector& aInfo ) const
       
   116     {
       
   117     const TMMCScBkupPublicFileEntry& entry = iEntries[ aIndex ];
       
   118     aInfo = entry.iInfo;
       
   119     return *entry.iFile;
       
   120     }
       
   121 
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CMMCScBkupIndexPublicDataFiles::StoreL()
       
   125 // 
       
   126 // 
       
   127 // ---------------------------------------------------------------------------
       
   128 void CMMCScBkupIndexPublicDataFiles::StoreL(MMMCScBkupDriver& aDriver)
       
   129     {
       
   130     MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI();
       
   131     RWriteStream stream(archiveDataInterface.ADIWriteStreamUncompressedLC());
       
   132     //    
       
   133     const TInt count = iEntries.Count();
       
   134     stream.WriteInt32L(count);
       
   135     //
       
   136     for(TInt i=0; i<count; i++)
       
   137         {
       
   138         const TMMCScBkupPublicFileEntry& entry = iEntries[i];
       
   139         stream << *entry.iFile;
       
   140         stream << entry.iInfo;
       
   141         }
       
   142     //
       
   143     stream.CommitL();
       
   144     CleanupStack::PopAndDestroy(); // stream
       
   145 
       
   146     // Update our base class info with the offset to the index
       
   147     SetVector( archiveDataInterface.ADICurrentArchiveVectorInfo() );
       
   148     }
       
   149 
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CMMCScBkupIndexPublicDataFiles::RestoreL()
       
   153 // 
       
   154 // 
       
   155 // ---------------------------------------------------------------------------
       
   156 void CMMCScBkupIndexPublicDataFiles::RestoreL(MMMCScBkupDriver& aDriver)
       
   157     {
       
   158     CMMCScBkupFileListCollection& fileList = aDriver.DrvFileList();
       
   159     //
       
   160     MMMCScBkupArchiveDataInterface& archiveDataInterface = aDriver.DrvADI();
       
   161     RReadStream& stream = archiveDataInterface.ADIReadStreamUncompressedLC( Vector().Offset() );
       
   162     //
       
   163     const TInt count = stream.ReadInt32L();
       
   164     for(TInt i=0; i<count; i++)
       
   165         {
       
   166         TMMCScBkupPublicFileEntry entry;
       
   167 
       
   168         // Reconstruct the CMMCScBkupFileInfo entry in the stream
       
   169         CMMCScBkupFileInfo* fileInfo = CMMCScBkupFileInfo::NewLC( stream );
       
   170 
       
   171         // Give ownership to the file list collection
       
   172         fileList.AppendL( fileInfo );
       
   173         CleanupStack::Pop( fileInfo );
       
   174         entry.iFile = fileInfo;
       
   175 
       
   176         // Then read the offset to the file...
       
   177         stream >> entry.iInfo;
       
   178 
       
   179         // And finally add a new record to our index, so client's can
       
   180         // retrieve the info.
       
   181         iEntries.AppendL( entry );
       
   182         }
       
   183     //
       
   184     CleanupStack::PopAndDestroy(); // stream
       
   185     //
       
   186     const TMMCScBkupArchiveVector& readInfo = archiveDataInterface.ADICurrentArchiveVectorInfo();
       
   187     if  ( readInfo.Length() > Vector().Length() )
       
   188         {
       
   189         // We've read too much!
       
   190         User::Leave( KErrCorrupt );
       
   191         }
       
   192     }
       
   193 
       
   194 
       
   195 
       
   196