xdmprotocols/XcapProtocol/XcapUtils/src/XcapStaticUtils.cpp
changeset 0 c8caa15ef882
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 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:   XcapStaticUtils
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <f32file.h>  
       
    22 #include "XcapStaticUtils.h"
       
    23 
       
    24 // ----------------------------------------------------------
       
    25 // XcapStaticUtils::CheckFileExistsL
       
    26 // 
       
    27 // ----------------------------------------------------------
       
    28 //
       
    29 EXPORT_C TBool XcapStaticUtils::CheckFileExistsL( RFs& aFileSession, const TDesC& aFileName )
       
    30     {
       
    31     TBool found = EFalse;
       
    32     CDir* directory = NULL;
       
    33     const TInt KBackSlash = 92;
       
    34     TInt index = aFileName.LocateReverse( KBackSlash );
       
    35     TPtrC dir( aFileName.Left( index + 1 ) );
       
    36     TPtrC name( aFileName.Right( aFileName.Length() - index - 1 ) );
       
    37     User::LeaveIfError( aFileSession.GetDir( dir, KEntryAttNormal, ESortNone, directory ) );
       
    38     CleanupStack::PushL( directory );
       
    39     const TInt count = directory->Count();
       
    40     for( TInt i = 0;!found && i < count;i++ )
       
    41         {
       
    42         if( name.CompareF( ( *directory )[i].iName ) == 0 )
       
    43             found = ETrue;
       
    44         }
       
    45 	CleanupStack::PopAndDestroy();  //directory
       
    46     return found;
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------
       
    50 // XcapStaticUtils::GenerateFileNameLC
       
    51 // 
       
    52 // ----------------------------------------------------------
       
    53 //
       
    54 EXPORT_C HBufC* XcapStaticUtils::GenerateFileNameLC( RFs& aFileSession, const TDesC& aFileName,
       
    55                                                      const TDesC& aExtension )
       
    56     {
       
    57     TBuf<KMaxFileName> name;
       
    58     name.Copy( aFileName );
       
    59     name.Append( aExtension );
       
    60     TBool exists = XcapStaticUtils::CheckFileExistsL( aFileSession, name );
       
    61     for( TInt i = 1;exists;i++ )
       
    62         {
       
    63         name.Zero();
       
    64         name.Copy( aFileName );
       
    65         name.AppendNum( i );
       
    66         name.Append( aExtension );
       
    67         exists = XcapStaticUtils::CheckFileExistsL( aFileSession, name );
       
    68         }
       
    69     return name.AllocLC();
       
    70     }
       
    71       
       
    72 
       
    73 
       
    74 
       
    75 
       
    76 // End of File