ResKnife/External/MoreFiles/DirectoryCopy.c

1 line
22 KiB
C
Raw Normal View History

2002-03-29 14:59:03 +00:00
/* File: DirectoryCopy.c Contains: A robust, general purpose directory copy routine. Version: MoreFiles Copyright: <09> 1992-2001 by Apple Computer, Inc., all rights reserved. You may incorporate this sample code into your applications without restriction, though the sample code has been provided "AS IS" and the responsibility for its operation is 100% yours. However, what you are not permitted to do is to redistribute the source as "DSC Sample Code" after having made changes. If you're going to re-distribute the source, we require that you make it clear in the source that the code was descended from Apple Sample Code, but that you've made changes. File Ownership: DRI: Apple Macintosh Developer Technical Support Other Contact: Apple Macintosh Developer Technical Support <http://developer.apple.com/bugreporter/> Technology: DTS Sample Code Writers: (JL) Jim Luther Change History (most recent first): <2> 2/7/01 JL Added standard header. Updated names of includes. <1> 12/06/99 JL MoreFiles 1.5. */ #include <MacTypes.h> #include <MacErrors.h> #include <MacMemory.h> #include <Files.h> #include <Script.h> #include <Math64.h> #define __COMPILINGMOREFILES #include "MoreFiles.h" #include "MoreFilesExtras.h" #include "MoreDesktopMgr.h" #include "FileCopy.h" #include "DirectoryCopy.h" /*****************************************************************************/ /* local constants */ enum { dirCopyBigCopyBuffSize = 0x00004000, dirCopyMinCopyBuffSize = 0x00000200 }; /*****************************************************************************/ /* local data structures */ /* The EnumerateGlobals structure is used to minimize the amount of ** stack space used when recursively calling CopyLevel and to hold ** global information that might be needed at any time. */ #if PRAGMA_STRUCT_ALIGN #pragma options align=mac68k #endif struct EnumerateGlobals { Ptr copyBuffer; /* pointer to buffer used for file copy operations */ long bufferSize; /* the size of the copy buffer */ CopyErrProcPtr errorHandler; /* pointer to error handling function */ CopyFilterProcPtr copyFilterProc; /* pointer to filter function */ OSErr error; /* temporary holder of results - saves 2 bytes of stack each level */ Boolean bailout; /* set to true to by error handling function if fatal error */ short destinationVRefNum; /* the destination vRefNum */ Str63 itemName; /* the name of the current item */ CInfoPBRec myCPB; /* the parameter block used for PBGetCatInfo calls */ }; #if PRAGMA_STRUCT_ALIGN #pragma options align=reset #endif typedef struct EnumerateGlobals EnumerateGlobals; typedef EnumerateGlobals *EnumerateGlobalsPtr; /* The PreflightGlobals structure is used to minimize the amount of ** stack space used when recursively calling GetLevelSize and to hold ** global information that might be needed at any time. */ #if PRAGMA_STRUCT_ALIGN #pragma options align=mac68k #endif struct PreflightGlobals { OSErr result; /* temporary holder of results - saves 2 bytes of stack each level */ Str63 itemName; /* the name of the current item */ CInfoPBRec myCPB; /* the parameter block used for PBGetCatInfo calls */ unsigned long dstBlksPerAllocBlk; /* the number of 512 byte blocks per allocation block on destination */ unsigned long allocBlksNeeded; /* the total number of allocation blocks needed */ unsigned long tempBlocks; /* temporary storage for calculations (save some stack space) */ CopyFilterProcPtr copyFilterProc; /* pointer to filter function */ }; #if PRAGMA_STRUCT_ALIGN #pragma options align=reset #endif typedef struct PreflightGlobals PreflightGlobals; typedef PreflightGlobals *PreflightGlobalsPtr; /*****************************************************************************/ /* static prototypes */ static void GetLevelSize(long currentDirID, PreflightGlobals *theGlobals); static OSErr PreflightDirectoryCopySpace(short srcVRefNum, long srcDirID, short dstVRefNum, CopyFilterProc