epoc32/include/mw/eikfutil.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:27:01 +0100
branchSymbian2
changeset 3 e1b950c65cb4
parent 2 epoc32/include/eikfutil.h@2fe1408b6811
child 4 837f303aceeb
permissions -rw-r--r--
Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
williamr@2
     1
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@2
     2
// All rights reserved.
williamr@2
     3
// This component and the accompanying materials are made available
williamr@2
     4
// 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
     5
// which accompanies this distribution, and is available
williamr@2
     6
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
williamr@2
     7
//
williamr@2
     8
// Initial Contributors:
williamr@2
     9
// Nokia Corporation - initial contribution.
williamr@2
    10
//
williamr@2
    11
// Contributors:
williamr@2
    12
//
williamr@2
    13
// Description:
williamr@2
    14
//
williamr@2
    15
williamr@2
    16
#ifndef __EIKFUTIL_H__
williamr@2
    17
#define __EIKFUTIL_H__
williamr@2
    18
williamr@2
    19
#include <e32std.h>
williamr@2
    20
#include <f32file.h>
williamr@2
    21
#include <badesca.h>
williamr@2
    22
#include <bautils.h>
williamr@2
    23
#include <eikenv.h>
williamr@2
    24
williamr@2
    25
class CFont;
williamr@2
    26
class CBaflFileSortTable;
williamr@2
    27
class TResourceReader;
williamr@2
    28
williamr@2
    29
williamr@2
    30
/** Provides a set of drive, path and file utility functions.
williamr@2
    31
williamr@2
    32
This class is essentially a thin layer over the BaflUtils class.
williamr@2
    33
williamr@2
    34
@publishedAll 
williamr@2
    35
@released */
williamr@2
    36
NONSHARABLE_CLASS(EikFileUtils)
williamr@2
    37
	{ 
williamr@2
    38
public:
williamr@2
    39
	inline static TBool PathExists(const TDesC& aPath);
williamr@2
    40
	inline static TInt IsFolder(const TDesC& aFullName, TBool& aIsFolder);
williamr@2
    41
	inline static TBool FolderExists(const TDesC& aFolderName);
williamr@2
    42
	inline static TFileName FolderNameFromFullName(const TDesC& aFullName);
williamr@2
    43
	inline static TFileName DriveAndPathFromFullName(const TDesC& aFullName);
williamr@2
    44
	inline static TFileName RootFolderPath(const TBuf<1> aDriveLetter);
williamr@2
    45
	inline static void AbbreviateFileName(const TFileName& aOriginalFileName, TDes& aAbbreviatedFileName);
williamr@2
    46
	IMPORT_C static TFileName AbbreviatePath(TDesC& aPathName, const CFont& aFont, TInt aMaxWidthInPixels);
williamr@2
    47
	inline static TBool UidTypeMatches(const TUidType& aFileUid, const TUidType& aMatchUid);
williamr@2
    48
	inline static TInt Parse(const TDesC& aName);
williamr@2
    49
	IMPORT_C static TFileName ValidateFolderNameTypedByUserL(const TDesC& aFolderNameTypedByUser, const TDesC& aCurrentPath);
williamr@2
    50
	inline static TInt CopyFile(const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch = CFileMan::EOverWrite);
williamr@2
    51
	inline static TInt RenameFile(const TDesC& aOldFullName, const TDesC& aNewFullName, TUint aSwitch = CFileMan::EOverWrite);
williamr@2
    52
	inline static TInt DeleteFile(const TDesC& aSourceFullName, TUint aSwitch=0);
williamr@2
    53
	inline static TInt CheckWhetherFullNameRefersToFolder(const TDesC& aFullName, TBool& aIsFolder);
williamr@2
    54
	inline static TInt MostSignificantPartOfFullName(const TDesC& aFullName, TFileName& aMostSignificantPart);
williamr@2
    55
	inline static TInt CheckFolder(const TDesC& aFolderName);
williamr@2
    56
	inline static TInt DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly);
williamr@2
    57
	inline static void UpdateDiskListL(const RFs& aFs,CDesCArray& aArray,TBool aIncludeRom,TDriveNumber aDriveNumber);
williamr@2
    58
	inline static void RemoveSystemDirectory(CDir& aDir);
williamr@2
    59
	inline static TBool IsFirstDriveForSocket(TDriveUnit aDriveUnit);
williamr@2
    60
	inline static TInt SortByTable(CDir& aDir,CBaflFileSortTable* aTable);
williamr@2
    61
private:
williamr@2
    62
	EikFileUtils();
williamr@2
    63
	};
williamr@2
    64
williamr@2
    65
williamr@2
    66
/** Tests whether a path exists.
williamr@2
    67
williamr@2
    68
@param aPath The path to check. 
williamr@2
    69
@return ETrue if the path exists, EFalse otherwise. */
williamr@2
    70
inline TBool EikFileUtils::PathExists(const TDesC& aPath)
williamr@2
    71
	{	return BaflUtils::PathExists(CEikonEnv::Static()->FsSession(),aPath);	}
williamr@2
    72
williamr@2
    73
/** Tests whether aFullName is a folder.
williamr@2
    74
williamr@2
    75
@param aFullName The drive and path to test. 
williamr@2
    76
@param aIsFolder On return, indicates whether aFullName is a folder. 
williamr@2
    77
@return KErrNone if successful otherwise another of the system-wide error codes. */
williamr@2
    78
inline TInt EikFileUtils::IsFolder(const TDesC& aFullName, TBool& aIsFolder)
williamr@2
    79
	{	return BaflUtils::IsFolder(CEikonEnv::Static()->FsSession(), aFullName,aIsFolder);	}
williamr@2
    80
williamr@2
    81
/** Tests whether a specified folder exists. 
williamr@2
    82
williamr@2
    83
This returns a boolean value indicating whether the folder exists: see also 
williamr@2
    84
CheckFolder() which returns an error code instead.
williamr@2
    85
williamr@2
    86
@param aFolderName The folder's path.
williamr@2
    87
@return ETrue if the folder exists, EFalse if not. */
williamr@2
    88
inline TBool EikFileUtils::FolderExists(const TDesC& aFolderName)
williamr@2
    89
	{	return BaflUtils::FolderExists(CEikonEnv::Static()->FsSession(), aFolderName);	}
williamr@2
    90
williamr@2
    91
/** Gets a folder name from a path and file name.
williamr@2
    92
williamr@2
    93
@param aFullName The full path and file name from which the folder will be 
williamr@2
    94
obtained. 
williamr@2
    95
@return Folder name */
williamr@2
    96
inline TFileName EikFileUtils::FolderNameFromFullName(const TDesC& aFullName)
williamr@2
    97
	{	return BaflUtils::FolderNameFromFullName(aFullName);	}
williamr@2
    98
williamr@2
    99
/** Parses the specified full path and file name to obtain the drive and path.
williamr@2
   100
williamr@2
   101
@param aFullName The full path and file name from which the drive and path 
williamr@2
   102
will be obtained. 
williamr@2
   103
@return The drive and path. */
williamr@2
   104
inline TFileName EikFileUtils::DriveAndPathFromFullName(const TDesC& aFullName)
williamr@2
   105
	{ 	return BaflUtils::DriveAndPathFromFullName(aFullName);	}
williamr@2
   106
williamr@2
   107
/** Gets the root folder for the specified drive.
williamr@2
   108
williamr@2
   109
@param aDriveLetter The drive letter, C for example. 
williamr@2
   110
@return The root folder for the drive, C:\ for example. */
williamr@2
   111
inline TFileName EikFileUtils::RootFolderPath(const TBuf<1> aDriveLetter)
williamr@2
   112
	{	return BaflUtils::RootFolderPath(aDriveLetter);	}
williamr@2
   113
williamr@2
   114
/** Abbreviates a file name.
williamr@2
   115
williamr@2
   116
If aOriginalFileName is less than the maximum length of aAbbreviatedFileName, 
williamr@2
   117
then the name is simply copied to aAbbreviatedFileName.
williamr@2
   118
williamr@2
   119
If this is not the case, then the left-most characters of aOriginalFileName are 
williamr@2
   120
copied to aAbbreviatedFileName, up to aAbbreviatedFileName's maximum length-1 and 
williamr@2
   121
aAbbreviatedFileName's first character is set to be an ellipsis.
williamr@2
   122
williamr@2
   123
For example, if c:\\home\\letters\\abcdef is the original file name and aAbbreviatedFileName 
williamr@2
   124
allows only 7 characters, the abbreviated file name will be ...abcdef. 
williamr@2
   125
This can be used to display a file or folder name in an error or progress 
williamr@2
   126
dialog.
williamr@2
   127
williamr@2
   128
@param aOriginalFileName Original file name. 
williamr@2
   129
@param aAbbreviatedFileName On return, the abbreviated file name. */
williamr@2
   130
inline void EikFileUtils::AbbreviateFileName(const TFileName& aOriginalFileName, TDes& aAbbreviatedFileName)
williamr@2
   131
	{	BaflUtils::AbbreviateFileName(aOriginalFileName,aAbbreviatedFileName);	}
williamr@2
   132
williamr@2
   133
/** Tests whether two UID types match.
williamr@2
   134
williamr@2
   135
A match is made if each UID in aMatchUid is either identical to the corresponding 
williamr@2
   136
one in aFileUid, or is KNullUid.
williamr@2
   137
williamr@2
   138
@param aFileUid The UID type to match. 
williamr@2
   139
@param aMatchUid The UID type to match against. 
williamr@2
   140
@return ETrue if the UIDs match, EFalse if not. */
williamr@2
   141
inline TBool EikFileUtils::UidTypeMatches(const TUidType& aFileUid, const TUidType& aMatchUid)
williamr@2
   142
	{	return BaflUtils::UidTypeMatches(aFileUid,aMatchUid);	}
williamr@2
   143
williamr@2
   144
/** Tests whether a specified file name can be parsed.
williamr@2
   145
williamr@2
   146
@param aName The file name to parse.
williamr@2
   147
@return KErrNone if the filename can be parsed, otherwise one 
williamr@2
   148
of the system-wide error codes. 
williamr@2
   149
@see TParse */
williamr@2
   150
inline TInt EikFileUtils::Parse(const TDesC& aName)
williamr@2
   151
	{	return BaflUtils::Parse(aName);	}
williamr@2
   152
williamr@2
   153
/** Copies the specified file.
williamr@2
   154
williamr@2
   155
Notes:
williamr@2
   156
williamr@2
   157
- files can be copied across drives
williamr@2
   158
williamr@2
   159
- open files can be copied only if they have been opened using the EFileShareReadersOnly 
williamr@2
   160
file share mode
williamr@2
   161
williamr@2
   162
- the source file's attributes are preserved in the target file
williamr@2
   163
williamr@2
   164
@param aSourceFullName Path indicating the file(s) to be copied. Any path 
williamr@2
   165
components which are not specified here will be taken from the session path. 
williamr@2
   166
@param aTargetFullName Path indicating the directory into which the file(s) 
williamr@2
   167
are to be copied. 
williamr@2
   168
@param aSwitch Optional switch to allow overwriting files with the same name 
williamr@2
   169
in the target directory, or recursion. By default, this function operates with 
williamr@2
   170
overwriting and non-recursively. Switch options are defined using the enum TSwitch. 
williamr@2
   171
If recursive operation is set, any intermediate directories are created. If no overwriting 
williamr@2
   172
is set, any files with the same name are not overwritten, and an error is returned 
williamr@2
   173
for that file.
williamr@2
   174
@return KErrNone if the copy is successful, otherwise another of the system-wide 
williamr@2
   175
error codes. */
williamr@2
   176
inline TInt EikFileUtils::CopyFile(const TDesC& aSourceFullName, const TDesC& aTargetFullName, TUint aSwitch)
williamr@2
   177
	{	return BaflUtils::CopyFile(CEikonEnv::Static()->FsSession(),aSourceFullName,aTargetFullName,aSwitch);	}
williamr@2
   178
williamr@2
   179
/** Renames one or more files or directories. 
williamr@2
   180
williamr@2
   181
This can also be used to move files by specifying different destination and 
williamr@2
   182
source directories, but note that the destination and source directories must be 
williamr@2
   183
on the same drive.
williamr@2
   184
williamr@2
   185
If moving files, you can set aSwitch so that any files with the same name 
williamr@2
   186
that exist in the target directory are overwritten. If aSwitch is set for 
williamr@2
   187
no overwriting, any files with the same name are not overwritten, and an error 
williamr@2
   188
(KErrAlreadyExists) is returned for that file.
williamr@2
   189
williamr@2
   190
This function can only operate non-recursively, so that only the matching 
williamr@2
   191
files located in the single directory specified by aOldFullName may be renamed.
williamr@2
   192
williamr@2
   193
Read-only, system and hidden files may be renamed or moved, and the source 
williamr@2
   194
file's attributes are preserved in the target file, but attempting to rename 
williamr@2
   195
or move an open file will return an error for that file.
williamr@2
   196
williamr@2
   197
@param aOldFullName Path specifying the file or directory to be renamed. 
williamr@2
   198
@param aNewFullName Path specifying the new name for the file or directory. 
williamr@2
   199
Any directories specified in this path which do not exist will be created. 
williamr@2
   200
@param aSwitch Optional, sets whether files are overwritten on the target. 
williamr@2
   201
@return KErrNone if successful otherwise another of the system-wide error codes. */
williamr@2
   202
inline TInt EikFileUtils::RenameFile(const TDesC& aOldFullName, const TDesC& aNewFullName, TUint aSwitch)
williamr@2
   203
	{	return BaflUtils::RenameFile(CEikonEnv::Static()->FsSession(),aOldFullName,aNewFullName,aSwitch);	}
williamr@2
   204
williamr@2
   205
/** Deletes one or more files.
williamr@2
   206
williamr@2
   207
This function may operate recursively or non-recursively. When operating non-recursively, 
williamr@2
   208
only the matching files located in the directory specified in aSourceFullName 
williamr@2
   209
are affected. When operating recursively, all matching files in the directory 
williamr@2
   210
hierarchy below the directory specified in aSourceFullName are deleted.
williamr@2
   211
williamr@2
   212
Attempting to delete read-only or open files returns an error.
williamr@2
   213
williamr@2
   214
@param aSourceFullName Path indicating the file(s) to be deleted. This can 
williamr@2
   215
either be a full path, or a path relative to the session path. Use wildcards 
williamr@2
   216
to specify more than one file. 
williamr@2
   217
@param aSwitch Determines whether this function operates recursively. By default, 
williamr@2
   218
this function operates non-recursively. 
williamr@2
   219
@return KErrNone if aSourceFullName is successfully deleted, otherwise another 
williamr@2
   220
of the system-wide error codes. */
williamr@2
   221
inline TInt EikFileUtils::DeleteFile(const TDesC& aSourceFullName, TUint aSwitch)
williamr@2
   222
	{	return BaflUtils::DeleteFile(CEikonEnv::Static()->FsSession(), aSourceFullName,aSwitch);	}
williamr@2
   223
williamr@2
   224
/** Tests whether a file specification is a valid folder name.
williamr@2
   225
williamr@2
   226
@param aFullName The string to check. 
williamr@2
   227
@param aIsFolder True if aFullName is a valid folder name, otherwise false.
williamr@2
   228
@return KErrNone if successful, otherwise another of the system-wide error codes 
williamr@2
   229
(probably because aFullName cannot be parsed). */
williamr@2
   230
inline TInt EikFileUtils::CheckWhetherFullNameRefersToFolder(const TDesC& aFullName, TBool& aIsFolder)
williamr@2
   231
	{	return BaflUtils::CheckWhetherFullNameRefersToFolder(aFullName,aIsFolder);	}
williamr@2
   232
williamr@2
   233
/** Gets the folder name if the specified item is a valid folder name, otherwise gets the file name.
williamr@2
   234
williamr@2
   235
@param aFullName Item to parse. 
williamr@2
   236
@param aMostSignificantPart On return, the folder or file name.
williamr@2
   237
@return KErrNone if successful otherwise another of the system-wide error codes. */
williamr@2
   238
inline TInt EikFileUtils::MostSignificantPartOfFullName(const TDesC& aFullName, TFileName& aMostSignificantPart)
williamr@2
   239
	{	return BaflUtils::MostSignificantPartOfFullName(aFullName,aMostSignificantPart);	}
williamr@2
   240
williamr@2
   241
/** Tests whether the specified folder exists and can be opened.
williamr@2
   242
williamr@2
   243
This returns an error code if the folder does not exist: see also FolderExists() 
williamr@2
   244
which returns a boolean value.
williamr@2
   245
williamr@2
   246
@param aFolderName The folder's name and path. 
williamr@2
   247
@return KErrNone if aFolderName exists, otherwise another of the system-wide 
williamr@2
   248
error codes. */
williamr@2
   249
inline TInt EikFileUtils::CheckFolder(const TDesC& aFolderName)
williamr@2
   250
	{	return BaflUtils::CheckFolder(CEikonEnv::Static()->FsSession(),aFolderName);	}
williamr@2
   251
williamr@2
   252
/** Tests whether the specified drive is read-only.
williamr@2
   253
williamr@2
   254
@param aFullName File name, including drive. 
williamr@2
   255
@param aIsReadOnly On return, true if the drive is read-only, otherwise false. 
williamr@2
   256
@return KErrNone if successful otherwise another of the system-wide error codes. */
williamr@2
   257
