Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
nsAppleSingleEncoder Class Reference

#include <nsAppleSingleEncoder.h>

List of all members.

Public Member Functions

 nsAppleSingleEncoder ()
 ~nsAppleSingleEncoder ()
OSErr Encode (FSSpecPtr aFile)
OSErr Encode (FSSpecPtr aInFile, FSSpecPtr aOutFile)
OSErr EncodeFolder (FSSpecPtr aFolder)
void ReInit ()

Static Public Member Functions

static Boolean HasResourceFork (FSSpecPtr aFile)
static OSErr FSpGetCatInfo (CInfoPBRec *pb, FSSpecPtr aFile)

Private Member Functions

OSErr WriteHeader ()
OSErr WriteEntryDescs ()
OSErr WriteEntries ()
OSErr WriteResourceFork ()
OSErr WriteDataFork ()

Private Attributes

FSSpecPtr mInFile
FSSpecPtr mOutFile
FSSpecPtr mTransient
short mTransRefNum

Detailed Description

Definition at line 58 of file nsAppleSingleEncoder.h.


Constructor & Destructor Documentation

Definition at line 51 of file nsAppleSingleEncoder.cpp.

Definition at line 57 of file nsAppleSingleEncoder.cpp.

{
}

Member Function Documentation

Definition at line 84 of file nsAppleSingleEncoder.cpp.

{
       OSErr         err = noErr;
       FSSpec        transient, exists;
       
       // handle init in lieu of overloading 
       if (!mOutFile || !mInFile)
       {
              mInFile = aFile;
              mOutFile = aFile;
       }
       
       // param check
       if (!mInFile)
              return paramErr;
              
       // stomp old temp file
       mTransient = &transient;
       err = FSMakeFSSpec(  mInFile->vRefNum, mInFile->parID, kTransientName, 
                                          mTransient);
       if (err == noErr) 
              FSpDelete(mTransient);
              
       // write to transient file 
       ERR_CHECK( WriteHeader() );
       ERR_CHECK( WriteEntryDescs() );
       ERR_CHECK( WriteEntries() );
       
       // rename transient file to out file      
       err = FSMakeFSSpec( mOutFile->vRefNum, mOutFile->parID, mOutFile->name,
                                          &exists );
       if (err == noErr)
              FSpDelete(mOutFile);
       FSpRename(mTransient, mOutFile->name);

       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr nsAppleSingleEncoder::Encode ( FSSpecPtr  aInFile,
FSSpecPtr  aOutFile 
)

Definition at line 123 of file nsAppleSingleEncoder.cpp.

{
       OSErr err = noErr;
       
       // param check
       if (!aInFile || !aOutFile)
              return paramErr;
              
       mInFile = aInFile;
       mOutFile = aOutFile;
       
       err = Encode(NULL);

       return err;
}

Here is the call graph for this function:

Definition at line 185 of file nsAppleSingleEncoder.cpp.

{
       OSErr  err = noErr;
       long   dummy;
       Boolean       isDir = false;
       
       // check that FSSpec is folder
       if (aFolder)
       {
              FSpGetDirectoryID(aFolder, &dummy, &isDir);
              if (!isDir)
                     return dirNFErr;
       }
       
       // recursively enumerate contents of folder (maxLevels=0 means recurse all)
       FSpIterateDirectory(aFolder, 0, EncodeDirIterateFilter, (void*)this);
                     
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr nsAppleSingleEncoder::FSpGetCatInfo ( CInfoPBRec *  pb,
FSSpecPtr  aFile 
) [static]

Definition at line 465 of file nsAppleSingleEncoder.cpp.

{
       OSErr err = noErr;
       Str31 name;
       
       nsAppleSingleDecoder::PLstrncpy(name, aFile->name, aFile->name[0]);
       name[0] = aFile->name[0]; // XXX paranoia

       pb->hFileInfo.ioNamePtr = name;
       pb->hFileInfo.ioVRefNum = aFile->vRefNum;
       pb->hFileInfo.ioDirID = aFile->parID;
       pb->hFileInfo.ioFDirIndex = 0; // use ioNamePtr and ioDirID 
       ERR_CHECK( PBGetCatInfoSync(pb) );

       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 62 of file nsAppleSingleEncoder.cpp.

{
       OSErr  err = noErr;
       Boolean bHasResFork = false;
       short  refnum;
       long   bytes2Read = 1;
       char   buf[2];
       
       err = FSpOpenRF(aFile, fsRdPerm, &refnum);
       if (err == noErr)
       {
              err = FSRead(refnum, &bytes2Read, &buf[0]);
              if (err == noErr)    /* err==eofErr if all OK but no res fork */
                     bHasResFork = true;
       }
       
       FSClose(refnum);
       
       return bHasResFork;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 206 of file nsAppleSingleEncoder.cpp.

Here is the caller graph for this function:

Definition at line 426 of file nsAppleSingleEncoder.cpp.

{
       OSErr         err = noErr;
       short         refnum;
       long          bytes2Rd, bytes2Wr;
       char          buf[BUFSIZE];
       
       // open infile's data fork
       ERR_CHECK( FSpOpenDF(mInFile, fsRdPerm, &refnum) );
       
       while (err != eofErr)
       {
              // keep reading chunks till infile's eof encountered
              bytes2Rd = BUFSIZE;
              err = FSRead(refnum, &bytes2Rd, buf);
              if (bytes2Rd <= 0)
                     goto cleanup;
              if (err == noErr || err == eofErr)
              {             
                     // keep writing 
                     bytes2Wr = bytes2Rd;
                     err = FSWrite(mTransRefNum, &bytes2Wr, buf);
                     if (err != noErr || bytes2Wr != bytes2Rd)
                            goto cleanup;
              }      
       }
              
cleanup:
       // close infile
       FSClose(refnum);
       
       // eof is OK so translate          
       if (err == eofErr)
              err = noErr;
       
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 298 of file nsAppleSingleEncoder.cpp.

{
       OSErr                err = noErr;
       long                 bytes2Wr;
       DateTimeRec          currTime;
       ASFileDates          asDates;
       unsigned long currSecs;
       ASMacInfo            asMacInfo;
       int                         i;
       CInfoPBRec           pb;
       char                 name[32];
       
       FSpGetCatInfo(&pb, mInFile);
       
       // real name
       bytes2Wr = pb.hFileInfo.ioNamePtr[0];
       strncpy(name, (char*)(pb.hFileInfo.ioNamePtr+1), bytes2Wr);
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, name) );
       FSpGetCatInfo(&pb, mInFile); // XXX refresh after write
       if (bytes2Wr != pb.hFileInfo.ioNamePtr[0])
       {
              err = -1;
              goto cleanup;
       }
              
       // finder info
       bytes2Wr = sizeof(FInfo);
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, &pb.hFileInfo.ioFlFndrInfo) );
       FSpGetCatInfo(&pb, mInFile); // XXX refresh after write
       if (bytes2Wr != sizeof(FInfo))
       {
              err = -1;
              goto cleanup;
       }
       
       bytes2Wr = sizeof(FXInfo);
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, &pb.hFileInfo.ioFlXFndrInfo) );
       FSpGetCatInfo(&pb, mInFile); // XXX refresh after write 
       if (bytes2Wr != sizeof(FXInfo))
       {
              err = -1;
              goto cleanup;
       }
              
       // file dates
       GetTime(&currTime);
       DateToSeconds(&currTime, &currSecs);
       FSpGetCatInfo(&pb, mInFile); // XXX refresh after sys calls
       asDates.create = pb.hFileInfo.ioFlCrDat + kConvertTime;
       asDates.modify = pb.hFileInfo.ioFlMdDat + kConvertTime;
       asDates.backup = pb.hFileInfo.ioFlBkDat + kConvertTime;
       asDates.access = currSecs + kConvertTime;
       bytes2Wr = sizeof(ASFileDates);
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, &asDates) );
       FSpGetCatInfo(&pb, mInFile); // XXX refresh after write
       if (bytes2Wr != sizeof(ASFileDates))
       {
              err = -1;
              goto cleanup;
       }
              
       // resource fork
       ERR_CHECK( WriteResourceFork() );
       
       // data fork
       ERR_CHECK( WriteDataFork() );
       
       // mac info   
       for (i=0; i<3; i++)
              asMacInfo.filler[i];
       FSpGetCatInfo(&pb, mInFile); // XXX refresh
       asMacInfo.ioFlAttrib = pb.hFileInfo.ioFlAttrib;
       bytes2Wr = sizeof(ASMacInfo);
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, &asMacInfo) );
       if (bytes2Wr != sizeof(ASMacInfo))
       {
              err = -1;
              goto cleanup;
       }
       
cleanup:
       FSClose(mTransRefNum);
       
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 249 of file nsAppleSingleEncoder.cpp.

