new version 1.5.2 for morefiles

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11937 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2001-10-10 22:57:33 +00:00
parent a46935cb54
commit 92622ef4c2
36 changed files with 9332 additions and 9314 deletions

View File

@@ -41,10 +41,8 @@
#endif #endif
#ifndef __DARWIN__ #ifndef __DARWIN__
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "fullpath.h"
#include "fspcompa.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -35,11 +35,8 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog)
#endif #endif
#ifndef __DARWIN__ #ifndef __DARWIN__
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "fullpath.h"
#include "fspcompa.h"
#include "PLStringFuncs.h"
#endif #endif
extern bool gUseNavServices ; extern bool gUseNavServices ;

View File

@@ -28,8 +28,8 @@
#include <stdarg.h> #include <stdarg.h>
#ifndef __DARWIN__ #ifndef __DARWIN__
# include "morefile.h" #include "MoreFiles.h"
# include "moreextr.h" #include "MoreFilesExtras.h"
#endif #endif
#ifndef __DARWIN__ #ifndef __DARWIN__

View File

@@ -41,10 +41,8 @@
#endif #endif
#ifndef __DARWIN__ #ifndef __DARWIN__
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "fullpath.h"
#include "fspcompa.h"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -35,11 +35,8 @@ IMPLEMENT_CLASS(wxFileDialog, wxDialog)
#endif #endif
#ifndef __DARWIN__ #ifndef __DARWIN__
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "fullpath.h"
#include "fspcompa.h"
#include "PLStringFuncs.h"
#endif #endif
extern bool gUseNavServices ; extern bool gUseNavServices ;

View File

@@ -1,493 +0,0 @@
/*
** Apple Macintosh Developer Technical Support
**
** DirectoryCopy: A robust, general purpose directory copy routine.
**
** by Jim Luther, Apple Developer Technical Support Emeritus
**
** File: DirectoryCopy.h
**
** Copyright <20> 1992-1998 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.
*/
#ifndef __DIRECTORYCOPY__
#define __DIRECTORYCOPY__
#include <Types.h>
#include <Files.h>
#include "optim.h"
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
enum
{
getNextItemOp = 1, /* couldn't access items in this directory - no access privileges */
copyDirCommentOp = 2, /* couldn't copy directory's Finder comment */
copyDirAccessPrivsOp = 3, /* couldn't copy directory's AFP access privileges */
copyDirFMAttributesOp = 4, /* couldn't copy directory's File Manager attributes */
dirCreateOp = 5, /* couldn't create destination directory */
fileCopyOp = 6 /* couldn't copy file */
};
/*****************************************************************************/
typedef pascal Boolean (*CopyErrProcPtr) (OSErr error,
short failedOperation,
short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName);
/* <09> Prototype for the CopyErrProc function DirectoryCopy calls.
This is the prototype for the CopyErrProc function DirectoryCopy
calls if an error condition is detected sometime during the copy. If
CopyErrProc returns false, then DirectoryCopy attempts to continue with
the directory copy operation. If CopyErrProc returns true, then
DirectoryCopy stops the directory copy operation.
error input: The error result code that caused CopyErrProc to
be called.
failedOperation input: The operation that returned an error to
DirectoryCopy.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Source file or directory name, or nil if
srcDirID specifies the directory.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Destination file or directory name, or nil if
dstDirID specifies the directory.
__________
Also see: FilteredDirectoryCopy, FSpFilteredDirectoryCopy, DirectoryCopy, FSpDirectoryCopy
*/
#define CallCopyErrProc(userRoutine, error, failedOperation, srcVRefNum, srcDirID, srcName, dstVRefNum, dstDirID, dstName) \
(*(userRoutine))((error), (failedOperation), (srcVRefNum), (srcDirID), (srcName), (dstVRefNum), (dstDirID), (dstName))
/*****************************************************************************/
typedef pascal Boolean (*CopyFilterProcPtr) (const CInfoPBRec * const cpbPtr);
/* <09> Prototype for the CopyFilterProc function.
This is the prototype for the CopyFilterProc function called by
FilteredDirectoryCopy and GetLevelSize. If true is returned,
the file/folder is included in the copy, otherwise it is excluded.
pb input: Points to the CInfoPBRec for the item under consideration.
__________
Also see: FilteredDirectoryCopy, FSpFilteredDirectoryCopy
*/
#define CallCopyFilterProc(userRoutine, cpbPtr) (*(userRoutine))((cpbPtr))
/*****************************************************************************/
pascal OSErr FilteredDirectoryCopy(short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName,
void *copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler,
CopyFilterProcPtr copyFilterProc);
/* <09> Make a copy of a directory structure in a new location with item filtering.
The FilteredDirectoryCopy function makes a copy of a directory
structure in a new location. If copyBufferPtr <> NIL, it points to
a buffer of copyBufferSize that is used to copy files data. The
larger the supplied buffer, the faster the copy. If
copyBufferPtr = NIL, then this routine allocates a buffer in the
application heap. If you pass a copy buffer to this routine, make
its size a multiple of 512 ($200) bytes for optimum performance.
The optional copyFilterProc parameter lets a routine you define
decide what files or directories are copied to the destination.
FilteredDirectoryCopy normally creates a new directory *in* the
specified destination directory and copies the source directory's
content into the new directory. However, if root parent directory
(fsRtParID) is passed as the dstDirID parameter and NULL is
passed as the dstName parameter, DirectoryCopy renames the
destination volume to the source directory's name (truncating
if the name is longer than 27 characters) and copies the source
directory's content into the destination volume's root directory.
This special case is supported by FilteredDirectoryCopy, but
not by FSpFilteredDirectoryCopy since with FSpFilteredDirectoryCopy,
the dstName parameter can not be NULL.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Source directory name, or nil if
srcDirID specifies the directory.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Destination directory name, or nil if
dstDirID specifies the directory.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, DirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
copyFilterProc input: A pointer to the filter routine you want called
for each item in the source directory, or NULL
if you don't want to filter.
Result Codes
noErr 0 No error
readErr <09>19 Driver does not respond to read requests
writErr <09>20 Driver does not respond to write requests
badUnitErr <09>21 Driver reference number does not
match unit table
unitEmptyErr <09>22 Driver reference number specifies a
nil handle in unit table
abortErr <09>27 Request aborted by KillIO
notOpenErr <09>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, CopyFilterProcPtr, FSpFilteredDirectoryCopy,
DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
pascal OSErr FSpFilteredDirectoryCopy(const FSSpec *srcSpec,
const FSSpec *dstSpec,
void *copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler,
CopyFilterProcPtr copyFilterProc);
/* <09> Make a copy of a directory structure in a new location with item filtering.
The FSpFilteredDirectoryCopy function makes a copy of a directory
structure in a new location. If copyBufferPtr <> NIL, it points to
a buffer of copyBufferSize that is used to copy files data. The
larger the supplied buffer, the faster the copy. If
copyBufferPtr = NIL, then this routine allocates a buffer in the
application heap. If you pass a copy buffer to this routine, make
its size a multiple of 512 ($200) bytes for optimum performance.
The optional copyFilterProc parameter lets a routine you define
decide what files or directories are copied to the destination.
srcSpec input: An FSSpec record specifying the directory to copy.
dstSpec input: An FSSpec record specifying destination directory
of the copy.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, FSpDirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
copyFilterProc input: A pointer to the filter routine you want called
for each item in the source directory, or NULL
if you don't want to filter.
Result Codes
noErr 0 No error
readErr <09>19 Driver does not respond to read requests
writErr <09>20 Driver does not respond to write requests
badUnitErr <09>21 Driver reference number does not
match unit table
unitEmptyErr <09>22 Driver reference number specifies a
nil handle in unit table
abortErr <09>27 Request aborted by KillIO
notOpenErr <09>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, CopyFilterProcPtr, FilteredDirectoryCopy,
DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
pascal OSErr DirectoryCopy(short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName,
void *copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler);
/* <09> Make a copy of a directory structure in a new location.
The DirectoryCopy function makes a copy of a directory structure in a
new location. If copyBufferPtr <> NIL, it points to a buffer of
copyBufferSize that is used to copy files data. The larger the
supplied buffer, the faster the copy. If copyBufferPtr = NIL, then this
routine allocates a buffer in the application heap. If you pass a
copy buffer to this routine, make its size a multiple of 512
($200) bytes for optimum performance.
DirectoryCopy normally creates a new directory *in* the specified
destination directory and copies the source directory's content into
the new directory. However, if root parent directory (fsRtParID)
is passed as the dstDirID parameter and NULL is passed as the
dstName parameter, DirectoryCopy renames the destination volume to
the source directory's name (truncating if the name is longer than
27 characters) and copies the source directory's content into the
destination volume's root directory. This special case is supported
by DirectoryCopy, but not by FSpDirectoryCopy since with
FSpDirectoryCopy, the dstName parameter can not be NULL.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Source directory name, or nil if
srcDirID specifies the directory.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Destination directory name, or nil if
dstDirID specifies the directory.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, DirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
Result Codes
noErr 0 No error
readErr <09>19 Driver does not respond to read requests
writErr <09>20 Driver does not respond to write requests
badUnitErr <09>21 Driver reference number does not
match unit table
unitEmptyErr <09>22 Driver reference number specifies a
nil handle in unit table
abortErr <09>27 Request aborted by KillIO
notOpenErr <09>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, FSpDirectoryCopy, FilteredDirectoryCopy,
FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
pascal OSErr FSpDirectoryCopy(const FSSpec *srcSpec,
const FSSpec *dstSpec,
void *copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler);
/* <09> Make a copy of a directory structure in a new location.
The FSpDirectoryCopy function makes a copy of a directory structure in a
new location. If copyBufferPtr <> NIL, it points to a buffer of
copyBufferSize that is used to copy files data. The larger the
supplied buffer, the faster the copy. If copyBufferPtr = NIL, then this
routine allocates a buffer in the application heap. If you pass a
copy buffer to this routine, make its size a multiple of 512
($200) bytes for optimum performance.
srcSpec input: An FSSpec record specifying the directory to copy.
dstSpec input: An FSSpec record specifying destination directory
of the copy.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, FSpDirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
Result Codes
noErr 0 No error
readErr <09>19 Driver does not respond to read requests
writErr <09>20 Driver does not respond to write requests
badUnitErr <09>21 Driver reference number does not
match unit table
unitEmptyErr <09>22 Driver reference number specifies a
nil handle in unit table
abortErr <09>27 Request aborted by KillIO
notOpenErr <09>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, DirectoryCopy, FilteredDirectoryCopy,
FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
#ifdef __cplusplus
}
#endif
#include "optimend.h"
#endif /* __DIRECTORYCOPY__ */

View File

