LFile is a PowerPlant class that is used as a wrapper class for a Macintosh file with a data and/or a resource fork.
A FSSpec (File System Specification) record identifies a Mac file. When
open, the data fork has a file refNum. Likewise, when open, the resource fork has a file refNum. The LFile class stores an FSSpec and the refNums for the data and resource forks.
This class does not provide many functions for manipulating files.
You should get the FSSpec or refNum of the fork you want to manipulate and make direct calls to the
Mac File Manager. However, use the member functions for opening
and closing data and resource forks.
The only file accessing functions provided are ones for reading and writing the entire data fork.
Methods :
The methods in this class are:
Data Members:
The data members in this class are:
Source files:
See also:
Purpose:
There are three constructor methods.
The default constructor sets the items in mMacFileSpec to 0, mDataForkRefNum and mResourceForkRefNum to refNum_Undefined.
The second constructor is a parameter constructor which sets mMacFileSpec to inFileSpec, mDataForkRefNum and mResourceForkRefNum to refNum_Undefined.
The third constructor is also a parameter constructor that creates
a File from an AliasHandle. outWasChanged indicates if the AliasHandle was changed during resolution. inFromFile is a File Specifiier for the starting point for a relative search.
If nil, an absolute search should be performed. Also sets mDataForkRefNum and mResourceForkRefNum to refNum_Undefined. Calls an exception if the OS returns an error.
Access :
Prototypes:
LFile(); // Default Constructor
LFile (const FSSpec &inFileSpec);
LFile ( AliasHandle inAlias,
Boolean& outWasChanged, FSSpec* inFromFile); No return value for a constructor.
Purpose:
The destructor closes the data and resource forks before deletion.
Access :
Prototype:
virtual ~LFile();Parameters:
Return:
No return value for a destructor
Purpose:
Close the data fork of a File (if any). It's a good idea to close files just after reading or writing, to avoid damage if something crashes.
Access :
Prototype:
void CloseDataFork();Parameters:
Return:
Remarks:
Throws anexception if it fails.
Purpose:
Close the resource fork of a File (if any). It's a good idea to close files just after reading or writing, to avoid damage if something crashes.
Access :
Prototype:
void CloseResourceFork();Parameters:
Return:
Remarks:
Throws an exception if it fails.
Purpose:
Create a new disk File, with an empty data fork and no resource map. You must call OpenDataFork (with write permission) before you can store data in the File. The resource fork is uninitialized (no resource map), so you can't call OpenResourceFork for the File. You can initialize the resource fork by calling CreateNewFile.
Access :
Prototype:
void CreateNewDataFile(
OSType inCreator, OSType inFileType, ScriptCode inScriptCode); Return:
Remarks:
The resource fork is uninitialized (no resource map), so you can't call OpenResourceFork() for the file. You can initialize the resource fork by calling CreateNewFile().
Purpose:
Create a new disk File, with an empty data fork and a resoure map. You must call OpenDataFork or OpenResourceFork (with write permission) before you can store information in the File. If the file already exists, but doesn't have a resource map, this function will create a resource map.
Access :
Prototype:
void CreateNewFile(
OSType inCreator, OSType inFileType, ScriptCode inScriptCode); Return:
Remarks:
If the file already exists, but doesn't have a resource map, this function will create a resource map.
Purpose:
Compare two FSSpec structs for equality. Compares each field in the FSSpec struct.
Access :
Prototype:
Boolean EqualFileSpec(
const FSSpec& inFileSpecA, const FSSpec& inFileSpecB); Return:
True if both FSSpec structs are equal.
Purpose:
Return the current Mac File System Specification record (mMacFileSpec) for a File.
Access :
Prototype:
void GetSpecifier(
FSSpec& outFileSpec) const; Return:
Purpose:
Return a newly created AliasHandle for a File.
Access :
Prototype:
virtual AliasHandle MakeAlias( FSSpec* inFromFile);Parameters:
Return:
Purpose:
Open the data fork of a File with the specified permissions and return the reference number for the opened fork A data fork must be Open before you can read or write data
Access :
Prototype:
virtual SInt16 OpenDataFork( SInt16 inPrivileges);Parameters:
Return:
Reference number for the open data fork.
Remarks:
A data fork must be open before you can read or write data.
Purpose:
Open the resource fork of a File with the specified permissions andreturn the reference number for the opened fork A resource fork must be Open before you can read or write resources
Access :
Prototype:
virtual SInt16 OpenResourceFork(
SInt16 inPrivileges) Return:
Referencenumber for the open resource fork.
Remarks:
A resource fork must be open before you can read or write resources.
Purpose:
Read the entire contents of a File's data fork into a newly created Handle. The caller is responsible for disposing of the Handle.
Access :
Prototype:
virtual Handle ReadDataFork();Parameters:
Return:
Remarks:
Throws an exception if it fails.
Purpose:
Set a new Toolbox File System Specification for a File. This has the side effect of closing any open forks of the file identified by the old Specifier.
Access :
Prototype:
virtual void SetSpecifier(
const FSSpec& inFileSpec);Parameters:
Return:
Purpose:
Returns whether the File's FSSpec is the same as the input FSSpec.
Access :
Prototype:
Boolean UsesSpecifier(
const FSSpec& inFileSpec) const; Return:
True if FSSpec's are the same.
Remarks:
Calls EqualFileSpec().
Purpose:
Write to the data fork of a File from a buffer. The buffer contents completely replace any existing data.
Access :
Prototype:
SInt32 WriteDataFork(
const void* inBuffer, SInt32 inByteCount); Return:
Number of bytes actually written.
Remarks:
Throws an exception if it fails.
Purpose:
Stores the FSSpec of the file.
Access :
Prototype:
FSSpec mMacFileSpec;
Purpose:
refNum for the File's data fork.
Access :
Prototype:
SInt16 mDataForkRefNum;
Purpose:
refNum for the File's resource fork.
Access :
Prototype:
SInt16 mResourceForkRefNum;