emailservices/emailstore/message_store/MsgStoreRfsPlugin/src/RfsMsgStorePlugin.cpp
changeset 1 12c456ceeff2
parent 0 8466d47a6819
child 8 e1b6206813b4
equal deleted inserted replaced
0:8466d47a6819 1:12c456ceeff2
    18 #include <driveinfo.h>
    18 #include <driveinfo.h>
    19 #include <f32file.h>
    19 #include <f32file.h>
    20 
    20 
    21 #include "RfsMsgStorePlugin.h"
    21 #include "RfsMsgStorePlugin.h"
    22 #include "EmailStoreUids.hrh"
    22 #include "EmailStoreUids.hrh"
       
    23 #include <bautils.h>  
       
    24 #include <s32file.h>
    23 
    25 
    24 // -----------------------------------------------------------------------------
    26 // -----------------------------------------------------------------------------
    25 // CRfsMsgStorePlugin::NewL()
    27 // CRfsMsgStorePlugin::NewL()
    26 // -----------------------------------------------------------------------------
    28 // -----------------------------------------------------------------------------
    27 //
    29 //
    51 void CRfsMsgStorePlugin::RestoreFactorySettingsL( const TRfsReason aType )
    53 void CRfsMsgStorePlugin::RestoreFactorySettingsL( const TRfsReason aType )
    52     {
    54     {
    53     if ( aType == ENormalRfs || aType == EDeepRfs || aType == EInitRfs )
    55     if ( aType == ENormalRfs || aType == EDeepRfs || aType == EInitRfs )
    54         {
    56         {
    55         TUint driveStatus( 0 );
    57         TUint driveStatus( 0 );
    56 
    58 				TDriveNumber drive( EDriveC );
    57         if ( DriveInfo::GetDriveStatus( iFs, EDriveE, driveStatus ) == KErrNone )
    59      		GetDriveL( drive );
       
    60         if ( DriveInfo::GetDriveStatus( iFs, drive, driveStatus ) == KErrNone )
    58             {
    61             {
    59             // check if internal E: drive is exists on the device
    62             _LIT( KPrivate, ":\\Private\\" );    
    60             if ( ( driveStatus & DriveInfo::EDriveUserVisible ) &&
    63             TChar driveChar;
    61                     ( driveStatus & DriveInfo::EDriveInternal )  &&
    64             RFs::DriveToChar(drive, driveChar);
    62                     ( driveStatus & DriveInfo::EDrivePresent ) )
    65             TFileName msgStorePath;
    63                 {
    66             TBuf<5> driveLetter;
    64                 // since we are dealing with internal E: drive only,
    67             driveLetter.Append(driveChar);
    65                 // it is ok to hardcoded the E: in the string
    68             msgStorePath.Append(driveLetter);
    66                 _LIT( KMsgStoreEDrivePrivate, "E:\\Private\\" );
    69             msgStorePath.Append(KPrivate);                
    67 
    70             msgStorePath.AppendNum( KUidMessageStoreExe, EHex );
    68                 TFileName msgStorePath( KMsgStoreEDrivePrivate );
    71             msgStorePath.Append( KPathDelimiter );
    69                 msgStorePath.AppendNum( KUidMessageStoreExe, EHex );
    72             CFileMan* fileManager = CFileMan::NewL( iFs );
    70                 msgStorePath.Append( KPathDelimiter );
    73             // this will recursively delete all files in all directories under the msgStorePath
    71                 CFileMan* fileManager = CFileMan::NewL( iFs );
    74             // but directories under the msgStorePath are not deleted
    72                 // this will recursively delete all files in all directories under the msgStorePath
    75             fileManager->Delete( msgStorePath, CFileMan::ERecurse );
    73                 // but directories under the msgStorePath are not deleted
    76             delete fileManager;
    74                 fileManager->Delete( msgStorePath, CFileMan::ERecurse );
       
    75                 delete fileManager;
       
    76                 }
       
    77             }
    77             }
    78         }
    78         }
    79     }
    79     }
    80 
    80 
    81 // ---------------------------------------------------------------------------
    81 // ---------------------------------------------------------------------------
   113 //
   113 //
   114 void CRfsMsgStorePlugin::ConstructL()
   114 void CRfsMsgStorePlugin::ConstructL()
   115     {
   115     {
   116     User::LeaveIfError( iFs.Connect() );
   116     User::LeaveIfError( iFs.Connect() );
   117     }
   117     }
       
   118     
       
   119 // -----------------------------------------------------------------------------
       
   120 // CRfsMsgStorePlugin::GetDriveL(TDriveNumber&)
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 TInt CRfsMsgStorePlugin::GetDriveL( TDriveNumber& aDrive )
       
   124     {
       
   125     _LIT16( KDriveToUseFile, "db_drive.cfg" );
       
   126     TInt ret( KErrNotFound );
       
   127     RFs fs;
       
   128     if( fs.Connect() == KErrNone )
       
   129         {
       
   130         CleanupClosePushL( fs );               //+fs
       
   131         TFileName fileName;
       
   132         _LIT( KCDrive, "C:" );
       
   133         _LIT( KPrivate, "Private" );   
       
   134         fileName.Append(KCDrive());
       
   135         fileName.Append( KPathDelimiter ); 
       
   136         fileName.Append(KPrivate);
       
   137         fileName.Append( KPathDelimiter );                 
       
   138         fileName.AppendNum( KUidMessageStoreExe, EHex );
       
   139         fileName.Append( KPathDelimiter );        
       
   140         fileName.Append( KDriveToUseFile );
       
   141         if( BaflUtils::FileExists( fs, fileName ) )
       
   142             {
       
   143             RFileReadStream reader;
       
   144             if ( reader.Open( fs, fileName, EFileRead ) == KErrNone )
       
   145           		{
       
   146            		CleanupClosePushL( reader );             //+reader
       
   147            		TUint drive = reader.ReadUint32L();
       
   148               CleanupStack::PopAndDestroy( &reader );  //-reader
       
   149               if(drive <=EDriveZ)
       
   150 	              {
       
   151 	           		aDrive = static_cast<TDriveNumber>( drive );
       
   152            			ret = KErrNone;
       
   153            			}
       
   154            		}
       
   155             }
       
   156         CleanupStack::PopAndDestroy( &fs );    //-fs
       
   157         } // end if
       
   158     return ret;
       
   159     }
   118 
   160 
   119 // END FILE RfsMsgStorePlugin.cpp
   161 // END FILE RfsMsgStorePlugin.cpp