os/ossrv/lowlevellibsandfws/apputils/src/BAFINDF.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/lowlevellibsandfws/apputils/src/BAFINDF.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,101 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include "BAFINDF.H"
    1.20 +
    1.21 +//
    1.22 +// class CFindFileByType
    1.23 +//
    1.24 +
    1.25 +EXPORT_C CFindFileByType::CFindFileByType(RFs& aFs)
    1.26 +//
    1.27 +// Constructor
    1.28 +//
    1.29 +	: iFind(aFs)
    1.30 +	{
    1.31 +	__DECLARE_NAME(_S("CFindFileByType"));
    1.32 +	}
    1.33 +
    1.34 +EXPORT_C CFindFileByType::~CFindFileByType()
    1.35 +//
    1.36 +// Destructor
    1.37 +//
    1.38 +	{
    1.39 +	CloseDir();
    1.40 +	}
    1.41 +
    1.42 +EXPORT_C TInt CFindFileByType::FindFirst(const TDesC& aName,const TDesC& aDir,const TUidType& aType)
    1.43 +//
    1.44 +// Look for first file
    1.45 +//
    1.46 +	{
    1.47 +	iType=aType;
    1.48 +	CloseDir();
    1.49 +	TInt r=iFind.FindWildByDir(aName,aDir,iDir);
    1.50 +	if (r!=KErrNone)
    1.51 +		return r;
    1.52 +	iCurrentFile=-1;
    1.53 +	return FindNext();
    1.54 +	}
    1.55 +
    1.56 +EXPORT_C TInt CFindFileByType::FindNext()
    1.57 +//
    1.58 +// Look for next file
    1.59 +//
    1.60 +	{
    1.61 +	TInt ii=iCurrentFile;
    1.62 +	FOREVER
    1.63 +		{
    1.64 +		__ASSERT_DEBUG(iDir!=NULL,User::Invariant());
    1.65 +//
    1.66 +		TInt count=iDir->Count();
    1.67 +		while (++ii<count)
    1.68 +			{
    1.69 +			const TEntry& entry=(*iDir)[ii];
    1.70 +			TInt id=0;
    1.71 +			FOREVER
    1.72 +				{
    1.73 +				TUid uid=iType[id];
    1.74 +				if (uid!=KNullUid && uid!=entry[id])
    1.75 +					break;					// wrong type
    1.76 +				if (++id==KMaxCheckedUid)
    1.77 +					{						// we have a matching file
    1.78 +					iCurrentFile=ii;
    1.79 +					iFile.Set(entry.iName,&iFind.File(),NULL);
    1.80 +					return KErrNone;
    1.81 +					}
    1.82 +				}
    1.83 +			}
    1.84 +		CloseDir();
    1.85 +		TInt r=iFind.FindWild(iDir);
    1.86 +		if (r!=KErrNone)
    1.87 +			return r;
    1.88 +		ii=-1;
    1.89 +		}
    1.90 +	}
    1.91 +
    1.92 +EXPORT_C const TEntry& CFindFileByType::Entry() const
    1.93 +	{
    1.94 +	return (*iDir)[iCurrentFile];
    1.95 +	}
    1.96 +
    1.97 +void CFindFileByType::CloseDir()
    1.98 +//
    1.99 +// Close iDir 
   1.100 +//
   1.101 +	{
   1.102 +	delete(iDir);
   1.103 +	iDir=NULL;
   1.104 +	}