@@ -1,37 +1,53 @@
/* /*
** Apple Macintosh Developer Technical Support File: DirectoryCopy.c
**
** DirectoryCopy: A robust, general purpose directory copy routine. Contains: A robust, general purpose directory copy routine.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: MoreFiles
**
** File: DirectoryCopy.c Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
**
** Copyright © 1992-1998 Apple Computer, Inc. You may incorporate this sample code into your applications without
** All rights reserved. restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** You may incorporate this sample code into your applications without not permitted to do is to redistribute the source as "DSC Sample Code"
** restriction, though the sample code has been provided "AS IS" and the after having made changes. If you're going to re-distribute the source,
** responsibility for its operation is 100% yours. However, what you are we require that you make it clear in the source that the code was
** not permitted to do is to redistribute the source as "DSC Sample Code" descended from Apple Sample Code, but that you've made changes.
** 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 File Ownership:
** descended from Apple Sample Code, but that you've made changes.
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 <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Memory.h> #include <MacMemory.h>
#include <Files.h> #include <Files.h>
#include <Script.h> #include <Script.h>
#include <Math64.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "moredesk.h" #include "MoreDesktopMgr.h"
#include "filecopy.h" #include "FileCopy.h"
#include "director.h" #include "DirectoryCopy.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -53,13 +69,8 @@ enum
** global information that might be needed at any time. */ ** global information that might be needed at any time. */
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif #endif
struct EnumerateGlobals struct EnumerateGlobals
{ {
Ptr copyBuffer; /* pointer to buffer used for file copy operations */ Ptr copyBuffer; /* pointer to buffer used for file copy operations */
@@ -73,11 +84,7 @@ struct EnumerateGlobals
CInfoPBRec myCPB; /* the parameter block used for PBGetCatInfo calls */ CInfoPBRec myCPB; /* the parameter block used for PBGetCatInfo calls */
}; };
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset #pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif #endif
typedef struct EnumerateGlobals EnumerateGlobals; typedef struct EnumerateGlobals EnumerateGlobals;
@@ -89,13 +96,8 @@ typedef EnumerateGlobals *EnumerateGlobalsPtr;
** global information that might be needed at any time. */ ** global information that might be needed at any time. */
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif #endif
struct PreflightGlobals struct PreflightGlobals
{ {
OSErr result; /* temporary holder of results - saves 2 bytes of stack each level */ OSErr result; /* temporary holder of results - saves 2 bytes of stack each level */
@@ -110,11 +112,7 @@ struct PreflightGlobals
CopyFilterProcPtr copyFilterProc; /* pointer to filter function */ CopyFilterProcPtr copyFilterProc; /* pointer to filter function */
}; };
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset #pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif #endif
typedef struct PreflightGlobals PreflightGlobals; typedef struct PreflightGlobals PreflightGlobals;
@@ -157,7 +155,7 @@ static void GetLevelSize(long currentDirID,
CallCopyFilterProc(theGlobals->copyFilterProc, &theGlobals->myCPB) ) /* filter if filter proc was supplied */ CallCopyFilterProc(theGlobals->copyFilterProc, &theGlobals->myCPB) ) /* filter if filter proc was supplied */
{ {
/* Either there's no filter proc OR the filter proc says to use this item */ /* Either there's no filter proc OR the filter proc says to use this item */
if ( (theGlobals->myCPB.dirInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (theGlobals->myCPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
/* we have a directory */ /* we have a directory */
@@ -214,9 +212,6 @@ static void GetLevelSize(long currentDirID,
} while ( theGlobals->result == noErr ); } while ( theGlobals->result == noErr );
} }
#if !TARGET_CARBON
/*****************************************************************************/ /*****************************************************************************/
static OSErr PreflightDirectoryCopySpace(short srcVRefNum, static OSErr PreflightDirectoryCopySpace(short srcVRefNum,
@@ -234,8 +229,7 @@ static OSErr PreflightDirectoryCopySpace(short srcVRefNum,
if ( error == noErr ) if ( error == noErr )
{ {
/* Convert freeBytes to free disk blocks (512-byte blocks) */ /* Convert freeBytes to free disk blocks (512-byte blocks) */
// dstFreeBlocks = (pb.ioVFreeBytes.hi << 23) + (pb.ioVFreeBytes.lo >> 9); dstFreeBlocks = U32SetU(U64ShiftRight(pb.ioVFreeBytes, 9));
dstFreeBlocks = pb.ioVFreeBytes >> 9 ;
/* get allocation block size (always multiple of 512) and divide by 512 /* get allocation block size (always multiple of 512) and divide by 512
to get number of 512-byte blocks per allocation block */ to get number of 512-byte blocks per allocation block */
@@ -259,7 +253,7 @@ static OSErr PreflightDirectoryCopySpace(short srcVRefNum,
return ( error ); return ( error );
} }
#endif
/*****************************************************************************/ /*****************************************************************************/
static void CopyLevel(long sourceDirID, static void CopyLevel(long sourceDirID,
@@ -286,7 +280,7 @@ static void CopyLevel(long sourceDirID,
/* Either there's no filter proc OR the filter proc says to use this item */ /* Either there's no filter proc OR the filter proc says to use this item */
/* We have an item. Is it a file or directory? */ /* We have an item. Is it a file or directory? */
if ( (theGlobals->myCPB.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (theGlobals->myCPB.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
/* We have a directory */ /* We have a directory */
@@ -425,6 +419,7 @@ pascal OSErr FilteredDirectoryCopy(short srcVRefNum,
short dstVRefNum, short dstVRefNum,
long dstDirID, long dstDirID,
ConstStr255Param dstName, ConstStr255Param dstName,
ConstStr255Param copyName,
void *copyBufferPtr, void *copyBufferPtr,
long copyBufferSize, long copyBufferSize,
Boolean preflight, Boolean preflight,
@@ -537,18 +532,26 @@ pascal OSErr FilteredDirectoryCopy(short srcVRefNum,
error = GetDirName(dstVRefNum, fsRtDirID, oldDiskName); error = GetDirName(dstVRefNum, fsRtDirID, oldDiskName);
if ( error == noErr ) if ( error == noErr )
{ {
/* use the copyName as srcDirName if supplied */
if ( copyName != NULL )
{
/* make a copy since copyName is a const input */
BlockMoveData(copyName, srcDirName, sizeof(Str31));
}
/* Shorten the name if it's too long to be the volume name */ /* Shorten the name if it's too long to be the volume name */
TruncPString(srcDirName, srcDirName, 27); TruncPString(srcDirName, srcDirName, 27);
/* Rename the disk */ /* Rename the disk */
error = HRename(dstVRefNum, fsRtParID, oldDiskName, srcDirName); error = HRename(dstVRefNum, fsRtParID, oldDiskName, srcDirName);
/* and copy to the root directory */ /* and copy to the root directory */
dstDirID = fsRtDirID; dstDirID = fsRtDirID;
} }
} }
else else
{ {
error = DirCreate(dstVRefNum, dstDirID, srcDirName, &dstDirID); /* use the copyName as srcDirName if supplied */
error = DirCreate(dstVRefNum, dstDirID, ((copyName != NULL) ? copyName : srcDirName), &dstDirID);
} }
if ( error != noErr ) if ( error != noErr )
{ {
@@ -629,6 +632,7 @@ pascal OSErr DirectoryCopy(short srcVRefNum,
short dstVRefNum, short dstVRefNum,
long dstDirID, long dstDirID,
ConstStr255Param dstName, ConstStr255Param dstName,
ConstStr255Param copyName,
void *copyBufferPtr, void *copyBufferPtr,
long copyBufferSize, long copyBufferSize,
Boolean preflight, Boolean preflight,
@@ -636,6 +640,7 @@ pascal OSErr DirectoryCopy(short srcVRefNum,
{ {
return ( FilteredDirectoryCopy(srcVRefNum, srcDirID, srcName, return ( FilteredDirectoryCopy(srcVRefNum, srcDirID, srcName,
dstVRefNum, dstDirID, dstName, dstVRefNum, dstDirID, dstName,
copyName,
copyBufferPtr, copyBufferSize, preflight, copyBufferPtr, copyBufferSize, preflight,
copyErrHandler, NULL) ); copyErrHandler, NULL) );
} }
@@ -644,6 +649,7 @@ pascal OSErr DirectoryCopy(short srcVRefNum,
pascal OSErr FSpFilteredDirectoryCopy(const FSSpec *srcSpec, pascal OSErr FSpFilteredDirectoryCopy(const FSSpec *srcSpec,
const FSSpec *dstSpec, const FSSpec *dstSpec,
ConstStr255Param copyName,
void *copyBufferPtr, void *copyBufferPtr,
long copyBufferSize, long copyBufferSize,
Boolean preflight, Boolean preflight,
@@ -652,6 +658,7 @@ pascal OSErr FSpFilteredDirectoryCopy(const FSSpec *srcSpec,
{ {
return ( FilteredDirectoryCopy(srcSpec->vRefNum, srcSpec->parID, srcSpec->name, return ( FilteredDirectoryCopy(srcSpec->vRefNum, srcSpec->parID, srcSpec->name,
dstSpec->vRefNum, dstSpec->parID, dstSpec->name, dstSpec->vRefNum, dstSpec->parID, dstSpec->name,
copyName,
copyBufferPtr, copyBufferSize, preflight, copyBufferPtr, copyBufferSize, preflight,
copyErrHandler, copyFilterProc) ); copyErrHandler, copyFilterProc) );
} }
@@ -660,6 +667,7 @@ pascal OSErr FSpFilteredDirectoryCopy(const FSSpec *srcSpec,
pascal OSErr FSpDirectoryCopy(const FSSpec *srcSpec, pascal OSErr FSpDirectoryCopy(const FSSpec *srcSpec,
const FSSpec *dstSpec, const FSSpec *dstSpec,
ConstStr255Param copyName,
void *copyBufferPtr, void *copyBufferPtr,
long copyBufferSize, long copyBufferSize,
Boolean preflight, Boolean preflight,
@@ -667,6 +675,7 @@ pascal OSErr FSpDirectoryCopy(const FSSpec *srcSpec,
{ {
return ( FilteredDirectoryCopy(srcSpec->vRefNum, srcSpec->parID, srcSpec->name, return ( FilteredDirectoryCopy(srcSpec->vRefNum, srcSpec->parID, srcSpec->name,
dstSpec->vRefNum, dstSpec->parID, dstSpec->name, dstSpec->vRefNum, dstSpec->parID, dstSpec->name,
copyName,
copyBufferPtr, copyBufferSize, preflight, copyBufferPtr, copyBufferSize, preflight,
copyErrHandler, NULL) ); copyErrHandler, NULL) );
} }

View File

@@ -0,0 +1,559 @@
/*
File: DirectoryCopy.h
Contains: A robust, general purpose directory copy routine.
Version: Technology: MoreFiles
Release: 1.5.2
Copyright: <20> 1992-2001 by Apple Computer, Inc., all rights reserved.
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
/*
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.
*/
#ifndef __DIRECTORYCOPY__
#define __DIRECTORYCOPY__
#ifndef __MACTYPES__
#include <MacTypes.h>
#endif
#ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/
enum {
getNextItemOp = 1, /* couldn't access items in this directory - no access privileges */
copyDirCommentOp = 2, /* couldn't copy directory's Finder comment */
copyDirAccessPrivsOp = 3, /* couldn't copy directory's AFP access privileges */
copyDirFMAttributesOp = 4, /* couldn't copy directory's File Manager attributes */
dirCreateOp = 5, /* couldn't create destination directory */
fileCopyOp = 6 /* couldn't copy file */
};
/*****************************************************************************/
typedef CALLBACK_API( Boolean , CopyErrProcPtr )(OSErr error, short failedOperation, short srcVRefNum, long srcDirID, ConstStr255Param srcName, short dstVRefNum, long dstDirID, ConstStr255Param dstName);
/*
This is the prototype for the CopyErrProc function DirectoryCopy
calls if an error condition is detected sometime during the copy. If
CopyErrProc returns false, then DirectoryCopy attempts to continue with
the directory copy operation. If CopyErrProc returns true, then
DirectoryCopy stops the directory copy operation.
error input: The error result code that caused CopyErrProc to
be called.
failedOperation input: The operation that returned an error to
DirectoryCopy.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Source file or directory name, or nil if
srcDirID specifies the directory.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Destination file or directory name, or nil if
dstDirID specifies the directory.
__________
Also see: FilteredDirectoryCopy, FSpFilteredDirectoryCopy, DirectoryCopy, FSpDirectoryCopy
*/
#define CallCopyErrProc(userRoutine, error, failedOperation, srcVRefNum, srcDirID, srcName, dstVRefNum, dstDirID, dstName) \
(*(userRoutine))((error), (failedOperation), (srcVRefNum), (srcDirID), (srcName), (dstVRefNum), (dstDirID), (dstName))
/*****************************************************************************/
typedef CALLBACK_API( Boolean , CopyFilterProcPtr )(const CInfoPBRec * cpbPtr);
/*
This is the prototype for the CopyFilterProc function called by
FilteredDirectoryCopy and GetLevelSize. If true is returned,
the file/folder is included in the copy, otherwise it is excluded.
pb input: Points to the CInfoPBRec for the item under consideration.
__________
Also see: FilteredDirectoryCopy, FSpFilteredDirectoryCopy
*/
#define CallCopyFilterProc(userRoutine, cpbPtr) \
(*(userRoutine))((cpbPtr))
/*****************************************************************************/
EXTERN_API( OSErr )
FilteredDirectoryCopy(
short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName,
ConstStr255Param copyName,
void * copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler,
CopyFilterProcPtr copyFilterProc);
/*
The FilteredDirectoryCopy function makes a copy of a directory
structure in a new location. If copyBufferPtr <> NIL, it points to
a buffer of copyBufferSize that is used to copy files data. The
larger the supplied buffer, the faster the copy. If
copyBufferPtr = NIL, then this routine allocates a buffer in the
application heap. If you pass a copy buffer to this routine, make
its size a multiple of 512 ($200) bytes for optimum performance.
The optional copyFilterProc parameter lets a routine you define
decide what files or directories are copied to the destination.
FilteredDirectoryCopy normally creates a new directory *in* the
specified destination directory and copies the source directory's
content into the new directory. However, if root parent directory
(fsRtParID) is passed as the dstDirID parameter and NULL is
passed as the dstName parameter, DirectoryCopy renames the
destination volume to the source directory's name (truncating
if the name is longer than 27 characters) and copies the source
directory's content into the destination volume's root directory.
This special case is supported by FilteredDirectoryCopy, but
not by FSpFilteredDirectoryCopy since with FSpFilteredDirectoryCopy,
the dstName parameter can not be NULL.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Source directory name, or nil if
srcDirID specifies the directory.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Destination directory name, or nil if
dstDirID specifies the directory.
copyName input: Points to the new directory name if the directory
is to be renamed or nil if the directory isn't to
be renamed.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, DirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
copyFilterProc input: A pointer to the filter routine you want called
for each item in the source directory, or NULL
if you don't want to filter.
Result Codes
noErr 0 No error
readErr <20>19 Driver does not respond to read requests
writErr <20>20 Driver does not respond to write requests
badUnitErr <20>21 Driver reference number does not
match unit table
unitEmptyErr <20>22 Driver reference number specifies a
nil handle in unit table
abortErr <20>27 Request aborted by KillIO
notOpenErr <20>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, CopyFilterProcPtr, FSpFilteredDirectoryCopy,
DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpFilteredDirectoryCopy(
const FSSpec * srcSpec,
const FSSpec * dstSpec,
ConstStr255Param copyName,
void * copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler,
CopyFilterProcPtr copyFilterProc);
/*
The FSpFilteredDirectoryCopy function makes a copy of a directory
structure in a new location. If copyBufferPtr <> NIL, it points to
a buffer of copyBufferSize that is used to copy files data. The
larger the supplied buffer, the faster the copy. If
copyBufferPtr = NIL, then this routine allocates a buffer in the
application heap. If you pass a copy buffer to this routine, make
its size a multiple of 512 ($200) bytes for optimum performance.
The optional copyFilterProc parameter lets a routine you define
decide what files or directories are copied to the destination.
srcSpec input: An FSSpec record specifying the directory to copy.
dstSpec input: An FSSpec record specifying destination directory
of the copy.
copyName input: Points to the new directory name if the directory
is to be renamed or nil if the directory isn't to
be renamed.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, FSpDirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
copyFilterProc input: A pointer to the filter routine you want called
for each item in the source directory, or NULL
if you don't want to filter.
Result Codes
noErr 0 No error
readErr <20>19 Driver does not respond to read requests
writErr <20>20 Driver does not respond to write requests
badUnitErr <20>21 Driver reference number does not
match unit table
unitEmptyErr <20>22 Driver reference number specifies a
nil handle in unit table
abortErr <20>27 Request aborted by KillIO
notOpenErr <20>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, CopyFilterProcPtr, FilteredDirectoryCopy,
DirectoryCopy, FSpDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DirectoryCopy(
short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName,
ConstStr255Param copyName,
void * copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler);
/*
The DirectoryCopy function makes a copy of a directory structure in a
new location. If copyBufferPtr <> NIL, it points to a buffer of
copyBufferSize that is used to copy files data. The larger the
supplied buffer, the faster the copy. If copyBufferPtr = NIL, then this
routine allocates a buffer in the application heap. If you pass a
copy buffer to this routine, make its size a multiple of 512
($200) bytes for optimum performance.
DirectoryCopy normally creates a new directory *in* the specified
destination directory and copies the source directory's content into
the new directory. However, if root parent directory (fsRtParID)
is passed as the dstDirID parameter and NULL is passed as the
dstName parameter, DirectoryCopy renames the destination volume to
the source directory's name (truncating if the name is longer than
27 characters) and copies the source directory's content into the
destination volume's root directory. This special case is supported
by DirectoryCopy, but not by FSpDirectoryCopy since with
FSpDirectoryCopy, the dstName parameter can not be NULL.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Source directory name, or nil if
srcDirID specifies the directory.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Destination directory name, or nil if
dstDirID specifies the directory.
copyName input: Points to the new directory name if the directory
is to be renamed or nil if the directory isn't to
be renamed.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, DirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
Result Codes
noErr 0 No error
readErr <20>19 Driver does not respond to read requests
writErr <20>20 Driver does not respond to write requests
badUnitErr <20>21 Driver reference number does not
match unit table
unitEmptyErr <20>22 Driver reference number specifies a
nil handle in unit table
abortErr <20>27 Request aborted by KillIO
notOpenErr <20>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, FSpDirectoryCopy, FilteredDirectoryCopy,
FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDirectoryCopy(
const FSSpec * srcSpec,
const FSSpec * dstSpec,
ConstStr255Param copyName,
void * copyBufferPtr,
long copyBufferSize,
Boolean preflight,
CopyErrProcPtr copyErrHandler);
/*
The FSpDirectoryCopy function makes a copy of a directory structure in a
new location. If copyBufferPtr <> NIL, it points to a buffer of
copyBufferSize that is used to copy files data. The larger the
supplied buffer, the faster the copy. If copyBufferPtr = NIL, then this
routine allocates a buffer in the application heap. If you pass a
copy buffer to this routine, make its size a multiple of 512
($200) bytes for optimum performance.
srcSpec input: An FSSpec record specifying the directory to copy.
dstSpec input: An FSSpec record specifying destination directory
of the copy.
copyName input: Points to the new directory name if the directory
is to be renamed or nil if the directory isn't to
be renamed.
copyBufferPtr input: Points to a buffer of copyBufferSize that
is used the i/o buffer for the copy or
nil if you want DirectoryCopy to allocate its
own buffer in the application heap.
copyBufferSize input: The size of the buffer pointed to
by copyBufferPtr.
preflight input: If true, FSpDirectoryCopy makes sure there are
enough allocation blocks on the destination
volume to hold the directory's files before
starting the copy.
copyErrHandler input: A pointer to the routine you want called if an
error condition is detected during the copy, or
nil if you don't want to handle error conditions.
If you don't handle error conditions, the first
error will cause the copy to quit and
DirectoryCopy will return the error.
Error handling is recommended...
Result Codes
noErr 0 No error
readErr <20>19 Driver does not respond to read requests
writErr <20>20 Driver does not respond to write requests
badUnitErr <20>21 Driver reference number does not
match unit table
unitEmptyErr <20>22 Driver reference number specifies a
nil handle in unit table
abortErr <20>27 Request aborted by KillIO
notOpenErr <20>28 Driver not open
dskFulErr -34 Destination volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 Source file not found, or destination
directory does not exist
wPrErr -44 Volume locked by hardware
fLckdErr -45 File is locked
vLckdErr -46 Destination volume is read-only
fBsyErr -47 The source or destination file could
not be opened with the correct access
modes
dupFNErr -48 Destination file already exists
opWrErr -49 File already open for writing
paramErr -50 No default volume or function not
supported by volume
permErr -54 File is already open and cannot be opened using specified deny modes
memFullErr -108 Copy buffer could not be allocated
dirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Function not supported by volume
afpAccessDenied -5000 User does not have the correct access
afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
modes
afpObjectTypeErr -5025 Source is a directory, directory not found
or incomplete pathname
__________
Also see: CopyErrProcPtr, DirectoryCopy, FilteredDirectoryCopy,
FSpFilteredDirectoryCopy, FileCopy, FSpFileCopy
*/
/*****************************************************************************/
#include "OptimizationEnd.h"
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#endif /* __DIRECTORYCOPY__ */

View File

@@ -1,488 +0,0 @@
/*
** Apple Macintosh Developer Technical Support
**
** FSSpec compatibility functions.
**
** by Jim Luther, Apple Developer Technical Support Emeritus
**
** File: FSpCompat.h
**
** Copyright <20> 1992-1998 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.
*/
#ifndef __FSPCOMPAT__
#define __FSPCOMPAT__
#include <Types.h>
#include <Files.h>
#include "optim.h"
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
pascal OSErr FSMakeFSSpecCompat(short vRefNum,
long dirID,
ConstStr255Param fileName,
FSSpec *spec);
/* <09> Initialize a FSSpec record.
The FSMakeFSSpecCompat function fills in the fields of an FSSpec record.
If the file system can't create the FSSpec, then the compatibility code
creates a FSSpec that is exactly like an FSSpec except that spec.name
for a file may not have the same capitalization as the file's catalog
entry on the disk volume. That is because fileName is parsed to get the
name instead of getting the name back from the file system. This works
fine with System 6 where FSMakeSpec isn't available.
vRefNum input: Volume specification.
dirID input: Directory ID.
fileName input: Pointer to object name, or nil when dirID specifies
a directory that's the object.
spec output: A file system specification to be filled in by
FSMakeFSSpecCompat.
Result Codes
noErr 0 No error
nsvErr -35 Volume doesn<73>t exist
fnfErr -43 File or directory does not exist
(FSSpec is still valid)
*/
/*****************************************************************************/
pascal OSErr FSpOpenDFCompat(const FSSpec *spec,
char permission,
short *refNum);
/* <09> Open a file's data fork.
The FSpOpenDFCompat function opens the data fork of the file specified
by spec.
Differences from FSpOpenDF: If FSpOpenDF isn't available,
FSpOpenDFCompat uses PHBOpen because System 6 doesn't support PBHOpenDF.
This means FSpOpenDFCompat could accidentally open a driver if the
spec->name begins with a period.
spec input: An FSSpec record specifying the file whose data
fork is to be opened.
permission input: A constant indicating the desired file access
permissions.
refNum output: A reference number of an access path to the file's
data fork.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 File not found
opWrErr -49 File already open for writing
permErr -54 Attempt to open locked file for writing
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
__________
See also: FSpOpenAware
*/
/*****************************************************************************/
pascal OSErr FSpOpenRFCompat(const FSSpec *spec,
char permission,
short *refNum);
/* <09> Open a file's resource fork.
The FSpOpenRFCompat function opens the resource fork of the file
specified by spec.
spec input: An FSSpec record specifying the file whose resource
fork is to be opened.
permission input: A constant indicating the desired file access
permissions.
refNum output: A reference number of an access path to the file's
resource fork.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 File not found
opWrErr -49 File already open for writing
permErr -54 Attempt to open locked file for writing
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
__________
See also: FSpOpenRFAware
*/
/*****************************************************************************/
pascal OSErr FSpCreateCompat(const FSSpec *spec,
OSType creator,
OSType fileType,
ScriptCode scriptTag);
/* <09> Create a new file.
The FSpCreateCompat function creates a new file with the specified
type, creator, and script code.
Differences from FSpCreate: FSpCreateCompat correctly sets the
fdScript in the file's FXInfo record to scriptTag if the problem
isn't fixed in the File Manager code.
spec input: An FSSpec record specifying the file to create.
creator input: The creator of the new file.
fileType input The file type of the new file.
scriptCode input: The code of the script system in which the file
name is to be displayed.
Result Codes
noErr 0 No error
dirFulErr -33 File directory full
dskFulErr -34 Disk is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 Directory not found or incomplete pathname
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 A directory exists with that name
*/
/*****************************************************************************/
pascal OSErr FSpDirCreateCompat(const FSSpec *spec,
ScriptCode scriptTag,
long *createdDirID);
/* <09> Create a new directory.
The FSpDirCreateCompat function creates a new directory and returns the
directory ID of the newDirectory.
spec input: An FSSpec record specifying the directory to
create.
scriptCode input: The code of the script system in which the
directory name is to be displayed.
createdDirID output: The directory ID of the directory that was
created.
Result Codes
noErr 0 No error
dirFulErr -33 File directory full
dskFulErr -34 Disk is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 Directory not found or incomplete pathname
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Not an HFS volume
afpAccessDenied -5000 User does not have the correct access
*/
/*****************************************************************************/
pascal OSErr FSpDeleteCompat(const FSSpec *spec);
/* <09> Delete a file or directory.
The FSpDeleteCompat function deletes a file or directory.
spec input: An FSSpec record specifying the file or
directory to delete.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 File is locked
vLckdErr -46 Software volume lock
fBsyErr -47 File busy, directory not empty, or
working directory control block open
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
*/
/*****************************************************************************/
pascal OSErr FSpGetFInfoCompat(const FSSpec *spec,
FInfo *fndrInfo);
/* <09> Get the finder information for a file.
The FSpGetFInfoCompat function gets the finder information for a file.
spec input: An FSSpec record specifying the file.
fndrInfo output: If the object is a file, then its FInfo.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
paramErr -50 No default volume
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
Also see: FSpGetDInfo
*/
/*****************************************************************************/
pascal OSErr FSpSetFInfoCompat(const FSSpec *spec,
const FInfo *fndrInfo);
/* <09> Set the finder information for a file.
The FSpSetFInfoCompat function sets the finder information for a file.
spec input: An FSSpec record specifying the file.
fndrInfo input: The FInfo.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 File is locked
vLckdErr -46 Software volume lock
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Object was a directory
__________
Also see: FSpSetDInfo
*/
/*****************************************************************************/
pascal OSErr FSpSetFLockCompat(const FSSpec *spec);
/* <09> Lock a file.
The FSpSetFLockCompat function locks a file.
spec input: An FSSpec record specifying the file.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
afpObjectTypeErr -5025 Folder locking not supported by volume
*/
/*****************************************************************************/
pascal OSErr FSpRstFLockCompat(const FSSpec *spec);
/* <09> Unlock a file.
The FSpRstFLockCompat function unlocks a file.
spec input: An FSSpec record specifying the file.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
afpObjectTypeErr -5025 Folder locking not supported by volume
*/
/*****************************************************************************/
pascal OSErr FSpRenameCompat(const FSSpec *spec,
ConstStr255Param newName);
/* <09> Rename a file or directory.
The FSpRenameCompat function renames a file or directory.
spec input: An FSSpec record specifying the file.
newName input: The new name of the file or directory.
Result Codes
noErr 0 No error
dirFulErr -33 File directory full
dskFulErr -34 Volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 File is locked
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
paramErr -50 No default volume
fsRnErr -59 Problem during rename
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
*/
/*****************************************************************************/
pascal OSErr FSpCatMoveCompat(const FSSpec *source,
const FSSpec *dest);
/* <09> Move a file or directory to a different location on on the same volume.
The FSpCatMoveCompat function moves a file or directory to a different
location on on the same volume.
source input: An FSSpec record specifying the file or directory.
dest input: An FSSpec record specifying the name and location
of the directory into which the source file or
directory is to be moved.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename or attempt to move into
a file
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 Target directory is locked
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
paramErr -50 No default volume
badMovErr -122 Attempt to move into offspring
wrgVolTypErr -123 Not an HFS volume
afpAccessDenied -5000 User does not have the correct access to
the file
*/
/*****************************************************************************/
pascal OSErr FSpExchangeFilesCompat(const FSSpec *source,
const FSSpec *dest);
/* <09> Exchange the data stored in two files on the same volume.
The FSpExchangeFilesCompat function swaps the data in two files by
changing the information in the volume's catalog and, if the files
are open, in the file control blocks.
Differences from FSpExchangeFiles: Correctly exchanges files on volumes
that don't support PBExchangeFiles. FSpExchangeFiles attempts to support
volumes that don't support PBExchangeFiles, but in System 7, 7.0.1, 7.1,
and 7 Pro, the compatibility code just doesn't work on volumes that
don't support PBExchangeFiles (even though you may get a noErr result).
System Update 3.0 and System 7.5 and later have the problems in
FSpExchangeFiles corrected.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr -43 File not found
fLckdErr -45 File is locked
vLckdErr -46 Volume is locked or read-only
paramErr -50 Function not supported by volume
volOfflinErr -53 Volume is offline
wrgVolTypErr -123 Not an HFS volume
diffVolErr -1303 Files on different volumes
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Object is a directory, not a file
afpSameObjectErr -5038 Source and destination files are the same
*/
/*****************************************************************************/
pascal short FSpOpenResFileCompat(const FSSpec *spec,
SignedByte permission);
/* <09> Open a file's resource file.
The FSpOpenResFileCompat function opens the resource file specified
by spec.
spec input: An FSSpec record specifying the file whose
resource file is to be opened.
permission input: A constant indicating the desired file access
permissions.
function result output: A resource file reference number, or if there's
an error -1.
Result Codes
noErr 0 No error
nsvErr <09>35 No such volume
ioErr <09>36 I/O error
bdNamErr <09>37 Bad filename or volume name (perhaps zero
length)
eofErr <09>39 End of file
tmfoErr <09>42 Too many files open
fnfErr <09>43 File not found
opWrErr <09>49 File already open with write permission
permErr <09>54 Permissions error (on file open)
extFSErr <09>58 Volume belongs to an external file system
memFullErr <09>108 Not enough room in heap zone
dirNFErr <09>120 Directory not found
mapReadErr <09>199 Map inconsistent with operation
*/
/*****************************************************************************/
pascal void FSpCreateResFileCompat(const FSSpec *spec,
OSType creator,
OSType fileType,
ScriptCode scriptTag);
/* <09> Create a resource file.
The FSpCreateResFileCompat function creates a new resource file with
the specified type, creator, and script code.
Differences from FSpCreateResFile: FSpCreateResFileCompat correctly
sets the fdScript in the file's FXInfo record to scriptTag if the
problem isn't fixed in the File Manager code.
spec input: An FSSpec record specifying the resource file to create.
creator input: The creator of the new file.
fileType input The file type of the new file.
scriptCode input: The code of the script system in which the file
name is to be displayed.
Result Codes
noErr 0 No error
dirFulErr <09>33 Directory full
dskFulErr <09>34 Disk full
nsvErr <09>35 No such volume
ioErr <09>36 I/O error
bdNamErr <09>37 Bad filename or volume name (perhaps zero
length)
tmfoErr <09>42 Too many files open
wPrErrw <09>44 Disk is write-protected
fLckdErr <09>45 File is locked
*/
/*****************************************************************************/
#ifdef __cplusplus
}
#endif
#include "optimend.h"
#endif /* __FSPCOMPAT__ */

View File

@@ -1,22 +1,39 @@
/* /*
** Apple Macintosh Developer Technical Support File: FSpCompat.c
**
** FSSpec compatibility functions. Contains: FSSpec compatibility functions.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: MoreFiles
**
** File: FSpCompat.c Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
**
** Copyright © 1992-1998 Apple Computer, Inc. You may incorporate this sample code into your applications without
** All rights reserved. restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** You may incorporate this sample code into your applications without not permitted to do is to redistribute the source as "DSC Sample Code"
** restriction, though the sample code has been provided "AS IS" and the after having made changes. If you're going to re-distribute the source,
** responsibility for its operation is 100% yours. However, what you are we require that you make it clear in the source that the code was
** not permitted to do is to redistribute the source as "DSC Sample Code" descended from Apple Sample Code, but that you've made changes.
** 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 File Ownership:
** descended from Apple Sample Code, but that you've made changes.
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. Updated
various routines to use new calling convention of the
MoreFilesExtras accessor functions.
<1> 12/06/99 JL MoreFiles 1.5.
*/ */
/* /*
@@ -28,8 +45,9 @@
#define GENERATENODATA 0 #define GENERATENODATA 0
#endif #endif
#include <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Files.h>
#include <LowMem.h> #include <LowMem.h>
#include <Gestalt.h> #include <Gestalt.h>
#include <Resources.h> #include <Resources.h>
@@ -37,8 +55,8 @@
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "fspcompa.h" #include "FSpCompat.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -684,7 +702,7 @@ pascal OSErr FSpExchangeFilesCompat(const FSSpec *source,
result2 = PBHGetVolParmsSync(&pb); result2 = PBHGetVolParmsSync(&pb);
/* continue if volume has no fileID support (or no GetVolParms support) */ /* continue if volume has no fileID support (or no GetVolParms support) */
if ( (result2 == noErr) && hasFileIDs(volInfo) ) if ( (result2 == noErr) && hasFileIDs(&volInfo) )
{ {
goto errorExit3; goto errorExit3;
} }
@@ -701,7 +719,7 @@ pascal OSErr FSpExchangeFilesCompat(const FSSpec *source,
{ {
goto errorExit3; goto errorExit3;
} }
if ( (catInfoSource.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (catInfoSource.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
result = notAFileErr; result = notAFileErr;
goto errorExit3; goto errorExit3;
@@ -717,7 +735,7 @@ pascal OSErr FSpExchangeFilesCompat(const FSSpec *source,
{ {
goto errorExit3; goto errorExit3;
} }
if ( (catInfoDest.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (catInfoDest.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
result = notAFileErr; result = notAFileErr;
goto errorExit3; goto errorExit3;

View File

@@ -0,0 +1,586 @@
/*
File: FSpCompat.h
Contains: FSSpec compatibility functions.
Version: Technology: MoreFiles
Release: 1.5.2
Copyright: <20> 1992-2001 by Apple Computer, Inc., all rights reserved.
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
/*
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.
*/
#ifndef __FSPCOMPAT__
#define __FSPCOMPAT__
#ifndef __MACTYPES__
#include <MacTypes.h>
#endif
#ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/
EXTERN_API( OSErr )
FSMakeFSSpecCompat(
short vRefNum,
long dirID,
ConstStr255Param fileName,
FSSpec * spec);
/*
The FSMakeFSSpecCompat function fills in the fields of an FSSpec record.
If the file system can't create the FSSpec, then the compatibility code
creates a FSSpec that is exactly like an FSSpec except that spec.name
for a file may not have the same capitalization as the file's catalog
entry on the disk volume. That is because fileName is parsed to get the
name instead of getting the name back from the file system. This works
fine with System 6 where FSMakeSpec isn't available.
vRefNum input: Volume specification.
dirID input: Directory ID.
fileName input: Pointer to object name, or nil when dirID specifies
a directory that's the object.
spec output: A file system specification to be filled in by
FSMakeFSSpecCompat.
Result Codes
noErr 0 No error
nsvErr -35 Volume doesn<73>t exist
fnfErr -43 File or directory does not exist
(FSSpec is still valid)
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpOpenDFCompat(
const FSSpec * spec,
char permission,
short * refNum);
/*
The FSpOpenDFCompat function opens the data fork of the file specified
by spec.
Differences from FSpOpenDF: If FSpOpenDF isn't available,
FSpOpenDFCompat uses PHBOpen because System 6 doesn't support PBHOpenDF.
This means FSpOpenDFCompat could accidentally open a driver if the
spec->name begins with a period.
spec input: An FSSpec record specifying the file whose data
fork is to be opened.
permission input: A constant indicating the desired file access
permissions.
refNum output: A reference number of an access path to the file's
data fork.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 File not found
opWrErr -49 File already open for writing
permErr -54 Attempt to open locked file for writing
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
__________
See also: FSpOpenAware
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpOpenRFCompat(
const FSSpec * spec,
char permission,
short * refNum);
/*
The FSpOpenRFCompat function opens the resource fork of the file
specified by spec.
spec input: An FSSpec record specifying the file whose resource
fork is to be opened.
permission input: A constant indicating the desired file access
permissions.
refNum output: A reference number of an access path to the file's
resource fork.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
tmfoErr -42 Too many files open
fnfErr -43 File not found
opWrErr -49 File already open for writing
permErr -54 Attempt to open locked file for writing
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
__________
See also: FSpOpenRFAware
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpCreateCompat(
const FSSpec * spec,
OSType creator,
OSType fileType,
ScriptCode scriptTag);
/*
The FSpCreateCompat function creates a new file with the specified
type, creator, and script code.
Differences from FSpCreate: FSpCreateCompat correctly sets the
fdScript in the file's FXInfo record to scriptTag if the problem
isn't fixed in the File Manager code.
spec input: An FSSpec record specifying the file to create.
creator input: The creator of the new file.
fileType input The file type of the new file.
scriptCode input: The code of the script system in which the file
name is to be displayed.
Result Codes
noErr 0 No error
dirFulErr -33 File directory full
dskFulErr -34 Disk is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 Directory not found or incomplete pathname
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 A directory exists with that name
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDirCreateCompat(
const FSSpec * spec,
ScriptCode scriptTag,
long * createdDirID);
/*
The FSpDirCreateCompat function creates a new directory and returns the
directory ID of the newDirectory.
spec input: An FSSpec record specifying the directory to
create.
scriptCode input: The code of the script system in which the
directory name is to be displayed.
createdDirID output: The directory ID of the directory that was
created.
Result Codes
noErr 0 No error
dirFulErr -33 File directory full
dskFulErr -34 Disk is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 Directory not found or incomplete pathname
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
wrgVolTypErr -123 Not an HFS volume
afpAccessDenied -5000 User does not have the correct access
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDeleteCompat(const FSSpec * spec);
/*
The FSpDeleteCompat function deletes a file or directory.
spec input: An FSSpec record specifying the file or
directory to delete.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 File is locked
vLckdErr -46 Software volume lock
fBsyErr -47 File busy, directory not empty, or
working directory control block open
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpGetFInfoCompat(
const FSSpec * spec,
FInfo * fndrInfo);
/*
The FSpGetFInfoCompat function gets the finder information for a file.
spec input: An FSSpec record specifying the file.
fndrInfo output: If the object is a file, then its FInfo.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
paramErr -50 No default volume
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
Also see: FSpGetDInfo
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpSetFInfoCompat(
const FSSpec * spec,
const FInfo * fndrInfo);
/*
The FSpSetFInfoCompat function sets the finder information for a file.
spec input: An FSSpec record specifying the file.
fndrInfo input: The FInfo.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 File is locked
vLckdErr -46 Software volume lock
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Object was a directory
__________
Also see: FSpSetDInfo
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpSetFLockCompat(const FSSpec * spec);
/*
The FSpSetFLockCompat function locks a file.
spec input: An FSSpec record specifying the file.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
afpObjectTypeErr -5025 Folder locking not supported by volume
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpRstFLockCompat(const FSSpec * spec);
/*
The FSpRstFLockCompat function unlocks a file.
spec input: An FSSpec record specifying the file.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
vLckdErr -46 Software volume lock
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
afpObjectTypeErr -5025 Folder locking not supported by volume
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpRenameCompat(
const FSSpec * spec,
ConstStr255Param newName);
/*
The FSpRenameCompat function renames a file or directory.
spec input: An FSSpec record specifying the file.
newName input: The new name of the file or directory.
Result Codes
noErr 0 No error
dirFulErr -33 File directory full
dskFulErr -34 Volume is full
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 File is locked
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
paramErr -50 No default volume
fsRnErr -59 Problem during rename
dirNFErrdirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access to
the file
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpCatMoveCompat(
const FSSpec * source,
const FSSpec * dest);
/*
The FSpCatMoveCompat function moves a file or directory to a different
location on on the same volume.
source input: An FSSpec record specifying the file or directory.
dest input: An FSSpec record specifying the name and location
of the directory into which the source file or
directory is to be moved.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename or attempt to move into
a file
fnfErr -43 File not found
wPrErr -44 Hardware volume lock
fLckdErr -45 Target directory is locked
vLckdErr -46 Software volume lock
dupFNErr -48 Duplicate filename and version
paramErr -50 No default volume
badMovErr -122 Attempt to move into offspring
wrgVolTypErr -123 Not an HFS volume
afpAccessDenied -5000 User does not have the correct access to
the file
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpExchangeFilesCompat(
const FSSpec * source,
const FSSpec * dest);
/*
The FSpExchangeFilesCompat function swaps the data in two files by
changing the information in the volume's catalog and, if the files
are open, in the file control blocks.
Differences from FSpExchangeFiles: Correctly exchanges files on volumes
that don't support PBExchangeFiles. FSpExchangeFiles attempts to support
volumes that don't support PBExchangeFiles, but in System 7, 7.0.1, 7.1,
and 7 Pro, the compatibility code just doesn't work on volumes that
don't support PBExchangeFiles (even though you may get a noErr result).
System Update 3.0 and System 7.5 and later have the problems in
FSpExchangeFiles corrected.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr -43 File not found
fLckdErr -45 File is locked
vLckdErr -46 Volume is locked or read-only
paramErr -50 Function not supported by volume
volOfflinErr -53 Volume is offline
wrgVolTypErr -123 Not an HFS volume
diffVolErr -1303 Files on different volumes
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Object is a directory, not a file
afpSameObjectErr -5038 Source and destination files are the same
*/
/*****************************************************************************/
EXTERN_API( short )
FSpOpenResFileCompat(
const FSSpec * spec,
SignedByte permission);
/*
The FSpOpenResFileCompat function opens the resource file specified
by spec.
spec input: An FSSpec record specifying the file whose
resource file is to be opened.
permission input: A constant indicating the desired file access
permissions.
function result output: A resource file reference number, or if there's
an error -1.
Result Codes
noErr 0 No error
nsvErr <20>35 No such volume
ioErr <20>36 I/O error
bdNamErr <20>37 Bad filename or volume name (perhaps zero
length)
eofErr <20>39 End of file
tmfoErr <20>42 Too many files open
fnfErr <20>43 File not found
opWrErr <20>49 File already open with write permission
permErr <20>54 Permissions error (on file open)
extFSErr <20>58 Volume belongs to an external file system
memFullErr <20>108 Not enough room in heap zone
dirNFErr <20>120 Directory not found
mapReadErr <20>199 Map inconsistent with operation
*/
/*****************************************************************************/
EXTERN_API( void )
FSpCreateResFileCompat(
const FSSpec * spec,
OSType creator,
OSType fileType,
ScriptCode scriptTag);
/*
The FSpCreateResFileCompat function creates a new resource file with
the specified type, creator, and script code.
Differences from FSpCreateResFile: FSpCreateResFileCompat correctly
sets the fdScript in the file's FXInfo record to scriptTag if the
problem isn't fixed in the File Manager code.
spec input: An FSSpec record specifying the resource file to create.
creator input: The creator of the new file.
fileType input The file type of the new file.
scriptCode input: The code of the script system in which the file
name is to be displayed.
Result Codes
noErr 0 No error
dirFulErr <20>33 Directory full
dskFulErr <20>34 Disk full
nsvErr <20>35 No such volume
ioErr <20>36 I/O error
bdNamErr <20>37 Bad filename or volume name (perhaps zero
length)
tmfoErr <20>42 Too many files open
wPrErrw <20>44 Disk is write-protected
fLckdErr <20>45 File is locked
*/
/*****************************************************************************/
#include "OptimizationEnd.h"
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#endif /* __FSPCOMPAT__ */

View File

@@ -1,36 +1,53 @@
/* /*
** Apple Macintosh Developer Technical Support File: FileCopy.c
**
** FileCopy: A robust, general purpose file copy routine. Contains: A robust, general purpose file copy routine.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: MoreFiles
**
** File: FileCopy.c Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
**
** Copyright © 1992-1998 Apple Computer, Inc. You may incorporate this sample code into your applications without
** All rights reserved. restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** You may incorporate this sample code into your applications without not permitted to do is to redistribute the source as "DSC Sample Code"
** restriction, though the sample code has been provided "AS IS" and the after having made changes. If you're going to re-distribute the source,
** responsibility for its operation is 100% yours. However, what you are we require that you make it clear in the source that the code was
** not permitted to do is to redistribute the source as "DSC Sample Code" descended from Apple Sample Code, but that you've made changes.
** 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 File Ownership:
** descended from Apple Sample Code, but that you've made changes.
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. Updated
various routines to use new calling convention of the
MoreFilesExtras accessor functions.
<1> 12/06/99 JL MoreFiles 1.5.
*/ */
#include <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Memory.h> #include <MacMemory.h>
#include <Files.h> #include <Files.h>
#include <Math64.h> #include <Math64.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "moredesk.h" #include "MoreDesktopMgr.h"
#include "filecopy.h" #include "FileCopy.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -129,9 +146,9 @@ static OSErr GetDestinationDirInfo(short vRefNum,
pb.dirInfo.ioACUser = 0; /* ioACUser used to be filler2, clear it before calling GetCatInfo */ pb.dirInfo.ioACUser = 0; /* ioACUser used to be filler2, clear it before calling GetCatInfo */
error = GetCatInfoNoName(vRefNum, dirID, name, &pb); error = GetCatInfoNoName(vRefNum, dirID, name, &pb);
*theDirID = pb.dirInfo.ioDrDirID; *theDirID = pb.dirInfo.ioDrDirID;
*isDirectory = (pb.dirInfo.ioFlAttrib & ioDirMask) != 0; *isDirectory = (pb.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0;
/* see if access priviledges are make changes, not see folder, and not see files (drop box) */ /* see if access priviledges are make changes, not see folder, and not see files (drop box) */
*isDropBox = ((pb.dirInfo.ioACUser & 0x07) == 0x03); *isDropBox = userHasDropBoxAccess(pb.dirInfo.ioACUser);
return ( error ); return ( error );
} }
@@ -161,8 +178,6 @@ static OSErr CheckForForks(short vRefNum,
/*****************************************************************************/ /*****************************************************************************/
#if !TARGET_CARBON
static OSErr PreflightFileCopySpace(short srcVRefNum, static OSErr PreflightFileCopySpace(short srcVRefNum,
long srcDirID, long srcDirID,
ConstStr255Param srcName, ConstStr255Param srcName,
@@ -185,8 +200,7 @@ static OSErr PreflightFileCopySpace(short srcVRefNum,
dstBlksPerAllocBlk = ((unsigned long)pb.xPB.ioVAlBlkSiz >> 9); dstBlksPerAllocBlk = ((unsigned long)pb.xPB.ioVAlBlkSiz >> 9);
/* Convert freeBytes to free disk blocks (512-byte blocks) */ /* Convert freeBytes to free disk blocks (512-byte blocks) */
// dstFreeBlocks = (pb.xPB.ioVFreeBytes.hi << 23) + (pb.xPB.ioVFreeBytes.lo >> 9); dstFreeBlocks = U32SetU(U64ShiftRight(pb.xPB.ioVFreeBytes, 9));
dstFreeBlocks = pb.xPB.ioVFreeBytes >> 9 ;
/* Now, get the size of the file's data resource forks */ /* Now, get the size of the file's data resource forks */
pb.hPB.fileParam.ioNamePtr = (StringPtr)srcName; pb.hPB.fileParam.ioNamePtr = (StringPtr)srcName;
@@ -247,7 +261,7 @@ static OSErr PreflightFileCopySpace(short srcVRefNum,
return ( error ); return ( error );
} }
#endif
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr FileCopy(short srcVRefNum, pascal OSErr FileCopy(short srcVRefNum,
@@ -331,7 +345,7 @@ pascal OSErr FileCopy(short srcVRefNum,
return ( err ); return ( err );
} }
if ( (err != paramErr) && hasCopyFile(infoBuffer) ) if ( (err != paramErr) && hasCopyFile(&infoBuffer) )
{ {
/* The source volume supports PBHCopyFile. */ /* The source volume supports PBHCopyFile. */
srcServerAdr = infoBuffer.vMServerAdr; srcServerAdr = infoBuffer.vMServerAdr;

View File

@@ -1,220 +1,271 @@
/* /*
** Apple Macintosh Developer Technical Support File: FileCopy.h
**
** FileCopy: A robust, general purpose file copy routine. Contains: A robust, general purpose file copy routine.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: Technology: MoreFiles
** Release: 1.5.2
** File: FileCopy.h
** Copyright: <20> 1992-2001 by Apple Computer, Inc., all rights reserved.
** Copyright <20> 1992-1998 Apple Computer, Inc.
** All rights reserved. Bugs?: For bug reports, consult the following page on
** the World Wide Web:
** You may incorporate this sample code into your applications without
** restriction, though the sample code has been provided "AS IS" and the http://developer.apple.com/bugreporter/
** 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. 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.
*/ */
#ifndef __FILECOPY__ #ifndef __FILECOPY__
#define __FILECOPY__ #define __FILECOPY__
#include <Types.h> #ifndef __MACTYPES__
#include <Files.h> #include <MacTypes.h>
#endif
#include "optim.h" #ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr FileCopy(short srcVRefNum, EXTERN_API( OSErr )
long srcDirID, FileCopy(
ConstStr255Param srcName, short srcVRefNum,
short dstVRefNum, long srcDirID,
long dstDirID, ConstStr255Param srcName,
ConstStr255Param dstPathname, short dstVRefNum,
ConstStr255Param copyName, long dstDirID,
void *copyBufferPtr, ConstStr255Param dstPathname,
long copyBufferSize, ConstStr255Param copyName,
Boolean preflight); void * copyBufferPtr,
/* <09> Duplicate a file and optionally rename it. long copyBufferSize,
The FileCopy function duplicates a file and optionally renames it. Boolean preflight);
Since the PBHCopyFile routine is only available on some
AFP server volumes under specific conditions, this routine
either uses PBHCopyFile, or does all of the work PBHCopyFile /*
does. The srcVRefNum, srcDirID and srcName are used to The FileCopy function duplicates a file and optionally renames it.
determine the location of the file to copy. The dstVRefNum Since the PBHCopyFile routine is only available on some
dstDirID and dstPathname are used to determine the location of AFP server volumes under specific conditions, this routine
the destination directory. If copyName <> NIL, then it points either uses PBHCopyFile, or does all of the work PBHCopyFile
to the name of the new file. If copyBufferPtr <> NIL, it does. The srcVRefNum, srcDirID and srcName are used to
points to a buffer of copyBufferSize that is used to copy determine the location of the file to copy. The dstVRefNum
the file's data. The larger the supplied buffer, the dstDirID and dstPathname are used to determine the location of
faster the copy. If copyBufferPtr = NIL, then this routine the destination directory. If copyName <> NIL, then it points
allocates a buffer in the application heap. If you pass a to the name of the new file. If copyBufferPtr <> NIL, it
copy buffer to this routine, make its size a multiple of 512 points to a buffer of copyBufferSize that is used to copy
($200) bytes for optimum performance. the file's data. The larger the supplied buffer, the
faster the copy. If copyBufferPtr = NIL, then this routine
srcVRefNum input: Source volume specification. allocates a buffer in the application heap. If you pass a
srcDirID input: Source directory ID. copy buffer to this routine, make its size a multiple of 512
srcName input: Source file name. ($200) bytes for optimum performance.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID. srcVRefNum input: Source volume specification.
dstPathname input: Pointer to destination directory name, or srcDirID input: Source directory ID.
nil when dstDirID specifies a directory. srcName input: Source file name.
copyName input: Points to the new file name if the file is dstVRefNum input: Destination volume specification.
to be renamed or nil if the file isn't to dstDirID input: Destination directory ID.
be renamed. dstPathname input: Pointer to destination directory name, or
copyBufferPtr input: Points to a buffer of copyBufferSize that nil when dstDirID specifies a directory.
is used the i/o buffer for the copy or copyName input: Points to the new file name if the file is
nil if you want FileCopy to allocate its to be renamed or nil if the file isn't to
own buffer in the application heap. be renamed.
copyBufferSize input: The size of the buffer pointed to copyBufferPtr input: Points to a buffer of copyBufferSize that
by copyBufferPtr. is used the i/o buffer for the copy or
preflight input: If true, FileCopy makes sure there are enough nil if you want FileCopy to allocate its
allocation blocks on the destination volume to own buffer in the application heap.
hold both the data and resource forks before copyBufferSize input: The size of the buffer pointed to
starting the copy. by copyBufferPtr.
preflight input: If true, FileCopy makes sure there are enough
Result Codes allocation blocks on the destination volume to
noErr 0 No error hold both the data and resource forks before
readErr <09>19 Driver does not respond to read requests starting the copy.
writErr <09>20 Driver does not respond to write requests
badUnitErr <09>21 Driver reference number does not Result Codes
match unit table noErr 0 No error
unitEmptyErr <09>22 Driver reference number specifies a readErr <20>19 Driver does not respond to read requests
nil handle in unit table writErr <20>20 Driver does not respond to write requests
abortErr <09>27 Request aborted by KillIO badUnitErr <20>21 Driver reference number does not
notOpenErr <09>28 Driver not open match unit table
dskFulErr -34 Destination volume is full unitEmptyErr <20>22 Driver reference number specifies a
nsvErr -35 No such volume nil handle in unit table
ioErr -36 I/O error abortErr <20>27 Request aborted by KillIO
bdNamErr -37 Bad filename notOpenErr <20>28 Driver not open
tmfoErr -42 Too many files open dskFulErr -34 Destination volume is full
fnfErr -43 Source file not found, or destination nsvErr -35 No such volume
directory does not exist ioErr -36 I/O error
wPrErr -44 Volume locked by hardware bdNamErr -37 Bad filename
fLckdErr -45 File is locked tmfoErr -42 Too many files open
vLckdErr -46 Destination volume is read-only fnfErr -43 Source file not found, or destination
fBsyErr -47 The source or destination file could directory does not exist
not be opened with the correct access wPrErr -44 Volume locked by hardware
modes fLckdErr -45 File is locked
dupFNErr -48 Destination file already exists vLckdErr -46 Destination volume is read-only
opWrErr -49 File already open for writing fBsyErr -47 The source or destination file could
paramErr -50 No default volume or function not not be opened with the correct access
supported by volume modes
permErr -54 File is already open and cannot be opened using specified deny modes dupFNErr -48 Destination file already exists
memFullErr -108 Copy buffer could not be allocated opWrErr -49 File already open for writing
dirNFErr -120 Directory not found or incomplete pathname paramErr -50 No default volume or function not
wrgVolTypErr -123 Function not supported by volume supported by volume
afpAccessDenied -5000 User does not have the correct access permErr -54 File is already open and cannot be opened using specified deny modes
afpDenyConflict -5006 The source or destination file could memFullErr -108 Copy buffer could not be allocated
not be opened with the correct access dirNFErr -120 Directory not found or incomplete pathname
modes wrgVolTypErr -123 Function not supported by volume
afpObjectTypeErr -5025 Source is a directory, directory not found afpAccessDenied -5000 User does not have the correct access
or incomplete pathname afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
__________ modes
afpObjectTypeErr -5025 Source is a directory, directory not found
Also see: FSpFileCopy, DirectoryCopy, FSpDirectoryCopy or incomplete pathname
__________
Also see: FSpFileCopy, DirectoryCopy, FSpDirectoryCopy
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr FSpFileCopy(const FSSpec *srcSpec, EXTERN_API( OSErr )
const FSSpec *dstSpec, FSpFileCopy(
ConstStr255Param copyName, const FSSpec * srcSpec,
void *copyBufferPtr, const FSSpec * dstSpec,
long copyBufferSize, ConstStr255Param copyName,
Boolean preflight); void * copyBufferPtr,
/* <09> Duplicate a file and optionally rename it. long copyBufferSize,
The FSpFileCopy function duplicates a file and optionally renames it. Boolean preflight);
Since the PBHCopyFile routine is only available on some
AFP server volumes under specific conditions, this routine
either uses PBHCopyFile, or does all of the work PBHCopyFile /*
does. The srcSpec is used to The FSpFileCopy function duplicates a file and optionally renames it.
determine the location of the file to copy. The dstSpec is Since the PBHCopyFile routine is only available on some
used to determine the location of the AFP server volumes under specific conditions, this routine
destination directory. If copyName <> NIL, then it points either uses PBHCopyFile, or does all of the work PBHCopyFile
to the name of the new file. If copyBufferPtr <> NIL, it does. The srcSpec is used to
points to a buffer of copyBufferSize that is used to copy determine the location of the file to copy. The dstSpec is
the file's data. The larger the supplied buffer, the used to determine the location of the
faster the copy. If copyBufferPtr = NIL, then this routine destination directory. If copyName <> NIL, then it points
allocates a buffer in the application heap. If you pass a to the name of the new file. If copyBufferPtr <> NIL, it
copy buffer to this routine, make its size a multiple of 512 points to a buffer of copyBufferSize that is used to copy
($200) bytes for optimum performance. the file's data. The larger the supplied buffer, the
faster the copy. If copyBufferPtr = NIL, then this routine
srcSpec input: An FSSpec record specifying the source file. allocates a buffer in the application heap. If you pass a
dstSpec input: An FSSpec record specifying the destination copy buffer to this routine, make its size a multiple of 512
directory. ($200) bytes for optimum performance.
copyName input: Points to the new file name if the file is
to be renamed or nil if the file isn't to srcSpec input: An FSSpec record specifying the source file.
be renamed. dstSpec input: An FSSpec record specifying the destination
copyBufferPtr input: Points to a buffer of copyBufferSize that directory.
is used the i/o buffer for the copy or copyName input: Points to the new file name if the file is
nil if you want FileCopy to allocate its to be renamed or nil if the file isn't to
own buffer in the application heap. be renamed.
copyBufferSize input: The size of the buffer pointed to copyBufferPtr input: Points to a buffer of copyBufferSize that
by copyBufferPtr. is used the i/o buffer for the copy or
preflight input: If true, FSpFileCopy makes sure there are nil if you want FileCopy to allocate its
enough allocation blocks on the destination own buffer in the application heap.
volume to hold both the data and resource forks copyBufferSize input: The size of the buffer pointed to
before starting the copy. by copyBufferPtr.
preflight input: If true, FSpFileCopy makes sure there are
Result Codes enough allocation blocks on the destination
noErr 0 No error volume to hold both the data and resource forks
readErr <09>19 Driver does not respond to read requests before starting the copy.
writErr <09>20 Driver does not respond to write requests
badUnitErr <09>21 Driver reference number does not Result Codes
match unit table noErr 0 No error
unitEmptyErr <09>22 Driver reference number specifies a readErr <20>19 Driver does not respond to read requests
nil handle in unit table writErr <20>20 Driver does not respond to write requests
abortErr <09>27 Request aborted by KillIO badUnitErr <20>21 Driver reference number does not
notOpenErr <09>28 Driver not open match unit table
dskFulErr -34 Destination volume is full unitEmptyErr <20>22 Driver reference number specifies a
nsvErr -35 No such volume nil handle in unit table
ioErr -36 I/O error abortErr <20>27 Request aborted by KillIO
bdNamErr -37 Bad filename notOpenErr <20>28 Driver not open
tmfoErr -42 Too many files open dskFulErr -34 Destination volume is full
fnfErr -43 Source file not found, or destination nsvErr -35 No such volume
directory does not exist ioErr -36 I/O error
wPrErr -44 Volume locked by hardware bdNamErr -37 Bad filename
fLckdErr -45 File is locked tmfoErr -42 Too many files open
vLckdErr -46 Destination volume is read-only fnfErr -43 Source file not found, or destination
fBsyErr -47 The source or destination file could directory does not exist
not be opened with the correct access wPrErr -44 Volume locked by hardware
modes fLckdErr -45 File is locked
dupFNErr -48 Destination file already exists vLckdErr -46 Destination volume is read-only
opWrErr -49 File already open for writing fBsyErr -47 The source or destination file could
paramErr -50 No default volume or function not not be opened with the correct access
supported by volume modes
permErr -54 File is already open and cannot be opened using specified deny modes dupFNErr -48 Destination file already exists
memFullErr -108 Copy buffer could not be allocated opWrErr -49 File already open for writing
dirNFErr -120 Directory not found or incomplete pathname paramErr -50 No default volume or function not
wrgVolTypErr -123 Function not supported by volume supported by volume
afpAccessDenied -5000 User does not have the correct access permErr -54 File is already open and cannot be opened using specified deny modes
afpDenyConflict -5006 The source or destination file could memFullErr -108 Copy buffer could not be allocated
not be opened with the correct access dirNFErr -120 Directory not found or incomplete pathname
modes wrgVolTypErr -123 Function not supported by volume
afpObjectTypeErr -5025 Source is a directory, directory not found afpAccessDenied -5000 User does not have the correct access
or incomplete pathname afpDenyConflict -5006 The source or destination file could
not be opened with the correct access
__________ modes
afpObjectTypeErr -5025 Source is a directory, directory not found
Also see: FileCopy, DirectoryCopy, FSpDirectoryCopy or incomplete pathname
__________
Also see: FileCopy, DirectoryCopy, FSpDirectoryCopy
*/ */
/*****************************************************************************/ /*****************************************************************************/
#include "OptimizationEnd.h"
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include "optimend.h" #endif /* __FILECOPY__ */
#endif /* __FILECOPY__ */

View File

@@ -1,35 +1,50 @@
/* /*
** Apple Macintosh Developer Technical Support File: FullPath.c
**
** Routines for dealing with full pathnames... if you really must. Contains: Routines for dealing with full pathnames... if you really must.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: MoreFiles
**
** File: FullPath.c Copyright: © 1995-2001 by Apple Computer, Inc., all rights reserved.
**
** Copyright © 1995-1998 Apple Computer, Inc. You may incorporate this sample code into your applications without
** All rights reserved. restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** You may incorporate this sample code into your applications without not permitted to do is to redistribute the source as "DSC Sample Code"
** restriction, though the sample code has been provided "AS IS" and the after having made changes. If you're going to re-distribute the source,
** responsibility for its operation is 100% yours. However, what you are we require that you make it clear in the source that the code was
** not permitted to do is to redistribute the source as "DSC Sample Code" descended from Apple Sample Code, but that you've made changes.
** 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 File Ownership:
** descended from Apple Sample Code, but that you've made changes.
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 <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Memory.h> #include <MacMemory.h>
#include <Files.h> #include <Files.h>
#include <TextUtils.h> #include <TextUtils.h>
#include <Aliases.h> #include <Aliases.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "fspcompa.h" #include "FSpCompat.h"
#include "fullpath.h" #include "FullPath.h"
/* /*
IMPORTANT NOTE: IMPORTANT NOTE:
@@ -112,79 +127,88 @@ pascal OSErr FSpGetFullPath(const FSSpec *spec,
*fullPathLength = 0; *fullPathLength = 0;
*fullPath = NULL; *fullPath = NULL;
// Default to noErr
realResult = noErr;
/* Make a copy of the input FSSpec that can be modified */ /* Default to noErr */
BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); realResult = result = noErr;
if ( tempSpec.parID == fsRtParID ) /* work around Nav Services "bug" (it returns invalid FSSpecs with empty names) */
if ( spec->name[0] == 0 )
{ {
/* The object is a volume */ result = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, spec->name, &tempSpec);
/* Add a colon to make it a full pathname */
++tempSpec.name[0];
tempSpec.name[tempSpec.name[0]] = ':';
/* We're done */
result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
} }
else else
{ {
/* The object isn't a volume */ /* Make a copy of the input FSSpec that can be modified */
BlockMoveData(spec, &tempSpec, sizeof(FSSpec));
/* Is the object a file or a directory? */ }
pb.dirInfo.ioNamePtr = tempSpec.name;
pb.dirInfo.ioVRefNum = tempSpec.vRefNum; if ( result == noErr )
pb.dirInfo.ioDrDirID = tempSpec.parID; {
pb.dirInfo.ioFDirIndex = 0; if ( tempSpec.parID == fsRtParID )
result = PBGetCatInfoSync(&pb);
// Allow file/directory name at end of path to not exist.
realResult = result;
if ( (result == noErr) || (result == fnfErr) )
{ {
/* if the object is a directory, append a colon so full pathname ends with colon */ /* The object is a volume */
if ( (result == noErr) && (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0 )
{
++tempSpec.name[0];
tempSpec.name[tempSpec.name[0]] = ':';
}
/* Put the object name in first */ /* Add a colon to make it a full pathname */
++tempSpec.name[0];
tempSpec.name[tempSpec.name[0]] = ':';
/* We're done */
result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
if ( result == noErr ) }
else
{
/* The object isn't a volume */
/* Is the object a file or a directory? */
pb.dirInfo.ioNamePtr = tempSpec.name;
pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
pb.dirInfo.ioDrDirID = tempSpec.parID;
pb.dirInfo.ioFDirIndex = 0;
result = PBGetCatInfoSync(&pb);
// Allow file/directory name at end of path to not exist.
realResult = result;
if ( (result == noErr) || (result == fnfErr) )
{ {
/* Get the ancestor directory names */ /* if the object is a directory, append a colon so full pathname ends with colon */
pb.dirInfo.ioNamePtr = tempSpec.name; if ( (result == noErr) && (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
pb.dirInfo.ioDrParID = tempSpec.parID;
do /* loop until we have an error or find the root directory */
{ {
pb.dirInfo.ioFDirIndex = -1; ++tempSpec.name[0];
pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; tempSpec.name[tempSpec.name[0]] = ':';
result = PBGetCatInfoSync(&pb); }
if ( result == noErr )
/* Put the object name in first */
result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]);
if ( result == noErr )
{
/* Get the ancestor directory names */
pb.dirInfo.ioNamePtr = tempSpec.name;
pb.dirInfo.ioVRefNum = tempSpec.vRefNum;
pb.dirInfo.ioDrParID = tempSpec.parID;
do /* loop until we have an error or find the root directory */
{ {
/* Append colon to directory name */ pb.dirInfo.ioFDirIndex = -1;
++tempSpec.name[0]; pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
tempSpec.name[tempSpec.name[0]] = ':'; result = PBGetCatInfoSync(&pb);
if ( result == noErr )
/* Add directory name to beginning of fullPath */ {
(void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1], tempSpec.name[0]); /* Append colon to directory name */
result = MemError(); ++tempSpec.name[0];
} tempSpec.name[tempSpec.name[0]] = ':';
} while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) );
/* Add directory name to beginning of fullPath */
(void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1], tempSpec.name[0]);
result = MemError();
}
} while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) );
}
} }
} }
} }
if ( result == noErr ) if ( result == noErr )
{ {
/* Return the length */ /* Return the length */
#if TARGET_CARBON
*fullPathLength = GetHandleSize(*fullPath); *fullPathLength = GetHandleSize(*fullPath);
#else
*fullPathLength = InlineGetHandleSize(*fullPath);
#endif
result = realResult; // return realResult in case it was fnfErr result = realResult; // return realResult in case it was fnfErr
} }
else else
@@ -220,6 +244,14 @@ pascal OSErr FSpLocationFromFullPath(short fullPathLength,
/* Let the Alias Manager resolve the alias. */ /* Let the Alias Manager resolve the alias. */
result = ResolveAlias(NULL, alias, spec, &wasChanged); result = ResolveAlias(NULL, alias, spec, &wasChanged);
/* work around Alias Mgr sloppy volume matching bug */
if ( spec->vRefNum == 0 )
{
/* invalidate wrong FSSpec */
spec->parID = 0;
spec->name[0] = 0;
result = nsvErr;
}
DisposeHandle((Handle)alias); /* Free up memory used */ DisposeHandle((Handle)alias); /* Free up memory used */
} }
return ( result ); return ( result );

View File

@@ -1,243 +1,311 @@
/* /*
** Apple Macintosh Developer Technical Support File: FullPath.h
**
** Routines for dealing with full pathnames... if you really must. Contains: Routines for dealing with full pathnames... if you really must.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: Technology: MoreFiles
** Release: 1.5.2
** File: FullPath.h
** Copyright: <20> 1995-2001 by Apple Computer, Inc., all rights reserved.
** Copyright <20> 1995-1998 Apple Computer, Inc.
** All rights reserved. Bugs?: For bug reports, consult the following page on
** the World Wide Web:
** You may incorporate this sample code into your applications without
** restriction, though the sample code has been provided "AS IS" and the http://developer.apple.com/bugreporter/
** 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. 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.
*/
/*
IMPORTANT NOTE:
The use of full pathnames is strongly discouraged. Full pathnames are
particularly unreliable as a means of identifying files, directories
or volumes within your application, for two primary reasons:
<20> The user can change the name of any element in the path at
virtually any time.
<20> Volume names on the Macintosh are *not* unique. Multiple
mounted volumes can have the same name. For this reason, the use of
a full pathname to identify a specific volume may not produce the
results you expect. If more than one volume has the same name and
a full pathname is used, the File Manager currently uses the first
mounted volume it finds with a matching name in the volume queue.
In general, you should use a file<6C>s name, parent directory ID, and
volume reference number to identify a file you want to open, delete,
or otherwise manipulate.
If you need to remember the location of a particular file across
subsequent system boots, use the Alias Manager to create an alias
record describing the file. If the Alias Manager is not available, you
can save the file<6C>s name, its parent directory ID, and the name of the
volume on which it<69>s located. Although none of these methods is
foolproof, they are much more reliable than using full pathnames to
identify files.
Nonetheless, it is sometimes useful to display a file<6C>s full pathname
to the user. For example, a backup utility might display a list of full
pathnames of files as it copies them onto the backup medium. Or, a
utility might want to display a dialog box showing the full pathname of
a file when it needs the user<65>s confirmation to delete the file. No
matter how unreliable full pathnames may be from a file-specification
viewpoint, users understand them more readily than volume reference
numbers or directory IDs. (Hint: Use the TruncString function from
TextUtils.h with truncMiddle as the truncWhere argument to shorten
full pathnames to a displayable length.)
The following technique for constructing the full pathname of a file is
intended for display purposes only. Applications that depend on any
particular structure of a full pathname are likely to fail on alternate
foreign file systems or under future system software versions.
*/ */
#ifndef __FULLPATH__ #ifndef __FULLPATH__
#define __FULLPATH__ #define __FULLPATH__
#include <Types.h> #ifndef __MACTYPES__
#include <Files.h> #include <MacTypes.h>
#endif
#include "optim.h" #ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/
EXTERN_API( OSErr )
GetFullPath(
short vRefNum,
long dirID,
ConstStr255Param name,
short * fullPathLength,
Handle * fullPath);
/* /*
IMPORTANT NOTE: The GetFullPath function builds a full pathname to the specified
object. The full pathname is returned in the newly created handle
The use of full pathnames is strongly discouraged. Full pathnames are fullPath and the length of the full pathname is returned in
particularly unreliable as a means of identifying files, directories fullPathLength. Your program is responsible for disposing of the
or volumes within your application, for two primary reasons: fullPath handle.
<09> The user can change the name of any element in the path at Note that a full pathname can be made to a file/directory that does not
virtually any time. yet exist if all directories up to that file/directory exist. In this case,
<09> Volume names on the Macintosh are *not* unique. Multiple GetFullPath will return a fnfErr.
mounted volumes can have the same name. For this reason, the use of
a full pathname to identify a specific volume may not produce the vRefNum input: Volume specification.
results you expect. If more than one volume has the same name and dirID input: Directory ID.
a full pathname is used, the File Manager currently uses the first name input: Pointer to object name, or nil when dirID
mounted volume it finds with a matching name in the volume queue. specifies a directory that's the object.
fullPathLength output: The number of characters in the full pathname.
In general, you should use a file<EFBFBD>s name, parent directory ID, and If the function fails to create a full
volume reference number to identify a file you want to open, delete, pathname, it sets fullPathLength to 0.
or otherwise manipulate. fullPath output: A handle to the newly created full pathname
buffer. If the function fails to create a
If you need to remember the location of a particular file across full pathname, it sets fullPath to NULL.
subsequent system boots, use the Alias Manager to create an alias
record describing the file. If the Alias Manager is not available, you Result Codes
can save the file<6C>s name, its parent directory ID, and the name of the noErr 0 No error
volume on which it<69>s located. Although none of these methods is nsvErr -35 No such volume
foolproof, they are much more reliable than using full pathnames to ioErr -36 I/O error
identify files. bdNamErr -37 Bad filename
fnfErr -43 File or directory does not exist (fullPath
Nonetheless, it is sometimes useful to display a file<6C>s full pathname and fullPathLength are still valid)
to the user. For example, a backup utility might display a list of full paramErr -50 No default volume
pathnames of files as it copies them onto the backup medium. Or, a memFullErr -108 Not enough memory
utility might want to display a dialog box showing the full pathname of dirNFErr -120 Directory not found or incomplete pathname
a file when it needs the user<65>s confirmation to delete the file. No afpAccessDenied -5000 User does not have the correct access
matter how unreliable full pathnames may be from a file-specification afpObjectTypeErr -5025 Directory not found or incomplete pathname
viewpoint, users understand them more readily than volume reference
numbers or directory IDs. (Hint: Use the TruncString function from __________
TextUtils.h with truncMiddle as the truncWhere argument to shorten
full pathnames to a displayable length.) See also: FSpGetFullPath
The following technique for constructing the full pathname of a file is
intended for display purposes only. Applications that depend on any
particular structure of a full pathname are likely to fail on alternate
foreign file systems or under future system software versions.
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr GetFullPath(short vRefNum, EXTERN_API( OSErr )
long dirID, FSpGetFullPath(
ConstStr255Param name, const FSSpec * spec,
short *fullPathLength, short * fullPathLength,
Handle *fullPath); Handle * fullPath);
/* <09> Get a full pathname to a volume, directory or file.
The GetFullPath function builds a full pathname to the specified
object. The full pathname is returned in the newly created handle /*
fullPath and the length of the full pathname is returned in The GetFullPath function builds a full pathname to the specified
fullPathLength. Your program is responsible for disposing of the object. The full pathname is returned in the newly created handle
fullPath handle. fullPath and the length of the full pathname is returned in
fullPathLength. Your program is responsible for disposing of the
Note that a full pathname can be made to a file/directory that does not fullPath handle.
yet exist if all directories up to that file/directory exist. In this case,
GetFullPath will return a fnfErr. Note that a full pathname can be made to a file/directory that does not
yet exist if all directories up to that file/directory exist. In this case,
vRefNum input: Volume specification. FSpGetFullPath will return a fnfErr.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID IMPORTANT: The definition of a FSSpec is a volume reference number (not a
specifies a directory that's the object. drive number, working directory number, or 0), a parent directory ID (not 0),
fullPathLength output: The number of characters in the full pathname. and the name of a file or folder (not an empty name, a full pathname, or
If the function fails to create a full a partial pathname containing one or more colon (:) characters).
pathname, it sets fullPathLength to 0. FSpGetFullPath assumes it is getting a FSSpec that matches the rules.
fullPath output: A handle to the newly created full pathname If you have an FSSpec record that wasn't created by FSMakeFSSpec (or
buffer. If the function fails to create a FSMakeFSSpecCompat from FSpCompat in MoreFiles which correctly builds
full pathname, it sets fullPath to NULL. FSSpecs), you should call GetFullPath instead of FSpGetFullPath.
Result Codes spec input: An FSSpec record specifying the object.
noErr 0 No error fullPathLength output: The number of characters in the full pathname.
nsvErr -35 No such volume If the function fails to create a full pathname,
ioErr -36 I/O error it sets fullPathLength to 0.
bdNamErr -37 Bad filename fullPath output: A handle to the newly created full pathname
fnfErr -43 File or directory does not exist (fullPath buffer. If the function fails to create a
and fullPathLength are still valid) full pathname, it sets fullPath to NULL.
paramErr -50 No default volume
memFullErr -108 Not enough memory Result Codes
dirNFErr -120 Directory not found or incomplete pathname noErr 0 No error
afpAccessDenied -5000 User does not have the correct access nsvErr -35 No such volume
afpObjectTypeErr -5025 Directory not found or incomplete pathname ioErr -36 I/O error
bdNamErr -37 Bad filename
__________ fnfErr -43 File or directory does not exist (fullPath
and fullPathLength are still valid)
See also: FSpGetFullPath paramErr -50 No default volume
memFullErr -108 Not enough memory
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
See also: GetFullPath
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr FSpGetFullPath(const FSSpec *spec, EXTERN_API( OSErr )
short *fullPathLength, FSpLocationFromFullPath(
Handle *fullPath); short fullPathLength,
/* <09> Get a full pathname to a volume, directory or file. const void * fullPath,
The GetFullPath function builds a full pathname to the specified FSSpec * spec);
object. The full pathname is returned in the newly created handle
fullPath and the length of the full pathname is returned in
fullPathLength. Your program is responsible for disposing of the /*
fullPath handle. The FSpLocationFromFullPath function returns a FSSpec to the object
specified by full pathname. This function requires the Alias Manager.
Note that a full pathname can be made to a file/directory that does not
yet exist if all directories up to that file/directory exist. In this case, fullPathLength input: The number of characters in the full pathname
FSpGetFullPath will return a fnfErr. of the target.
fullPath input: A pointer to a buffer that contains the full
spec input: An FSSpec record specifying the object. pathname of the target. The full pathname
fullPathLength output: The number of characters in the full pathname. starts with the name of the volume, includes
If the function fails to create a full pathname, all of the directory names in the path to the
it sets fullPathLength to 0. target, and ends with the target name.
fullPath output: A handle to the newly created full pathname spec output: An FSSpec record specifying the object.
buffer. If the function fails to create a
full pathname, it sets fullPath to NULL. Result Codes
noErr 0 No error
Result Codes nsvErr -35 The volume is not mounted
noErr 0 No error fnfErr -43 Target not found, but volume and parent
nsvErr -35 No such volume directory found
ioErr -36 I/O error paramErr -50 Parameter error
bdNamErr -37 Bad filename usrCanceledErr -128 The user canceled the operation
fnfErr -43 File or directory does not exist (fullPath
and fullPathLength are still valid) __________
paramErr -50 No default volume
memFullErr -108 Not enough memory See also: LocationFromFullPath
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
See also: GetFullPath
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr FSpLocationFromFullPath(short fullPathLength, EXTERN_API( OSErr )
const void *fullPath, LocationFromFullPath(
FSSpec *spec); short fullPathLength,
/* <09> Get a FSSpec from a full pathname. const void * fullPath,
The FSpLocationFromFullPath function returns a FSSpec to the object short * vRefNum,
specified by full pathname. This function requires the Alias Manager. long * parID,
Str31 name);
fullPathLength input: The number of characters in the full pathname
of the target.
fullPath input: A pointer to a buffer that contains the full /*
pathname of the target. The full pathname The LocationFromFullPath function returns the volume reference number,
starts with the name of the volume, includes parent directory ID and name of the object specified by full pathname.
all of the directory names in the path to the This function requires the Alias Manager.
target, and ends with the target name.
spec output: An FSSpec record specifying the object. fullPathLength input: The number of characters in the full pathname
of the target.
Result Codes fullPath input: A pointer to a buffer that contains the full
noErr 0 No error pathname of the target. The full pathname starts
nsvErr -35 The volume is not mounted with the name of the volume, includes all of
fnfErr -43 Target not found, but volume and parent the directory names in the path to the target,
directory found and ends with the target name.
paramErr -50 Parameter error vRefNum output: The volume reference number.
usrCanceledErr -128 The user canceled the operation parID output: The parent directory ID of the specified object.
name output: The name of the specified object.
__________
Result Codes
See also: LocationFromFullPath noErr 0 No error
nsvErr -35 The volume is not mounted
fnfErr -43 Target not found, but volume and parent
directory found
paramErr -50 Parameter error
usrCanceledErr -128 The user canceled the operation
__________
See also: FSpLocationFromFullPath
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr LocationFromFullPath(short fullPathLength, #include "OptimizationEnd.h"
const void *fullPath,
short *vRefNum,
long *parID,
Str31 name);
/* <09> Get an object's location from a full pathname.
The LocationFromFullPath function returns the volume reference number,
parent directory ID and name of the object specified by full pathname.
This function requires the Alias Manager.
fullPathLength input: The number of characters in the full pathname
of the target.
fullPath input: A pointer to a buffer that contains the full
pathname of the target. The full pathname starts
with the name of the volume, includes all of
the directory names in the path to the target,
and ends with the target name.
vRefNum output: The volume reference number.
parID output: The parent directory ID of the specified object.
name output: The name of the specified object.
Result Codes
noErr 0 No error
nsvErr -35 The volume is not mounted
fnfErr -43 Target not found, but volume and parent
directory found
paramErr -50 Parameter error
usrCanceledErr -128 The user canceled the operation
__________
See also: FSpLocationFromFullPath
*/
/*****************************************************************************/ #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include "optimend.h" #endif /* __FULLPATH__ */
#endif /* __FULLPATH__ */

View File

@@ -1,171 +0,0 @@
/*
** IterateDirectory: File Manager directory iterator routines.
**
** by Jim Luther
**
** File: IterateDirectory.h
**
** Copyright <20> 1995-1998 Jim Luther and 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.
**
** IterateDirectory is designed to drop into the MoreFiles sample code
** library I wrote while in Apple Developer Technical Support
*/
#ifndef __ITERATEDIRECTORY__
#define __ITERATEDIRECTORY__
#include <Types.h>
#include <Files.h>
#include "optim.h"
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
typedef pascal void (*IterateFilterProcPtr) (const CInfoPBRec * const cpbPtr,
Boolean *quitFlag,
void *yourDataPtr);
/* <09> Prototype for the IterateFilterProc function IterateDirectory calls.
This is the prototype for the IterateFilterProc function which is
called once for each file and directory found by IterateDirectory. The
IterateFilterProc gets a pointer to the CInfoPBRec that IterateDirectory
used to call PBGetCatInfo. The IterateFilterProc can use the read-only
data in the CInfoPBRec for whatever it wants.
If the IterateFilterProc wants to stop IterateDirectory, it can set
quitFlag to true (quitFlag will be passed to the IterateFilterProc
false).
The yourDataPtr parameter can point to whatever data structure you might
want to access from within the IterateFilterProc.
cpbPtr input: A pointer to the CInfoPBRec that IterateDirectory
used to call PBGetCatInfo. The CInfoPBRec and the
data it points to must not be changed by your
IterateFilterProc.
quitFlag output: Your IterateFilterProc can set quitFlag to true
if it wants to stop IterateDirectory.
yourDataPtr input: A pointer to whatever data structure you might
want to access from within the IterateFilterProc.
__________
Also see: IterateDirectory, FSpIterateDirectory
*/
#define CallIterateFilterProc(userRoutine, cpbPtr, quitFlag, yourDataPtr) \
(*(userRoutine))((cpbPtr), (quitFlag), (yourDataPtr))
/*****************************************************************************/
pascal OSErr IterateDirectory(short vRefNum,
long dirID,
ConstStr255Param name,
unsigned short maxLevels,
IterateFilterProcPtr iterateFilter,
void *yourDataPtr);
/* <09> Iterate (scan) through a directory's content.
The IterateDirectory function performs a recursive iteration (scan) of
the specified directory and calls your IterateFilterProc function once
for each file and directory found.
The maxLevels parameter lets you control how deep the recursion goes.
If maxLevels is 1, IterateDirectory only scans the specified directory;
if maxLevels is 2, IterateDirectory scans the specified directory and
one subdirectory below the specified directory; etc. Set maxLevels to
zero to scan all levels.
The yourDataPtr parameter can point to whatever data structure you might
want to access from within the IterateFilterProc.
vRefNum input: Volume specification.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID
specifies a directory that's the object.
maxLevels input: Maximum number of directory levels to scan or
zero to scan all directory levels.
iterateFilter input: A pointer to the routine you want called once
for each file and directory found by
IterateDirectory.
yourDataPtr input: A pointer to whatever data structure you might
want to access from within the IterateFilterProc.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
paramErr -50 No default volume or iterateFilter was NULL
dirNFErr -120 Directory not found or incomplete pathname
or a file was passed instead of a directory
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
See also: IterateFilterProcPtr, FSpIterateDirectory
*/
/*****************************************************************************/
pascal OSErr FSpIterateDirectory(const FSSpec *spec,
unsigned short maxLevels,
IterateFilterProcPtr iterateFilter,
void *yourDataPtr);
/* <09> Iterate (scan) through a directory's content.
The FSpIterateDirectory function performs a recursive iteration (scan)
of the specified directory and calls your IterateFilterProc function once
for each file and directory found.
The maxLevels parameter lets you control how deep the recursion goes.
If maxLevels is 1, FSpIterateDirectory only scans the specified directory;
if maxLevels is 2, FSpIterateDirectory scans the specified directory and
one subdirectory below the specified directory; etc. Set maxLevels to
zero to scan all levels.
The yourDataPtr parameter can point to whatever data structure you might
want to access from within the IterateFilterProc.
spec input: An FSSpec record specifying the directory to scan.
maxLevels input: Maximum number of directory levels to scan or
zero to scan all directory levels.
iterateFilter input: A pointer to the routine you want called once
for each file and directory found by
FSpIterateDirectory.
yourDataPtr input: A pointer to whatever data structure you might
want to access from within the IterateFilterProc.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
paramErr -50 No default volume or iterateFilter was NULL
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
See also: IterateFilterProcPtr, IterateDirectory
*/
/*****************************************************************************/
#ifdef __cplusplus
}
#endif
#include "optimend.h"
#endif /* __ITERATEDIRECTORY__ */

View File

@@ -1,29 +1,47 @@
/* /*
** IterateDirectory: File Manager directory iterator routines. File: IterateDirectory.c
**
** by Jim Luther Contains: File Manager directory iterator routines.
**
** File: IterateDirectory.c Version: MoreFiles
**
** Copyright © 1995-1998 Jim Luther and Apple Computer, Inc. Copyright: © 1995-2001 by Jim Luther and Apple Computer, Inc., all rights reserved.
** All rights reserved.
** You may incorporate this sample code into your applications without
** You may incorporate this sample code into your applications without restriction, though the sample code has been provided "AS IS" and the
** restriction, though the sample code has been provided "AS IS" and the responsibility for its operation is 100% yours. However, what you are
** responsibility for its operation is 100% yours. 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,
** IterateDirectory is designed to drop into the MoreFiles sample code we require that you make it clear in the source that the code was
** library I wrote while in Apple Developer Technical Support 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 <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Files.h> #include <Files.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "iterated.h" #include "IterateDirectory.h"
/* /*
** Type definitions ** Type definitions
@@ -34,13 +52,8 @@
** and to hold global information that might be needed at any time. ** and to hold global information that might be needed at any time.
*/ */
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif #endif
struct IterateGlobals struct IterateGlobals
{ {
IterateFilterProcPtr iterateFilter; /* pointer to IterateFilterProc */ IterateFilterProcPtr iterateFilter; /* pointer to IterateFilterProc */
@@ -52,13 +65,8 @@ struct IterateGlobals
unsigned short currentLevel; /* The current level IterateLevel is on */ unsigned short currentLevel; /* The current level IterateLevel is on */
void *yourDataPtr; /* A pointer to caller data the filter may need to access */ void *yourDataPtr; /* A pointer to caller data the filter may need to access */
}; };
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset #pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif #endif
typedef struct IterateGlobals IterateGlobals; typedef struct IterateGlobals IterateGlobals;
@@ -102,7 +110,7 @@ static void IterateDirectoryLevel(long dirID,
CallIterateFilterProc(theGlobals->iterateFilter, &theGlobals->cPB, &theGlobals->quitFlag, theGlobals->yourDataPtr); CallIterateFilterProc(theGlobals->iterateFilter, &theGlobals->cPB, &theGlobals->quitFlag, theGlobals->yourDataPtr);
/* Is it a directory? */ /* Is it a directory? */
if ( (theGlobals->cPB.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (theGlobals->cPB.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
/* We have a directory */ /* We have a directory */
if ( !theGlobals->quitFlag ) if ( !theGlobals->quitFlag )

View File

@@ -0,0 +1,222 @@
/*
File: IterateDirectory.h
Contains: File Manager directory iterator routines.
Version: Technology: MoreFiles
Release: 1.5.2
Copyright: <20> 1995-2001 by Jim Luther and Apple Computer, Inc., all rights reserved.
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
/*
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.
*/
#ifndef __ITERATEDIRECTORY__
#define __ITERATEDIRECTORY__
#ifndef __MACTYPES__
#include <MacTypes.h>
#endif
#ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/
typedef CALLBACK_API( void , IterateFilterProcPtr )(const CInfoPBRec *cpbPtr, Boolean *quitFlag, void *yourDataPtr);
/*
This is the prototype for the IterateFilterProc function which is
called once for each file and directory found by IterateDirectory. The
IterateFilterProc gets a pointer to the CInfoPBRec that IterateDirectory
used to call PBGetCatInfo. The IterateFilterProc can use the read-only
data in the CInfoPBRec for whatever it wants.
If the IterateFilterProc wants to stop IterateDirectory, it can set
quitFlag to true (quitFlag will be passed to the IterateFilterProc
false).
The yourDataPtr parameter can point to whatever data structure you might
want to access from within the IterateFilterProc.
cpbPtr input: A pointer to the CInfoPBRec that IterateDirectory
used to call PBGetCatInfo. The CInfoPBRec and the
data it points to must not be changed by your
IterateFilterProc.
quitFlag output: Your IterateFilterProc can set quitFlag to true
if it wants to stop IterateDirectory.
yourDataPtr input: A pointer to whatever data structure you might
want to access from within the IterateFilterProc.
__________
Also see: IterateDirectory, FSpIterateDirectory
*/
#define CallIterateFilterProc(userRoutine, cpbPtr, quitFlag, yourDataPtr) \
(*(userRoutine))((cpbPtr), (quitFlag), (yourDataPtr))
/*****************************************************************************/
EXTERN_API( OSErr )
IterateDirectory(
short vRefNum,
long dirID,
ConstStr255Param name,
unsigned short maxLevels,
IterateFilterProcPtr iterateFilter,
void * yourDataPtr);
/*
The IterateDirectory function performs a recursive iteration (scan) of
the specified directory and calls your IterateFilterProc function once
for each file and directory found.
The maxLevels parameter lets you control how deep the recursion goes.
If maxLevels is 1, IterateDirectory only scans the specified directory;
if maxLevels is 2, IterateDirectory scans the specified directory and
one subdirectory below the specified directory; etc. Set maxLevels to
zero to scan all levels.
The yourDataPtr parameter can point to whatever data structure you might
want to access from within the IterateFilterProc.
vRefNum input: Volume specification.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID
specifies a directory that's the object.
maxLevels input: Maximum number of directory levels to scan or
zero to scan all directory levels.
iterateFilter input: A pointer to the routine you want called once
for each file and directory found by
IterateDirectory.
yourDataPtr input: A pointer to whatever data structure you might
want to access from within the IterateFilterProc.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
paramErr -50 No default volume or iterateFilter was NULL
dirNFErr -120 Directory not found or incomplete pathname
or a file was passed instead of a directory
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
See also: IterateFilterProcPtr, FSpIterateDirectory
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpIterateDirectory(
const FSSpec * spec,
unsigned short maxLevels,
IterateFilterProcPtr iterateFilter,
void * yourDataPtr);
/*
The FSpIterateDirectory function performs a recursive iteration (scan)
of the specified directory and calls your IterateFilterProc function once
for each file and directory found.
The maxLevels parameter lets you control how deep the recursion goes.
If maxLevels is 1, FSpIterateDirectory only scans the specified directory;
if maxLevels is 2, FSpIterateDirectory scans the specified directory and
one subdirectory below the specified directory; etc. Set maxLevels to
zero to scan all levels.
The yourDataPtr parameter can point to whatever data structure you might
want to access from within the IterateFilterProc.
spec input: An FSSpec record specifying the directory to scan.
maxLevels input: Maximum number of directory levels to scan or
zero to scan all directory levels.
iterateFilter input: A pointer to the routine you want called once
for each file and directory found by
FSpIterateDirectory.
yourDataPtr input: A pointer to whatever data structure you might
want to access from within the IterateFilterProc.
Result Codes
noErr 0 No error
nsvErr -35 No such volume
ioErr -36 I/O error
bdNamErr -37 Bad filename
fnfErr -43 File not found
paramErr -50 No default volume or iterateFilter was NULL
dirNFErr -120 Directory not found or incomplete pathname
afpAccessDenied -5000 User does not have the correct access
afpObjectTypeErr -5025 Directory not found or incomplete pathname
__________
See also: IterateFilterProcPtr, IterateDirectory
*/
/*****************************************************************************/
#include "OptimizationEnd.h"
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#endif /* __ITERATEDIRECTORY__ */

View File

@@ -1,541 +0,0 @@
/*
** Apple Macintosh Developer Technical Support
**
** A collection of useful high-level Desktop Manager routines.
** If the Desktop Manager isn't available, use the Desktop file
** for 'read' operations.
**
** We do more because we can...
**
** by Jim Luther and Nitin Ganatra, Apple Developer Technical Support Emeriti
**
** File: MoreDesktopMgr.h
**
** Copyright <20> 1992-1998 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.
*/
#ifndef __MOREDESKTOPMGR__
#define __MOREDESKTOPMGR__
#include <Types.h>
#include <Files.h>
#include "optim.h"
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
pascal OSErr DTOpen(ConstStr255Param volName,
short vRefNum,
short *dtRefNum,
Boolean *newDTDatabase);
/* <09> Open a volume's desktop database and return the desktop database refNum.
The DTOpen function opens a volume's desktop database. It returns
the reference number of the desktop database and indicates if the
desktop database was created as a result of this call (if it was created,
then it is empty).
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
dtRefNum output: The reference number of Desktop Manager's
desktop database on the specified volume.
newDTDatabase output: true if the desktop database was created as a
result of this call and thus empty.
false if the desktop database was already created,
or if it could not be determined if it was already
created.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
*/
/*****************************************************************************/
pascal OSErr DTXGetAPPL(ConstStr255Param volName,
short vRefNum,
OSType creator,
Boolean searchCatalog,
short *applVRefNum,
long *applParID,
Str255 applName);
/* <09> Find an application on a volume that can open a file with a given creator.
The DTXGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails and searchCatalog is true, then it tries to find an application
with the specified creator using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
searchCatalog input: If true, search the catalog for the application
if it isn't found in the desktop database.
applVRefNum output: The volume reference number of the volume the
application is on.
applParID output: The parent directory ID of the application.
applName output: The name of the application.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTGetAPPL
*/
/*****************************************************************************/
pascal OSErr FSpDTXGetAPPL(ConstStr255Param volName,
short vRefNum,
OSType creator,
Boolean searchCatalog,
FSSpec *spec);
/* <09> Find an application on a volume that can open a file with a given creator.
The FSpDTXGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails and searchCatalog is true, then it tries to find an application
with the specified creator using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
searchCatalog input: If true, search the catalog for the application
if it isn't found in the desktop database.
spec output: FSSpec record containing the application name and
location.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTGetAPPL
*/
/*****************************************************************************/
pascal OSErr DTGetAPPL(ConstStr255Param volName,
short vRefNum,
OSType creator,
short *applVRefNum,
long *applParID,
Str255 applName);
/* <09> Find an application on a volume that can open a file with a given creator.
The DTGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails, then it tries to find an application with the specified creator
using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
applVRefNum output: The volume reference number of the volume the
application is on.
applParID output: The parent directory ID of the application.
applName output: The name of the application.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTGetAPPL
*/
/*****************************************************************************/
pascal OSErr FSpDTGetAPPL(ConstStr255Param volName,
short vRefNum,
OSType creator,
FSSpec *spec);
/* <09> Find an application on a volume that can open a file with a given creator.
The FSpDTGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails, then it tries to find an application with the specified creator
using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
spec output: FSSpec record containing the application name and
location.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTGetAPPL
*/
/*****************************************************************************/
pascal OSErr DTGetIcon(ConstStr255Param volName,
short vRefNum,
short iconType,
OSType fileCreator,
OSType fileType,
Handle *iconHandle);
/* <09> Get an icon from the desktop database or Desktop file.
The DTGetIcon function retrieves the specified icon and returns it in
a newly created handle. The icon is retrieves from the Desktop Manager
or if the Desktop Manager is not available, from the Finder's Desktop
file. Your program is responsible for disposing of the handle when it is
done using the icon.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
iconType input: The icon type as defined in Files.h. Valid values are:
kLargeIcon
kLarge4BitIcon
kLarge8BitIcon
kSmallIcon
kSmall4BitIcon
kSmall8BitIcon
fileCreator input: The icon's creator type.
fileType input: The icon's file type.
iconHandle output: A Handle containing the newly created icon.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 Volume doesn't support this function
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
memFullErr -108 iconHandle could not be allocated
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
*/
/*****************************************************************************/
pascal OSErr DTSetComment(short vRefNum,
long dirID,
ConstStr255Param name,
ConstStr255Param comment);
/* <09> Set a file or directory's Finder comment field.
The DTSetComment function sets a file or directory's Finder comment
field. The volume must support the Desktop Manager because you only
have read access to the Desktop file.
vRefNum input: Volume specification.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID
specifies a directory that's the object.
comment input: The comment to add. Comments are limited to 200 characters;
longer comments are truncated.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <09>43 File or directory doesn<73>t exist
paramErr -50 Volume doesn't support this function
wPrErr <09>44 Volume is locked through hardware
vLckdErr <09>46 Volume is locked through software
rfNumErr <09>51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
__________
Also see: DTCopyComment, FSpDTCopyComment, FSpDTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
pascal OSErr FSpDTSetComment(const FSSpec *spec,
ConstStr255Param comment);
/* <09> Set a file or directory's Finder comment field.
The FSpDTSetComment function sets a file or directory's Finder comment
field. The volume must support the Desktop Manager because you only
have read access to the Desktop file.
spec input: An FSSpec record specifying the file or directory.
comment input: The comment to add. Comments are limited to 200 characters;
longer comments are truncated.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <09>43 File or directory doesn<73>t exist
wPrErr <09>44 Volume is locked through hardware
vLckdErr <09>46 Volume is locked through software
rfNumErr <09>51 Reference number invalid
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
__________
Also see: DTCopyComment, FSpDTCopyComment, DTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
pascal OSErr DTGetComment(short vRefNum,
long dirID,
ConstStr255Param name,
Str255 comment);
/* <09> Get a file or directory's Finder comment field (if any).
The DTGetComment function gets a file or directory's Finder comment
field (if any) from the Desktop Manager or if the Desktop Manager is
not available, from the Finder's Desktop file.
IMPORTANT NOTE: Inside Macintosh says that comments are up to
200 characters. While that may be correct for the HFS file system's
Desktop Manager, other file systems (such as Apple Photo Access) return
up to 255 characters. Make sure the comment buffer is a Str255 or you'll
regret it.
vRefNum input: Volume specification.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID
specifies a directory that's the object.
comment output: A Str255 where the comment is to be returned.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr -43 File not found
paramErr -50 Volume doesn't support this function
rfNumErr <09>51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTCopyComment, FSpDTCopyComment, DTSetComment, FSpDTSetComment,
FSpDTGetComment
*/
/*****************************************************************************/
pascal OSErr FSpDTGetComment(const FSSpec *spec,
Str255 comment);
/* <09> Get a file or directory's Finder comment field (if any).
The FSpDTGetComment function gets a file or directory's Finder comment
field (if any) from the Desktop Manager or if the Desktop Manager is
not available, from the Finder's Desktop file.
IMPORTANT NOTE: Inside Macintosh says that comments are up to
200 characters. While that may be correct for the HFS file system's
Desktop Manager, other file systems (such as Apple Photo Access) return
up to 255 characters. Make sure the comment buffer is a Str255 or you'll
regret it.
spec input: An FSSpec record specifying the file or directory.
comment output: A Str255 where the comment is to be returned.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr -43 File not found
paramErr -50 Volume doesn't support this function
rfNumErr <09>51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTCopyComment, FSpDTCopyComment, DTSetComment, FSpDTSetComment,
DTGetComment
*/
/*****************************************************************************/
pascal OSErr DTCopyComment(short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName);
/* <09> Copy the file or folder comment from the source to the destination object.
The DTCopyComment function copies the file or folder comment from the
source to the destination object. The destination volume must support
the Desktop Manager because you only have read access to the Desktop file.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Pointer to source object name, or nil when srcDirID
specifies a directory that's the object.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Pointer to destination object name, or nil when
dstDirID specifies a directory that's the object.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <09>43 File or directory doesn<73>t exist
wPrErr <09>44 Volume is locked through hardware
vLckdErr <09>46 Volume is locked through software
paramErr -50 Volume doesn't support this function
rfNumErr <09>51 Reference number invalid
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTCopyComment, DTSetComment, FSpDTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
pascal OSErr FSpDTCopyComment(const FSSpec *srcSpec,
const FSSpec *dstSpec);
/* <09> Copy the desktop database comment from the source to the destination object.
The FSpDTCopyComment function copies the desktop database comment from
the source to the destination object. Both the source and the
destination volumes must support the Desktop Manager.
srcSpec input: An FSSpec record specifying the source object.
dstSpec input: An FSSpec record specifying the destination object.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <09>43 File or directory doesn<73>t exist
wPrErr <09>44 Volume is locked through hardware
vLckdErr <09>46 Volume is locked through software
paramErr -50 Volume doesn't support this function
rfNumErr <09>51 Reference number invalid
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTCopyComment, DTSetComment, FSpDTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
#ifdef __cplusplus
}
#endif
#include "optimend.h"
#endif /* __MOREDESKTOPMGR__ */

View File

@@ -1,41 +1,57 @@
/* /*
** Apple Macintosh Developer Technical Support File: MoreDesktopMgr.c
**
** A collection of useful high-level Desktop Manager routines. Contains: A collection of useful high-level Desktop Manager routines.
** If the Desktop Manager isn't available, use the Desktop file If the Desktop Manager is not available, use the Desktop file
** for 'read' operations. for 'read' operations.
**
** We do more because we can... Version: MoreFiles
**
** by Jim Luther and Nitin Ganatra, Apple Developer Technical Support Emeriti Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
**
** File: MoreDesktopMgr.c You may incorporate this sample code into your applications without
** restriction, though the sample code has been provided "AS IS" and the
** Copyright © 1992-1998 Apple Computer, Inc. responsibility for its operation is 100% yours. However, what you are
** All rights reserved. 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,
** You may incorporate this sample code into your applications without we require that you make it clear in the source that the code was
** restriction, though the sample code has been provided "AS IS" and the descended from Apple Sample Code, but that you've made changes.
** responsibility for its operation is 100% yours. However, what you are
** not permitted to do is to redistribute the source as "DSC Sample Code" File Ownership:
** 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 DRI: Apple Macintosh Developer Technical Support
** descended from Apple Sample Code, but that you've made changes.
Other Contact: Apple Macintosh Developer Technical Support
<http://developer.apple.com/bugreporter/>
Technology: DTS Sample Code
Writers:
(JL) Jim Luther
(NG) Nitin Ganatra
Change History (most recent first):
<2> 2/7/01 JL Added standard header. Updated names of includes. Updated
various routines to use new calling convention of the
MoreFilesExtras accessor functions.
<1> 12/06/99 JL MoreFiles 1.5.
*/ */
#include <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Memory.h> #include <MacMemory.h>
#include <Files.h> #include <Files.h>
#include <Resources.h> #include <Resources.h>
#include <Icons.h> #include <Icons.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
#include "mfsearch.h" #include "Search.h"
#include "moredesk.h" #include "MoreDesktopMgr.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -81,11 +97,7 @@ enum
/* local data structures */ /* local data structures */
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k #pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif #endif
struct IDRec struct IDRec
@@ -134,11 +146,7 @@ typedef struct APPLRec APPLRec;
typedef APPLRec *APPLRecPtr; typedef APPLRec *APPLRecPtr;
#if PRAGMA_STRUCT_ALIGN #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset #pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif #endif
/*****************************************************************************/ /*****************************************************************************/
@@ -245,7 +253,7 @@ pascal OSErr DTOpen(ConstStr255Param volName,
error = HGetVolParms(volName, vRefNum, &volParmsInfo, &infoSize); error = HGetVolParms(volName, vRefNum, &volParmsInfo, &infoSize);
if ( error == noErr ) if ( error == noErr )
{ {
if ( hasDesktopMgr(volParmsInfo) ) if ( hasDesktopMgr(&volParmsInfo) )
{ {
pb.ioNamePtr = (StringPtr)volName; pb.ioNamePtr = (StringPtr)volName;
pb.ioVRefNum = vRefNum; pb.ioVRefNum = vRefNum;
@@ -317,11 +325,7 @@ static OSErr GetAPPLFromDesktopFile(ConstStr255Param volName,
applResHandle = Get1Resource(kAPPLResType, 0); applResHandle = Get1Resource(kAPPLResType, 0);
if ( applResHandle != NULL ) if ( applResHandle != NULL )
{ {
#if !TARGET_CARBON
applSize = InlineGetHandleSize((Handle)applResHandle);
#else
applSize = GetHandleSize((Handle)applResHandle); applSize = GetHandleSize((Handle)applResHandle);
#endif
if ( applSize != 0 ) /* make sure the APPL resource isn't empty */ if ( applSize != 0 ) /* make sure the APPL resource isn't empty */
{ {
foundCreator = false; foundCreator = false;
@@ -1117,11 +1121,7 @@ static OSErr GetCommentFromDesktopFile(short vRefNum,
commentHandle = (StringHandle)Get1Resource(kFCMTResType,commentID); commentHandle = (StringHandle)Get1Resource(kFCMTResType,commentID);
if ( commentHandle != NULL ) if ( commentHandle != NULL )
{ {
#if !TARGET_CARBON
if ( InlineGetHandleSize((Handle)commentHandle) > 0 )
#else
if ( GetHandleSize((Handle)commentHandle) > 0 ) if ( GetHandleSize((Handle)commentHandle) > 0 )
#endif
{ {
BlockMoveData(*commentHandle, comment, *commentHandle[0] + 1); BlockMoveData(*commentHandle, comment, *commentHandle[0] + 1);
} }

View File

@@ -0,0 +1,628 @@
/*
File: MoreDesktopMgr.h
Contains: A collection of useful high-level Desktop Manager routines. If the Desktop Manager is not available, use the Desktop file for 'read' operations.
Version: Technology: MoreFiles
Release: 1.5.2
Copyright: <20> 1992-2001 by Apple Computer, Inc., all rights reserved.
Bugs?: For bug reports, consult the following page on
the World Wide Web:
http://developer.apple.com/bugreporter/
*/
/*
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.
*/
#ifndef __MOREDESKTOPMGR__
#define __MOREDESKTOPMGR__
#ifndef __MACTYPES__
#include <MacTypes.h>
#endif
#ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/
EXTERN_API( OSErr )
DTOpen(
ConstStr255Param volName,
short vRefNum,
short * dtRefNum,
Boolean * newDTDatabase);
/*
The DTOpen function opens a volume's desktop database. It returns
the reference number of the desktop database and indicates if the
desktop database was created as a result of this call (if it was created,
then it is empty).
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
dtRefNum output: The reference number of Desktop Manager's
desktop database on the specified volume.
newDTDatabase output: true if the desktop database was created as a
result of this call and thus empty.
false if the desktop database was already created,
or if it could not be determined if it was already
created.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DTXGetAPPL(
ConstStr255Param volName,
short vRefNum,
OSType creator,
Boolean searchCatalog,
short * applVRefNum,
long * applParID,
Str255 applName);
/*
The DTXGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails and searchCatalog is true, then it tries to find an application
with the specified creator using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
searchCatalog input: If true, search the catalog for the application
if it isn't found in the desktop database.
applVRefNum output: The volume reference number of the volume the
application is on.
applParID output: The parent directory ID of the application.
applName output: The name of the application.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTGetAPPL
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDTXGetAPPL(
ConstStr255Param volName,
short vRefNum,
OSType creator,
Boolean searchCatalog,
FSSpec * spec);
/*
The FSpDTXGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails and searchCatalog is true, then it tries to find an application
with the specified creator using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
searchCatalog input: If true, search the catalog for the application
if it isn't found in the desktop database.
spec output: FSSpec record containing the application name and
location.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTGetAPPL
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DTGetAPPL(
ConstStr255Param volName,
short vRefNum,
OSType creator,
short * applVRefNum,
long * applParID,
Str255 applName);
/*
The DTGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails, then it tries to find an application with the specified creator
using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
applVRefNum output: The volume reference number of the volume the
application is on.
applParID output: The parent directory ID of the application.
applName output: The name of the application.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTGetAPPL
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDTGetAPPL(
ConstStr255Param volName,
short vRefNum,
OSType creator,
FSSpec * spec);
/*
The FSpDTGetAPPL function finds an application (file type 'APPL') with
the specified creator on the specified volume. It first tries to get
the application mapping from the desktop database. If that fails,
then it tries to find an application in the Desktop file. If that
fails, then it tries to find an application with the specified creator
using the File Manager's CatSearch routine.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The file's creator type.
spec output: FSSpec record containing the application name and
location.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 No default volume
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTGetAPPL
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DTGetIcon(
ConstStr255Param volName,
short vRefNum,
short iconType,
OSType fileCreator,
OSType fileType,
Handle * iconHandle);
/*
The DTGetIcon function retrieves the specified icon and returns it in
a newly created handle. The icon is retrieves from the Desktop Manager
or if the Desktop Manager is not available, from the Finder's Desktop
file. Your program is responsible for disposing of the handle when it is
done using the icon.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
iconType input: The icon type as defined in Files.h. Valid values are:
kLargeIcon
kLarge4BitIcon
kLarge8BitIcon
kSmallIcon
kSmall4BitIcon
kSmall8BitIcon
fileCreator input: The icon's creator type.
fileType input: The icon's file type.
iconHandle output: A Handle containing the newly created icon.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
paramErr -50 Volume doesn't support this function
rfNumErr -51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call
memFullErr -108 iconHandle could not be allocated
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DTSetComment(
short vRefNum,
long dirID,
ConstStr255Param name,
ConstStr255Param comment);
/*
The DTSetComment function sets a file or directory's Finder comment
field. The volume must support the Desktop Manager because you only
have read access to the Desktop file.
vRefNum input: Volume specification.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID
specifies a directory that's the object.
comment input: The comment to add. Comments are limited to 200 characters;
longer comments are truncated.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <20>43 File or directory doesn<73>t exist
paramErr -50 Volume doesn't support this function
wPrErr <20>44 Volume is locked through hardware
vLckdErr <20>46 Volume is locked through software
rfNumErr <20>51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
__________
Also see: DTCopyComment, FSpDTCopyComment, FSpDTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDTSetComment(
const FSSpec * spec,
ConstStr255Param comment);
/*
The FSpDTSetComment function sets a file or directory's Finder comment
field. The volume must support the Desktop Manager because you only
have read access to the Desktop file.
spec input: An FSSpec record specifying the file or directory.
comment input: The comment to add. Comments are limited to 200 characters;
longer comments are truncated.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <20>43 File or directory doesn<73>t exist
wPrErr <20>44 Volume is locked through hardware
vLckdErr <20>46 Volume is locked through software
rfNumErr <20>51 Reference number invalid
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
__________
Also see: DTCopyComment, FSpDTCopyComment, DTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DTGetComment(
short vRefNum,
long dirID,
ConstStr255Param name,
Str255 comment);
/*
The DTGetComment function gets a file or directory's Finder comment
field (if any) from the Desktop Manager or if the Desktop Manager is
not available, from the Finder's Desktop file.
IMPORTANT NOTE: Inside Macintosh says that comments are up to
200 characters. While that may be correct for the HFS file system's
Desktop Manager, other file systems (such as Apple Photo Access) return
up to 255 characters. Make sure the comment buffer is a Str255 or you'll
regret it.
vRefNum input: Volume specification.
dirID input: Directory ID.
name input: Pointer to object name, or nil when dirID
specifies a directory that's the object.
comment output: A Str255 where the comment is to be returned.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr -43 File not found
paramErr -50 Volume doesn't support this function
rfNumErr <20>51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTCopyComment, FSpDTCopyComment, DTSetComment, FSpDTSetComment,
FSpDTGetComment
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDTGetComment(
const FSSpec * spec,
Str255 comment);
/*
The FSpDTGetComment function gets a file or directory's Finder comment
field (if any) from the Desktop Manager or if the Desktop Manager is
not available, from the Finder's Desktop file.
IMPORTANT NOTE: Inside Macintosh says that comments are up to
200 characters. While that may be correct for the HFS file system's
Desktop Manager, other file systems (such as Apple Photo Access) return
up to 255 characters. Make sure the comment buffer is a Str255 or you'll
regret it.
spec input: An FSSpec record specifying the file or directory.
comment output: A Str255 where the comment is to be returned.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr -43 File not found
paramErr -50 Volume doesn't support this function
rfNumErr <20>51 Reference number invalid
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTCopyComment, FSpDTCopyComment, DTSetComment, FSpDTSetComment,
DTGetComment
*/
/*****************************************************************************/
EXTERN_API( OSErr )
DTCopyComment(
short srcVRefNum,
long srcDirID,
ConstStr255Param srcName,
short dstVRefNum,
long dstDirID,
ConstStr255Param dstName);
/*
The DTCopyComment function copies the file or folder comment from the
source to the destination object. The destination volume must support
the Desktop Manager because you only have read access to the Desktop file.
srcVRefNum input: Source volume specification.
srcDirID input: Source directory ID.
srcName input: Pointer to source object name, or nil when srcDirID
specifies a directory that's the object.
dstVRefNum input: Destination volume specification.
dstDirID input: Destination directory ID.
dstName input: Pointer to destination object name, or nil when
dstDirID specifies a directory that's the object.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <20>43 File or directory doesn<73>t exist
wPrErr <20>44 Volume is locked through hardware
vLckdErr <20>46 Volume is locked through software
paramErr -50 Volume doesn't support this function
rfNumErr <20>51 Reference number invalid
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: FSpDTCopyComment, DTSetComment, FSpDTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
EXTERN_API( OSErr )
FSpDTCopyComment(
const FSSpec * srcSpec,
const FSSpec * dstSpec);
/*
The FSpDTCopyComment function copies the desktop database comment from
the source to the destination object. Both the source and the
destination volumes must support the Desktop Manager.
srcSpec input: An FSSpec record specifying the source object.
dstSpec input: An FSSpec record specifying the destination object.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
fnfErr <20>43 File or directory doesn<73>t exist
wPrErr <20>44 Volume is locked through hardware
vLckdErr <20>46 Volume is locked through software
paramErr -50 Volume doesn't support this function
rfNumErr <20>51 Reference number invalid
paramErr -50 Volume doesn't support this function
extFSErr -58 External file system error - no file
system claimed this call.
desktopDamagedErr -1305 The desktop database has become corrupted -
the Finder will fix this, but if your
application is not running with the
Finder, use PBDTReset or PBDTDelete
afpItemNotFound -5012 Information not found
__________
Also see: DTCopyComment, DTSetComment, FSpDTSetComment, DTGetComment,
FSpDTGetComment
*/
/*****************************************************************************/
#include "OptimizationEnd.h"
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus
}
#endif
#endif /* __MOREDESKTOPMGR__ */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +1,47 @@
/* /*
** Apple Macintosh Developer Technical Support File: MoreFiles.c
**
** The long lost high-level and FSSpec File Manager functions. Contains: The long lost high-level and FSSpec File Manager functions.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: MoreFiles
**
** File: MoreFiles.c Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
**
** Copyright © 1992-1998 Apple Computer, Inc. You may incorporate this sample code into your applications without
** All rights reserved. restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** You may incorporate this sample code into your applications without not permitted to do is to redistribute the source as "DSC Sample Code"
** restriction, though the sample code has been provided "AS IS" and the after having made changes. If you're going to re-distribute the source,
** responsibility for its operation is 100% yours. However, what you are we require that you make it clear in the source that the code was
** not permitted to do is to redistribute the source as "DSC Sample Code" descended from Apple Sample Code, but that you've made changes.
** 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 File Ownership:
** descended from Apple Sample Code, but that you've made changes.
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 <Types.h> #include <MacTypes.h>
#include <Errors.h> #include <MacErrors.h>
#include <Files.h> #include <Files.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "morefile.h" #include "MoreFiles.h"
#include "moreextr.h" #include "MoreFilesExtras.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -153,7 +168,7 @@ pascal OSErr CreateFileIDRef(short vRefNum,
pb.fidParam.ioVRefNum = vRefNum; pb.fidParam.ioVRefNum = vRefNum;
pb.fidParam.ioSrcDirID = parID; pb.fidParam.ioSrcDirID = parID;
error = PBCreateFileIDRefSync(&pb); error = PBCreateFileIDRefSync(&pb);
if ( error == noErr ) if ( (error == noErr) || (error == fidExists) || (error == afpIDExists) )
{ {
*fileID = pb.fidParam.ioFileID; *fileID = pb.fidParam.ioFileID;
} }

1420
src/mac/morefile/MoreFiles.h Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,120 +0,0 @@
/*
** Apple Macintosh Developer Technical Support
**
** DirectoryCopy: #defines that let you make MoreFiles code more efficient.
**
** by Jim Luther, Apple Developer Technical Support Emeritus
**
** File: Optimization.h
**
** Copyright <20> 1992-1998 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.
**
** The Optimization changes to MoreFiles source and header files, along with
** this file and OptimizationEnd.h, let you optimize the code produced
** by MoreFiles in several ways.
**
** 1 -- MoreFiles contains extra code so that many routines can run under
** Mac OS systems back to System 6. If your program requires a specific
** version of Mac OS and your program checks for that version before
** calling MoreFiles routines, then you can remove a lot of compatibility
** code by defining one of the following to 1:
**
** __MACOSSEVENFIVEONEORLATER // assume Mac OS 7.5.1 or later
** __MACOSSEVENFIVEORLATER // assume Mac OS 7.5 or later
** __MACOSSEVENORLATER // assume Mac OS 7.0 or later
**
** By default, all compatibility code is ON.
**
** 2 -- You may disable Pascal calling conventions in all MoreFiles routines
** except for system callbacks that require Pascal calling conventions.
** This will make C programs both smaller and faster.
** Just define __WANTPASCALELIMINATION to be 1 to turn this optimization on
** when building MoreFiles for use from C programs (you'll need to keep
** Pascal calling conventions when linking MoreFiles routines with Pascal
** programs).
**
** 3 -- If Metrowerks compiler is used, "#pragma internal on" may help produce
** better code. However, this option can also cause problems if you're
** trying to build MoreFiles as a shared library, so it is by default not used.
** Just define __USEPRAGMAINTERNAL to be 1 to turn this optimization on.
**
** Original changes supplied by Fabrizio Oddone
**
** File: Optimization.h
*/
#if TARGET_CARBON
#define __MACOSSEVENFIVEONEORLATER 1
#define __MACOSSEVENORLATER 1
#ifndef __WANTPASCALELIMINATION
#define __WANTPASCALELIMINATION 0
#endif
#if __WANTPASCALELIMINATION
#define pascal
#endif
#ifndef __USEPRAGMAINTERNAL
#define __USEPRAGMAINTERNAL 0
#endif
#if __USEPRAGMAINTERNAL
#if defined(__MWERKS__)
#pragma internal on
#endif
#endif
#else
// we have a basic requirements of 7.5.3 Rev 2 or 7.6
#define __MACOSSEVENFIVEONEORLATER 1
#ifndef __MACOSSEVENFIVEONEORLATER
#define __MACOSSEVENFIVEONEORLATER 0
#endif
#ifndef __MACOSSEVENFIVEORLATER
#define __MACOSSEVENFIVEORLATER __MACOSSEVENFIVEONEORLATER
#endif
#ifndef __MACOSSEVENORLATER
#if GENERATINGCFM
#define __MACOSSEVENORLATER 1
#else
#define __MACOSSEVENORLATER __MACOSSEVENFIVEORLATER
#endif
#endif
#ifndef __WANTPASCALELIMINATION
#define __WANTPASCALELIMINATION 0
#endif
#if __WANTPASCALELIMINATION
#define pascal
#endif
#ifndef __USEPRAGMAINTERNAL
#define __USEPRAGMAINTERNAL 0
#endif
#if __USEPRAGMAINTERNAL
#if defined(__MWERKS__)
#pragma internal on
#endif
#endif
#endif

View File

@@ -1,40 +0,0 @@
/*
** Apple Macintosh Developer Technical Support
**
** DirectoryCopy: #defines that let you make MoreFiles code more efficient.
**
** by Jim Luther, Apple Developer Technical Support Emeritus
**
** File: OptimizationEnd.h
**
** Copyright <20> 1992-1998 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.
**
** The Optimization changes to MoreFiles source and header files, along with
** this file and Optimization.h, let you optimize the code produced by MoreFiles
** in several ways.
**
** Original changes supplied by Fabrizio Oddone
*/
#if __USEPRAGMAINTERNAL
#if defined(__MWERKS__)
#pragma internal reset
#endif
#endif
#if __WANTPASCALELIMINATION
#ifndef __COMPILINGMOREFILES
#undef pascal
#endif
#endif

View File

@@ -0,0 +1,109 @@
/*
File: Optimization.h
Contains: Defines that let you make MoreFiles code more efficient.
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):
<1> 2/7/01 JL first checked in
*/
/*
The Optimization changes to MoreFiles source and header files, along with
this file and OptimizationEnd.h, let you optimize the code produced
by MoreFiles in several ways.
1 -- MoreFiles contains extra code so that many routines can run under
Mac OS systems back to System 6. If your program requires a specific
version of Mac OS and your program checks for that version before
calling MoreFiles routines, then you can remove a lot of compatibility
code by defining one of the following to 1:
__MACOSSEVENFIVEONEORLATER // assume Mac OS 7.5.1 or later
__MACOSSEVENFIVEORLATER // assume Mac OS 7.5 or later
__MACOSSEVENORLATER // assume Mac OS 7.0 or later
If you're compiling 68K code, the default is to include all compatibility code.
If you're compiling PowerPC code (TARGET_RT_MAC_CFM), the default is __MACOSSEVENORLATER
If you're compiling for Carbon code (TARGET_API_MAC_CARBON), the default is __MACOSSEVENFIVEONEORLATER
2 -- You may disable Pascal calling conventions in all MoreFiles routines
except for system callbacks that require Pascal calling conventions.
This will make 68K C programs both smaller and faster.
(PowerPC compilers ignore pascal calling conventions.)
Just define __WANTPASCALELIMINATION to be 1 to turn this optimization on
when building MoreFiles for use from C programs (you'll need to keep
Pascal calling conventions when linking MoreFiles routines with Pascal
programs).
3 -- If Metrowerks compiler is used, "#pragma internal on" may help produce
better code. However, this option can also cause problems if you're
trying to build MoreFiles as a shared library, so it is by default not used.
Just define __USEPRAGMAINTERNAL to be 1 to turn this optimization on.
Original changes supplied by Fabrizio Oddone
*/
#include <ConditionalMacros.h>
// if we're compiling for Carbon, then we're running on Mac OS 8.1 or later
#ifndef __MACOSSEVENFIVEONEORLATER
#define __MACOSSEVENFIVEONEORLATER TARGET_API_MAC_CARBON
#endif
#ifndef __MACOSSEVENFIVEORLATER
#define __MACOSSEVENFIVEORLATER __MACOSSEVENFIVEONEORLATER
#endif
#ifndef __MACOSSEVENORLATER
#if TARGET_RT_MAC_CFM
#define __MACOSSEVENORLATER 1
#else
#define __MACOSSEVENORLATER __MACOSSEVENFIVEORLATER
#endif
#endif
#ifndef __WANTPASCALELIMINATION
#define __WANTPASCALELIMINATION 0
#endif
#if __WANTPASCALELIMINATION
#define pascal
#endif
#ifndef __USEPRAGMAINTERNAL
#define __USEPRAGMAINTERNAL 0
#endif
#if __USEPRAGMAINTERNAL
#if defined(__MWERKS__)
#pragma internal on
#endif
#endif

View File

@@ -0,0 +1,56 @@
/*
File: OptimizationEnd.h
Contains: Defines that let you make MoreFiles code more efficient.
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):
<1> 2/7/01 JL first checked in
*/
/*
The Optimization changes to MoreFiles source and header files, along with
this file and Optimization.h, let you optimize the code produced by MoreFiles
in several ways.
Original changes supplied by Fabrizio Oddone
*/
#if __USEPRAGMAINTERNAL
#if defined(__MWERKS__)
#pragma internal reset
#endif
#endif
#if __WANTPASCALELIMINATION
#ifndef __COMPILINGMOREFILES
#undef pascal
#endif
#endif

View File

@@ -1,36 +1,55 @@
/* /*
** Apple Macintosh Developer Technical Support File: Search.c
**
** IndexedSearch and the PBCatSearch compatibility function. Contains: IndexedSearch and the PBCatSearch compatibility function.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: MoreFiles
**
** File: Search.c Copyright: © 1992-2001 by Apple Computer, Inc., all rights reserved.
**
** Copyright © 1992-1998 Apple Computer, Inc. You may incorporate this sample code into your applications without
** All rights reserved. restriction, though the sample code has been provided "AS IS" and the
** responsibility for its operation is 100% yours. However, what you are
** You may incorporate this sample code into your applications without not permitted to do is to redistribute the source as "DSC Sample Code"
** restriction, though the sample code has been provided "AS IS" and the after having made changes. If you're going to re-distribute the source,
** responsibility for its operation is 100% yours. However, what you are we require that you make it clear in the source that the code was
** not permitted to do is to redistribute the source as "DSC Sample Code" descended from Apple Sample Code, but that you've made changes.
** 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 File Ownership:
** descended from Apple Sample Code, but that you've made changes.
DRI: Jim Luther
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. Updated
various routines to use new calling convention of the
MoreFilesExtras accessor functions. Added TARGET_API_MAC_CARBON
conditional checks around TimeOutTask.
<1> 12/06/99 JL MoreFiles 1.5.
*/ */
#include <Types.h> #include <MacTypes.h>
#include <Gestalt.h> #include <Gestalt.h>
#include <Timer.h> #include <Timer.h>
#include <Errors.h> #include <MacErrors.h>
#include <Memory.h> #include <MacMemory.h>
#include <Files.h> #include <Files.h>
#include <TextUtils.h> #include <TextUtils.h>
#define __COMPILINGMOREFILES #define __COMPILINGMOREFILES
#include "MoreFile.h" #include "MoreFiles.h"
#include "MoreExtr.h" #include "MoreFilesExtras.h"
#include "Search.h" #include "Search.h"
/*****************************************************************************/ /*****************************************************************************/
@@ -66,7 +85,7 @@ typedef LevelRec *LevelRecPtr, **LevelRecHandle;
** SearchPositionRec is my version of a CatPositionRec. It holds the ** SearchPositionRec is my version of a CatPositionRec. It holds the
** information I need to resuming searching. ** information I need to resuming searching.
*/ */
#if PRAGMA_ALIGN_SUPPORTED #if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k #pragma options align=mac68k
#endif #endif
struct SearchPositionRec struct SearchPositionRec
@@ -76,7 +95,7 @@ struct SearchPositionRec
unsigned short stackDepth; /* Current depth on searchStack. */ unsigned short stackDepth; /* Current depth on searchStack. */
short priv[11]; /* For future use... */ short priv[11]; /* For future use... */
}; };
#if PRAGMA_ALIGN_SUPPORTED #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset #pragma options align=reset
#endif #endif
typedef struct SearchPositionRec SearchPositionRec; typedef struct SearchPositionRec SearchPositionRec;
@@ -86,7 +105,7 @@ typedef SearchPositionRec *SearchPositionRecPtr;
/* /*
** ExtendedTMTask is a TMTask record extended to hold the timer flag. ** ExtendedTMTask is a TMTask record extended to hold the timer flag.
*/ */
#if PRAGMA_ALIGN_SUPPORTED #if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k #pragma options align=mac68k
#endif #endif
struct ExtendedTMTask struct ExtendedTMTask
@@ -95,7 +114,7 @@ struct ExtendedTMTask
Boolean stopSearch; /* the Time Mgr task will set stopSearch to */ Boolean stopSearch; /* the Time Mgr task will set stopSearch to */
/* true when the timer expires */ /* true when the timer expires */
}; };
#if PRAGMA_ALIGN_SUPPORTED #if PRAGMA_STRUCT_ALIGN
#pragma options align=reset #pragma options align=reset
#endif #endif
typedef struct ExtendedTMTask ExtendedTMTask; typedef struct ExtendedTMTask ExtendedTMTask;
@@ -135,7 +154,7 @@ static void CheckForMatches(CInfoPBPtr cPB,
#undef pascal #undef pascal
#endif #endif
#if GENERATINGCFM #if TARGET_RT_MAC_CFM || TARGET_API_MAC_CARBON
static pascal void TimeOutTask(TMTaskPtr tmTaskPtr); static pascal void TimeOutTask(TMTaskPtr tmTaskPtr);
@@ -205,7 +224,7 @@ static OSErr CheckStack(unsigned short stackDepth,
/* Time to grow stack */ /* Time to grow stack */
SetHandleSize((Handle)searchStack, *searchStackSize + (kAdditionalLevelRecs * sizeof(LevelRec))); SetHandleSize((Handle)searchStack, *searchStackSize + (kAdditionalLevelRecs * sizeof(LevelRec)));
result = MemError(); /* should be noErr */ result = MemError(); /* should be noErr */
*searchStackSize = InlineGetHandleSize((Handle)searchStack); *searchStackSize = GetHandleSize((Handle)searchStack);
} }
else else
{ {
@@ -277,16 +296,16 @@ static OSErr VerifyUserPB(CSParamPtr userPB,
{ {
/* The only attributes you can search on are the directory flag */ /* The only attributes you can search on are the directory flag */
/* and the locked flag. */ /* and the locked flag. */
if ( (searchInfo2->hFileInfo.ioFlAttrib & ~(ioDirMask | 0x01)) != 0 ) if ( (searchInfo2->hFileInfo.ioFlAttrib & ~(kioFlAttribDirMask | kioFlAttribLockedMask)) != 0 )
{ {
goto ParamErrExit; goto ParamErrExit;
} }
/* interested in the directory bit? */ /* interested in the directory bit? */
if ( (searchInfo2->hFileInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (searchInfo2->hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
/* yes, so do they want just directories or just files? */ /* yes, so do they want just directories or just files? */
if ( (searchInfo1->hFileInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (searchInfo1->hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
*includeDirs = true; *includeDirs = true;
} }
@@ -313,7 +332,7 @@ static OSErr VerifyUserPB(CSParamPtr userPB,
/* then the locked attribute cannot be requested. */ /* then the locked attribute cannot be requested. */
if ( *includeDirs && if ( *includeDirs &&
((userPB->ioSearchBits & fsSBFlAttrib) != 0) && ((userPB->ioSearchBits & fsSBFlAttrib) != 0) &&
((searchInfo2->hFileInfo.ioFlAttrib & 0x01) != 0) ) ((searchInfo2->hFileInfo.ioFlAttrib & kioFlAttribLockedMask) != 0) )
{ {
goto ParamErrExit; goto ParamErrExit;
} }
@@ -462,7 +481,7 @@ static void CheckForMatches(CInfoPBPtr cPB,
/* Into the if statements that go on forever... */ /* Into the if statements that go on forever... */
if ( (cPB->hFileInfo.ioFlAttrib & ioDirMask) == 0 ) if ( (cPB->hFileInfo.ioFlAttrib & kioFlAttribDirMask) == 0 )
{ {
if (!includeFiles) if (!includeFiles)
{ {
@@ -678,7 +697,7 @@ Failed:
#undef pascal #undef pascal
#endif #endif
#if GENERATINGCFM #if TARGET_RT_MAC_CFM || TARGET_API_MAC_CARBON
static pascal void TimeOutTask(TMTaskPtr tmTaskPtr) static pascal void TimeOutTask(TMTaskPtr tmTaskPtr)
{ {
@@ -761,7 +780,7 @@ pascal OSErr IndexedSearch(CSParamPtr pb,
if ( pb->ioSearchTime != 0 ) if ( pb->ioSearchTime != 0 )
{ {
/* Start timer */ /* Start timer */
timerTask.theTask.tmAddr = NewTimerProc(TimeOutTask); timerTask.theTask.tmAddr = NewTimerUPP(TimeOutTask);
InsTime((QElemPtr)&(timerTask.theTask)); InsTime((QElemPtr)&(timerTask.theTask));
PrimeTime((QElemPtr)&(timerTask.theTask), pb->ioSearchTime); PrimeTime((QElemPtr)&(timerTask.theTask), pb->ioSearchTime);
} }
@@ -800,7 +819,7 @@ pascal OSErr IndexedSearch(CSParamPtr pb,
/* Make sure searchStack really exists */ /* Make sure searchStack really exists */
if ( searchStack != NULL ) if ( searchStack != NULL )
{ {
searchStackSize = InlineGetHandleSize((Handle)searchStack); searchStackSize = GetHandleSize((Handle)searchStack);
/* See if the search is a new search or a resumed search. */ /* See if the search is a new search or a resumed search. */
if ( catPosition->initialize == 0 ) if ( catPosition->initialize == 0 )
@@ -897,7 +916,7 @@ pascal OSErr IndexedSearch(CSParamPtr pb,
CheckForMatches(&cPB, pb, upperName, includeFiles, includeDirs); CheckForMatches(&cPB, pb, upperName, includeFiles, includeDirs);
++index; ++index;
if ( (cPB.dirInfo.ioFlAttrib & ioDirMask) != 0 ) if ( (cPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0 )
{ {
/* It's a directory */ /* It's a directory */
@@ -1007,7 +1026,7 @@ pascal OSErr IndexedSearch(CSParamPtr pb,
{ {
/* Stop Time Manager task here if it was installed */ /* Stop Time Manager task here if it was installed */
RmvTime((QElemPtr)&(timerTask.theTask)); RmvTime((QElemPtr)&(timerTask.theTask));
DisposeRoutineDescriptor(timerTask.theTask.tmAddr); DisposeTimerUPP(timerTask.theTask.tmAddr);
} }
return ( result ); return ( result );
@@ -1017,19 +1036,22 @@ pascal OSErr IndexedSearch(CSParamPtr pb,
pascal OSErr PBCatSearchSyncCompat(CSParamPtr paramBlock) pascal OSErr PBCatSearchSyncCompat(CSParamPtr paramBlock)
{ {
static Boolean fullExtFSDispatchingtested = false;
static Boolean hasFullExtFSDispatching = false;
OSErr result; OSErr result;
Boolean supportsCatSearch; Boolean supportsCatSearch;
long response;
GetVolParmsInfoBuffer volParmsInfo; GetVolParmsInfoBuffer volParmsInfo;
long infoSize; long infoSize;
#if !__MACOSSEVENORLATER
static Boolean fullExtFSDispatchingtested = false;
static Boolean hasFullExtFSDispatching = false;
long response;
#endif
result = noErr; result = noErr;
#if !__MACOSSEVENORLATER
/* See if File Manager will pass CatSearch requests to external file systems */ /* See if File Manager will pass CatSearch requests to external file systems */
/* we'll store the results in a static variable so we don't have to call Gestalt */ /* we'll store the results in a static variable so we don't have to call Gestalt */
/* everytime we're called. */ /* everytime we're called. (System 7.0 and later always do this) */
if ( !fullExtFSDispatchingtested ) if ( !fullExtFSDispatchingtested )
{ {
fullExtFSDispatchingtested = true; fullExtFSDispatchingtested = true;
@@ -1038,18 +1060,21 @@ pascal OSErr PBCatSearchSyncCompat(CSParamPtr paramBlock)
hasFullExtFSDispatching = ((response & (1L << gestaltFullExtFSDispatching)) != 0); hasFullExtFSDispatching = ((response & (1L << gestaltFullExtFSDispatching)) != 0);
} }
} }
#endif
/* CatSearch is a per volume attribute, so we have to check each time we're */ /* CatSearch is a per volume attribute, so we have to check each time we're */
/* called to see if it is available on the volume specified. */ /* called to see if it is available on the volume specified. */
supportsCatSearch = false; supportsCatSearch = false;
#if !__MACOSSEVENORLATER
if ( hasFullExtFSDispatching ) if ( hasFullExtFSDispatching )
#endif
{ {
infoSize = sizeof(GetVolParmsInfoBuffer); infoSize = sizeof(GetVolParmsInfoBuffer);
result = HGetVolParms(paramBlock->ioNamePtr, paramBlock->ioVRefNum, result = HGetVolParms(paramBlock->ioNamePtr, paramBlock->ioVRefNum,
&volParmsInfo, &infoSize); &volParmsInfo, &infoSize);
if ( result == noErr ) if ( result == noErr )
{ {
supportsCatSearch = hasCatSearch(volParmsInfo); supportsCatSearch = hasCatSearch(&volParmsInfo);
} }
} }
@@ -1125,7 +1150,7 @@ pascal OSErr NameFileSearch(ConstStr255Param volName,
/* only match files (not directories) */ /* only match files (not directories) */
searchInfo1.hFileInfo.ioFlAttrib = 0x00; searchInfo1.hFileInfo.ioFlAttrib = 0x00;
searchInfo2.hFileInfo.ioFlAttrib = ioDirMask; searchInfo2.hFileInfo.ioFlAttrib = kioFlAttribDirMask;
error = PBCatSearchSyncCompat((CSParamPtr)&pb); error = PBCatSearchSyncCompat((CSParamPtr)&pb);
@@ -1204,7 +1229,7 @@ pascal OSErr CreatorTypeFileSearch(ConstStr255Param volName,
/* only match files (not directories) */ /* only match files (not directories) */
searchInfo1.hFileInfo.ioFlAttrib = 0x00; searchInfo1.hFileInfo.ioFlAttrib = 0x00;
searchInfo2.hFileInfo.ioFlAttrib = ioDirMask; searchInfo2.hFileInfo.ioFlAttrib = kioFlAttribDirMask;
/* search for creator; if creator = 0x00000000, ignore creator */ /* search for creator; if creator = 0x00000000, ignore creator */
searchInfo1.hFileInfo.ioFlFndrInfo.fdCreator = creator; searchInfo1.hFileInfo.ioFlFndrInfo.fdCreator = creator;

View File

@@ -1,246 +1,304 @@
/* /*
** Apple Macintosh Developer Technical Support File: Search.h
**
** IndexedSearch and the PBCatSearch compatibility function. Contains: IndexedSearch and the PBCatSearch compatibility function.
**
** by Jim Luther, Apple Developer Technical Support Emeritus Version: Technology: MoreFiles
** Release: 1.5.2
** File: Search.h
** Copyright: <20> 1992-2001 by Apple Computer, Inc., all rights reserved.
** Copyright <20> 1992-1998 Apple Computer, Inc.
** All rights reserved. Bugs?: For bug reports, consult the following page on
** the World Wide Web:
** You may incorporate this sample code into your applications without
** restriction, though the sample code has been provided "AS IS" and the http://developer.apple.com/bugreporter/
** 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. 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.
*/ */
#ifndef __SEARCH__ #ifndef __SEARCH__
#define __SEARCH__ #define __SEARCH__
#include <Types.h> #ifndef __MACTYPES__
#include <Files.h> #include <MacTypes.h>
#endif
#include "Optim.h" #ifndef __FILES__
#include <Files.h>
#endif
#include "Optimization.h"
#if PRAGMA_ONCE
#pragma once
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#if PRAGMA_IMPORT
#pragma import on
#endif
#if PRAGMA_STRUCT_ALIGN
#pragma options align=mac68k
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(push, 2)
#elif PRAGMA_STRUCT_PACK
#pragma pack(2)
#endif
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr IndexedSearch(CSParamPtr pb, EXTERN_API( OSErr )
long dirID); IndexedSearch(
/* <09> Search in and below a directory. CSParamPtr pb,
The IndexedSearch function performs an indexed search in and below the long dirID);
specified directory using the same parameters (in pb) as is passed to
PBCatSearch. See Inside Macintosh: Files for a description of the
parameter block. /*
The IndexedSearch function performs an indexed search in and below the
pb input: A CSParamPtr record specifying the volume to search specified directory using the same parameters (in pb) as is passed to
and the search criteria. PBCatSearch. See Inside Macintosh: Files for a description of the
output: Fields in the parameter block are returned indicating parameter block.
the number of matches found, the matches, and if the
search ended with noErr, the CatPosition record that pb input: A CSParamPtr record specifying the volume to search
lets you resume a search where the last search left and the search criteria.
off. output: Fields in the parameter block are returned indicating
dirID input: The directory to search. If fsRtDirID is passed, the number of matches found, the matches, and if the
the entire volume is searched. search ended with noErr, the CatPosition record that
lets you resume a search where the last search left
Note: If you use a high-level debugger and use ioSearchTime to limit off.
the length of time to run the search, you'll want to step over dirID input: The directory to search. If fsRtDirID is passed,
calls to IndexedSearch because it installs a Time Manager task. the entire volume is searched.
Most high-level debuggers don't deal gracefully with interrupt
driven code. Note: If you use a high-level debugger and use ioSearchTime to limit
the length of time to run the search, you'll want to step over
Result Codes calls to IndexedSearch because it installs a Time Manager task.
noErr 0 No error Most high-level debuggers don't deal gracefully with interrupt
nsvErr -35 Volume not found driven code.
ioErr -36 I/O error
eofErr -39 End of catalog found (this is normal!) Result Codes
paramErr -50 Parameter block has invalid parameters noErr 0 No error
(see source for VerifyUserPB) or nsvErr -35 Volume not found
invalid catPosition record was passed ioErr -36 I/O error
extFSErr -58 External file system error - no file eofErr -39 End of catalog found (this is normal!)
system claimed this call. paramErr -50 Parameter block has invalid parameters
memFullErr -108 Memory could not be allocated in heap (see source for VerifyUserPB) or
catChangedErr -1304 Catalog has changed and catalog position invalid catPosition record was passed
record may be invalid extFSErr -58 External file system error - no file
system claimed this call.
__________ memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
See also: PBCatSearch, PBCatSearchSyncCompat record may be invalid
__________
See also: PBCatSearch, PBCatSearchSyncCompat
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr PBCatSearchSyncCompat(CSParamPtr paramBlock); EXTERN_API( OSErr )
/* <09> Search a volume using PBCatSearch or IndexedSearch. PBCatSearchSyncCompat(CSParamPtr paramBlock);
The PBCatSearchSyncCompat function uses PBCatSearch (if available) or
IndexedSearch (if PBCatSearch is not available) to search a volume
using a set of search criteria that you specify. It builds a list of all /*
files or directories that meet your specifications. The PBCatSearchSyncCompat function uses PBCatSearch (if available) or
IndexedSearch (if PBCatSearch is not available) to search a volume
pb input: A CSParamPtr record specifying the volume to search using a set of search criteria that you specify. It builds a list of all
and the search criteria. files or directories that meet your specifications.
output: Fields in the parameter block are returned indicating
the number of matches found, the matches, and if the pb input: A CSParamPtr record specifying the volume to search
search ended with noErr, the CatPosition record that and the search criteria.
lets you resume a search where the last search left output: Fields in the parameter block are returned indicating
off. the number of matches found, the matches, and if the
search ended with noErr, the CatPosition record that
Note: If you use a high-level debugger and use ioSearchTime to limit lets you resume a search where the last search left
the length of time to run the search, you'll want to step over off.
calls to PBCatSearchSyncCompat because it calls IndexedSearch
which installs a Time Manager task. Most high-level debuggers Note: If you use a high-level debugger and use ioSearchTime to limit
don't deal gracefully with interrupt driven code. the length of time to run the search, you'll want to step over
calls to PBCatSearchSyncCompat because it calls IndexedSearch
Result Codes which installs a Time Manager task. Most high-level debuggers
noErr 0 No error don't deal gracefully with interrupt driven code.
nsvErr -35 Volume not found
ioErr -36 I/O error Result Codes
eofErr -39 End of catalog found (this is normal!) noErr 0 No error
paramErr -50 Parameter block has invalid parameters nsvErr -35 Volume not found
(see source for VerifyUserPB) or ioErr -36 I/O error
invalid catPosition record was passed eofErr -39 End of catalog found (this is normal!)
extFSErr -58 External file system error - no file paramErr -50 Parameter block has invalid parameters
system claimed this call. (see source for VerifyUserPB) or
memFullErr -108 Memory could not be allocated in heap invalid catPosition record was passed
catChangedErr -1304 Catalog has changed and catalog position extFSErr -58 External file system error - no file
record may be invalid system claimed this call.
afpCatalogChanged -5037 Catalog has changed and search cannot memFullErr -108 Memory could not be allocated in heap
be resumed catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
__________ afpCatalogChanged -5037 Catalog has changed and search cannot
be resumed
See also: PBCatSearch, IndexedSearch
__________
See also: PBCatSearch, IndexedSearch
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr NameFileSearch(ConstStr255Param volName, EXTERN_API( OSErr )
short vRefNum, NameFileSearch(
ConstStr255Param fileName, ConstStr255Param volName,
FSSpecPtr matches, short vRefNum,
long reqMatchCount, ConstStr255Param fileName,
long *actMatchCount, FSSpecPtr matches,
Boolean newSearch, long reqMatchCount,
Boolean partial); long * actMatchCount,
/* <09> Search for files by file name with PBCatSearch. Boolean newSearch,
The NameFileSearch function searches for files with a specific file Boolean partial);
name on a volume that supports PBCatSearch.
Note: A result of catChangedErr means the catalog has changed between
searches, but the search can be continued with the possiblity that you
may miss some matches or get duplicate matches. For all other results
(except for noErr), the search cannot be continued.
volName input: A pointer to the name of a mounted volume
or nil. /*
vRefNum input: Volume specification. The NameFileSearch function searches for files with a specific file
fileName input: The name of the file to search for. name on a volume that supports PBCatSearch.
matches input: Pointer to array of FSSpec where the match list is Note: A result of catChangedErr means the catalog has changed between
returned. searches, but the search can be continued with the possiblity that you
reqMatchCount input: Maximum number of matches to return (the number of may miss some matches or get duplicate matches. For all other results
elements in the matches array). (except for noErr), the search cannot be continued.
actMatchCount output: The number of matches actually returned.
newSearch input: If true, start a new search. If false and if volName input: A pointer to the name of a mounted volume
vRefNum is the same as the last call to or nil.
NameFileSearch, then start searching at the vRefNum input: Volume specification.
position where the last search left off. fileName input: The name of the file to search for.
partial input: If the partial parameter is false, then only files matches input: Pointer to array of FSSpec where the match list is
that exactly match fileName will be found. If the returned.
partial parameter is true, then all file names that reqMatchCount input: Maximum number of matches to return (the number of
contain fileName will be found. elements in the matches array).
actMatchCount output: The number of matches actually returned.
Result Codes newSearch input: If true, start a new search. If false and if
noErr 0 No error vRefNum is the same as the last call to
nsvErr -35 Volume not found NameFileSearch, then start searching at the
ioErr -36 I/O error position where the last search left off.
eofErr -39 End of catalog found (this is normal!) partial input: If the partial parameter is false, then only files
paramErr -50 Parameter block has invalid parameters that exactly match fileName will be found. If the
(see source for VerifyUserPB) or partial parameter is true, then all file names that
invalid catPosition record was passed contain fileName will be found.
extFSErr -58 External file system error - no file
system claimed this call. Result Codes
memFullErr -108 Memory could not be allocated in heap noErr 0 No error
catChangedErr -1304 Catalog has changed and catalog position nsvErr -35 Volume not found
record may be invalid ioErr -36 I/O error
afpCatalogChanged -5037 Catalog has changed and search cannot eofErr -39 End of catalog found (this is normal!)
be resumed paramErr -50 Parameter block has invalid parameters
(see source for VerifyUserPB) or
__________ invalid catPosition record was passed
extFSErr -58 External file system error - no file
Also see: CreatorTypeFileSearch system claimed this call.
memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
afpCatalogChanged -5037 Catalog has changed and search cannot
be resumed
__________
Also see: CreatorTypeFileSearch
*/ */
/*****************************************************************************/ /*****************************************************************************/
pascal OSErr CreatorTypeFileSearch(ConstStr255Param volName, EXTERN_API( OSErr )
short vRefNum, CreatorTypeFileSearch(
OSType creator, ConstStr255Param volName,
OSType fileType, short vRefNum,
FSSpecPtr matches, OSType creator,
long reqMatchCount, OSType fileType,
long *actMatchCount, FSSpecPtr matches,
Boolean newSearch); long reqMatchCount,
/* <09> Search for files by creator/fileType with PBCatSearch. long * actMatchCount,
The CreatorTypeFileSearch function searches for files with a specific Boolean newSearch);
creator or fileType on a volume that supports PBCatSearch.
Note: A result of catChangedErr means the catalog has changed between
searches, but the search can be continued with the possiblity that you
may miss some matches or get duplicate matches. For all other results
(except for noErr), the search cannot be continued.
volName input: A pointer to the name of a mounted volume
or nil. /*
vRefNum input: Volume specification. The CreatorTypeFileSearch function searches for files with a specific
creator input: The creator type of the file to search for. creator or fileType on a volume that supports PBCatSearch.
To ignore the creator type, pass 0x00000000 in Note: A result of catChangedErr means the catalog has changed between
this field. searches, but the search can be continued with the possiblity that you
fileType input: The file type of the file to search for. may miss some matches or get duplicate matches. For all other results
To ignore the file type, pass 0x00000000 in (except for noErr), the search cannot be continued.
this field.
matches input: Pointer to array of FSSpec where the match list is volName input: A pointer to the name of a mounted volume
returned. or nil.
reqMatchCount input: Maximum number of matches to return (the number of vRefNum input: Volume specification.
elements in the matches array). creator input: The creator type of the file to search for.
actMatchCount output: The number of matches actually returned. To ignore the creator type, pass 0x00000000 in
newSearch input: If true, start a new search. If false and if this field.
vRefNum is the same as the last call to fileType input: The file type of the file to search for.
CreatorTypeFileSearch, then start searching at the To ignore the file type, pass 0x00000000 in
position where the last search left off. this field.
matches input: Pointer to array of FSSpec where the match list is
Result Codes returned.
noErr 0 No error reqMatchCount input: Maximum number of matches to return (the number of
nsvErr -35 Volume not found elements in the matches array).
ioErr -36 I/O error actMatchCount output: The number of matches actually returned.
eofErr -39 End of catalog found (this is normal!) newSearch input: If true, start a new search. If false and if
paramErr -50 Parameter block has invalid parameters vRefNum is the same as the last call to
(see source for VerifyUserPB) or CreatorTypeFileSearch, then start searching at the
invalid catPosition record was passed position where the last search left off.
extFSErr -58 External file system error - no file
system claimed this call. Result Codes
memFullErr -108 Memory could not be allocated in heap noErr 0 No error
catChangedErr -1304 Catalog has changed and catalog position nsvErr -35 Volume not found
record may be invalid ioErr -36 I/O error
afpCatalogChanged -5037 Catalog has changed and search cannot eofErr -39 End of catalog found (this is normal!)
be resumed paramErr -50 Parameter block has invalid parameters
(see source for VerifyUserPB) or
__________ invalid catPosition record was passed
extFSErr -58 External file system error - no file
Also see: NameFileSearch system claimed this call.
memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
afpCatalogChanged -5037 Catalog has changed and search cannot
be resumed
__________
Also see: NameFileSearch
*/ */
/*****************************************************************************/ /*****************************************************************************/
#include "OptimizationEnd.h"
#if PRAGMA_STRUCT_ALIGN
#pragma options align=reset
#elif PRAGMA_STRUCT_PACKPUSH
#pragma pack(pop)
#elif PRAGMA_STRUCT_PACK
#pragma pack()
#endif
#ifdef PRAGMA_IMPORT_OFF
#pragma import off
#elif PRAGMA_IMPORT
#pragma import reset
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#include "OptimEnd.h" #endif /* __SEARCH__ */
#endif /* __SEARCH__ */

File diff suppressed because it is too large Load Diff

View File

@@ -1,246 +0,0 @@
/*
** Apple Macintosh Developer Technical Support
**
** IndexedSearch and the PBCatSearch compatibility function.
**
** by Jim Luther, Apple Developer Technical Support Emeritus
**
** File: Search.h
**
** Copyright <20> 1992-1998 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.
*/
#ifndef __SEARCH__
#define __SEARCH__
#include <Types.h>
#include <Files.h>
#include "optim.h"
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************/
pascal OSErr IndexedSearch(CSParamPtr pb,
long dirID);
/* <09> Search in and below a directory.
The IndexedSearch function performs an indexed search in and below the
specified directory using the same parameters (in pb) as is passed to
PBCatSearch. See Inside Macintosh: Files for a description of the
parameter block.
pb input: A CSParamPtr record specifying the volume to search
and the search criteria.
output: Fields in the parameter block are returned indicating
the number of matches found, the matches, and if the
search ended with noErr, the CatPosition record that
lets you resume a search where the last search left
off.
dirID input: The directory to search. If fsRtDirID is passed,
the entire volume is searched.
Note: If you use a high-level debugger and use ioSearchTime to limit
the length of time to run the search, you'll want to step over
calls to IndexedSearch because it installs a Time Manager task.
Most high-level debuggers don't deal gracefully with interrupt
driven code.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
eofErr -39 End of catalog found (this is normal!)
paramErr -50 Parameter block has invalid parameters
(see source for VerifyUserPB) or
invalid catPosition record was passed
extFSErr -58 External file system error - no file
system claimed this call.
memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
__________
See also: PBCatSearch, PBCatSearchSyncCompat
*/
/*****************************************************************************/
pascal OSErr PBCatSearchSyncCompat(CSParamPtr paramBlock);
/* <09> Search a volume using PBCatSearch or IndexedSearch.
The PBCatSearchSyncCompat function uses PBCatSearch (if available) or
IndexedSearch (if PBCatSearch is not available) to search a volume
using a set of search criteria that you specify. It builds a list of all
files or directories that meet your specifications.
pb input: A CSParamPtr record specifying the volume to search
and the search criteria.
output: Fields in the parameter block are returned indicating
the number of matches found, the matches, and if the
search ended with noErr, the CatPosition record that
lets you resume a search where the last search left
off.
Note: If you use a high-level debugger and use ioSearchTime to limit
the length of time to run the search, you'll want to step over
calls to PBCatSearchSyncCompat because it calls IndexedSearch
which installs a Time Manager task. Most high-level debuggers
don't deal gracefully with interrupt driven code.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
eofErr -39 End of catalog found (this is normal!)
paramErr -50 Parameter block has invalid parameters
(see source for VerifyUserPB) or
invalid catPosition record was passed
extFSErr -58 External file system error - no file
system claimed this call.
memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
afpCatalogChanged -5037 Catalog has changed and search cannot
be resumed
__________
See also: PBCatSearch, IndexedSearch
*/
/*****************************************************************************/
pascal OSErr NameFileSearch(ConstStr255Param volName,
short vRefNum,
ConstStr255Param fileName,
FSSpecPtr matches,
long reqMatchCount,
long *actMatchCount,
Boolean newSearch,
Boolean partial);
/* <09> Search for files by file name with PBCatSearch.
The NameFileSearch function searches for files with a specific file
name on a volume that supports PBCatSearch.
Note: A result of catChangedErr means the catalog has changed between
searches, but the search can be continued with the possiblity that you
may miss some matches or get duplicate matches. For all other results
(except for noErr), the search cannot be continued.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
fileName input: The name of the file to search for.
matches input: Pointer to array of FSSpec where the match list is
returned.
reqMatchCount input: Maximum number of matches to return (the number of
elements in the matches array).
actMatchCount output: The number of matches actually returned.
newSearch input: If true, start a new search. If false and if
vRefNum is the same as the last call to
NameFileSearch, then start searching at the
position where the last search left off.
partial input: If the partial parameter is false, then only files
that exactly match fileName will be found. If the
partial parameter is true, then all file names that
contain fileName will be found.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
eofErr -39 End of catalog found (this is normal!)
paramErr -50 Parameter block has invalid parameters
(see source for VerifyUserPB) or
invalid catPosition record was passed
extFSErr -58 External file system error - no file
system claimed this call.
memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
afpCatalogChanged -5037 Catalog has changed and search cannot
be resumed
__________
Also see: CreatorTypeFileSearch
*/
/*****************************************************************************/
pascal OSErr CreatorTypeFileSearch(ConstStr255Param volName,
short vRefNum,
OSType creator,
OSType fileType,
FSSpecPtr matches,
long reqMatchCount,
long *actMatchCount,
Boolean newSearch);
/* <09> Search for files by creator/fileType with PBCatSearch.
The CreatorTypeFileSearch function searches for files with a specific
creator or fileType on a volume that supports PBCatSearch.
Note: A result of catChangedErr means the catalog has changed between
searches, but the search can be continued with the possiblity that you
may miss some matches or get duplicate matches. For all other results
(except for noErr), the search cannot be continued.
volName input: A pointer to the name of a mounted volume
or nil.
vRefNum input: Volume specification.
creator input: The creator type of the file to search for.
To ignore the creator type, pass 0x00000000 in
this field.
fileType input: The file type of the file to search for.
To ignore the file type, pass 0x00000000 in
this field.
matches input: Pointer to array of FSSpec where the match list is
returned.
reqMatchCount input: Maximum number of matches to return (the number of
elements in the matches array).
actMatchCount output: The number of matches actually returned.
newSearch input: If true, start a new search. If false and if
vRefNum is the same as the last call to
CreatorTypeFileSearch, then start searching at the
position where the last search left off.
Result Codes
noErr 0 No error
nsvErr -35 Volume not found
ioErr -36 I/O error
eofErr -39 End of catalog found (this is normal!)
paramErr -50 Parameter block has invalid parameters
(see source for VerifyUserPB) or
invalid catPosition record was passed
extFSErr -58 External file system error - no file
system claimed this call.
memFullErr -108 Memory could not be allocated in heap
catChangedErr -1304 Catalog has changed and catalog position
record may be invalid
afpCatalogChanged -5037 Catalog has changed and search cannot
be resumed
__________
Also see: NameFileSearch
*/
/*****************************************************************************/
#ifdef __cplusplus
}
#endif
#include "optimend.h"
#endif /* __SEARCH__ */

View File

@@ -28,8 +28,8 @@
#include <stdarg.h> #include <stdarg.h>
#ifndef __DARWIN__ #ifndef __DARWIN__
# include "morefile.h" #include "MoreFiles.h"
# include "moreextr.h" #include "MoreFilesExtras.h"
#endif #endif
#ifndef __DARWIN__ #ifndef __DARWIN__