inline TInt EikFileUtils::DiskIsReadOnly(const TDesC& aFullName, TBool& aIsReadOnly)	
williamr@2
   258
	{	return BaflUtils::DiskIsReadOnly(CEikonEnv::Static()->FsSession(),aFullName,aIsReadOnly);	}
williamr@2
   259
williamr@2
   260
/** Gets a list of all drives present on the system.
williamr@2
   261
williamr@2
   262
The file server is interrogated for a list of the drive letters for all available 
williamr@2
   263
drives. The drive letter that corresponds to aDriveNumber is added to the list 
williamr@2
   264
regardless of whether it is present, or is corrupt. Also, the C: drive and the 
williamr@2
   265
primary partitions on removable media slots are forced onto the list, even if 
williamr@2
   266
corrupt or not present.
williamr@2
   267
williamr@2
   268
@param aFs A connected session with the file server. 
williamr@2
   269
@param aArray On return, contains the drive letters that correspond to the available 
williamr@2
   270
drives. The drive letters are uppercase and are in alphabetical order. 
williamr@2
   271
@param aIncludeRom ETrue if the ROM is included as a drive, EFalse otherwise. 
williamr@2
   272
@param aDriveNumber The drive to force into the list, e.g. the drive in the default 
williamr@2
   273
path. */
williamr@2
   274
inline void EikFileUtils::UpdateDiskListL(const RFs& aFs,CDesCArray& aArray,TBool aIncludeRom,TDriveNumber aDriveNumber)
williamr@2
   275
	{	BaflUtils::UpdateDiskListL(aFs,aArray,aIncludeRom,aDriveNumber);	}
williamr@2
   276
williamr@2
   277
/** Removes the System directory from a list of directory entries.
williamr@2
   278
williamr@2
   279
@param aDir Array of directory entries. */
williamr@2
   280
inline void EikFileUtils::RemoveSystemDirectory(CDir& aDir)
williamr@2
   281
	{	BaflUtils::RemoveSystemDirectory(aDir);	}
williamr@2
   282
williamr@2
   283
/** Tests whether the specified drive corresponds to the primary partition 
williamr@2
   284
in a removable media slot.
williamr@2
   285
williamr@2
   286
Note that the function assumes that the D: drive corresponds to the primary 
williamr@2
   287
partition on socket 0, and that the E: drive corresponds to the primary 
williamr@2
   288
partition on socket 1 (a socket is a slot for removable media). This mapping 
williamr@2
   289
may not always be the case because it is set up in the variant layer of Symbian 
williamr@2
   290
OS. 
williamr@2
   291
williamr@2
   292
@param aDriveUnit The drive to check. 
williamr@2
   293
@return True if the drive is the primary partition in a removable media 
williamr@2
   294
slot. True is also returned if the drive is C:. False is returned otherwise. */
williamr@2
   295
inline TBool EikFileUtils::IsFirstDriveForSocket(TDriveUnit aDriveUnit)
williamr@2
   296
	{	return BaflUtils::IsFirstDriveForSocket(aDriveUnit);	}
williamr@2
   297
williamr@2
   298
/** Sorts files by UID.
williamr@2
   299
williamr@2
   300
The caller supplies a table which specifies the order in which files are to be sorted. 
williamr@2
   301
The files whose UID3 is the first UID in the table appear first. The files whose UID3 
williamr@2
   302
is the UID specified second appear next, and so on. Files whose UID3 is not specified 
williamr@2
   303
in the table, and directories, appear at the end of the list, with directories preceding 
williamr@2
   304
the files, and with files sorted in ascending order of UID3.
williamr@2
   305
williamr@2
   306
This function is used for customising how lists of application files are sorted.
williamr@2
   307
williamr@2
   308
@param aDir The array of files and directories to sort. 
williamr@2
   309
@param aTable A sort order table containing the UIDs to use in the sort. 
williamr@2
   310
@return KErrNone if successful otherwise another of the system-wide error codes. */
williamr@2
   311
inline TInt EikFileUtils::SortByTable(CDir& aDir,CBaflFileSortTable* aTable)
williamr@2
   312
	{	return BaflUtils::SortByTable(aDir,aTable);	}
williamr@2
   313
williamr@2
   314
williamr@2
   315
#endif	// __EIKFUTIL_H__