XDMEngine/src/XdmStaticUtils.cpp
branchRCL_3
changeset 17 2669f8761a99
parent 16 2580314736af
child 18 fbd2e7cec7ef
equal deleted inserted replaced
16:2580314736af 17:2669f8761a99
     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:   XDM Engine static utils
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <f32file.h>
       
    22 #include "XdmStaticUtils.h"
       
    23 #include "XdmLogWriter.h"
       
    24 
       
    25 // ----------------------------------------------------------
       
    26 // XdmStaticUtils::CheckFileExistsL
       
    27 // 
       
    28 // ----------------------------------------------------------
       
    29 //
       
    30 EXPORT_C TBool XdmStaticUtils::CheckFileExistsL( RFs& aFileSession, const TDesC& aFileName )
       
    31     {
       
    32     TBool found = EFalse;
       
    33     CDir* directory = NULL;
       
    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 // XdmStaticUtils::GenerateFileNameLC
       
    51 // 
       
    52 // ----------------------------------------------------------
       
    53 //
       
    54 EXPORT_C HBufC* XdmStaticUtils::GenerateFileNameL( RFs& aFileSession, const TDesC& aFileName,
       
    55                                                    const TDesC& aExtension )
       
    56     {
       
    57     TInt i = 1;
       
    58     TBuf<KMaxFileName> name;
       
    59     name.Copy( aFileName );
       
    60     name.Append( aExtension );
       
    61     TBool exists = XdmStaticUtils::CheckFileExistsL( aFileSession, name );
       
    62     for( ;exists && i <= KMaxLogFiles;i++ )
       
    63         {
       
    64         name.Zero();
       
    65         name.Copy( aFileName );
       
    66         name.AppendNum( i );
       
    67         name.Append( aExtension );
       
    68         exists = XdmStaticUtils::CheckFileExistsL( aFileSession, name );
       
    69         }
       
    70     if( i >= KMaxLogFiles )
       
    71         {
       
    72         TPtrC dir( aFileName.Left( aFileName.LocateReverse( KBackSlash ) ) );
       
    73         CleanUpDirectoryL( aFileSession, dir );
       
    74         name.Zero();
       
    75         name.Copy( aFileName );
       
    76         name.Append( aExtension );
       
    77         }
       
    78     return name.AllocL();
       
    79     }
       
    80 
       
    81 // ----------------------------------------------------------
       
    82 // XdmStaticUtils::CleanUpDirectoryL
       
    83 // 
       
    84 // ----------------------------------------------------------
       
    85 //
       
    86 EXPORT_C void XdmStaticUtils::CleanUpDirectoryL( RFs& aFileSession, const TDesC& aDirectory )
       
    87     {
       
    88     TBuf<KMaxFileName> allFiles;
       
    89     allFiles.Copy( aDirectory );
       
    90     allFiles.Append( _L( "\\*.*") );
       
    91     CFileMan* manager = CFileMan::NewL( aFileSession );
       
    92     manager->Delete( allFiles );
       
    93     delete manager;
       
    94     manager = NULL;
       
    95     }
       
    96          
       
    97 // End of File  
       
    98 
       
    99 
       
   100