{
       OSErr         err = noErr;
       long          offset = sizeof(ASHeader), bytes2Wr = kNumASEntries*sizeof(ASEntry);
       ASEntry       entries[kNumASEntries];
       int           i;
       CInfoPBRec    pb;
       
       ERR_CHECK( FSpGetCatInfo(&pb, mInFile) );
       
       // real name
       entries[0].entryOffset = sizeof(ASHeader) + (sizeof(ASEntry) * kNumASEntries);
       entries[0].entryID = AS_REALNAME;
       entries[0].entryLength = pb.hFileInfo.ioNamePtr[0];
              
       // finder info
       entries[1].entryID = AS_FINDERINFO;
       entries[1].entryLength = sizeof(FInfo) + sizeof(FXInfo);
              
       // file dates
       entries[2].entryID = AS_FILEDATES;
       entries[2].entryLength = sizeof(ASFileDates);
              
       // resource fork
       entries[3].entryID = AS_RESOURCE;
       entries[3].entryLength = pb.hFileInfo.ioFlRLgLen;

       // data fork
       entries[4].entryID = AS_DATA;
       entries[4].entryLength = pb.hFileInfo.ioFlLgLen;
       
       // mac info
       entries[5].entryID = AS_MACINFO;
       entries[5].entryLength = sizeof(ASMacInfo);
       
       for (i=1; i<kNumASEntries; i++) /* start at 1, not 0 */
       {
              entries[i].entryOffset = entries[i-1].entryOffset + entries[i-1].entryLength;
       }
       
       // ERR_CHECK( SetFPos(mTransRefNum, fsFromStart, sizeof(ASHeader)) ); // revisit
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, &entries[0]) );
       if (bytes2Wr != (kNumASEntries * sizeof(ASEntry)))
              err = -1;
              
       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSErr nsAppleSingleEncoder::WriteHeader ( ) [private]

Definition at line 213 of file nsAppleSingleEncoder.cpp.

{
       OSErr         err = noErr;
       ASHeader      hdr;
       int                  i;
       long          bytes2Wr;
       
       // init header info
       hdr.magicNum = kAppleSingleMagicNum; 
       hdr.versionNum = kAppleSingleVerNum;
       for (i=0; i<16; i++)
              hdr.filler[i] = 0;
       hdr.numEntries = kNumASEntries;           
              /*
              ** Entries:
              **
              ** 1> Real name
              ** 2> Finder info
              ** 3> File dates
              ** 4> Resource fork
              ** 5> Data fork
              ** 6> Mac info
              */
       
       bytes2Wr = sizeof(ASHeader);
       ERR_CHECK( FSpCreate(mTransient, 'MOZZ', '????', 0) );
       ERR_CHECK( FSpOpenDF(mTransient, fsRdWrPerm, &mTransRefNum) );
       // ERR_CHECK( SetFPos(mTransRefNum, fsFromStart, 0) ); // XXX revisit
       ERR_CHECK( FSWrite(mTransRefNum, &bytes2Wr, &hdr) );
       if (bytes2Wr != sizeof(ASHeader))
              err = -1;
              
       return err;
}

Here is the caller graph for this function:

Definition at line 387 of file nsAppleSingleEncoder.cpp.

{
       OSErr         err = noErr;
       short         refnum;
       long          bytes2Rd, bytes2Wr;
       char          buf[BUFSIZE];
       
       // open infile's resource fork
       ERR_CHECK( FSpOpenRF(mInFile, fsRdPerm, &refnum) );
       
       while (err != eofErr)
       {
              // keep reading chunks till infile's eof encountered
              bytes2Rd = BUFSIZE;
              err = FSRead(refnum, &bytes2Rd, buf);
              if (bytes2Rd <= 0)
                     goto cleanup;
              if (err == noErr || err == eofErr)
              {             
                     // keep writing 
                     bytes2Wr = bytes2Rd;
                     err = FSWrite(mTransRefNum, &bytes2Wr, buf);
                     if (err != noErr || bytes2Wr != bytes2Rd)
                            goto cleanup;
              }      
       }
              
cleanup:
       // close infile
       FSClose(refnum);
              
       // eof is OK so translate          
       if (err == eofErr)
              err = noErr;

       return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 74 of file nsAppleSingleEncoder.h.

Definition at line 75 of file nsAppleSingleEncoder.h.

Definition at line 76 of file nsAppleSingleEncoder.h.

Definition at line 77 of file nsAppleSingleEncoder.h.


The documentation for this class was generated from the following files: