williamr@2: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef __EIKFUTIL_H__ williamr@2: #define __EIKFUTIL_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: class CFont; williamr@2: class CBaflFileSortTable; williamr@2: class TResourceReader; williamr@2: williamr@2: williamr@2: /** Provides a set of drive, path and file utility functions. williamr@2: williamr@2: This class is essentially a thin layer over the BaflUtils class. williamr@2: williamr@2: @publishedAll williamr@2: @released */ williamr@2: NONSHARABLE_CLASS(EikFileUtils) williamr@2: { williamr@2: public: williamr@2: inline static TBool PathExists(const TDesC& aPath); williamr@2: inline static TInt IsFolder(const TDesC& aFullName, TBool& aIsFolder); williamr@2: inline static TBool FolderExists(const TDesC& aFolderName); williamr@2: inline static TFileName FolderNameFromFullName(const TDesC& aFullName); williamr@2: inline static TFileName DriveAndPathFromFullName(const TDesC& aFullName); williamr@2: inline static TFileName RootFolderPath(const TBuf<1> aDriveLetter); williamr@2: inline static void AbbreviateFileName(const TFileName& aOriginalFileName, TDes& aAbbreviatedFileName); williamr@2: IMPORT_C static TFileName AbbreviatePath(TDesC& aPathName, const CFont& aFont, TInt aMaxWidthInPixels); williamr@2: inline static TBool UidTypeMatches(const TUidType& aFileUid, const TUidType& aMatchUid); williamr@2: inline static TInt Parse(const TDesC& aName); williamr@2: IMPORT_C static TFileName ValidateFolderNameTypedByUserL(const TDesC& aFolderNameTypedByUser, const TDesC& aCurrentPath); williamr@2: inline static TInt CopyFile(const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch = CFileMan::EOverWrite); williamr@2: inline static TInt RenameFile(const TDesC& aOldFullName, const TDesC& aNewFullName, TUint aSwitch = CFileMan::EOverWrite); williamr@2: inline static TInt DeleteFile(const TDesC& aSourceFullName, TUint aSwitch=0); williamr@2: inline static TInt CheckWhetherFullNameRefersToFolder(const TDesC& aFullName, TBool& aIsFolder); williamr@2: inline static TInt MostSignificantPartOfFullName(const TDesC& aFullName, TFileName& aMostSignificantPart); williamr@2: inline static TInt CheckFolder(const TDesC& aFolderName); williamr@2: inline static TInt DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly); williamr@2: inline static void UpdateDiskListL(const RFs& aFs,CDesCArray& aArray,TBool aIncludeRom,TDriveNumber aDriveNumber); williamr@2: inline static void RemoveSystemDirectory(CDir& aDir); williamr@2: inline static TBool IsFirstDriveForSocket(TDriveUnit aDriveUnit); williamr@2: inline static TInt SortByTable(CDir& aDir,CBaflFileSortTable* aTable); williamr@2: private: williamr@2: EikFileUtils(); williamr@2: }; williamr@2: williamr@2: williamr@2: /** Tests whether a path exists. williamr@2: williamr@2: @param aPath The path to check. williamr@2: @return ETrue if the path exists, EFalse otherwise. */ williamr@2: inline TBool EikFileUtils::PathExists(const TDesC& aPath) williamr@2: { return BaflUtils::PathExists(CEikonEnv::Static()->FsSession(),aPath); } williamr@2: williamr@2: /** Tests whether aFullName is a folder. williamr@2: williamr@2: @param aFullName The drive and path to test. williamr@2: @param aIsFolder On return, indicates whether aFullName is a folder. williamr@2: @return KErrNone if successful otherwise another of the system-wide error codes. */ williamr@2: inline TInt EikFileUtils::IsFolder(const TDesC& aFullName, TBool& aIsFolder) williamr@2: { return BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), aFullName,aIsFolder); } williamr@2: williamr@2: /** Tests whether a specified folder exists. williamr@2: williamr@2: This returns a boolean value indicating whether the folder exists: see also williamr@2: CheckFolder() which returns an error code instead. williamr@2: williamr@2: @param aFolderName The folder's path. williamr@2: @return ETrue if the folder exists, EFalse if not. */ williamr@2: inline TBool EikFileUtils::FolderExists(const TDesC& aFolderName) williamr@2: { return BaflUtils::FolderExists(CEikonEnv::Static()->FsSession(), aFolderName); } williamr@2: williamr@2: /** Gets a folder name from a path and file name. williamr@2: williamr@2: @param aFullName The full path and file name from which the folder will be williamr@2: obtained. williamr@2: @return Folder name */ williamr@2: inline TFileName EikFileUtils::FolderNameFromFullName(const TDesC& aFullName) williamr@2: { return BaflUtils::FolderNameFromFullName(aFullName); } williamr@2: williamr@2: /** Parses the specified full path and file name to obtain the drive and path. williamr@2: williamr@2: @param aFullName The full path and file name from which the drive and path williamr@2: will be obtained. williamr@2: @return The drive and path. */ williamr@2: inline TFileName EikFileUtils::DriveAndPathFromFullName(const TDesC& aFullName) williamr@2: { return BaflUtils::DriveAndPathFromFullName(aFullName); } williamr@2: williamr@2: /** Gets the root folder for the specified drive. williamr@2: williamr@2: @param aDriveLetter The drive letter, C for example. williamr@2: @return The root folder for the drive, C:\ for example. */ williamr@2: inline TFileName EikFileUtils::RootFolderPath(const TBuf<1> aDriveLetter) williamr@2: { return BaflUtils::RootFolderPath(aDriveLetter); } williamr@2: williamr@2: /** Abbreviates a file name. williamr@2: williamr@2: If aOriginalFileName is less than the maximum length of aAbbreviatedFileName, williamr@2: then the name is simply copied to aAbbreviatedFileName. williamr@2: williamr@2: If this is not the case, then the left-most characters of aOriginalFileName are williamr@2: copied to aAbbreviatedFileName, up to aAbbreviatedFileName's maximum length-1 and williamr@2: aAbbreviatedFileName's first character is set to be an ellipsis. williamr@2: williamr@2: For example, if c:\\home\\letters\\abcdef is the original file name and aAbbreviatedFileName williamr@2: allows only 7 characters, the abbreviated file name will be ...abcdef. williamr@2: This can be used to display a file or folder name in an error or progress williamr@2: dialog. williamr@2: williamr@2: @param aOriginalFileName Original file name. williamr@2: @param aAbbreviatedFileName On return, the abbreviated file name. */ williamr@2: inline void EikFileUtils::AbbreviateFileName(const TFileName& aOriginalFileName, TDes& aAbbreviatedFileName) williamr@2: { BaflUtils::AbbreviateFileName(aOriginalFileName,aAbbreviatedFileName); } williamr@2: williamr@2: /** Tests whether two UID types match. williamr@2: williamr@2: A match is made if each UID in aMatchUid is either identical to the corresponding williamr@2: one in aFileUid, or is KNullUid. williamr@2: williamr@2: @param aFileUid The UID type to match. williamr@2: @param aMatchUid The UID type to match against. williamr@2: @return ETrue if the UIDs match, EFalse if not. */ williamr@2: inline TBool EikFileUtils::UidTypeMatches(const TUidType& aFileUid, const TUidType& aMatchUid) williamr@2: { return BaflUtils::UidTypeMatches(aFileUid,aMatchUid); } williamr@2: williamr@2: /** Tests whether a specified file name can be parsed. williamr@2: williamr@2: @param aName The file name to parse. williamr@2: @return KErrNone if the filename can be parsed, otherwise one williamr@2: of the system-wide error codes. williamr@2: @see TParse */ williamr@2: inline TInt EikFileUtils::Parse(const TDesC& aName) williamr@2: { return BaflUtils::Parse(aName); } williamr@2: williamr@2: /** Copies the specified file. williamr@2: williamr@2: Notes: williamr@2: williamr@2: - files can be copied across drives williamr@2: williamr@2: - open files can be copied only if they have been opened using the EFileShareReadersOnly williamr@2: file share mode williamr@2: williamr@2: - the source file's attributes are preserved in the target file williamr@2: williamr@2: @param aSourceFullName Path indicating the file(s) to be copied. Any path williamr@2: components which are not specified here will be taken from the session path. williamr@2: @param aTargetFullName Path indicating the directory into which the file(s) williamr@2: are to be copied. williamr@2: @param aSwitch Optional switch to allow overwriting files with the same name williamr@2: in the target directory, or recursion. By default, this function operates with williamr@2: overwriting and non-recursively. Switch options are defined using the enum TSwitch. williamr@2: If recursive operation is set, any intermediate directories are created. If no overwriting williamr@2: is set, any files with the same name are not overwritten, and an error is returned williamr@2: for that file. williamr@2: @return KErrNone if the copy is successful, otherwise another of the system-wide williamr@2: error codes. */ williamr@2: inline TInt EikFileUtils::CopyFile(const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch) williamr@2: { return BaflUtils::CopyFile(CEikonEnv::Static()->FsSession(),aSourceFullName,aTargetFullName,aSwitch); } williamr@2: williamr@2: /** Renames one or more files or directories. williamr@2: williamr@2: This can also be used to move files by specifying different destination and williamr@2: source directories, but note that the destination and source directories must be williamr@2: on the same drive. williamr@2: williamr@2: If moving files, you can set aSwitch so that any files with the same name williamr@2: that exist in the target directory are overwritten. If aSwitch is set for williamr@2: no overwriting, any files with the same name are not overwritten, and an error williamr@2: (KErrAlreadyExists) is returned for that file. williamr@2: williamr@2: This function can only operate non-recursively, so that only the matching williamr@2: files located in the single directory specified by aOldFullName may be renamed. williamr@2: williamr@2: Read-only, system and hidden files may be renamed or moved, and the source williamr@2: file's attributes are preserved in the target file, but attempting to rename williamr@2: or move an open file will return an error for that file. williamr@2: williamr@2: @param aOldFullName Path specifying the file or directory to be renamed. williamr@2: @param aNewFullName Path specifying the new name for the file or directory. williamr@2: Any directories specified in this path which do not exist will be created. williamr@2: @param aSwitch Optional, sets whether files are overwritten on the target. williamr@2: @return KErrNone if successful otherwise another of the system-wide error codes. */ williamr@2: inline TInt EikFileUtils::RenameFile(const TDesC& aOldFullName, const TDesC& aNewFullName, TUint aSwitch) williamr@2: { return BaflUtils::RenameFile(CEikonEnv::Static()->FsSession(),aOldFullName,aNewFullName,aSwitch); } williamr@2: williamr@2: /** Deletes one or more files. williamr@2: williamr@2: This function may operate recursively or non-recursively. When operating non-recursively, williamr@2: only the matching files located in the directory specified in aSourceFullName williamr@2: are affected. When operating recursively, all matching files in the directory williamr@2: hierarchy below the directory specified in aSourceFullName are deleted. williamr@2: williamr@2: Attempting to delete read-only or open files returns an error. williamr@2: williamr@2: @param aSourceFullName Path indicating the file(s) to be deleted. This can williamr@2: either be a full path, or a path relative to the session path. Use wildcards williamr@2: to specify more than one file. williamr@2: @param aSwitch Determines whether this function operates recursively. By default, williamr@2: this function operates non-recursively. williamr@2: @return KErrNone if aSourceFullName is successfully deleted, otherwise another williamr@2: of the system-wide error codes. */ williamr@2: inline TInt EikFileUtils::DeleteFile(const TDesC& aSourceFullName, TUint aSwitch) williamr@2: { return BaflUtils::DeleteFile(CEikonEnv::Static()->FsSession(), aSourceFullName,aSwitch); } williamr@2: williamr@2: /** Tests whether a file specification is a valid folder name. williamr@2: williamr@2: @param aFullName The string to check. williamr@2: @param aIsFolder True if aFullName is a valid folder name, otherwise false. williamr@2: @return KErrNone if successful, otherwise another of the system-wide error codes williamr@2: (probably because aFullName cannot be parsed). */ williamr@2: inline TInt EikFileUtils::CheckWhetherFullNameRefersToFolder(const TDesC& aFullName, TBool& aIsFolder) williamr@2: { return BaflUtils::CheckWhetherFullNameRefersToFolder(aFullName,aIsFolder); } williamr@2: williamr@2: /** Gets the folder name if the specified item is a valid folder name, otherwise gets the file name. williamr@2: williamr@2: @param aFullName Item to parse. williamr@2: @param aMostSignificantPart On return, the folder or file name. williamr@2: @return KErrNone if successful otherwise another of the system-wide error codes. */ williamr@2: inline TInt EikFileUtils::MostSignificantPartOfFullName(const TDesC& aFullName, TFileName& aMostSignificantPart) williamr@2: { return BaflUtils::MostSignificantPartOfFullName(aFullName,aMostSignificantPart); } williamr@2: williamr@2: /** Tests whether the specified folder exists and can be opened. williamr@2: williamr@2: This returns an error code if the folder does not exist: see also FolderExists() williamr@2: which returns a boolean value. williamr@2: williamr@2: @param aFolderName The folder's name and path. williamr@2: @return KErrNone if aFolderName exists, otherwise another of the system-wide williamr@2: error codes. */ williamr@2: inline TInt EikFileUtils::CheckFolder(const TDesC& aFolderName) williamr@2: { return BaflUtils::CheckFolder(CEikonEnv::Static()->FsSession(),aFolderName); } williamr@2: williamr@2: /** Tests whether the specified drive is read-only. williamr@2: williamr@2: @param aFullName File name, including drive. williamr@2: @param aIsReadOnly On return, true if the drive is read-only, otherwise false. williamr@2: @return KErrNone if successful otherwise another of the system-wide error codes. */ williamr@2: inline TInt EikFileUtils::DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly) williamr@2: { return BaflUtils::DiskIsReadOnly(CEikonEnv::Static()->FsSession(),aFullName,aIsReadOnly); } williamr@2: williamr@2: /** Gets a list of all drives present on the system. williamr@2: williamr@2: The file server is interrogated for a list of the drive letters for all available williamr@2: drives. The drive letter that corresponds to aDriveNumber is added to the list williamr@2: regardless of whether it is present, or is corrupt. Also, the C: drive and the williamr@2: primary partitions on removable media slots are forced onto the list, even if williamr@2: corrupt or not present. williamr@2: williamr@2: @param aFs A connected session with the file server. williamr@2: @param aArray On return, contains the drive letters that correspond to the available williamr@2: drives. The drive letters are uppercase and are in alphabetical order. williamr@2: @param aIncludeRom ETrue if the ROM is included as a drive, EFalse otherwise. williamr@2: @param aDriveNumber The drive to force into the list, e.g. the drive in the default williamr@2: path. */ williamr@2: inline void EikFileUtils::UpdateDiskListL(const RFs& aFs,CDesCArray& aArray,TBool aIncludeRom,TDriveNumber aDriveNumber) williamr@2: { BaflUtils::UpdateDiskListL(aFs,aArray,aIncludeRom,aDriveNumber); } williamr@2: williamr@2: /** Removes the System directory from a list of directory entries. williamr@2: williamr@2: @param aDir Array of directory entries. */ williamr@2: inline void EikFileUtils::RemoveSystemDirectory(CDir& aDir) williamr@2: { BaflUtils::RemoveSystemDirectory(aDir); } williamr@2: williamr@2: /** Tests whether the specified drive corresponds to the primary partition williamr@2: in a removable media slot. williamr@2: williamr@2: Note that the function assumes that the D: drive corresponds to the primary williamr@2: partition on socket 0, and that the E: drive corresponds to the primary williamr@2: partition on socket 1 (a socket is a slot for removable media). This mapping williamr@2: may not always be the case because it is set up in the variant layer of Symbian williamr@2: OS. williamr@2: williamr@2: @param aDriveUnit The drive to check. williamr@2: @return True if the drive is the primary partition in a removable media williamr@2: slot. True is also returned if the drive is C:. False is returned otherwise. */ williamr@2: inline TBool EikFileUtils::IsFirstDriveForSocket(TDriveUnit aDriveUnit) williamr@2: { return BaflUtils::IsFirstDriveForSocket(aDriveUnit); } williamr@2: williamr@2: /** Sorts files by UID. williamr@2: williamr@2: The caller supplies a table which specifies the order in which files are to be sorted. williamr@2: The files whose UID3 is the first UID in the table appear first. The files whose UID3 williamr@2: is the UID specified second appear next, and so on. Files whose UID3 is not specified williamr@2: in the table, and directories, appear at the end of the list, with directories preceding williamr@2: the files, and with files sorted in ascending order of UID3. williamr@2: williamr@2: This function is used for customising how lists of application files are sorted. williamr@2: williamr@2: @param aDir The array of files and directories to sort. williamr@2: @param aTable A sort order table containing the UIDs to use in the sort. williamr@2: @return KErrNone if successful otherwise another of the system-wide error codes. */ williamr@2: inline TInt EikFileUtils::SortByTable(CDir& aDir,CBaflFileSortTable* aTable) williamr@2: { return BaflUtils::SortByTable(aDir,aTable); } williamr@2: williamr@2: williamr@2: #endif // __EIKFUTIL_H__