sl@0: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: // Declarations for some internal  BAFL functions
sl@0: #include <bautils.h>
sl@0: #include <f32file.h>
sl@0: #include <e32std.h>
sl@0: 
sl@0: /**
sl@0: Specifies the maximum length of the numerical part of the suffix.
sl@0: 
sl@0: If this is changed the documentation of the following functions 
sl@0: must also be updated:
sl@0: 
sl@0: 	BaflUtils::NearestLanguageFile()
sl@0: 	TNearestLanguageFileFinder::CountDigitsFromEndInValidSuffix()
sl@0: 	TNearestLanguageFileFinder::SetFileName()
sl@0: */
sl@0: const TInt KMaxSuffixLength = 5;
sl@0: 
sl@0: class RDirectoryScanner
sl@0: /**
sl@0: @internalAll
sl@0: */
sl@0: 	{
sl@0: public:
sl@0: 	virtual TInt Open(RFs& aFs, const TDesC& aMatchPattern) = 0;
sl@0: 	virtual TInt Next(TEntry& aOut) = 0;
sl@0: 	virtual void Close() = 0;
sl@0: 	virtual ~RDirectoryScanner() {}
sl@0: 	};
sl@0: 
sl@0: NONSHARABLE_CLASS(RRealDirectoryScanner) : public RDirectoryScanner
sl@0: /**
sl@0: @internalAll
sl@0: */
sl@0: 	{
sl@0: public:
sl@0: 	virtual TInt Open(RFs& aFs, const TDesC& aMatchPattern);
sl@0: 	virtual TInt Next(TEntry& aOut);
sl@0: 	virtual void Close();
sl@0: private:
sl@0: 	RDir iDir;
sl@0: 	};
sl@0: 
sl@0: /**
sl@0:  * Add a language to the end of the language path, unless it is already
sl@0:  * present. On entry, the language path must have an ELangNone entry at its
sl@0:  * end. This will be true on exit also.
sl@0:  * @internalAll
sl@0:  */
sl@0: void AddLanguage(TLanguagePath& aPath, TLanguage aNewLanguage);
sl@0: 
sl@0: /**
sl@0:  * Create a language path from the current language, ideal language and locale. 
sl@0:  * The path may have up to eight entries in it.
sl@0:  * @internalAll
sl@0:  */
sl@0: 
sl@0: void MakeLanguageDowngradePath(TLanguagePath& aPath,
sl@0: 	TLanguage aCurrent, TLanguage aIdeal, const TLocale& aLocale);
sl@0: 
sl@0: 
sl@0: /**
sl@0:  * This class contains all the functions for working out the nearest language
sl@0:  * file. It can be derived from for test code purposes.
sl@0:  * @internalAll
sl@0:  */
sl@0: NONSHARABLE_CLASS(TNearestLanguageFileFinder)
sl@0: 	{
sl@0: public:
sl@0: 	TNearestLanguageFileFinder(const RFs& aFs);
sl@0: 	TBool SetFileName(TFileName& aFileName);
sl@0: 	TLanguage Language();
sl@0: 	// put back the original suffix and drive letter
sl@0: 	void RepairFileName();
sl@0: 	// add the preset custom resource drive, if any, to iDrives.
sl@0: 	TInt AddCustomResourceDrive();
sl@0: 	// add all remaining drives to iDrives. iDrives must not have more than one
sl@0: 	// drive in it on entry.
sl@0: 	void AddAllDrives();
sl@0: 	// Tries to append the language code to iFileName. This is 00..09 or just the number.
sl@0: 	// If there was not enough space, EFalse is returned.
sl@0: 	TBool AppendLanguageCode(TLanguage aLanguage);
sl@0: 	// Search the drives in iDrives for the file named iFileName.
sl@0: 	// iFileName must have a drive specifier, which will be overwritten.
sl@0: 	TBool FindDrive();
sl@0: 	// Search for files across all drives in all languages in the path plus the
sl@0: 	// language-neutral file.
sl@0: 	// On entry, iFileName should be the original name with a drive specifier
sl@0: 	// minus the suffix. On return, iFileName will be untouched if EFalse is
sl@0: 	// returned, but contain the result if ETrue is returned.
sl@0: 	TBool FindLanguageAndDrive();
sl@0: 	// Test whether the filename passed in matches the stem given + numbers
sl@0: 	// added to the end. Returns the number if it does, or KErrNotFound if not.
sl@0: 	// aFileName must not end in a digit.
sl@0: 	static TInt LanguageNumberFromFile(const TDesC& aFileName, const TDesC& aStem);
sl@0: 	// Find lowest numbered file that matches iFileName, which must be without
sl@0: 	// its suffix.
sl@0: 	TInt FindFirstLanguageFile(RFs&);
sl@0: 	// Try each drive for any language files that match iFileName.
sl@0: 	// iFileName must have a directory specifier and be without its suffix.
sl@0: 	// returns KErrNotFound, KErrNone or error code.
sl@0: 	TInt FindFirstLanguageFileAndDrive();
sl@0: 
sl@0: 	virtual TInt GetCustomResourceDriveNumber() const;
sl@0: 	
sl@0: 	virtual TInt FileExists(const TDesC& aFileName) const;
sl@0: 	// return our member that is our directory scanning class
sl@0: 	virtual RDirectoryScanner& DirectoryScanner();
sl@0: 	virtual ~TNearestLanguageFileFinder() {}
sl@0: 	
sl@0: private:
sl@0: 	TInt CountDigitsFromEnd(const TDesC& aFilename);
sl@0: 	TInt CountDigitsFromEndInSuffix (const TDesC& aFilename);
sl@0: 
sl@0: public:
sl@0: 	const RFs& iFs;
sl@0: 	TFileName* iFileName;
sl@0: 	TLanguage  iLanguage;
sl@0: 	TBuf<26> iDrives;
sl@0: 	TLanguagePath iPath;
sl@0: 	TBuf<KMaxSuffixLength> iSuffix;
sl@0: 	TInt iInitialDriveLetter;
sl@0: 	// length minus the removed suffix
sl@0: 	TInt iOriginalBaseLength;
sl@0: 	// length plus added drive letter minus removed suffix
sl@0: 	TInt iBaseLength;
sl@0: 	RRealDirectoryScanner iDirScanner;
sl@0: 	};
sl@0: