home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-05-01 | 25.8 KB | 1,046 lines | [TEXT/MPS ] |
- // UFile.cp
- // Copyright © 1988-1991 by Apple Computer Inc. All rights reserved.
-
- #ifndef __STDIO__
- #include <StdIo.h>
- #endif
-
- #ifndef __UFILE__
- #include <UFile.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include <UMacAppUtilities.h>
- #endif
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal TFile* NewFile(void)
- {
- TFile * theFile;
-
- theFile = new TFile;
- theFile->IFile();
- return theFile;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal void TFile::Initialize(void) // override
- {
- inherited::Initialize();
-
- fFileSpec.vRefNum = 0;
- fFileSpec.parID = 0;
- fFileSpec.name = "";
-
- fModDate = 0;
- fStationery = notStationery;
- fFileType = 'TEXT';
- fCreator = '????';
- fScriptTag = smSystemScript;
- fUsesDataFork = FALSE;
- fUsesRsrcFork = FALSE;
- fDataPermission = fsRdPerm;
- fRsrcPermission = fsRdPerm;
- fKeepDataOpen = FALSE;
- fKeepRsrcOpen = FALSE;
- fDataRefNum = kNoFileRefnum;
- fRsrcRefNum = kNoFileRefnum;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal void TFile::IFile(void)
- {
- this->IObject();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileClose
-
- pascal void TFile::Free(void) // override
- {
- this->CloseFile(TRUE);
-
- inherited::Free();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileClose
-
- pascal OSErr TFile::CloseFile(Boolean forceClose)
- {
- OSErr dataErr = noErr;
- OSErr rsrcErr = noErr;
-
- if (fUsesDataFork)
- dataErr = this->CloseDataFork(forceClose);
- if (fUsesRsrcFork)
- rsrcErr = this->CloseRsrcFork(forceClose);
-
- if (dataErr != noErr)
- return dataErr;
- else
- return rsrcErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileClose
-
- pascal OSErr TFile::CloseDataFork(Boolean forceClose)
- {
- OSErr theErr = noErr;
-
- if ((fDataRefNum != kNoFileRefnum) && (!fKeepDataOpen || forceClose))
- {
- theErr = FSClose(fDataRefNum);
- fDataRefNum = kNoFileRefnum;
- }
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileClose
-
- pascal OSErr TFile::CloseRsrcFork(Boolean forceClose)
- {
- OSErr theErr = noErr;
-
- if ((fRsrcRefNum != kNoFileRefnum) && (!fKeepRsrcOpen || forceClose))
- {
- CloseResFile(fRsrcRefNum);
- theErr = ResError();
- fRsrcRefNum = kNoFileRefnum;
- }
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal OSErr TFile::CreateFile(void)
- {
- OSErr dataErr = noErr;
- OSErr rsrcErr = noErr;
-
- if (fUsesDataFork)
- dataErr = this->CreateDataFork();
-
- if (fUsesRsrcFork)
- rsrcErr = this->CreateRsrcFork();
-
- if (dataErr != noErr)
- return dataErr;
- else
- return rsrcErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal OSErr TFile::CreateDataFork(void)
- {
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFile = fFileSpec;
-
- return FSpCreate(theFile, fCreator, fFileType, fScriptTag);
- }
- else
- {
- Str63 fileName = fFileSpec.name;
-
- return HCreate(fFileSpec.vRefNum, fFileSpec.parID, fileName, fCreator, fFileType);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal OSErr TFile::CreateRsrcFork(void)
- {
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFile = fFileSpec;
-
- FSpCreateResFile(theFile, fCreator, fFileType, fScriptTag);
- }
- else
- {
- Str63 fileName = fFileSpec.name;
-
- HCreateResFile(fFileSpec.vRefNum, fFileSpec.parID, fileName);
- }
- return ResError();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileClose
-
- pascal OSErr TFile::DeleteFile(void)
- {
- fModDate = 0;
-
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFileSpec = fFileSpec;
-
- return FSpDelete(theFileSpec);
- }
- else
- {
- Str63 fileName = fFileSpec.name;
-
- return HDelete(fFileSpec.vRefNum, fFileSpec.parID, fileName);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal OSErr TFile::OpenFile(void)
- {
- OSErr dataErr = noErr;
- OSErr rsrcErr = noErr;
-
- if (fUsesDataFork)
- dataErr = this->OpenDataFork(fDataPermission);
-
- if (fUsesRsrcFork)
- rsrcErr = this->OpenRsrcFork(fRsrcPermission);
-
- if (dataErr != noErr)
- return dataErr;
- else
- return rsrcErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal OSErr TFile::OpenDataFork(SignedByte permission)
- {
- OSErr theErr = noErr;
-
- if (fDataRefNum == kNoFileRefnum) // Don't open if already open
- {
- HParamBlockRec pb;
- Str63 fileName = fFileSpec.name;
-
- BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);
- pb.accessParam.ioNamePtr = &fileName;
- pb.accessParam.ioVRefNum = fFileSpec.vRefNum;
- pb.fileParam.ioDirID = fFileSpec.parID;
-
- switch (permission)
- {
- // read/deny write
- case fsRdPerm:
- pb.accessParam.ioDenyModes = fsRdPerm | 32;
- break;
-
- // read/write/deny read/deny write
- case fsWrPerm:
- case fsRdWrPerm:
- case fsCurPerm:
- pb.accessParam.ioDenyModes = fsRdWrPerm | 16 | 32;
- break;
-
- // read/write/deny none
- case fsRdWrShPerm:
- pb.accessParam.ioDenyModes = fsRdWrPerm;
- break;
-
- // read/deny write
- default:
- pb.accessParam.ioDenyModes = fsRdPerm | 32;
- }
-
- theErr = PBHOpenDenySync(&pb); // Try the shared volume open.
-
- if (theErr == paramErr) // Not on a shared volume, try HFS open.
- {
- pb.ioParam.ioPermssn = permission & 3;
- theErr = PBHOpenSync(&pb);
- }
-
- if (theErr == noErr)
- fDataRefNum = pb.ioParam.ioRefNum;
- }
-
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal OSErr TFile::OpenRsrcFork(SignedByte permission)
- {
- OSErr theErr = noErr;
-
- if (fRsrcRefNum == kNoFileRefnum) // Don't open if already open
- {
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFileSpec = fFileSpec;
-
- fRsrcRefNum = FSpOpenResFile(theFileSpec, (permission & 7));
- theErr = ResError();
- }
- else
- {
- Str63 fileName = fFileSpec.name;
-
- fRsrcRefNum = HOpenResFile(fFileSpec.vRefNum, fFileSpec.parID, fileName, (permission & 7));
- theErr = ResError();
- }
- }
- if (theErr != noErr)
- fRsrcRefNum = kNoFileRefnum;
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileOpen
-
- pascal void TFile::DefineFile(const OSType itsFileType,
- const OSType itsCreator,
- Boolean usesDataFork,
- Boolean usesRsrcFork,
- Boolean keepsDataOpen,
- Boolean keepsRsrcOpen)
- {
- #if qDebugMsg
- if (keepsDataOpen &&!usesDataFork)
- {
- fprintf(stderr, "In TFile.DefineFile: keepsDataOpen && !usesDataFork;");
- fprintf(stderr, "In TFile.DefineFile: usesDataFork = TRUE;");
- usesDataFork = TRUE;
- }
- if (keepsRsrcOpen && (!usesRsrcFork))
- {
- fprintf(stderr, "In TFile.DefineFile: keepsRsrcOpen && !usesRsrcFork;");
- fprintf(stderr, "In TFile.DefineFile: usesRsrcFork = TRUE;");
- usesRsrcFork = TRUE;
- }
- #endif
-
- fFileType = itsFileType;
- fCreator = itsCreator;
- fUsesDataFork = usesDataFork;
- fUsesRsrcFork = usesRsrcFork;
- fKeepDataOpen = keepsDataOpen;
- fKeepRsrcOpen = keepsRsrcOpen;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::ExchangeFiles(TFile* aFile)
- {
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec source = fFileSpec;
- FSSpec destination = aFile->fFileSpec;
-
- return FSpExchangeFiles(source, destination);
- }
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetAlias(AliasHandle& alias)
- {
- FSSpec theFileSpec;
-
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- theFileSpec = fFileSpec;
- return NewAliasMinimal(theFileSpec, alias);
- }
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetCatInfo(CInfoPBRec& cInfo)
- {
- Str63 itsName;
-
- itsName = fFileSpec.name;
- cInfo.hFileInfo.ioNamePtr = &itsName;
- cInfo.hFileInfo.ioVRefNum = fFileSpec.vRefNum;
- cInfo.hFileInfo.ioFDirIndex = 0;
- cInfo.hFileInfo.ioDirID = fFileSpec.parID;
- return PBGetCatInfoSync(&cInfo);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal long TFile::GetCreationDate(void)
- {
- HParamBlockRec pb;
-
- if (this->GetFileInfo(pb) == noErr)
- return pb.fileParam.ioFlCrDat;
- else
- return 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetDataLength(long& length)
- {
- if (fDataRefNum != kNoFileRefnum)
- return GetEOF(fDataRefNum, length);
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetDataMark(long& mark)
- {
- if (fDataRefNum != kNoFileRefnum)
- return GetFPos(fDataRefNum, mark);
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal long TFile::GetDirID(void)
- {
- return fFileSpec.parID;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetFileCreator(OSType& creator)
- {
- FInfo fndrInfo;
- OSErr theErr;
-
- if ((theErr = this->GetFinderInfo(fndrInfo)) == noErr)
- creator = fndrInfo.fdCreator;
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetFileInfo(HParamBlockRec& pb)
- {
- Str63 itsName;
-
- itsName = fFileSpec.name;
- pb.fileParam.ioNamePtr = &itsName;
- pb.fileParam.ioVRefNum = fFileSpec.vRefNum;
- pb.fileParam.ioDirID = fFileSpec.parID;
- pb.fileParam.ioFVersNum = 0;
- pb.fileParam.ioFDirIndex = 0;
- return PBHGetFInfoSync(&pb);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetFileType(OSType& fileType)
- {
- FInfo fndrInfo;
- OSErr theErr;
-
- if ((theErr = this->GetFinderInfo(fndrInfo)) == noErr)
- fileType = fndrInfo.fdType;
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::GetFileSpec(FSSpec& theFileSpec)
- {
- theFileSpec = fFileSpec;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetFinderInfo(FInfo& fndrInfo)
- {
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFileSpec = fFileSpec;
-
- return FSpGetFInfo(theFileSpec, fndrInfo);
- }
- else
- {
- Str63 fileName = fFileSpec.name;
-
- return HGetFInfo(fFileSpec.vRefNum, fFileSpec.parID, fileName, fndrInfo);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal long TFile::GetModificationDate(void)
- {
- HParamBlockRec pb;
-
- if (this->GetFileInfo(pb) == noErr)
- return pb.fileParam.ioFlMdDat;
- else
- return 0;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::GetName(Str63& name)
- {
- name = fFileSpec.name;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetPhysicalSize(long& dataSize,
- long& rsrcSize)
- {
- HParamBlockRec pb;
- OSErr theErr;
-
- if ((theErr = this->GetFileInfo(pb)) == noErr)
- {
- dataSize = pb.fileParam.ioFlPyLen;
- rsrcSize = pb.fileParam.ioFlRPyLen;
- }
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetScript(ScriptCode& theScript)
- {
- OSErr theErr;
- CInfoPBRec cInfo;
-
- BlockSet((Ptr) & cInfo, sizeof(CInfoPBRec), 0x00);// zero-out our storage
- theErr = this->GetCatInfo(cInfo);
- if (theErr == noErr)
- {
- theScript = cInfo.hFileInfo.ioFlXFndrInfo.fdScript;
- fScriptTag = theScript;
- }
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::FlushVolume(void)
- {
- return FlushVol(NULL, fFileSpec.vRefNum);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetBlockSize(long& blockSize)
- {
- HParamBlockRec pb;
- OSErr theErr;
-
- BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);// zero-out our storage
- theErr = this->GetVolumeInfo(pb);
- if (theErr == noErr)
- blockSize = pb.volumeParam.ioVAlBlkSiz;
- else
- blockSize = 0;
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetFreeBlocks(long& freeBlocks)
- {
- HParamBlockRec pb;
- OSErr theErr;
-
-
- BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);// zero-out our storage
- theErr = this->GetVolumeInfo(pb);
- if (theErr == noErr)
- freeBlocks = pb.volumeParam.ioVFrBlk;
- else
- freeBlocks = 0;
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetVolumeInfo(HParamBlockRec& pb)
- {
- pb.volumeParam.ioCompletion = NULL;
- pb.volumeParam.ioNamePtr = NULL;
- pb.volumeParam.ioVRefNum = fFileSpec.vRefNum;
- pb.volumeParam.ioVolIndex = -1; // Use the vRefNum since it is all we have
- return PBHGetVInfoSync(&pb);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::GetVolumeName(Str63& name)
- {
- HParamBlockRec pb;
-
- BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);
- pb.volumeParam.ioNamePtr = &name; // Fill in the name
- pb.volumeParam.ioVRefNum = fFileSpec.vRefNum;
- pb.volumeParam.ioVolIndex = 0; // Use the vRefNum since it is all we have
- return PBHGetVInfoSync(&pb);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal short TFile::GetVolRefNum(void)
- {
- return fFileSpec.vRefNum;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::Identify(const FSSpec& theFile)
- {
- OSErr theErr;
-
- // If we are re-identifying an open file, close the file
- theErr = this->CloseFile(TRUE);
- fFileSpec = theFile;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::IdentifyWithScript(const FSSpec& theFile,
- ScriptCode theScript)
- {
- fScriptTag = theScript;
- this->Identify(theFile);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::IdentifyByAlias(AliasHandle alias)
- {
- OSErr theErr = noErr;
-
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFileSpec;
- Boolean dontCare;
-
- theErr = ResolveAlias((FSSpecPtr)NULL, alias, theFileSpec, dontCare);
- if (theErr == noErr)
- {
- FInfo finderInfo;
-
- this->Identify(theFileSpec);
- theErr = this->GetFinderInfo(finderInfo);
- if (theErr == noErr)
- {
- fFileType = finderInfo.fdType;
- fCreator = finderInfo.fdCreator;
- }
- }
- }
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::IdentifyByFile(TFile* aFile)
- {
- FSSpec theFile = aFile->fFileSpec;
-
- this->IdentifyWithScript(theFile, aFile->fScriptTag);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::IdentifyByTrio(short volRefNum,
- long dirID,
- const Str63& name)
- {
- FSSpec theFileSpec;
- OSErr theErr = noErr;
-
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- if ((theErr = FSMakeFSSpec(volRefNum, dirID, name, &theFileSpec)) == fnfErr)
- theErr = noErr; // The file may not yet exist
- }
- else
- {
- if (dirID == 0) // Assume that vRefNum is a WDir
- {
- WDPBRec pb;
-
- BlockSet((Ptr) & pb, sizeof(pb), 0x00);
- pb.ioVRefNum = volRefNum;
- pb.ioWDVRefNum = volRefNum;
- theErr = PBGetWDInfoSync(&pb);
- theFileSpec.vRefNum = pb.ioWDVRefNum;
- theFileSpec.parID = pb.ioWDDirID;
- }
- else
- {
- theFileSpec.vRefNum = volRefNum;
- theFileSpec.parID = dirID;
- }
- theFileSpec.name = name;
- }
- if (theErr == noErr)
- this->Identify(theFileSpec);
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal Boolean TFile::IsDataForkOpen(void)
- {
- return (fDataRefNum != kNoFileRefnum);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal Boolean TFile::IsRsrcForkOpen(void)
- {
- return (fRsrcRefNum != kNoFileRefnum);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal Boolean TFile::IsSameFile(TFile* aFile)
- {
- Str63 name;
-
- if ((fFileSpec.vRefNum == aFile->GetVolRefNum()) && (fFileSpec.parID == aFile->GetDirID()))
- {
- aFile->GetName(name);
- if (EqualString(fFileSpec.name, name, FALSE, TRUE))
- return TRUE;
- }
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal Boolean TFile::IsModified(void)
- {
- long theDate;
-
- theDate = this->GetModificationDate();
- if (theDate != fModDate)
- return TRUE;
- else
- return FALSE;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::IsVolumeLocked(Boolean& locked)
- {
- HParamBlockRec pb;
- OSErr theErr;
-
- if ((theErr = this->GetVolumeInfo(pb)) == noErr)
- locked = ((pb.volumeParam.ioVAtrb & 0x8080) != 0);
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal Boolean TFile::HasDataFork(void)
- {
- return fUsesDataFork;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal Boolean TFile::HasRsrcFork(void)
- {
- return fUsesRsrcFork;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::MakeStationery(void)
- {
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::Modified(void)
- {
- fModDate = this->GetModificationDate();
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::MoveAndRename(const FSSpec& dest)
- {
- CInfoPBRec cInfoPB;
- CMovePBRec cMovePB;
- Str63 sourceName;
- Str63 destName;
- long parentDirID;
- OSErr theErr;
-
- cInfoPB.dirInfo.ioVRefNum = dest.vRefNum;
- cInfoPB.dirInfo.ioDrDirID = dest.parID;
- cInfoPB.dirInfo.ioNamePtr = &destName; // Will be filled in
- cInfoPB.dirInfo.ioFDirIndex = -1;
- if ((theErr = PBGetCatInfoSync(&cInfoPB)) != noErr)
- return theErr;
- parentDirID = cInfoPB.dirInfo.ioDrParID;
-
- sourceName = fFileSpec.name;
- cMovePB.ioVRefNum = fFileSpec.vRefNum;
- cMovePB.ioDirID = fFileSpec.parID;
- cMovePB.ioNamePtr = &sourceName;
- cMovePB.ioNewDirID = parentDirID;
- cMovePB.ioNewName = &destName;
- if ((theErr = PBCatMoveSync(&cMovePB)) != noErr)
- return theErr;
- return HRename(dest.vRefNum, dest.parID, sourceName, dest.name);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::ReadData(void* buffer,
- long& count)
- {
- if (fDataRefNum != kNoFileRefnum)
- return FSRead(fDataRefNum, count, (Ptr)buffer);
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::RenameFile(Str63& newName)
- {
- if (qNeedsAliasMgr || gConfiguration.hasAliasMgr)
- {
- FSSpec theFileSpec = fFileSpec;
-
- return FSpRename(theFileSpec, newName);
- }
- else
- {
- Str63 sourceName = fFileSpec.name;
-
- return HRename(fFileSpec.vRefNum, fFileSpec.parID, sourceName, newName);
- }
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::SetCatInfo(CInfoPBRec& cInfo)
- {
- Str63 fileName = fFileSpec.name;
-
- cInfo.hFileInfo.ioCompletion = NULL;
- cInfo.hFileInfo.ioNamePtr = &fileName;
- cInfo.hFileInfo.ioVRefNum = fFileSpec.vRefNum;
- cInfo.hFileInfo.ioDirID = fFileSpec.parID;
- return PBSetCatInfoSync(&cInfo);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::SetDataLength(long length)
- {
- if (fDataRefNum != kNoFileRefnum)
- return SetEOF(fDataRefNum, length);
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::SetDataMark(long mark,
- short fromWhere)
- {
- if (fDataRefNum != kNoFileRefnum)
- return SetFPos(fDataRefNum, fromWhere, mark);
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::SetFileInfo(HParamBlockRec& pb)
- {
- Str63 fileName = fFileSpec.name;
-
- BlockSet((Ptr) & pb, sizeof(HParamBlockRec), 0x00);
- pb.fileParam.ioNamePtr = &fileName;
- pb.fileParam.ioVRefNum = fFileSpec.vRefNum;
- pb.fileParam.ioDirID = fFileSpec.parID;
- return PBHSetFInfoSync(&pb);
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::SetName(const Str63& newName)
- {
- fFileSpec.name = newName;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::SetScript(ScriptCode theScript)
- {
- OSErr theErr;
- CInfoPBRec cInfo;
-
- // Get the current info so we don't have to set up the entire record
- if ((theErr = this->GetCatInfo(cInfo)) == noErr)
- {
- cInfo.hFileInfo.ioFlXFndrInfo.fdScript = theScript;
- theErr = this->SetCatInfo(cInfo);
- }
- return theErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal void TFile::SetPermissions(SignedByte dataPermission,
- SignedByte rsrcPermission)
- {
- fDataPermission = dataPermission;
- fRsrcPermission = rsrcPermission;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::UpdateResource(void)
- {
- if (fRsrcRefNum != kNoFileRefnum)
- {
- UpdateResFile(fRsrcRefNum);
- return ResError();
- }
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal short TFile::UseResource(void)
- {
- short curResFileRefNum = CurResFile(); // get the CurResFile ref num on entry
- if ((curResFileRefNum != fRsrcRefNum) && (fRsrcRefNum != kNoFileRefnum))
- UseResFile(fRsrcRefNum); // set the CurResFile for this file
- return curResFileRefNum; // return the CurResFile ref num on entry
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFileRes
-
- pascal OSErr TFile::WriteData(void* buffer,
- long& count)
- {
- if (fDataRefNum != kNoFileRefnum)
- return FSWrite(fDataRefNum, count, (Ptr)buffer);
- else
- return noErr;
- }
-
- //--------------------------------------------------------------------------------------------------
- #pragma segment MAFields
-
- pascal void TFile::Fields(TObject* obj)
- {
- obj->DoToField("TFile", NULL, bClass);
- obj->DoToField("fFileSpec.name", &fFileSpec.name, bString);
- obj->DoToField("fFileSpec.vRefNum", &fFileSpec.vRefNum, bInteger);
- obj->DoToField("fFileSpec.parID", &fFileSpec.parID, bLongInt);
- obj->DoToField("fModDate", &fModDate, bLongInt);
- obj->DoToField("fCreator", &fCreator, bOSType);
- obj->DoToField("fFileType", &fFileType, bOSType);
- obj->DoToField("fScriptTag", &fScriptTag, bByte);
- obj->DoToField("fUsesDataFork", &fUsesDataFork, bBoolean);
- obj->DoToField("fUsesRsrcFork", &fUsesRsrcFork, bBoolean);
- obj->DoToField("fDataPermission", &fDataPermission, bByte);
- obj->DoToField("fRsrcPermission", &fRsrcPermission, bByte);
- obj->DoToField("fKeepDataOpen", &fKeepDataOpen, bBoolean);
- obj->DoToField("fKeepRsrcOpen", &fKeepRsrcOpen, bBoolean);
- obj->DoToField("fDataRefNum", &fDataRefNum, bInteger);
- obj->DoToField("fRsrcRefNum", &fRsrcRefNum, bInteger);
- inherited::Fields(obj);
- }
-
-
-