Location:
bautils.h
Link against: bafl.lib
class BaflUtils;
Provides simple-to-use file system utilities.
The functions listed in "Copying, renaming, and deleting files" create and use a CFileMan
object. They are useful for one-off calls, but for repeated use it is more efficient to use CFileMan
directly.
Note that there is a very similiar group of functions available in EikFileUtils, which may be easier to use in GUI applications, as they do not require a file server session to be passed.
Defined in BaflUtils
:
AbbreviateFileName()
, CheckFolder()
, CheckWhetherFullNameRefersToFolder()
, CopyFile()
, CopyWithTruncation()
, DeleteFile()
, DiskIsReadOnly()
, DriveAndPathFromFullName()
, DriveIsReadOnlyInternal()
, EnsurePathExistsL()
, ExtractAppNameFromFullName()
, FileExists()
, FolderExists()
, FolderNameFromFullName()
, GetDiskListL()
, GetDowngradePathL()
, GetSystemDrive()
, InitialiseHAL()
, InitialiseLocale()
, InitialiseScreenCalibration()
, IsFirstDriveForSocket()
, IsFolder()
, MostSignificantPartOfFullName()
, NearestLanguageFile()
, NearestLanguageFile()
, Parse()
, PathExists()
, PersistHAL()
, PersistLocale()
, PersistScreenCalibration()
, RemoveSystemDirectory()
, RenameFile()
, RootFolderPath()
, SortByTable()
, UidTypeMatches()
, UpdateDiskListL()
, ValidateFolderNameTypedByUserL()
static IMPORT_C void CopyWithTruncation(TDes &aDest, const TDesC &aSrc, TChar aTruncationSymbol=KBaflCharTruncation);
Copies a descriptor, abbreviating it to fit the destination descriptor.
If aSrc is less than the maximum length of aDest, then the string is simply copied to aDest.
If this is not so, then the left-most characters of aSrc are copied to aDest, up to aDest's maximum length-1. aDest's final character is set to be aTruncationSymbol.
|
static IMPORT_C TBool FileExists(const RFs &aFs, const TDesC &aFileName);
Checks if the specified file exists.
|
|
static IMPORT_C void EnsurePathExistsL(RFs &aFs, const TDesC &aFileName);
Makes one or more directories, if they do not already exist.
Any valid path component in the specified path that does not already exist is created as a directory. If the specified path already exists, the function returns normally.
|
static IMPORT_C TPtrC ExtractAppNameFromFullName(const TFullName &aName);
Gets the application name from a full thread name.
|
|
static IMPORT_C void NearestLanguageFile(const RFs &aFs, TFileName &aName);
Searches for the file with the correct language extension for the language of the current locale, or failing this, the best matching file.
|
static IMPORT_C void NearestLanguageFile(const RFs &aFs, TFileName &aName, TLanguage &aLanguage);
Set most appropriate extension language code for filename and set corresponding language.
Symbian uses numeric values to identify natural languages as specified by the TLanguage enumeration defined in e32const.h
. These values are used at the end of filename extensions to identify the languages pertaining to files which have language
specific variants such as resource files. For instance filename.r01 and filename.r02 would be the English and French versions
of the resource file filename.rsc. Language codes can be between 2 to 5 digits in length.
Starting from Symbian OS v7.0 this function constructs and uses a language downgrade path which consists of up to sixteen
TLanguage values the first of which is the ideal language followed by the language of the current locale. Up to the next three
can be customised using TLocale::SetLanguageDowngrade()
. The rest of the language downgrade path is based on a table of language near equivalence which is internal to Symbian.
This function searches the custom resource drive (if set, retrieved from HAL
) and then searches the optional drive specified in aName or 'Z:' if none is specified in aName. The custom resource drive
is retrieved from the HAL
attribute ECustomResourceDrive if set, if not set it will retrieve the legacy value set in the legacy HAL
attribute ESystemDrive. No custom resource drive is searched if neither are set. Note - setting the custom resource drive
will reduce the performance of this routine which will adversely affect device performance e.g. at boot up. On NAND Flash
based devices use of a composite Z: drive file system made up of multiple ROM images is the preferred mechanism for customising
language resources on devices in Symbian OS 9.2 onwards, see Developer Library » Base Porting Guide » Porting: background
information » NAND flash » NAND Flash image format. Thus use of the custom resource drive HAL
attribute is effectively obsolete.
The last two characters of aName are removed along with any digits which appear before them. Then language codes specified in the constructed language downgrade path are appended in turn to aName as a match is searched for in the file system. In case no match is found using the constructed language downgradepath then files in the specified directory are searched for a suitable extension with preference given to the one specified if present. In cases where a match takes place the aName and aLanguage arguments are updated otherwise aName is left unchanged and aLanguage is set to ELangNone.
Here are some examples of correct and incorrect function usage with different aName inputs, file system state and downgrade paths as follows:
Following files exist:
C:\\abc.rsc - Language Neutral resource file.
C:\\abc.r01 - Resource file for the English language.
C:\\abc.r10 - Resource file for the American-English language.
C:\\abc.r160 - Resource file for the English as appropriate in Japan.
Constructed Downgrade Language Path cases:
- Case 1. (ELangAmerican -> ELangEnglish -> ELangNone).
- Case 2. (ELangEnglish_Japan -> ELangEnglish -> ELangNone).
- Case 3. Same as case 1, However "C:\\abc.r10" is deleted prior to the function call.
- Case 4. Same as case 1, However both "C:\\abc.r01" and "C:\\abc.r10" are deleted prior to the function call.
Input aName . . . . Output aName. . . aLanguage . . . . . Description
--------------------------------------------------------------------------------------------------------------------
"C:\\abc.rsc" . . . "C:\\abc.r10" . . ELangAmerican . . . Match on first language (Case 1)
"C:\\abc.r10" . . . "C:\\abc.r10" . . ELangAmerican . . . Match, However it's not the intended use of
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . the function (Case 1)
"C:\\abc.r" . . . . "C:\\abc.r" . . . ELangNone . . . . . The no. of characters in the suffix is less than
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . KInvNameAndMinSuffixLength(2)(Case 1)
"C:\\abc.". . . . . "C:\\abc.". . . . ELangNone . . . . . Invalid Suffix: The filename ends with a period(Case 1)
"C:\\abc.r123456" . "C:\\abc.r123456" ELangNone . . . . . Invalid Suffix: The no. of digits in the suffix is greater
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . than KMaxSuffixLength(5) (Case 1)
"C:\\abc.10". . . . "C:\\abc.10 . . . ELangNone . . . . . Invalid Suffix: There's no proceeding alphabetical
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . characters in the suffix (Case 1)
"\\abc.rsc" . . . . "\\abc.rsc" . . . ELangNone . . . . . No drive so Z: search, no match (Case 1)
"C:\\abc.rsc" . . . "C:\\abc.r160". . ELangEnglish_Japan. Match for language file 3 digits long (Case 2)
"C:\\abc.rsc" . . . "C:\\abc.r01" . . ELangEnglish. . . . Match on second language (Case 3)
"C:\\abc.rsc" . . . "C:\\abc.rsc" . . ELangNone . . . . . No corresponding langauge file match found (Case 4)
---------------------------------------------------------------------------------------------------------------------
|
static IMPORT_C TInt GetSystemDrive(TDriveNumber &aDriveNumber);
Get the value of the system drive.
The system drive can be set to one of the built-in read/write drives. Which drive is used is hardware-dependent. On some hardware, there may not be a system drive. The system drive is used as the drive on which localisable files are searched for. This enables a phone to be localised dynamically, using files not in the ROM.
|
|
static IMPORT_C TBool PathExists(RFs &aFs, const TDesC &aFileName);
Tests whether a path exists.
The path should contain a drive letter and a directory, or EFalse is returned. EFalse is also returned if it contains a filename or filename extension.
If the path is badly formed, for instance if it contains illegal characters, or any directory name consists of a single or double dot, or any directory name includes wildcard characters, the function returns EFalse.
|
|
static IMPORT_C TInt IsFolder(const RFs &aFs, const TDesC &aFullName, TBool &aIsFolder);
Checks if the specified item is a folder.
|
|
static IMPORT_C TBool FolderExists(RFs &aFs, const TDesC &aFolderName);
Tests whether a folder exists.
The folder is specified in a path. The path can omit the drive letter, in which case the drive letter is taken from the session path.
If the path is badly formed, for instance if it contains illegal characters, or any directory name consists of a single or double dot, or any directory name includes wildcard characters, the function returns EFalse.
If a filename is included in the path, it is ignored (the existence of the file will not be checked). However if included, it must not be badly formed - this will cause the function to return EFalse. If no filename is specified, the path should end in a backslash.
Examples of valid paths (returning ETrue): C:\; \; C:.txt; C:\; .dat
Examples of invalid paths (returning EFalse): C:\; ..\; C:*card\; C:>File.txt
|
|
static IMPORT_C TFileName FolderNameFromFullName(const TDesC &aFullName);
Gets the folder name from a path.
A valid full name should have a drive associated with it e.g ("a:\\" - "z:\\")("a:" - "z:")("c:\\system\data\file.txt") Invalid entry will have no drive and cause a panic EBafPanicBadOpenArg For example, if the path is "c:\documents\word\mydoc1", then "word" is returned. "c:" then "c:" is returned "c:\\" then "c:\" is returned "c:\\mydoc1.txt then "c:\" is returned
|
|
static IMPORT_C TFileName DriveAndPathFromFullName(const TDesC &aFullName);
Gets the drive letter and path from a file name.
This is in the form: drive-letter:\path\. The drive letter is folded using class TCharF
.
|
|
static IMPORT_C TFileName RootFolderPath(const TBuf< 1 > aDriveLetter);
Gets the root folder for the specified drive.
If aDriveLetter is an alphabet(lowercase or uppercase) then it will return the TFileName which is simply the drive letter plus ":\" If this is not the case, the function will panic with panic code EBafPanicBadOpenArg
|
|
static IMPORT_C void AbbreviateFileName(const TFileName &aOriginalFileName, TDes &aAbbreviatedFileName);
Abbreviates a file name.
If aOriginalFileName is less than the maximum length of aAbbreviatedFileName, then the name is simply copied to aAbbreviatedFileName.
If this is not so, then the left-most characters of aOriginalFileName are copied to aAbbreviatedFileName, up to aAbbreviatedFileName's maximum length-1. aAbbreviatedFileName's first character is set to be an ellipsis.
|
static IMPORT_C TBool UidTypeMatches(const TUidType &aFileUid, const TUidType &aMatchUid);
Tests whether two UID types match.
A match is made if each UID in aMatchUid is either identical to the corresponding one in aFileUid, or is KNullUid.
|
|
static IMPORT_C TInt Parse(const TDesC &aName);
Checks if a specified file name can be parsed.
|
|
static IMPORT_C TInt ValidateFolderNameTypedByUserL(const RFs &aFs, const TDesC &aFolderNameTypedByUser, const TDesC &aCurrentPath,
TFileName &aNewFolderFullName);
Checks if a folder name (without drive or path) is valid and returns the full name of the folder.
|
|
static IMPORT_C TInt CopyFile(RFs &aFs, const TDesC &aSourceFullName, const TDesC &aTargetFullName, TUint aSwitch=CFileMan::EOverWrite);
Copies one or more files.
For more details,
|
|
static IMPORT_C TInt RenameFile(RFs &aFs, const TDesC &aOldFullName, const TDesC &aNewFullName, TUint aSwitch=CFileMan::EOverWrite);
Renames or moves one or more files or directories.
It can be used to move one or more files by specifying different destination and source directories. For more details,
|
|
static IMPORT_C TInt DeleteFile(RFs &aFs, const TDesC &aSourceFullName, TUint aSwitch=0);
Deletes one or more files.
For more details,
|
|
static IMPORT_C TInt CheckWhetherFullNameRefersToFolder(const TDesC &aFullName, TBool &aIsFolder);
Checks if a string is a valid folder name.
|
|
static IMPORT_C TInt MostSignificantPartOfFullName(const TDesC &aFullName, TFileName &aMostSignificantPart);
Gets the folder name if the specified item is a valid folder name, otherwise gets the file name.
|
|
static IMPORT_C TInt CheckFolder(RFs &aFs, const TDesC &aFolderName);
Checks that the specified folder can be opened.
|
|
static IMPORT_C TInt DiskIsReadOnly(RFs &aFs, const TDesC &aFullName, TBool &aIsReadOnly);
Checks if the specified drive is read-only. Checks that the KMediaAttWriteProtected and EMediaRom flags are both set.
|
|
static IMPORT_C TInt DriveIsReadOnlyInternal(RFs &aFs, const TDesC &aFullName, TBool &aIsReadOnlyInternal);
Checks if the specified drive is read-only and is an internal drive i.e. non-removable. Checks that the KMediaAttWriteProtected and KDriveAttInternal flags are both set.
|
|
static IMPORT_C void GetDiskListL(const RFs &aFs, CDesCArray &aArray);
Retrieves a list of all drives on the system.
The file server is interrogated for a list of the drive letters for all available drives.
On emulator: The removable media is represented by drive X: .
On hardware: The removable media is represented by drives D: E: F: and G: .
|
static IMPORT_C void UpdateDiskListL(const RFs &aFs, CDesCArray &aArray, TBool aIncludeRom, TDriveNumber aDriveNumber);
Retrieves a list of all drives present on the system.
The file server is interrogated for a list of the drive letters for all available drives. The drive letter that corresponds to aDriveNumber is added to the list regardless of whether it is present, or is corrupt. Also, the C: drive is forced onto the list, even if corrupt or not present.
On emulator: The removable media is represented by drive X: and is forced onto the list unless removed (F5,F4).
On hardware: The removable media is represented by drives D: E: F: and G: and is forced onto the list regardless of whether it is present, or is corrupt.
|
static IMPORT_C void RemoveSystemDirectory(CDir &aDir);
Removes "System" from a list of directory entries.
|
static IMPORT_C TBool IsFirstDriveForSocket(TDriveUnit aDriveUnit);
Tests whether the specified drive corresponds to the primary partition in a removable media slot.
The function assumes that the D: drive corresponds to the primary partition on socket 0, and that the E: drive corresponds to the primary partition on socket 1 (a socket is a slot for removable media). This mapping may not always be the case because it is set up in the variant layer of the Symbian OS.
This function assumes that the drive mappings are contiguous, starting from drive D: .
On emulator: The removable media is represented by drive X: only.
|
|
static IMPORT_C TInt SortByTable(CDir &aDir, CBaflFileSortTable *aTable);
Sorts files by UID.
The caller supplies a table which specifies the order in which files are to be sorted. The files whose UID3 is the first UID in the table appear first. The files whose UID3 is the UID specified second appear next, and so on. Files whose UID3 is not specified in the table, and directories, appear at the end of the list, with directories preceding the files, and with files sorted in ascending order of UID3.
This function is used for customising how lists of application files are sorted.
|
|
static IMPORT_C void GetDowngradePathL(const RFs &aFs, const TLanguage aCurrentLanguage, RArray< TLanguage > &aLanguageArray);
Gets the full language downgrade path for a particular locale.
|
static IMPORT_C void PersistLocale();
Saves the locale settings in TLocale
and the currency symbol to file.
static IMPORT_C TInt PersistHAL();
Saves the HAL
settings to file. This will start a new executable and saves HAL
attributes to a file, little delay because of the creation of new process
|
static IMPORT_C void PersistScreenCalibration(const TDigitizerCalibration &aScreenCalibration);
|
static IMPORT_C void InitialiseHAL(RFs &aFs);
Initialise the HAL
settings from.
|