filemanager/bkupengine/src/CMMCScBkupFileListCollection.cpp
branchRCL_3
changeset 39 65326cf895ed
parent 0 6a9f87576119
equal deleted inserted replaced
38:491b3ed49290 39:65326cf895ed
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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: CMMCScBkupFileListCollection implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupFileListCollection.h"
       
    20 
       
    21 #include <bldvariant.hrh>
       
    22 #include <pathinfo.h>
       
    23 
       
    24 // User includes
       
    25 #include "MMCScBkupLogger.h"
       
    26 #include "CMMCScBkupDataOwnerInfo.h"
       
    27 #ifdef RD_FILE_MANAGER_BACKUP
       
    28 #include <driveinfo.h>
       
    29 #include "BkupEngine.hrh"
       
    30 #include "pathconfiguration.hrh"
       
    31 #endif 
       
    32 
       
    33 // Constants
       
    34 const TInt KMMCScBkupDataOwnerGranularity = 50;
       
    35 
       
    36 
       
    37 
       
    38 
       
    39 // ========================= MEMBER FUNCTIONS ================================
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CMMCScBkupFileListCollection::CMMCScBkupFileListCollection()
       
    43 // 
       
    44 // C++ constructor.
       
    45 // ---------------------------------------------------------------------------
       
    46 CMMCScBkupFileListCollection::CMMCScBkupFileListCollection( TBitFlags aCategory, 
       
    47     RFs& aFsSession )
       
    48     :iEntries(KMMCScBkupDataOwnerGranularity), 
       
    49     iCategory( aCategory ),
       
    50     iFsSession( aFsSession )
       
    51     {
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CMMCScBkupFileListCollection::~CMMCScBkupFileListCollection()
       
    56 // 
       
    57 // Destructor.
       
    58 // ---------------------------------------------------------------------------
       
    59 CMMCScBkupFileListCollection::~CMMCScBkupFileListCollection()
       
    60     {
       
    61     Reset();
       
    62     iEntries.Close();
       
    63     }
       
    64 
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CMMCScBkupFileListCollection::ConstructL()
       
    68 // 
       
    69 // 
       
    70 // ---------------------------------------------------------------------------
       
    71 void CMMCScBkupFileListCollection::ConstructL()
       
    72     {
       
    73     }
       
    74 
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CMMCScBkupFileListCollection::NewL()
       
    78 // 
       
    79 // 
       
    80 // ---------------------------------------------------------------------------
       
    81 CMMCScBkupFileListCollection* CMMCScBkupFileListCollection::NewL( TBitFlags aCategory,
       
    82     RFs& aFsSession )
       
    83     {
       
    84     CMMCScBkupFileListCollection* self = new(ELeave) CMMCScBkupFileListCollection( aCategory, aFsSession );
       
    85     CleanupStack::PushL(self);
       
    86     self->ConstructL();
       
    87     CleanupStack::Pop(self);
       
    88     return self;
       
    89     }
       
    90 
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // CMMCScBkupFileListCollection::AppendL()
       
    94 // 
       
    95 // 
       
    96 // ---------------------------------------------------------------------------
       
    97 void CMMCScBkupFileListCollection::AppendL( const RArray<TEntry>& aArray, RArray< const CMMCScBkupFileInfo* >& aAddedItems, TSecureId aAssociatedSID )
       
    98     {
       
    99     const TInt count = aArray.Count();
       
   100 
       
   101     __LOG2("CMMCScBkupFileListCollection::AppendL() - Number of files %d to check for category %x", count, Category().Value() );
       
   102     
       
   103     for(TInt i=0; i<count; i++)
       
   104         {
       
   105         const TEntry& entry = aArray[i];
       
   106 #ifdef RD_FILE_MANAGER_BACKUP
       
   107         TBool skipFile = EFalse;
       
   108 
       
   109         if(Category().Value() != EBUCatUserFiles && Category().Value() != EBUCatAllInOne)
       
   110             {
       
   111             // Check whether public file in system user data folder. If it is and not part of
       
   112             // user file category, then discard file from collection
       
   113             const TDesC& path = PathInfo::PhoneMemoryRootPath();
       
   114             TInt error = entry.iName.FindF(path);
       
   115             if(error != KErrNotFound)
       
   116                 {
       
   117                 __LOG1("CMMCScBkupFileListCollection::AppendL() - Skipping file %S", &entry.iName );
       
   118                 skipFile = ETrue;
       
   119                 }
       
   120             }
       
   121         else if(Category().Value() == EBUCatUserFiles)
       
   122             {
       
   123             // Check also if public file is from mass-storage. If yes and user-files category in
       
   124             // question, prevent file getting backed up, because otherwise it is probable 2 GB 
       
   125             // get exceeded and we cannot save larger than 2 GB archive. Allow public files being 
       
   126             // backed up in other categories.
       
   127             TUint drvStatus( 0 );
       
   128             TInt drive( KErrNotFound );
       
   129             
       
   130             if( RFs::CharToDrive( entry.iName[0], drive ) != KErrNone )
       
   131                 {
       
   132                 drive = KErrNotFound;
       
   133                 }
       
   134             
       
   135             TInt err = DriveInfo::GetDriveStatus(iFsSession, drive, drvStatus );
       
   136             
       
   137             if ( err == KErrNone && ( drvStatus & DriveInfo::EDriveInternal ) &&
       
   138                  ( drvStatus & DriveInfo::EDriveExternallyMountable ) )
       
   139                 {
       
   140                 __LOG1("CMMCScBkupFileListCollection::AppendL() - Skipping file %S due it in mass storage", &entry.iName );
       
   141                 skipFile = ETrue;
       
   142                 }
       
   143             }
       
   144 
       
   145         if(!skipFile)
       
   146 #endif // RD_FILE_MANAGER_BACKUP
       
   147             {
       
   148             // Check whether the file is already present before adding it (avoid duplicate 
       
   149             // public files)
       
   150             CMMCScBkupFileInfo* fileInfo = CMMCScBkupFileInfo::NewLC( entry, aAssociatedSID );
       
   151 
       
   152             TLinearOrder<CMMCScBkupFileInfo> comparer( CMMCScBkupFileInfo::OrderByFileName );
       
   153             const TInt indexIfFound = iEntries.FindInOrder( fileInfo, comparer );
       
   154             if  (indexIfFound < 0)
       
   155                 {
       
   156                 // Item wasn't found - insert it in sorted order
       
   157                 AppendL( fileInfo );
       
   158                 CleanupStack::Pop( fileInfo );
       
   159                 
       
   160                 __LOG1("CMMCScBkupFileListCollection::AppendL() - Adding file %S", &fileInfo->FileName() );
       
   161 
       
   162                 // Add a copy to our return array.
       
   163                 aAddedItems.AppendL( fileInfo );
       
   164                 }
       
   165             else
       
   166                 {
       
   167                 // Duplicate, discard
       
   168                 __LOG1("CMMCScBkupFileListCollection::AppendL() - Duplicate file %S", &fileInfo->FileName() );
       
   169                 CleanupStack::PopAndDestroy( fileInfo );
       
   170                 }
       
   171             }
       
   172         }
       
   173     }
       
   174 
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CMMCScBkupFileListCollection::AppendL()
       
   178 // 
       
   179 // 
       
   180 // ---------------------------------------------------------------------------
       
   181 void CMMCScBkupFileListCollection::AppendL( CMMCScBkupFileInfo* aFileInfo )
       
   182     {
       
   183     TLinearOrder<CMMCScBkupFileInfo> comparer( CMMCScBkupFileInfo::OrderByFileName );
       
   184     iEntries.InsertInOrderL( aFileInfo, comparer );
       
   185     }
       
   186 
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CMMCScBkupFileListCollection::Count()
       
   190 // 
       
   191 // 
       
   192 // ---------------------------------------------------------------------------
       
   193 TInt CMMCScBkupFileListCollection::Count() const
       
   194     {
       
   195     return iEntries.Count();
       
   196     }
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CMMCScBkupFileListCollection::Entry()
       
   201 // 
       
   202 // 
       
   203 // ---------------------------------------------------------------------------
       
   204 const CMMCScBkupFileInfo& CMMCScBkupFileListCollection::Entry(TInt aIndex) const
       
   205     {
       
   206     const CMMCScBkupFileInfo& entry = *iEntries[aIndex];
       
   207     return entry;
       
   208     }
       
   209 
       
   210 
       
   211 // ---------------------------------------------------------------------------
       
   212 // CMMCScBkupFileListCollection::Remove()
       
   213 // 
       
   214 // 
       
   215 // ---------------------------------------------------------------------------
       
   216 void CMMCScBkupFileListCollection::Remove( TInt aIndex )
       
   217     {
       
   218     CMMCScBkupFileInfo* entry = iEntries[aIndex];
       
   219     delete entry;
       
   220     iEntries.Remove(aIndex);
       
   221     }
       
   222 
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CMMCScBkupFileListCollection::Reset()
       
   226 // 
       
   227 // 
       
   228 // ---------------------------------------------------------------------------
       
   229 void CMMCScBkupFileListCollection::Reset()
       
   230     {
       
   231     iEntries.ResetAndDestroy();
       
   232     }
       
   233