filemanager/bkupengine/src/MMCScBkupPhoneModelUtils.cpp
branchRCL_3
changeset 38 491b3ed49290
parent 36 95243422089a
child 39 65326cf895ed
equal deleted inserted replaced
36:95243422089a 38: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: MMCScBkupPhoneModelUtils implementation
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 #include "MMCScBkupPhoneModelUtils.h"
       
    20 
       
    21 // User includes
       
    22 #include "MMCScBkupArchiveFlags.h"
       
    23 #include "MMCScBkupArchiveUtils.h"
       
    24 
       
    25 // System includes
       
    26 #include <sysutil.h>
       
    27 
       
    28 
       
    29 
       
    30 // ========================= MEMBER FUNCTIONS ================================
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // MMCScBkupPhoneModelUtils::CurrentPhoneModelLC()
       
    34 // 
       
    35 // 
       
    36 // ---------------------------------------------------------------------------
       
    37 HBufC8* MMCScBkupPhoneModelUtils::CurrentPhoneModelLC()
       
    38     {
       
    39     HBufC8* ret = HBufC8::NewLC( MaximumPhoneModelIdentifierLength() );
       
    40     //
       
    41     TBuf<KSysUtilVersionTextLength> version;
       
    42     const TInt thirdLine(3);
       
    43     const TInt err = SysUtil::GetSWVersion( version);
       
    44     
       
    45     if  ( err == KErrNone )
       
    46         {
       
    47         // Assume syntax Vxx.xx\ndd-mm-yy\nNHL-vvv\n(c)
       
    48         // Extract model version from third line
       
    49         for(TInt i(0); i < thirdLine; i++)
       
    50             {
       
    51             TInt cutPos = version.Locate( '\n' );
       
    52 
       
    53             if( cutPos == KErrNotFound )
       
    54                 {
       
    55                 break;
       
    56                 }
       
    57             else if(i < ( thirdLine - 1 ) )
       
    58                 {
       
    59                 version.Delete( 0, cutPos + 1 );
       
    60                 }
       
    61             else
       
    62                 {
       
    63                 cutPos = version.Locate( '\n' );
       
    64                 if( cutPos != KErrNotFound )
       
    65                     {
       
    66                     version.Delete( cutPos, (version.Length() - cutPos) );
       
    67                     }
       
    68                 ret->Des().Copy( version );
       
    69                 }
       
    70             }
       
    71         }
       
    72 
       
    73     // Implicit requirement - should always be the case though
       
    74     __ASSERT_ALWAYS( ret->Length() <= 255, User::Invariant());
       
    75     return ret;
       
    76     }
       
    77 
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // MMCScBkupPhoneModelUtils::MaximumPhoneModelIdentifierLength()
       
    81 // 
       
    82 // 
       
    83 // ---------------------------------------------------------------------------
       
    84 TInt MMCScBkupPhoneModelUtils::MaximumPhoneModelIdentifierLength()
       
    85     {
       
    86     return KSysUtilVersionTextLength;
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // MMCScBkupPhoneModelUtils::ArchiveRestorePermissableL()
       
    92 // 
       
    93 // 
       
    94 // ---------------------------------------------------------------------------
       
    95 TBool MMCScBkupPhoneModelUtils::ArchiveRestorePermissableL( const TDesC8& aPhoneModelData, TBitFlags aArchiveFlags, const TVersion& aArchiveVersion )
       
    96     {
       
    97     TBool restoreOkay = EFalse;
       
    98     
       
    99     // Check version first
       
   100     restoreOkay = ( aArchiveVersion.iMajor >= KMMCScBkupArchiveFileFormatFirstRestorableMajorVersion );
       
   101     
       
   102     // Check flags next
       
   103     if  ( restoreOkay )
       
   104         {
       
   105         restoreOkay = ( aArchiveFlags.Value() & EMMCScBkupArchiveFlagsContentValid );
       
   106        
       
   107         // Only check model if the flags were alright
       
   108         if  ( restoreOkay )
       
   109             {
       
   110             HBufC8* currentData = CurrentPhoneModelLC();
       
   111             restoreOkay = ( aPhoneModelData.Compare( *currentData ) == 0 );
       
   112             CleanupStack::PopAndDestroy( currentData );
       
   113             }
       
   114         }
       
   115 
       
   116     // Done
       
   117     return restoreOkay;
       
   118     }
       
   119 
       
   120 
       
   121 
       
   122