home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PlfmFil2.cpp
-
- Contains: Implementation of PlatformFile::HasFileSpecChanged
- and PlatformFile::IsInTrash.
-
- Owned by: Jens Alfke
- Written by: Jens Alfke, based on code by Mark Linton and Jim Luther
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- */
-
-
- #ifndef _PLFMFILE_
- #include "PlfmFile.h"
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef __EXCEPT__
- #include "Except.h"
- #endif
-
-
- const ODULong kMinCheckInterval = 1 * 60; // Never check more than once a second
-
- const long kRootDir = 2; // Directory ID of volume root
-
-
- static OSErr GetParentID(short vRefNum,
- long dirID,
- StringPtr name,
- long *parID);
- static OSErr GetDirName(short vRefNum,
- long dirID,
- StringPtr name);
-
-
- ODBoolean
- PlatformFile::IsInTrash( )
- {
- ODFileSpec fss = this->GetFileSpec();
- ODSShort foundVol;
- ODSLong trashDir, netTrashDir;
- OSErr err= FindFolder(fss.vRefNum,kTrashFolderType, kODTrue, &foundVol,&trashDir);
- if( err )
- trashDir = 0;
- err= FindFolder(fss.vRefNum,kWhereToEmptyTrashFolderType, kODTrue, &foundVol,&netTrashDir);
- if( err )
- netTrashDir = 0;
-
- while( fss.parID != kRootDir ) {
- if( fss.parID == trashDir || fss.parID == netTrashDir )
- return kODTrue;
- long parent;
- if( GetParentID(fss.vRefNum,fss.parID,NULL, &parent) != noErr ) // Get next parent
- break;
- if( GetDirName(fss.vRefNum,fss.parID, fss.name) != noErr ) // Get name of current parent
- break;
- fss.parID = parent;
- }
- return kODFalse;
- }
-
-
-
- /*============================================================================================*/
- // SWIPED FROM MOREFILES 1.2.1 (DTS)
- /*============================================================================================*/
-
-
- static OSErr GetParentID(short vRefNum,
- long dirID,
- StringPtr name,
- long *parID)
- {
- CInfoPBRec pb;
- OSErr error;
-
- pb.hFileInfo.ioNamePtr = name;
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- pb.hFileInfo.ioFDirIndex = name ?0 :-1;
- error = PBGetCatInfoSync(&pb);
- *parID = pb.hFileInfo.ioFlParID;
- return ( error );
- }
-
-
- static OSErr GetDirName(short vRefNum,
- long dirID,
- StringPtr name)
- {
- CInfoPBRec pb;
-
- pb.hFileInfo.ioNamePtr = name;
- pb.hFileInfo.ioVRefNum = vRefNum;
- pb.hFileInfo.ioDirID = dirID;
- pb.hFileInfo.ioFDirIndex = -1; /* get information about ioDirID */
- return ( PBGetCatInfoSync(&pb) );
- }
-