home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 5.6 KB | 230 lines | [TEXT/MPS ] |
- /*
- File: VVFileMacFile.cp
-
- Copyright: © 1991-1994 by Apple Computer, Inc.
- All rights reserved.
-
- Part of the AOCE Sample SMSAM Package. Consult the license
- which came with this software for your specific legal rights.
-
- */
-
-
-
- #ifndef __BLJSTANDARDINCLUDES__
- #include "BLJStandardIncludes.h"
- #endif
-
- #ifndef __VIRTUALMACFILE__
- #include "VirtualMacFile.h"
- #endif
-
- #ifndef __VVFILEMACFILE__
- #include "VVFileMacFile.h"
- #endif
-
- #ifndef __VIRTUALFILE__
- #include "VirtualFile.h"
- #endif
-
- #ifndef __VIRTUALRAMORDISKFILE__
- #include "VirtualRamOrDiskFile.h"
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifndef __DEBUGGINGGEAR__
- #include "DebuggingGear.h"
- #endif
-
- #pragma segment TVVFileMacFile
-
- /***********************************|****************************************/
-
- TVVFileMacFile::TVVFileMacFile(const Str31 fileName):
- TVirtualMacFile (),
- fDataFile ( new TVirtualRamOrDiskFile () ),
- fResourceFile ( new TVirtualRamOrDiskFile () ),
- fCreationDate ( NowDateTime () ),
- fRemoveRefs ( false ),
- fOpenCount ( 0 )
- {
- fSpec.vRefNum = -1;
- fSpec.parID = 2;
- SetFileName(fileName);
- fFinderInfo.fdType = 'TEXT';
- fFinderInfo.fdCreator = 'MPST';
- }
-
- /***********************************|****************************************/
-
- TVVFileMacFile::TVVFileMacFile(TVirtualFile* dfFile,TVirtualFile* rfFile,const Str31 fileName):
- TVirtualMacFile (),
- fDataFile ( dfFile ),
- fResourceFile ( rfFile ),
- fCreationDate ( NowDateTime () ),
- fRemoveRefs ( true )
- {
- fSpec.vRefNum = -1;
- fSpec.parID = 2;
- SetFileName(fileName);
- fFinderInfo.fdType = 'TEXT';
- fFinderInfo.fdCreator = 'MPST';
- dfFile->RegisterReference();
- rfFile->RegisterReference();
- }
-
- //--------------------------------------------------------------------------------
-
- TVVFileMacFile::~TVVFileMacFile()
- {
- if ( fRemoveRefs )
- {
- fDataFile->UnregisterReference();
- fResourceFile->UnregisterReference();
- }
- else
- {
- delete fDataFile;
- delete fResourceFile;
- }
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::Open ()
- {
- fOpenCount++;
- if (fOpenCount == 1) {
- fDataFile->SetPosition(fsFromStart, 0);
- fResourceFile->SetPosition(fsFromStart, 0);
- }
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::Close ()
- {
- if (fOpenCount <= 1) {
- fOpenCount = 0;
- }
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::ReadData (void* buffer,long& count,TVirtualMacFile::ForkType whichFork)
- {
- TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
- return file->ReadData (buffer,count);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::WriteData (const void* buffer, long& count, TVirtualMacFile::ForkType whichFork)
- {
- TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
- return file->WriteData (buffer,count);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::SetEnd (long logEof, TVirtualMacFile::ForkType whichFork)
- {
- TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
- return file->SetEnd (logEof);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::GetEnd (long& logEof, TVirtualMacFile::ForkType whichFork) const
- {
- TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
- return file->GetEnd (logEof);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::SetPosition (short posMode, long posOff, TVirtualMacFile::ForkType whichFork)
- {
- TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
- return file->SetPosition (posMode,posOff);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::GetPosition (long& filePos,TVirtualMacFile::ForkType whichFork) const
- {
- TVirtualFile* file = (whichFork == kData) ? fDataFile : fResourceFile;
- return file->GetPosition (filePos);
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::SetFinderInfo (const FInfo& finderInfo)
- {
- fFinderInfo = finderInfo;
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::GetFinderInfo (FInfo& finderInfo) const
- {
- finderInfo = fFinderInfo;
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::GetDate (unsigned long& dateTime,TVirtualMacFile::WhichDateType) const
- {
- dateTime = fCreationDate;
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::SetDate (unsigned long dateTime,TVirtualMacFile::WhichDateType whichDate)
- {
- if (whichDate == kCreationDate)
- fCreationDate = dateTime;
-
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- void TVVFileMacFile::SetUserRef(long ref)
- {
- fDataFile->SetUserRef(ref);
- }
-
- //--------------------------------------------------------------------------------
-
- long TVVFileMacFile::GetUserRef() const
- {
- return fDataFile->GetUserRef();
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::SetSpec ( const FSSpec& spec )
- {
- fSpec = spec;
- return noErr;
- }
-
- //--------------------------------------------------------------------------------
-
- OSErr TVVFileMacFile::GetSpec ( FSSpec& spec ) const
- {
- spec = fSpec;
- return noErr;
- }
-
- /***********************************|****************************************/
-