filemanager/src/filemanager/src/operationservice/fmoperationformat_s60.cpp
changeset 16 ada7962b4308
child 32 39cf9ced4cc4
child 35 060d0b1ab845
equal deleted inserted replaced
14:1957042d8c7e 16:ada7962b4308
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include "fmoperationformat.h"
       
    19 #include "fmcommon.h"
       
    20 #include "fmoperationbase.h"
       
    21 #include "fmutils.h"
       
    22 
       
    23 #include <QString>
       
    24 
       
    25 #include <f32file.h>
       
    26 #include <e32property.h>
       
    27 #include <coreapplicationuisdomainpskeys.h>
       
    28 
       
    29 FmOperationFormat::FmOperationFormat( QObject *parent, QString mDriverName ) : FmOperationBase( parent, FmOperationService::EOperationTypeFormat ),
       
    30     mDriverName( mDriverName )
       
    31 {
       
    32 }
       
    33 FmOperationFormat::~FmOperationFormat()
       
    34 {
       
    35 }
       
    36 
       
    37 QString FmOperationFormat::driverName()
       
    38 {
       
    39     return mDriverName;
       
    40 }
       
    41 
       
    42 int FmOperationFormat::start()
       
    43 { 
       
    44     QString logString = "FmOperationFormat::start";
       
    45     FmLogger::log( logString );
       
    46     
       
    47     emit notifyPreparing( false );
       
    48     
       
    49     if( mDriverName.isEmpty() ) {
       
    50         return FmErrWrongParam;
       
    51     }
       
    52     
       
    53     RFormat format;
       
    54     
       
    55     RFs fs;
       
    56     int err = fs.Connect();
       
    57     
       
    58     if( err != KErrNone ){
       
    59         return FmErrTypeFormatFailed;
       
    60     }
       
    61 
       
    62     TInt drive = 0;
       
    63     drive = mDriverName[0].toUpper().toAscii() - 'A' + EDriveA;
       
    64 
       
    65     TDriveName formatDriveName( TDriveUnit( drive ).Name() );
       
    66 
       
    67     int finalValue = 0;
       
    68     
       
    69     format.Close();
       
    70 
       
    71     err = format.Open(
       
    72         fs, formatDriveName, EFullFormat | ESpecialFormat, finalValue );
       
    73     
       
    74     if( err == KErrNone ){
       
    75         logString = "emit notifyStart";
       
    76         FmLogger::log( logString );
       
    77         mTotalSteps = finalValue;
       
    78         emit notifyStart( false, finalValue );
       
    79     }
       
    80     
       
    81     logString = "Format open error:" + QString::number( err );
       
    82     FmLogger::log( logString );
       
    83     
       
    84     if( err == KErrLocked ){
       
    85         err = fs.ErasePassword( drive );
       
    86         
       
    87         logString = "ErasePassword error:" + QString::number( err );
       
    88         FmLogger::log( logString );
       
    89         
       
    90         if( err == KErrNone ){
       
    91             err = format.Open(
       
    92                fs, formatDriveName, EFullFormat, finalValue ); 
       
    93             
       
    94             if( err == KErrNone ){
       
    95                 logString = "emit notifyStart";
       
    96                 FmLogger::log( logString );
       
    97                 mTotalSteps = finalValue;
       
    98                 emit notifyStart( false, finalValue );
       
    99             }           
       
   100             logString = "Second format open error:" + QString::number( err );
       
   101             FmLogger::log( logString );
       
   102         }
       
   103     }
       
   104     
       
   105     if (err == KErrInUse){
       
   106         TBool reallyFormat = ETrue;
       
   107         if (reallyFormat){
       
   108             err = format.Open(
       
   109                     fs, formatDriveName, EFullFormat | EForceFormat, finalValue );
       
   110             
       
   111             if( err == KErrNone ){
       
   112                 logString = "emit notifyStart";
       
   113                 FmLogger::log( logString );
       
   114                 mTotalSteps = finalValue;
       
   115                 emit notifyStart( false, finalValue );
       
   116             } 
       
   117             
       
   118             logString = "Reallyformat open error:" + QString::number( err );
       
   119             FmLogger::log( logString );
       
   120         }
       
   121     }
       
   122     
       
   123     TFullName fsName;
       
   124     if ( err == KErrNone )
       
   125         {
       
   126         err = fs.FileSystemName( fsName, drive  );
       
   127         
       
   128         logString = "FileSystemName error:" + QString::number( err );
       
   129         FmLogger::log( logString );
       
   130 
       
   131         if ( err == KErrNone && fsName.Length() > 0 )
       
   132             {
       
   133             // Prevent SysAp shutting down applications
       
   134             RProperty::Set(
       
   135                     KPSUidCoreApplicationUIs,
       
   136                     KCoreAppUIsMmcRemovedWithoutEject,
       
   137                     ECoreAppUIsEjectCommandUsed );
       
   138             
       
   139             logString = "Prevent SysAp shutting down applications" ;
       
   140             FmLogger::log( logString );
       
   141             }
       
   142         else
       
   143             {
       
   144             // Don't continue with format if there is no file system name
       
   145             // or file system name could not be obtained.
       
   146             err = KErrCancel;
       
   147             
       
   148             logString = QString( "Format cancel" );
       
   149             FmLogger::log( logString );
       
   150             }
       
   151         }
       
   152     
       
   153     if( err == KErrNone &&  finalValue ){
       
   154     
       
   155         while ( finalValue ){        
       
   156             logString = "Format tracks:" + QString::number( finalValue );
       
   157             FmLogger::log( logString );
       
   158             err = format.Next( finalValue );
       
   159             
       
   160             if( err != KErrNone ){ 
       
   161                 logString = "Format error:" + QString::number( err );
       
   162                 FmLogger::log( logString );
       
   163                 break; 
       
   164             }
       
   165             
       
   166             logString = "emit notifyProgress";
       
   167             FmLogger::log( logString );
       
   168             emit notifyProgress( mTotalSteps - finalValue );
       
   169         }
       
   170     }
       
   171     
       
   172     if( !finalValue || err != KErrNone ){
       
   173         format.Close();        
       
   174         fs.Close();
       
   175         
       
   176         FmUtils::createDefaultFolders( mDriverName );
       
   177     }
       
   178 
       
   179     if( err == KErrNone ){
       
   180         return FmErrNone;
       
   181     }
       
   182     else{
       
   183         return FmErrTypeFormatFailed;
       
   184     }
       
   185 }