Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions
PatchableAppleSingle.h File Reference
#include <Errors.h>
#include <Types.h>
#include <Files.h>
#include <Script.h>
#include <Resources.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  PASHeader
struct  PASEntry
struct  PASMiscInfo
struct  PASResFork
struct  PASResource

Defines

#define kCreator   'MOSS'
#define kType   'PASf'
#define PAS_BUFFER_SIZE   (1024*512)
#define PAS_MAGIC_NUM   (0x00244200)
#define PAS_VERSION   (0x00010000)

Typedefs

typedef struct PASHeader PASHeader
typedef struct PASEntry PASEntry
typedef struct PASMiscInfo PASMiscInfo
typedef struct PASResFork PASResFork
typedef struct PASResource PASResource

Enumerations

enum  { ePas_Data = 1, ePas_Misc, ePas_Resource }

Functions

OSErr PAS_EncodeFile (FSSpec *inSpec, FSSpec *outSpec)
OSErr PAS_DecodeFile (FSSpec *inSpec, FSSpec *outSpec)

Class Documentation

struct PASHeader

Definition at line 50 of file PatchableAppleSingle.h.

Class Members
UInt8 filler
UInt32 magicNum
UInt16 numEntries
UInt32 versionNum
struct PASEntry

Definition at line 59 of file PatchableAppleSingle.h.

Class Members
UInt32 entryID
UInt32 entryLength
UInt32 entryOffset
struct PASMiscInfo

Definition at line 69 of file PatchableAppleSingle.h.

Class Members
OSType fileCreator
UInt32 fileFlags
short fileHasResFork
short fileResAttrs
OSType fileType
struct PASResFork

Definition at line 80 of file PatchableAppleSingle.h.

Class Members
short NumberOfTypes
struct PASResource

Definition at line 87 of file PatchableAppleSingle.h.

Class Members
short attr
short attrID
Str255 attrName
OSType attrType
unsigned long length

Define Documentation

#define kCreator   'MOSS'

Definition at line 104 of file PatchableAppleSingle.h.

#define kType   'PASf'

Definition at line 105 of file PatchableAppleSingle.h.

#define PAS_BUFFER_SIZE   (1024*512)

Definition at line 106 of file PatchableAppleSingle.h.

#define PAS_MAGIC_NUM   (0x00244200)

Definition at line 108 of file PatchableAppleSingle.h.

#define PAS_VERSION   (0x00010000)

Definition at line 109 of file PatchableAppleSingle.h.


Typedef Documentation

typedef struct PASEntry PASEntry
typedef struct PASHeader PASHeader
typedef struct PASMiscInfo PASMiscInfo
typedef struct PASResFork PASResFork
typedef struct PASResource PASResource

Enumeration Type Documentation

anonymous enum
Enumerator:
ePas_Data 
ePas_Misc 
ePas_Resource 

Definition at line 111 of file PatchableAppleSingle.h.


Function Documentation

OSErr PAS_DecodeFile ( FSSpec inSpec,
FSSpec outSpec 
)

Definition at line 196 of file PatchableAppleSingle.cpp.

{
       OSErr         err;
       short         inRefNum;
       
       PASHeader     header;
       
       PASEntry      dataEntry, miscEntry, resourceEntry;
       long          sizeOfEntry;

       if (inSpec == NULL || outSpec == NULL)
              return paramErr;
              
              
       FSpDelete( outSpec ) ;
       
       err = FSpCreate( outSpec, kCreator, kType ,smSystemScript );
       
       if (err != noErr)    return err;
       
       
       
       err = FSpOpenDF(inSpec, fsRdPerm, &inRefNum);
       
       if (err != noErr)  goto error;

       
       // Read Header 
              
       err    = PAS_decodeHeader(inRefNum, &header);
       if (err != noErr)  goto error;
       
       if(    header.magicNum != PAS_MAGIC_NUM ||
              header.versionNum != PAS_VERSION)
       {
              err = -1;
              goto error;
       }
       
       
       
       // Read Data Entry 
       
       
       err = SetFPos(inRefNum, fsFromStart, sizeof(PASHeader));
       if (err != noErr)    goto error;
       
       sizeOfEntry                 =      sizeof(PASEntry);

       err = FSRead(inRefNum, &sizeOfEntry, &dataEntry);
       if (err != noErr)    goto error;
       
       
       
       
       // Read Misc Entry 
       
       
       err = SetFPos(inRefNum, fsFromStart, (sizeof(PASHeader) + sizeof(PASEntry)));
       if (err != noErr)    goto error;
       
       sizeOfEntry                 =      sizeof(PASEntry);

       err = FSRead(inRefNum, &sizeOfEntry, &miscEntry);
       if (err != noErr)    goto error;
       

       // Read Resource Entry 
       
       
       err = SetFPos(inRefNum, fsFromStart, (sizeof(PASHeader) + (2 * sizeof(PASEntry)))) ;
       if (err != noErr)    goto error;
       
       sizeOfEntry                 =      sizeof(PASEntry);

       err = FSRead(inRefNum, &sizeOfEntry, &resourceEntry);
       if (err != noErr)    goto error;





       err =  PAS_decodeData(&dataEntry, outSpec, inRefNum);   
       if (err != noErr)    goto error;

       err =  PAS_decodeMisc(&miscEntry, outSpec, inRefNum);
       if (err != noErr)    goto error;

       err =  PAS_decodeResource(&resourceEntry, outSpec, inRefNum);  
       if (err == kResFileNotOpened)
       {
              // there was no resource fork
              err = noErr;
       }
       else if (err != noErr)
       {
              goto error;
       }

       
       FSClose(inRefNum);
       
       return noErr;
       
       
       
error:

       if (inRefNum != kResFileNotOpened)
       {
              FSClose(inRefNum);
       }
              
       FSpDelete( outSpec ) ;
       
       return err;
       
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr PAS_EncodeFile ( FSSpec inSpec,
FSSpec outSpec 
)

Definition at line 72 of file PatchableAppleSingle.cpp.

{
       OSErr         err;
       short         outRefNum;
       
       PASEntry      dataEntry, miscEntry, resourceEntry;
       long          sizeOfEntry;


       if (inSpec == NULL || outSpec == NULL)
              return paramErr;
              

       memset(&dataEntry, 0, sizeof(PASEntry));
       memset(&miscEntry, 0, sizeof(PASEntry));
       memset(&resourceEntry, 0, sizeof(PASEntry));
       
       FSpDelete( outSpec ) ;
       
       err = FSpCreate( outSpec, kCreator, kType ,smSystemScript );
       
       if (err != noErr)    return err;
       
       
       err = FSpOpenDF(outSpec, fsRdWrPerm, &outRefNum);
       
       if (err != noErr)  goto error;
       

       // Write Out Header
              
       err = PAS_encodeHeader(outRefNum);
       if (err != noErr)  goto error;
       
       /* Why am I using three (3)?
              
              E stand for entry.
              
          The data for the entry is after the THREE headers 
       
              |---------|----|----|----|---------------------->
                 header    E    E    E
       
       */
       
       
       // Write Out Data Entry 
       dataEntry.entryID           =      ePas_Data;
       dataEntry.entryLength       =      PAS_getDataSize(inSpec);
       dataEntry.entryOffset       =      sizeof(PASHeader) + (3 * sizeof(PASEntry));
       
       sizeOfEntry                 =      sizeof(PASEntry);
       if(dataEntry.entryLength < 0)
       {
              err    = dataEntry.entryLength;
              goto error;
       }
       
       err = FSWrite(outRefNum, &sizeOfEntry, &dataEntry);
       if (err != noErr)    goto error;
       
       
       
       // Write Out Misc Entry 
       miscEntry.entryID           =      ePas_Misc;
       miscEntry.entryLength       =      sizeof(PASMiscInfo);
       miscEntry.entryOffset       =      sizeof(PASHeader) + (3 * sizeof(PASEntry)) + dataEntry.entryLength;

       sizeOfEntry                 =      sizeof(PASEntry);
       err = FSWrite(outRefNum, &sizeOfEntry, &miscEntry);
       if (err != noErr)    goto error;
       
       
       // Write Out Resource Entry 
       resourceEntry.entryID              =      ePas_Resource;
       resourceEntry.entryLength   =      -1;
       resourceEntry.entryOffset   =      sizeof(PASHeader) + (3 * sizeof(PASEntry)) + dataEntry.entryLength + miscEntry.entryLength;


       sizeOfEntry                 =      sizeof(PASEntry);
       err = FSWrite(outRefNum, &sizeOfEntry, &resourceEntry);
       if (err != noErr)    goto error;
       
       err =  PAS_encodeData(inSpec, outRefNum); 
       if (err != noErr)    goto error;
       
       
       err =  PAS_encodeMisc(inSpec, outRefNum); 
       if (err != noErr)    goto error;
       
       err =  PAS_encodeResource(inSpec, outRefNum);    
       
       if (err == kResFileNotOpened)
       {
              // there was no resource fork
              err = noErr;
       }
       else if (err != noErr)
       {
              goto error;
       }
              
       FSClose(outRefNum);
       
       return noErr;
       
       
       
error:
              
              
       if (outRefNum != kResFileNotOpened)
       {
              FSClose(outRefNum);
       }
              
       FSpDelete( outSpec ) ;
        
       return err;

}

Here is the call graph for this function:

Here is the caller graph for this function: