filemanager/bkupengine/src/CMMCScBkupDriveAndOperationTypeManager.cpp
branchRCL_3
changeset 20 491b3ed49290
parent 19 95243422089a
child 21 65326cf895ed
equal deleted inserted replaced
19:95243422089a 20:491b3ed49290
     1 /*
       
     2 * Copyright (c) 2006-2007 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: CMMCScBkupDriveAndOperationTypeManager implementation
       
    15 *     
       
    16 *
       
    17 */
       
    18 
       
    19 #include "CMMCScBkupDriveAndOperationTypeManager.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMCScBkupLogger.h"
       
    23 #ifdef RD_MULTIPLE_DRIVE
       
    24 #include "BkupEngine.hrh"
       
    25 #include <driveinfo.h>
       
    26 #include <coemain.h>
       
    27 #endif // RD_MULTIPLE_DRIVE
       
    28 
       
    29 
       
    30 // ========================= MEMBER FUNCTIONS ================================
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CMMCScBkupDriveAndOperationTypeManager::CMMCScBkupDriveAndOperationTypeManager()
       
    34 // 
       
    35 // C++ constructor.
       
    36 // ---------------------------------------------------------------------------
       
    37 CMMCScBkupDriveAndOperationTypeManager::CMMCScBkupDriveAndOperationTypeManager()
       
    38     {
       
    39     iCalculatedDriveList.SetMax();
       
    40     }
       
    41 
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CMMCScBkupDriveAndOperationTypeManager::CMMCScBkupDriveAndOperationTypeManager()
       
    45 // 
       
    46 // C++ destructor.
       
    47 // ---------------------------------------------------------------------------
       
    48 EXPORT_C CMMCScBkupDriveAndOperationTypeManager::~CMMCScBkupDriveAndOperationTypeManager()
       
    49     {
       
    50     iEntries.Close();
       
    51     }
       
    52 
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CMMCScBkupDriveAndOperationTypeManager::ConstructL()
       
    56 // 
       
    57 // 
       
    58 // ---------------------------------------------------------------------------
       
    59 void CMMCScBkupDriveAndOperationTypeManager::ConstructL( TResourceReader& aReader )
       
    60     {
       
    61 #ifdef RD_MULTIPLE_DRIVE
       
    62     RFs& fs( CCoeEnv::Static()->FsSession() );
       
    63 
       
    64     // Get all user visible drives
       
    65     TInt numDrives( 0 );
       
    66     TDriveList drvList;
       
    67     User::LeaveIfError( DriveInfo::GetUserVisibleDrives(
       
    68         fs, drvList, numDrives ) );
       
    69     TInt drvListLen( drvList.Length() );
       
    70     TMMCScBkupDriveAndOperationType op;
       
    71     TInt count( aReader.ReadInt8() );
       
    72 
       
    73     // Get default system drive
       
    74     TInt sysDrive( 0 );
       
    75     User::LeaveIfError( DriveInfo::GetDefaultDrive(
       
    76         DriveInfo::EDefaultSystem, sysDrive ) );
       
    77 
       
    78     for( TInt i( 0 ); i < count; ++i )
       
    79         {
       
    80         TUint drvCategories( aReader.ReadUint8() );
       
    81         TMMCScBkupOwnerDataType dataType(
       
    82             static_cast< TMMCScBkupOwnerDataType >( aReader.ReadUint8() ) );
       
    83 
       
    84         if ( drvCategories & EBkupDeviceMemories )
       
    85             {
       
    86             // Default system drive is always backed up when
       
    87             // device memories are defined
       
    88             op.SetDrive( static_cast< TDriveNumber >( sysDrive ) );
       
    89             op.SetDataType( dataType );
       
    90             iEntries.AppendL( op );
       
    91             iCalculatedDriveList[ op.Drive() ] = ETrue;
       
    92             }
       
    93 
       
    94         for ( TInt j( 0 ); j < drvListLen; ++j )
       
    95             {
       
    96             if ( sysDrive != j && drvList[ j ] )
       
    97                 {
       
    98                 // Check for other drives
       
    99                 TBool append( EFalse );
       
   100                 TUint drvStatus( 0 );
       
   101                 User::LeaveIfError( DriveInfo::GetDriveStatus(
       
   102                     fs, j, drvStatus ) );
       
   103                 if ( ( drvCategories & EBkupDeviceMemories ) &&
       
   104                     ( drvStatus & DriveInfo::EDriveInternal ) &&
       
   105                     !( drvStatus & DriveInfo::EDriveExternallyMountable ) &&
       
   106                     !( drvStatus & DriveInfo::EDriveReadOnly ) )
       
   107                     {
       
   108                     append = ETrue; // Allow additional device memory
       
   109                     }
       
   110                 else if ( ( drvCategories & EBkupInternalMassStorages ) &&
       
   111                     ( drvStatus & DriveInfo::EDriveInternal ) &&
       
   112                     ( drvStatus & DriveInfo::EDriveExternallyMountable ) )
       
   113                     {
       
   114                     append = ETrue; // Allow internal mass storage
       
   115                     }
       
   116                 else if ( ( drvCategories & EBkupExternalMassStorages ) &&
       
   117                     ( drvStatus & DriveInfo::EDriveRemovable ) )
       
   118                     {
       
   119                     append = ETrue; // Allow external mass storage
       
   120                     }
       
   121                 if ( append )
       
   122                     {
       
   123                     op.SetDrive(  static_cast< TDriveNumber >( j ) );
       
   124                     op.SetDataType( dataType );
       
   125                     iEntries.AppendL( op );
       
   126                     iCalculatedDriveList[ op.Drive() ] = ETrue;
       
   127                     }
       
   128                 }
       
   129             }
       
   130         }
       
   131 #else // RD_MULTIPLE_DRIVE
       
   132     TMMCScBkupDriveAndOperationType op;
       
   133     const TInt count = aReader.ReadInt8();
       
   134     //
       
   135     for( TInt i=0; i<count; i++ )
       
   136         {
       
   137         op.SetDrive( static_cast< TDriveNumber >( aReader.ReadInt8() ) );
       
   138         op.SetDataType( static_cast< TMMCScBkupOwnerDataType >( aReader.ReadInt8() ) );
       
   139         //
       
   140         iEntries.AppendL( op );
       
   141         //
       
   142         iCalculatedDriveList[ op.Drive() ] = ETrue;
       
   143         }
       
   144 #endif // RD_MULTIPLE_DRIVE
       
   145     }
       
   146 
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // CMMCScBkupDriveAndOperationTypeManager::NewL()
       
   150 // 
       
   151 //
       
   152 // ---------------------------------------------------------------------------
       
   153 EXPORT_C CMMCScBkupDriveAndOperationTypeManager* CMMCScBkupDriveAndOperationTypeManager::NewL( TResourceReader& aReader )
       
   154     {
       
   155     CMMCScBkupDriveAndOperationTypeManager* self = new(ELeave) CMMCScBkupDriveAndOperationTypeManager();
       
   156     CleanupStack::PushL( self );
       
   157     self->ConstructL( aReader );
       
   158     CleanupStack::Pop( self );
       
   159     return self;
       
   160     }
       
   161 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CMMCScBkupDriveAndOperationTypeManager::Count()
       
   165 // 
       
   166 //
       
   167 // ---------------------------------------------------------------------------
       
   168 TInt CMMCScBkupDriveAndOperationTypeManager::Count() const
       
   169     {
       
   170     return iEntries.Count();
       
   171     }
       
   172 
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CMMCScBkupDriveAndOperationTypeManager::At()
       
   176 // 
       
   177 //
       
   178 // ---------------------------------------------------------------------------
       
   179 const TMMCScBkupDriveAndOperationType& CMMCScBkupDriveAndOperationTypeManager::At( TInt aIndex ) const
       
   180     {
       
   181     return iEntries[ aIndex ];
       
   182     }
       
   183 
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive()
       
   187 // 
       
   188 //
       
   189 // ---------------------------------------------------------------------------
       
   190 TBool CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive( TDriveNumber aDrive, TMMCScBkupOwnerDataType aDataType ) const
       
   191     {
       
   192 //    __LOG2("CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive() - START - aDrive: %c, aDataType: %S", aDrive + 'A', &MMCScBkupLogger::DataType( aDataType ));
       
   193 
       
   194     TBool allowed = EFalse;
       
   195     //
       
   196     const TInt count = iEntries.Count();
       
   197     //
       
   198     for( TInt i=0; i<count; i++ )
       
   199         {
       
   200         const TMMCScBkupDriveAndOperationType& entry = iEntries[ i ];
       
   201         //
       
   202         if ( entry.DataType() == aDataType )
       
   203             {
       
   204             // Check drive...
       
   205             if ( entry.Drive() == aDrive )
       
   206                 {
       
   207                 allowed = ETrue;
       
   208                 break;
       
   209                 }
       
   210             }
       
   211         }
       
   212     //
       
   213 //    __LOG1("CMMCScBkupDriveAndOperationTypeManager::IsDataTypeAllowedToAccessDrive() - END - allowed: %d", allowed);
       
   214     return allowed;
       
   215     }
       
   216