|
From: <cre...@us...> - 2006-06-26 01:52:28
|
Revision: 1420 Author: creecode Date: 2006-06-25 18:52:22 -0700 (Sun, 25 Jun 2006) ViewCVS: http://svn.sourceforge.net/frontierkernel/?rev=1420&view=rev Log Message: ----------- FSRef-ized Modified Paths: -------------- Frontier/branches/FSRef_Migration/Common/source/filemp3.c Frontier/branches/FSRef_Migration/Common/source/fileops.c Modified: Frontier/branches/FSRef_Migration/Common/source/filemp3.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/filemp3.c 2006-06-25 20:38:54 UTC (rev 1419) +++ Frontier/branches/FSRef_Migration/Common/source/filemp3.c 2006-06-26 01:52:22 UTC (rev 1420) @@ -384,7 +384,7 @@ }/*getxingheader*/ -boolean getmp3info (const tyfilespec *fs, long *seconds, long *bitrate, long *frequency, long *offset, boolean *flvariablebitrate) { +boolean getmp3info (const ptrfilespec fs, long *seconds, long *bitrate, long *frequency, long *offset, boolean *flvariablebitrate) { tympeginfostruct mp3; long ix = 0; Modified: Frontier/branches/FSRef_Migration/Common/source/fileops.c =================================================================== --- Frontier/branches/FSRef_Migration/Common/source/fileops.c 2006-06-25 20:38:54 UTC (rev 1419) +++ Frontier/branches/FSRef_Migration/Common/source/fileops.c 2006-06-26 01:52:22 UTC (rev 1420) @@ -50,13 +50,9 @@ #ifdef MACVERSION - #if TARGET_API_MAC_CARBON - #include "MoreFilesX.h" - #else - pascal OSErr XGetVInfo(short volReference, StringPtr volName, short *vRefNum, UInt64 *freeBytes, - UInt64 *totalBytes); - #endif - + #include "MoreFilesX.h" + #include "FSCopyObject.h" + #ifdef flcomponent #include "SetUpA5.h" #endif @@ -133,19 +129,32 @@ typedef struct tyfileinfo tyvolinfo; -void setfserrorparam (const tyfilespec *fs) { +void setfserrorparam ( const tyfilespec *fs ) { + + // + // 2006-06-25 creedon; for Mac, FSRef-ized + // - /* - bigstring bs; + #ifdef MACVERSION - if (!filespectopath (fs, bs)) - copystring ((ptrstring) (*fs).name, bs); + bigstring bs; + + if ( ( *fs ).path != NULL ) + CFStringToStr255 ( ( *fs ).path, bs ); + else + FSRefGetNameStr255 ( &( *fs ).fsref, bs ); + + setoserrorparam ( bs ); + + #endif + + #ifdef WIN95VERSION - setoserrorparam (bs); - */ + setoserrorparam ((ptrstring) fsname (fs)); - setoserrorparam ((ptrstring) fsname (fs)); - } /*setfserrorparam*/ + #endif + + } /* setfserrorparam */ boolean endswithpathsep (bigstring bs) { @@ -214,91 +223,136 @@ #ifdef MACVERSION -boolean foldertest (CInfoPBRec *pb) { - - /* - return true if pb holds info describing a folder. - - 4/26/96 dmb: use mask, not BitTst (a toolbox call) - */ - - /* - return (BitTst (&pb->dirInfo.ioFlAttrib, 3)); - */ - return ((pb->dirInfo.ioFlAttrib & ioDirMask) != 0); - } /*foldertest*/ + boolean foldertest ( FSRefParamPtr pb ) { + + // + // return true if pb holds info describing a folder. + // + // 2006-06-25 creedon: FSRef-ized + // + // 1996-04-26 dmb: use mask, not BitTst (a toolbox call) + // + + // return (BitTst (&pb->dirInfo.ioFlAttrib, 3)); -static void filebeachball (void) { - + return ( ( pb -> catInfo -> nodeFlags & kFSNodeIsDirectoryMask ) != 0 ); + + } // foldertest + + + boolean foldertestcipbr (CInfoPBRec *pb) { + + /* + return true if pb holds info describing a folder. + + 4/26/96 dmb: use mask, not BitTst (a toolbox call) + */ + + /* + return (BitTst (&pb->dirInfo.ioFlAttrib, 3)); + */ + return ((pb->dirInfo.ioFlAttrib & ioDirMask) != 0); + } /*foldertest*/ + + /* - roll the beachball cursor if there is one. + static void filebeachball (void) { + + // + roll the beachball cursor if there is one. + // + + if (beachballcursor ()) + rollbeachball (); + } // filebeachball */ - - if (beachballcursor ()) - rollbeachball (); - } /*filebeachball*/ - -boolean getmacfileinfo (const tyfilespec *fs, CInfoPBRec *pb) { - - /* - 2.1b2 dmb: new fsspec-based version - */ - - setoserrorparam ((ptrstring) (*fs).name); /*in case error message takes a filename parameter*/ - - clearbytes (pb, sizeof (*pb)); - - (*pb).hFileInfo.ioNamePtr = (StringPtr) (*fs).name; - - (*pb).hFileInfo.ioVRefNum = (*fs).vRefNum; - - (*pb).hFileInfo.ioDirID = (*fs).parID; - - return (!oserror (PBGetCatInfoSync (pb))); - } /*getmacfileinfo*/ + boolean getmacfileinfo ( const ptrfilespec fs, FSRefParamPtr pb, FSCatalogInfoPtr catinfo ) { + + /* + 2.1b2 dmb: new fsspec-based version + */ + + OSErr err; + + setfserrorparam ( fs ); // in case error message takes a filename parameter + + clearbytes ( pb, sizeof ( *pb ) ); + clearbytes ( catinfo, sizeof ( *catinfo ) ); + + ( *pb ).catInfo = catinfo; + + ( *pb ).ref = &( *fs ).fsref; + ( *pb ).whichInfo = kFSCatInfoGettableInfo; + + err = PBGetCatalogInfoSync ( pb ); + + return ( ! oserror ( err ) ); + } /* getmacfileinfo */ -static boolean setmacfileinfo (const tyfilespec *fs, CInfoPBRec *pb) { - - /* - 2.1b2 dmb: new fsspec-based version - */ - - setoserrorparam ((ptrstring) (*fs).name); /*in case error message takes a filename parameter*/ - - (*pb).hFileInfo.ioNamePtr = (StringPtr) (*fs).name; - - (*pb).hFileInfo.ioVRefNum = (*fs).vRefNum; - - (*pb).hFileInfo.ioDirID = (*fs).parID; - - return (!oserror (PBSetCatInfoSync (pb))); - } /*setmacfileinfo*/ + boolean getmacfileinfocipbr (const FSSpecPtr fs, CInfoPBRec *pb) { + + /* + 2.1b2 dmb: new fsspec-based version + */ + + setoserrorparam ((ptrstring) (*fs).name); /*in case error message takes a filename parameter*/ + + clearbytes (pb, sizeof (*pb)); + + (*pb).hFileInfo.ioNamePtr = (StringPtr) (*fs).name; + + (*pb).hFileInfo.ioVRefNum = (*fs).vRefNum; + + (*pb).hFileInfo.ioDirID = (*fs).parID; + + return (!oserror (PBGetCatInfoSync (pb))); + } /*getmacfileinfo*/ -static boolean touchparentfolder (const tyfilespec *fs) { - - /* - touch the file date of the parent folder of fs - */ - - FSSpec fsfolder; - - if (FSMakeFSSpec ((*fs).vRefNum, (*fs).parID, nil, &fsfolder) != noErr) - return (false); - - setfilemodified (&fsfolder, timenow ()); - - return (true); - } /*touchparentfolder*/ + static boolean setmacfileinfo ( const ptrfilespec fs, FSRefParam *pb ) { + + /* + 2.1b2 dmb: new fsspec-based version + */ + + setfserrorparam ( fs ); /*in case error message takes a filename parameter*/ + + ( *pb ).ref = &( *fs ).fsref; + ( *pb ).whichInfo = kFSCatInfoSettableInfo; + + return ( ! oserror ( PBSetCatalogInfoSync ( pb ) ) ); + } /* setmacfileinfo */ + + + static boolean touchparentfolder ( const ptrfilespec fs ) { + + // + // touch the file date of the parent folder of fs + // + // 2006-06-18 creedon: FSRef-ized + // + + tyfilespec fsfolder = { { { 0 } }, 0 }; + + if ( FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoNone, NULL, NULL, NULL, &fsfolder.fsref ) != noErr ) + return (false); + + setfilemodified ( &fsfolder, timenow ( ) ); + + return (true); + + } // touchparentfolder + + #endif #ifdef WIN95VERSION -boolean winfileerror (const tyfilespec *fs) { +boolean winfileerror (const ptrfilespec fs) { DWORD err = GetLastError (); @@ -311,301 +365,440 @@ #ifdef MACVERSION // 1/29/97 dmb: adopt applet toolkit version -static boolean getinfofromvolpb (const HVolumeParam *pb, tyfileinfo *info) { - - /* - dmb 9/21/93: for a volume, dirid should be fsRtParID, not fsRtDirID. - */ - - short drivenum; - #if !TARGET_API_MAC_CARBON - QHdrPtr dqtop; - QElemPtr dqelem; - #endif + static boolean getinfofromvolpb (const FSVolumeInfoParamPtr pb, tyfileinfo *info) { + + // + // 2006-06-25 creedon: FSRef-ized + // + // 1993-09-21 dmb: for a volume, dirid should be fsRtParID, not fsRtDirID. + // + + short drivenum; + + clearbytes (info, sizeof (tyfileinfo)); + + ( *info ).vnum = (*pb).ioVRefNum; + + ( *info ).dirid = fsRtParID; + + ( *info ).flvolume = true; + + ( *info ).flfolder = true; + + /* date time */ { + + CFAbsoluteTime oCFTime; + OSStatus status; + + status = UCConvertUTCDateTimeToCFAbsoluteTime ( &( *( *pb ).volumeInfo ).createDate, &oCFTime ); + + status = UCConvertCFAbsoluteTimeToSeconds ( oCFTime, &( *info ).timecreated ); - - clearbytes (info, sizeof (tyfileinfo)); - - (*info).vnum = (*pb).ioVRefNum; - - (*info).dirid = fsRtParID; /*fsRtDirID*/ - - (*info).flvolume = true; - - (*info).flfolder = true; - - (*info).timecreated = (*pb).ioVCrDate; - - (*info).timemodified = (*pb).ioVLsMod; - - (*info).fllocked = ((*pb).ioVAtrb & 0x8000) != 0; - - (*info).flhardwarelock = ((*pb).ioVAtrb & 0x0080) != 0; - - if ((*info).flhardwarelock) - (*info).fllocked = true; - - (*info).ctfreebytes = (*pb).ioVAlBlkSiz * (*pb).ioVFrBlk; - - (*info).cttotalbytes = (*pb).ioVAlBlkSiz * (*pb).ioVNmAlBlks; - - (*info).blocksize = (*pb).ioVAlBlkSiz; - - (*info).ctfiles = (*pb).ioVFilCnt; - - (*info).ctfolders = (*pb).ioVDirCnt; - - drivenum = (*pb).ioVDrvInfo; - - //Code change by Timothy Paustian Sunday, June 25, 2000 9:17:36 PM - //The below code is to figure out if a volume is ejectable. I don't think - //you can do this in carbon, so just set it to false. - #if TARGET_API_MAC_CARBON == 1 - (*info).flejectable = false; - #else + status = UCConvertUTCDateTimeToCFAbsoluteTime ( &( *( *pb ).volumeInfo ).modifyDate, &oCFTime ); + + status = UCConvertCFAbsoluteTimeToSeconds ( oCFTime, &( *info ).timemodified ); + + } + + ( *info ).flhardwarelock = BitTst ( &( *( *pb ).volumeInfo ).flags, 7 ); - dqtop = GetDrvQHdr (); - - dqelem = (*dqtop).qHead; - - while (true) { + if (( *info ).flhardwarelock) + ( *info ).fllocked = true; + else + ( *info ).fllocked = BitTst ( &( *( *pb ).volumeInfo ).flags, 15 ); - if (dqelem == nil) { /*volume is no longer in a drive; it must be ejectable!*/ + ( *info ).ctfreebytes = ( *( *pb ).volumeInfo ).blockSize * ( *( *pb ).volumeInfo ).freeBlocks; + + ( *info ).cttotalbytes = ( *( *pb ).volumeInfo ).blockSize * ( *( *pb ).volumeInfo ).totalBlocks; + + ( *info ).blocksize = ( *( *pb ).volumeInfo ).blockSize; + + ( *info ).ctfiles = ( *( *pb ).volumeInfo ).fileCount; + + ( *info ).ctfolders = ( *( *pb ).volumeInfo ).folderCount; + + drivenum = ( *( *pb ).volumeInfo ).driveNumber; + + //Code change by Timothy Paustian Sunday, June 25, 2000 9:17:36 PM + //The below code is to figure out if a volume is ejectable. I don't think + //you can do this in carbon, so just set it to false. + + ( *info ).flejectable = false; + + return (true); + + } // getinfofromvolpb + + + boolean filegetvolumeinfo (short vnum, tyfileinfo *info) { + + // + // dmb 9/21/93: take vnum as parameter, not volname. otherwise, we can't distinguish between two vols w/the + // same name. + // + // 1993-09-07 DW: determine if it's a network volume + // + + FSVolumeInfoParam pb; + FSVolumeInfo volinfo; + + clearbytes ( &pb, sizeof ( pb ) ); // init all fields to zero + clearbytes ( &volinfo, sizeof ( volinfo ) ); // init all fields to zero + + pb.volumeInfo = &volinfo; + + pb.ioVRefNum = vnum; + pb.whichInfo = kFSVolInfoGettableInfo; + + if ( oserror ( PBGetVolumeInfoSync ( &pb ) ) ) + return ( false ); + + // clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ + + getinfofromvolpb ( &pb, info ); + + /* network volume */ { - (*info).flejectable = true; + HParamBlockRec lpb; + GetVolParmsInfoBuffer buffer; + OSErr err; - break; - } - - if ((*(DrvQEl *)dqelem).dQDrive == drivenum) { + clearbytes (&lpb, sizeof (lpb)); /*init all fields to zero*/ - byte driveflag = *((byte *) dqelem - 3); + lpb.ioParam.ioVRefNum = (*info).vnum; - (*info).flejectable = ((driveflag != 8) && (driveflag != 0x48)); /*IM IV-181*/ + lpb.ioParam.ioBuffer = ( Ptr ) &buffer; - break; + lpb.ioParam.ioReqCount = sizeof (buffer); + + err = PBHGetVolParmsSync (&lpb); + + if (err == noErr) + ( *info ).flremotevolume = VolIsNetworkVolume ( &buffer ); } - dqelem = (*dqelem).qLink; - } /*while*/ - #endif - - - return (true); - } /*getinfofromvolpb*/ + return (true); + } /*filegetvolumeinfo*/ -boolean filegetvolumeinfo (short vnum, tyfileinfo *info) { - - /* - dmb 9/21/93: take vnum as parameter, not volname. otherwise, - we can't distinguish between two vols w/the same name. - */ - - HVolumeParam pb; - - clearbytes (&pb, sizeof (pb)); /*init all fields to zero*/ - - pb.ioVRefNum = vnum; - - if (oserror (PBHGetVInfoSync ((HParmBlkPtr) &pb))) - return (false); - - clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ - - getinfofromvolpb (&pb, info); - - /*DW 9/7/93: determine if it's a network volume*/ { + void filegetinfofrompb ( FSRefParam *pb, tyfileinfo *info ) { - HParamBlockRec lpb; - GetVolParmsInfoBuffer buffer; - OSErr ec; + // + // 2006-06-24 creedon: FSRef-ized + // + // 5.1.4 dmb: set finderbits for folders too. + // + // 1993-09-24 dmb: handle volumes here, combining vol info with root directory folder info. I'm not sure if a + // volume lock is always reflected in the root directory, so don't set fllocked false if the + // attribute isn't set in the pb. (it starts out cleared anyway.) + // - clearbytes (&lpb, sizeof (lpb)); /*init all fields to zero*/ + unsigned short finderbits; - lpb.ioParam.ioVRefNum = (*info).vnum; + clearbytes ( info, sizeof ( tyfileinfo ) ); // init all fields to zero - lpb.ioParam.ioBuffer = (Ptr) &buffer; + ( *info ).dirid = ( *pb ).catInfo -> parentDirID; - lpb.ioParam.ioReqCount = sizeof (buffer); + /* date time */ { - ec = PBHGetVolParmsSync (&lpb); - - if (ec == noErr) - (*info).flremotevolume = buffer.vMServerAdr != 0; /*see Apple TN-Files docviewer doc*/ - } - - return (true); - } /*filegetvolumeinfo*/ + CFAbsoluteTime oCFTime; + OSStatus status; + + status = UCConvertUTCDateTimeToCFAbsoluteTime ( &( *pb ).catInfo -> createDate, &oCFTime ); + + status = UCConvertCFAbsoluteTimeToSeconds ( oCFTime, &info -> timecreated ); + status = UCConvertUTCDateTimeToCFAbsoluteTime ( &( *pb ).catInfo -> contentModDate, &oCFTime ); + + status = UCConvertCFAbsoluteTimeToSeconds ( oCFTime, &info -> timemodified ); + + } // date time -void filegetinfofrompb (CInfoPBRec *pb, tyfileinfo *info) { - - /* - dmb 9/24/93: handle volumes here, combining vol info with root - directory folder info. I'm not sure if a volume lock is always - reflected in the root directory, so don't set fllocked false - if the attribute isn't set in the pb. (it starts out cleared anyway.) - - 5.1.4 dmb: set finderbits for folders too. - */ - - short finderbits; - - clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ - - (*info).vnum = (*pb).hFileInfo.ioVRefNum; - - (*info).dirid = (*pb).hFileInfo.ioFlParID; - - if ((*info).dirid == fsRtParID) - filegetvolumeinfo ((*info).vnum, info); - else - (*info).flvolume = false; - - if (BitTst (&(*pb).dirInfo.ioFlAttrib, 7)) /*if it's a volume, fllocked may already be set*/ - (*info).fllocked = true; - -// (*info).flfolder = BitTst (&(*pb).dirInfo.ioFlAttrib, 3); - (*info).flfolder = (((*pb).dirInfo.ioFlAttrib & ioDirMask) != 0); - - (*info).ixlabel = ((*pb).hFileInfo.ioFlFndrInfo.fdFlags & 0x000E) >> 1; - - if ((*info).flfolder) { - - /*Folders are considered "busy" if there are any files within the folder */ + ( *info ).vnum = ( *( *pb ).catInfo ).volume; - (*info).flbusy = (*pb).dirInfo.ioDrNmFls > 0; + if ( ( *info ).dirid == fsRtParID) + filegetvolumeinfo (( *info ).vnum, info); + else + ( *info ).flvolume = false; + + if ( ( pb -> catInfo -> nodeFlags & kFSNodeForkOpenMask ) != 0 ) // if it's a volume, fllocked may already be set + ( *info ).fllocked = true; + else + ( *info ).fllocked = ( ( *pb ).catInfo -> nodeFlags & kFSNodeLockedMask ) != 0; - (*info).filecreator = (*info).filetype = ' '; + ( *info ).flfolder = ( ( pb -> catInfo -> nodeFlags & kFSNodeIsDirectoryMask ) != 0 ); - if (!(*info).flvolume) { /*these aren't the same for a volume & its root dir*/ + if ( ( *info ).flfolder ) { + + boolean flisapplication, flisbundle; - (*info).timecreated = (*pb).dirInfo.ioDrCrDat; + LSIsApplication ( ( *pb ).ref, &flisapplication, &flisbundle ); - (*info).timemodified = (*pb).dirInfo.ioDrMdDat; + if ( flisapplication || flisbundle ) { // Mac OS X bundles/packages are not considered folders - (*info).ctfiles = (*pb).dirInfo.ioDrNmFls; + ( *info ).flfolder = false; + + ( *info ).flbundle = true; + + } // if + + ( *info ).flbusy = pb -> catInfo -> valence > 0; // Folders are considered "busy" if there are any files + // within the folder + if ( ( *info ).flfolder ) + + ( *info ).filecreator = ( *info ).filetype = ' '; + + else { + + LSItemInfoRecord iteminfo; + OSStatus status; + + status = LSCopyItemInfoForRef ( ( *pb ).ref, kLSRequestTypeCreator, &iteminfo ); + + ( *info ).filecreator = iteminfo.creator; + + ( *info ).filetype = iteminfo.filetype; + + } // if + + ( *info ).iconposition = ( ( FolderInfo * ) pb -> catInfo -> finderInfo ) -> location; + + if ( ! ( *info ).flvolume ) { // these aren't the same for a volume & its root dir + + ( *info ).ctfiles = pb -> catInfo -> valence; + + } // if + + ( *info ).folderview = ( tyfolderview ) 0; // I can't find a way to get this info from FSRefParamPtr, I thought about trying to fake a DInfo structure and getting it from there but it may not even have the right value, I did find a reference to DRMacWindowView // dinfo.frView >> 8; + + finderbits = ( ( FolderInfo * ) pb -> catInfo -> finderInfo ) -> finderFlags; + } + else { // fill in fields for a file, somewhat different format than a folder - (*info).iconposition = (*pb).dirInfo.ioDrUsrWds.frLocation; + ( *info ).ixlabel = ( ( ( FileInfo * ) pb -> catInfo -> finderInfo ) -> finderFlags & kColor ) >> 1; - (*info).folderview = (tyfolderview) ((*pb).dirInfo.ioDrUsrWds.frView >> 8); - - finderbits = (*pb).dirInfo.ioDrUsrWds.frFlags; - } - else { /*fill in fields for a file, somewhat different format than a folder*/ - - (*info).flbusy = BitTst (&(*pb).hFileInfo.ioFlAttrib, 0); + ( *info ).flbusy = ( pb -> catInfo -> nodeFlags & kFSNodeForkOpenMask ) != 0; + + ( *info ).filecreator = ( ( FileInfo * ) pb -> catInfo -> finderInfo ) -> fileCreator; - (*info).filecreator = (*pb).hFileInfo.ioFlFndrInfo.fdCreator; + ( *info ).filetype = ( ( FileInfo * ) pb -> catInfo -> finderInfo ) -> fileType; + + ( *info ).sizedatafork = pb -> catInfo -> dataLogicalSize; + + ( *info ).sizeresourcefork = pb -> catInfo -> rsrcLogicalSize; + + ( *info ).iconposition = ( ( FileInfo * ) pb -> catInfo -> finderInfo ) -> location; + + finderbits = ( ( FileInfo * ) pb -> catInfo -> finderInfo ) -> finderFlags; + + } // if + + /* copy from the finder bits into the record */ { - (*info).filetype = (*pb).hFileInfo.ioFlFndrInfo.fdType; - - (*info).timecreated = (*pb).hFileInfo.ioFlCrDat; + ( *info ).flalias = (finderbits & kIsAlias) != 0; + + ( *info ).flbundle = (finderbits & kHasBundle) != 0; + + ( *info ).flinvisible = (finderbits & kIsInvisible) != 0; + + ( *info ).flstationery = (finderbits & kIsStationery) != 0; + + ( *info ).flshared = (finderbits & kIsShared) != 0; + + ( *info ).flnamelocked = (finderbits & kNameLocked) != 0; + + ( *info ).flcustomicon = (finderbits & kHasCustomIcon) != 0; + + } // finder bits + + } // filegetinfofrompb - (*info).timemodified = (*pb).hFileInfo.ioFlMdDat; + + void filegetinfofrompbcipbr (CInfoPBRec *pb, tyfileinfo *info) { - (*info).sizedatafork = (*pb).hFileInfo.ioFlLgLen; + /* + dmb 9/24/93: handle volumes here, combining vol info with root + directory folder info. I'm not sure if a volume lock is always + reflected in the root directory, so don't set fllocked false + if the attribute isn't set in the pb. (it starts out cleared anyway.) - (*info).sizeresourcefork = (*pb).hFileInfo.ioFlRLgLen; + 5.1.4 dmb: set finderbits for folders too. + */ - (*info).iconposition = (*pb).hFileInfo.ioFlFndrInfo.fdLocation; + short finderbits; - finderbits = (*pb).hFileInfo.ioFlFndrInfo.fdFlags; - } - - /*copy from the finder bits into the record*/ { - - (*info).flalias = (finderbits & kIsAlias) != 0; + clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ - (*info).flbundle = (finderbits & kHasBundle) != 0; + (*info).vnum = (*pb).hFileInfo.ioVRefNum; - (*info).flinvisible = (finderbits & kIsInvisible) != 0; + (*info).dirid = (*pb).hFileInfo.ioFlParID; - (*info).flstationery = (finderbits & kIsStationery) != 0; + if ((*info).dirid == fsRtParID) + filegetvolumeinfo ((*info).vnum, info); + else + (*info).flvolume = false; - (*info).flshared = (finderbits & kIsShared) != 0; + if (BitTst (&(*pb).dirInfo.ioFlAttrib, 7)) /*if it's a volume, fllocked may already be set*/ + (*info).fllocked = true; - (*info).flnamelocked = (finderbits & kNameLocked) != 0; + // (*info).flfolder = BitTst (&(*pb).dirInfo.ioFlAttrib, 3); + (*info).flfolder = (((*pb).dirInfo.ioFlAttrib & ioDirMask) != 0); - (*info).flcustomicon = (finderbits & kHasCustomIcon) != 0; - } - } /*filegetinfofrompb*/ + (*info).ixlabel = ((*pb).hFileInfo.ioFlFndrInfo.fdFlags & 0x000E) >> 1; + + if ((*info).flfolder) { + + /*Folders are considered "busy" if there are any files within the folder */ + + (*info).flbusy = (*pb).dirInfo.ioDrNmFls > 0; + + (*info).filecreator = (*info).filetype = ' '; + + if (!(*info).flvolume) { /*these aren't the same for a volume & its root dir*/ + + (*info).timecreated = (*pb).dirInfo.ioDrCrDat; + + (*info).timemodified = (*pb).dirInfo.ioDrMdDat; + + (*info).ctfiles = (*pb).dirInfo.ioDrNmFls; + } + + (*info).iconposition = (*pb).dirInfo.ioDrUsrWds.frLocation; + + (*info).folderview = (tyfolderview) ((*pb).dirInfo.ioDrUsrWds.frView >> 8); + + finderbits = (*pb).dirInfo.ioDrUsrWds.frFlags; + } + else { /*fill in fields for a file, somewhat different format than a folder*/ + + (*info).flbusy = BitTst (&(*pb).hFileInfo.ioFlAttrib, 0); + + (*info).filecreator = (*pb).hFileInfo.ioFlFndrInfo.fdCreator; + + (*info).filetype = (*pb).hFileInfo.ioFlFndrInfo.fdType; + + (*info).timecreated = (*pb).hFileInfo.ioFlCrDat; + + (*info).timemodified = (*pb).hFileInfo.ioFlMdDat; + + (*info).sizedatafork = (*pb).hFileInfo.ioFlLgLen; + + (*info).sizeresourcefork = (*pb).hFileInfo.ioFlRLgLen; + + (*info).iconposition = (*pb).hFileInfo.ioFlFndrInfo.fdLocation; + + finderbits = (*pb).hFileInfo.ioFlFndrInfo.fdFlags; + } + + /*copy from the finder bits into the record*/ { + + (*info).flalias = (finderbits & kIsAlias) != 0; + + (*info).flbundle = (finderbits & kHasBundle) != 0; + + (*info).flinvisible = (finderbits & kIsInvisible) != 0; + + (*info).flstationery = (finderbits & kIsStationery) != 0; + + (*info).flshared = (finderbits & kIsShared) != 0; + + (*info).flnamelocked = (finderbits & kNameLocked) != 0; + + (*info).flcustomicon = (finderbits & kHasCustomIcon) != 0; + } + } /* filegetinfofrompbcipbr */ + #endif -#ifdef MACVERSION -#define filegetfsvolumeinfo(fs, info) filegetvolumeinfo((*fs).vRefNum, info) -#endif +static boolean filegetfsvolumeinfo (const ptrfilespec fs, tyfileinfo *info) { -#ifdef WIN95VERSION -static boolean filegetfsvolumeinfo (const tyfilespec *fs, tyfileinfo *info) { - DWORD sectorsPerCluster, bytesPerSector, numberOfFreeClusters, totalNumberOfClusters; - UINT drivetype; - bigstring volname; - bigstring errmsg; + clearbytes (info, sizeof (tyfileinfo)); // init all fields to zero - clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ + #ifdef MACVERSION + + long vnum; + + getfsvolume ( fs, &vnum ); - if (fileisvolume (fs)) { - info->flvolume = true; - info->flbusy = true; + if ( !filegetvolumeinfo ( vnum, info ) ) + return ( false ); + + return ( true ); + + #endif - copystring (fsname(fs), volname); - cleanendoffilename (volname); - pushchar ('\\', volname); - nullterminate (volname); + #ifdef WIN95VERSION -// if (GetVolumeInformation (stringbaseaddress (volname), stringbaseaddress(volnamebuf), -// sizeof(volnamebuf)-2, &volserial, &maxfilelen, &filesystemflags, -// stringbaseaddress(filesystemnamebuffer), sizeof (filesystemnamebuffer)) { -// -// } + DWORD sectorsPerCluster, bytesPerSector, numberOfFreeClusters, totalNumberOfClusters; + UINT drivetype; + bigstring volname; + bigstring errmsg; - if (GetDiskFreeSpace (stringbaseaddress (volname), §orsPerCluster, &bytesPerSector, - &numberOfFreeClusters, &totalNumberOfClusters)) { + if (fileisvolume (fs)) { + info->flvolume = true; + info->flbusy = true; - DWORD bytesPerCluster; - DWORD numberOfClustersIn2GB; + copystring (fsname(fs), volname); + cleanendoffilename (volname); + pushchar ('\\', volname); + nullterminate (volname); - bytesPerCluster = bytesPerSector * sectorsPerCluster; + // if (GetVolumeInformation (stringbaseaddress (volname), stringbaseaddress(volnamebuf), + // sizeof(volnamebuf)-2, &volserial, &maxfilelen, &filesystemflags, + // stringbaseaddress(filesystemnamebuffer), sizeof (filesystemnamebuffer)) { + // + // } - numberOfClustersIn2GB = 0x7FFFFFFFL / bytesPerCluster; + if (GetDiskFreeSpace (stringbaseaddress (volname), §orsPerCluster, &bytesPerSector, + &numberOfFreeClusters, &totalNumberOfClusters)) { - info->ctfreebytes = (numberOfFreeClusters <= numberOfClustersIn2GB) - ? (numberOfFreeClusters * bytesPerCluster) - : (numberOfClustersIn2GB * bytesPerCluster); + DWORD bytesPerCluster; + DWORD numberOfClustersIn2GB; - info->cttotalbytes = (totalNumberOfClusters <= numberOfClustersIn2GB) - ? (totalNumberOfClusters * bytesPerCluster) - : (numberOfClustersIn2GB * bytesPerCluster); + bytesPerCluster = bytesPerSector * sectorsPerCluster; - info->blocksize = bytesPerCluster; - } + numberOfClustersIn2GB = 0x7FFFFFFFL / bytesPerCluster; - drivetype = GetDriveType (stringbaseaddress(volname)); + info->ctfreebytes = (numberOfFreeClusters <= numberOfClustersIn2GB) + ? (numberOfFreeClusters * bytesPerCluster) + : (numberOfClustersIn2GB * bytesPerCluster); - if ((drivetype == DRIVE_REMOVABLE) || (drivetype == DRIVE_CDROM)) { - info->flejectable = true; - } + info->cttotalbytes = (totalNumberOfClusters <= numberOfClustersIn2GB) + ? (totalNumberOfClusters * bytesPerCluster) + : (numberOfClustersIn2GB * bytesPerCluster); - if (drivetype == DRIVE_REMOTE) { - info->flremotevolume = true; + info->blocksize = bytesPerCluster; + } + + drivetype = GetDriveType (stringbaseaddress(volname)); + + if ((drivetype == DRIVE_REMOVABLE) || (drivetype == DRIVE_CDROM)) { + info->flejectable = true; + } + + if (drivetype == DRIVE_REMOTE) { + info->flremotevolume = true; + } + + return (true); } - return (true); - } + wsprintf (stringbaseaddress (errmsg), "Can't complete function because \"%s\" is not a valid volume name.", + stringbaseaddress (fsname (fs))); - wsprintf (stringbaseaddress (errmsg), "Can't complete function because \"%s\" is not a valid volume name.", - stringbaseaddress (fsname (fs))); + setstringlength (errmsg, strlen (stringbaseaddress (errmsg))); - setstringlength (errmsg, strlen (stringbaseaddress (errmsg))); + shellerrormessage (errmsg); - shellerrormessage (errmsg); + return (false); + + #endif + + } // filegetfsvolumeinfo - return (false); - } /*filegetfsvolumeinfo*/ +#ifdef WIN95VERSION void winsetfileinfo (WIN32_FIND_DATA * fileinfo, tyfileinfo *info) { @@ -657,103 +850,136 @@ #endif -boolean filegetinfo (const tyfilespec *fs, tyfileinfo *info) { +boolean filegetinfo (const ptrfilespec fs, tyfileinfo *info) { -#ifdef MACVERSION - /* - dmb 9/24/93: let filegetinfofrompb take care of volumes - */ + // + // 2006-06-25 creedon: for Mac, FSRef-ized + // + // 1993-09-24 dmb: for Mac, let filegetinfofrompb take care of volumes + // + + #ifdef MACVERSION - CInfoPBRec pb; + setfserrorparam ( fs ); + + if ( ( *fs ).path != NULL ) + return ( ! oserror ( fnfErr ) ); + + FSCatalogInfo catinfo; + FSRefParam pb; + OSErr err; + + clearbytes ( &pb, sizeof ( pb ) ); + + setfserrorparam ( fs ); // in case error message takes a filename parameter + + pb.catInfo = &catinfo; + /* + pb.outName = NULL; + pb.parentRef = NULL; + */ + pb.ref = &( *fs ).fsref; + // pb.spec = NULL; + pb.whichInfo = kFSCatInfoGettableInfo; + + err = PBGetCatalogInfoSync ( &pb ); + + if ( oserror ( err ) ) + return ( false ); + + /* + if (isvolumefilespec (pfs)) { + + return (filegetfsvolumeinfo (pfs, info)); + } + */ + + /* + if (!getmacfileinfo (fs, &pb)) + return (false); + */ + + filegetinfofrompb (&pb, info); + + #endif + + #ifdef WIN95VERSION - /* - if (isvolumefilespec (pfs)) { + HANDLE findHandle; + HANDLE fref; + WIN32_FIND_DATA fileinfo; + char fn[300]; - return (filegetfsvolumeinfo (pfs, info)); - } - */ - - if (!getmacfileinfo (fs, &pb)) - return (false); - - filegetinfofrompb (&pb, info); -#endif - -#ifdef WIN95VERSION - HANDLE findHandle; - HANDLE fref; - WIN32_FIND_DATA fileinfo; - char fn[300]; - - clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ - info->filecreator = ' '; - info->filetype = ' '; + clearbytes (info, sizeof (tyfileinfo)); /*init all fields to zero*/ + info->filecreator = ' '; + info->filetype = ' '; - if (fileisvolume (fs)) { - return (filegetfsvolumeinfo (fs, info)); - } + if (fileisvolume (fs)) { + return (filegetfsvolumeinfo (fs, info)); + } - copystring (fsname (fs), fn); - - /*if ends with \ get ride of it... and handle the root*/ + copystring (fsname (fs), fn); + + /*if ends with \ get ride of it... and handle the root*/ - cleanendoffilename (fn); + cleanendoffilename (fn); - nullterminate (fn); + nullterminate (fn); - findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo); + findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo); - if (findHandle == INVALID_HANDLE_VALUE) { - - winfileerror (fs); + if (findHandle == INVALID_HANDLE_VALUE) { + + winfileerror (fs); - return (false); - } + return (false); + } - winsetfileinfo (&fileinfo, info); + winsetfileinfo (&fileinfo, info); - FindClose(findHandle); + FindClose(findHandle); - //Set the file busy flag (this should be in winsetfileinfo, but we do not have the filename there) - if (info->flfolder) { - strcat (stringbaseaddress (fn), "\\*"); + //Set the file busy flag (this should be in winsetfileinfo, but we do not have the filename there) + if (info->flfolder) { + strcat (stringbaseaddress (fn), "\\*"); - info->flbusy = false; //presume empty folder (not busy) + info->flbusy = false; //presume empty folder (not busy) - findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo); + findHandle = FindFirstFile (stringbaseaddress(fn), &fileinfo); - if (findHandle != INVALID_HANDLE_VALUE) { - info->flbusy = true; //Found something + if (findHandle != INVALID_HANDLE_VALUE) { + info->flbusy = true; //Found something - while ((strcmp (fileinfo.cFileName, ".") == 0) || (strcmp (fileinfo.cFileName, "..") == 0)) { - info->flbusy = false; // Just . or .. + while ((strcmp (fileinfo.cFileName, ".") == 0) || (strcmp (fileinfo.cFileName, "..") == 0)) { + info->flbusy = false; // Just . or .. - if (FindNextFile (findHandle, &fileinfo)) - info->flbusy = true; //Found something else... - else - break; //exit while loop if FindNext fails (this is normal) + if (FindNextFile (findHandle, &fileinfo)) + info->flbusy = true; //Found something else... + else + break; //exit while loop if FindNext fails (this is normal) + } + + FindClose (findHandle); } - - FindClose (findHandle); } - } - else { - fref = (Handle) CreateFile (stringbaseaddress (fn), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, NULL); + else { + fref = (Handle) CreateFile (stringbaseaddress (fn), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, NULL); - if (fref == INVALID_HANDLE_VALUE) { - info->flbusy = true; + if (fref == INVALID_HANDLE_VALUE) { + info->flbusy = true; + } + else { + info->flbusy = false; + verify (CloseHandle (fref)); + } } - else { - info->flbusy = false; - verify (CloseHandle (fref)); - } - } -#endif + #endif + return (true); - } /*filegetinfo*/ + } // filegetinfo boolean filegetvolumename (short vnum, bigstring volname) { @@ -804,7 +1030,7 @@ } /*filegetvolumename*/ -boolean fileisbusy (const tyfilespec *fs, boolean *flbusy) { +boolean fileisbusy (const ptrfilespec fs, boolean *flbusy) { /* 6/x/91 mao @@ -821,7 +1047,7 @@ } /*fileisbusy*/ -boolean filehasbundle (const tyfilespec *fs, boolean *flbundle) { +boolean filehasbundle (const ptrfilespec fs, boolean *flbundle) { /* 6/x/91 mao @@ -838,32 +1064,59 @@ } /*filehasbundle*/ -boolean filesetbundle (const tyfilespec *fs, boolean flbundle) { -#ifdef MACVERSION - /* - 8/10/92 dmb - */ +boolean filesetbundle (const ptrfilespec fs, boolean flbundle) { + + // + // 2006-06-25 creedon: for Mac, FSRef-ized + // + // 1992-08-10 dmb: for Mac, created + // + + #ifdef MACVERSION - CInfoPBRec pb; + FSCatalogInfo catinfo; + FSRefParam pb; + + if ( ! getmacfileinfo ( fs, &pb, &catinfo ) ) + return ( false ); + + if ( BitTst ( &pb.catInfo -> nodeFlags, 4 ) ) { // is directory + + if (flbundle) + + ( ( FolderInfo * ) pb.catInfo -> finderInfo ) -> finderFlags |= kHasBundle; // turn on + + else + + ( ( FolderInfo * ) pb.catInfo -> finderInfo ) -> finderFlags &= ~kHasBundle; // turn off + + } + else { + + if (flbundle) + + ( ( FileInfo * ) pb.catInfo -> finderInfo ) -> finderFlags |= kHasBundle; // turn on + + else + + ( ( FileInfo * ) pb.catInfo -> finderInfo ) -> finderFlags &= ~kHasBundle; // turn off + + } + + return (setmacfileinfo (fs, &pb)); + + #endif + + #ifdef WIN95VERSION - if (!getmacfileinfo (fs, &pb)) return (false); + + #endif - if (flbundle) - pb.hFileInfo.ioFlFndrInfo.fdFlags |= kHasBundle; /*turn on*/ - else - pb.hFileInfo.ioFlFndrInfo.fdFlags &= ~kHasBundle; /*turn off*/ - - return (setmacfileinfo (fs, &pb)); -#endif + } // filesetbundle -#ifdef WIN95VERSION - return (false); -#endif - } /*filesetbundle*/ - -boolean fileisalias (const tyfilespec *fs, boolean *flalias) { +boolean fileisalias (const ptrfilespec fs, boolean *flalias) { /* 6/x/91 mao @@ -880,7 +1133,7 @@ } /*fileisalias*/ -boolean fileisvisible (const tyfilespec *fs, boolean *flvisible) { +boolean fileisvisible (const ptrfilespec fs, boolean *flvisible) { /* 6/9/92 dmb @@ -897,55 +1150,67 @@ } /*fileisvisible*/ -boolean filesetvisible (const tyfilespec *fs, boolean flvisible) { -#ifdef MACVERSION - /* - 6/9/92 dmb - */ +boolean filesetvisible (const ptrfilespec fs, boolean flvisible) { + + // + // 2006-06-13 creedon: for Mac, FSRef-ized + // + // 6/9/92 dmb: for Mac, created + // - CInfoPBRec pb; + #ifdef MACVERSION - if (!getmacfileinfo (fs, &pb)) - return (false); + OSErr err; + + if ( flvisible ) { + + err = FSClearInvisible ( &( *fs ).fsref ); + + if ( err != noErr ) + return ( true ); + } + else { + err = FSSetInvisible ( &( *fs ).fsref ); + + if ( err != noErr ) + return ( true ); + } + + touchparentfolder (fs); + + #endif + + #ifdef WIN95VERSION - if (flvisible) - pb.hFileInfo.ioFlFndrInfo.fdFlags &= ~kIsInvisible; /*turn off*/ - else - pb.hFileInfo.ioFlFndrInfo.fdFlags |= kIsInvisible; /*turn on*/ - - if (!setmacfileinfo (fs, &pb)) - return (false); - - touchparentfolder (fs); -#endif - -#ifdef WIN95VERSION - tyfileinfo info; - DWORD attr; - - if (!filegetinfo (fs, &info)) - return (false); + tyfileinfo info; + DWORD attr; + + if (!filegetinfo (fs, &info)) + return (false); - if (info.flinvisible == flvisible) /*check if we need to do anything first*/ - { - attr = GetFileAttributes (stringbaseaddress (fsname (fs))); + if (info.flinvisible == flvisible) // check if we need to do anything first + { + attr = GetFileAttributes (stringbaseaddress (fsname (fs))); - if (attr == 0xFFFFFFFF) - return (false); + if (attr == 0xFFFFFFFF) + return (false); - attr = attr & (~FILE_ATTRIBUTE_HIDDEN); + attr = attr & (~FILE_ATTRIBUTE_HIDDEN); - if (! flvisible) - attr = attr | FILE_ATTRIBUTE_HIDDEN; + if (! flvisible) + attr = attr | FILE_ATTRIBUTE_HIDDEN; - return(SetFileAttributes (stringbaseaddress (fsname (fs)), attr)); - } -#endif + return(SetFileAttributes (stringbaseaddress (fsname (fs)), attr)); + } + + #endif + return (true); - } /*filesetvisible*/ + + } // filesetvisible -boolean getfiletype (const tyfilespec *fs, OSType *type) { +boolean getfiletype (const ptrfilespec fs, OSType *type) { tyfileinfo info; @@ -960,7 +1225,7 @@ } /*getfiletype*/ -boolean getfilecreator (const tyfilespec *fs, OSType *creator) { +boolean getfilecreator (const ptrfilespec fs, OSType *creator) { tyfileinfo info; @@ -975,7 +1240,7 @@ } /*getfilecreator*/ -boolean filesize (const tyfilespec *fs, long *size) { +boolean filesize (const ptrfilespec fs, long *size) { tyfileinfo info; @@ -988,12 +1253,18 @@ } /*filesize*/ -boolean fileisfolder (const tyfilespec *fs, boolean *flfolder) { +boolean fileisfolder (const ptrfilespec fs, boolean *flfolder) { + + // + // 2006-06-19 creedon: Mac OS X bundles/packages are not considered folders + // tyfileinfo info; #ifdef WIN95VERSION - /* special case the root directory on Windows */ + + // special case the root directory on Windows + char fn[300]; copystring (fsname (fs), fn); @@ -1010,64 +1281,98 @@ } } } - #endif if (!filegetinfo (fs, &info)) return (false); - + *flfolder = info.flfolder; - return (true); - } /*fileisfolder*/ + #ifdef MACVERSION + + // Mac OS X bundles/packages are not considered folders + + boolean flisapplication, flisbundle; + + LSIsApplication ( &( *fs ).fsref, &flisapplication, &flisbundle ); - -boolean fileisvolume (const tyfilespec *fs) { -#ifdef MACVERSION - if (isemptystring ((*fs).name)) - return (false); + if ( flisapplication || flisbundle ) + *flfolder = false; + + #endif - return ((*fs).parID == fsRtParID); -#endif + return ( true ); + + } // fileisfolder -#ifdef WIN95VERSION - bigstring bsvol; - short drivenum; - DWORD drivemap, drivemask; - copystring (fsname(fs), bsvol); +boolean fileisvolume (const ptrfilespec fs) { - switch (stringlength (bsvol)) { + // + // 2006-06-25 creedon: for Mac, FSRef-ized + // + + #ifdef MACVERSION + + bigstring bsname; - case 3: - if (getstringcharacter(bsvol, 2) != '\\') - return (false); + getfsfile ( fs, bsname ); + + if ( isemptystring ( bsname ) ) + return ( false ); + + FSCatalogInfo catalogInfo; + OSStatus status; + + clearbytes ( &catalogInfo, longsizeof ( catalogInfo ) ); - case 2: - if (getstringcharacter(bsvol, 1) != ':') - return (false); + status = FSGetCatalogInfo ( &( *fs ).fsref, kFSCatInfoParentDirID, &catalogInfo, NULL, NULL, NULL ); + + return ( catalogInfo.parentDirID == fsRtParID ); + + #endif - if (! isalpha (getstringcharacter(bsvol, 0))) - return (false); + #ifdef WIN95VERSION + + bigstring bsvol; + short drivenum; + DWORD drivemap, drivemask; - drivenum = getlower(getstringcharacter(bsvol, 0)) - 'a'; - break; + copystring (fsname(fs), bsvol); - default: - return (false); - } + switch (stringlength (bsvol)) { + + case 3: + if (getstringcharacter(bsvol, 2) != '\\') + return (false); - drivemap = GetLogicalDrives(); - - drivemask = 1 << drivenum; + case 2: + if (getstringcharacter(bsvol, 1) != ':') + return (false); - return ((drivemap & drivemask) == drivemask); -#endif - } /*fileisvolume*/ + if (! isalpha (getstringcharacter(bsvol, 0))) + return (false); + drivenum = getlower(getstringcharacter(bsvol, 0)) - 'a'; + break; -boolean fileislocked (const tyfilespec *fs, boolean *fllocked) { + default: + return (false); + } + + drivemap = GetLogicalDrives(); + + drivemask = 1 << drivenum; + + return ((drivemap & drivemask) == drivemask); + + #endif + } // fileisvolume + + +boolean fileislocked (const ptrfilespec fs, boolean *fllocked) { + tyfileinfo info; if (!filegetinfo (fs, &info)) @@ -1079,7 +1384,7 @@ } /*fileislocked*/ -boolean getfiledates (const tyfilespec *fs, unsigned long *datecreated, unsigned long *datemodified) { +boolean getfiledates (const ptrfilespec fs, unsigned long *datecreated, unsigned long *datemodified) { tyfileinfo info; @@ -1094,121 +1399,86 @@ } /*getfiledates*/ -boolean setfiledates (const tyfilespec *fs, unsigned long datecreated, unsigned long datemodified) { -#ifdef MACVERSION - /* - 6/x/91 mao: modified to work with new getmacilfeinfo/setmacfileinfo. - */ +boolean setfiledates (const ptrfilespec fs, unsigned long datecreated, unsigned long datemodified) { + + // + // 2006-06-25 creedon: for Mac, work with UTC + // + // 1991-06 mao: modified to work with new getmacilfeinfo/setmacfileinfo. + // + + #ifdef MACVERSION + + CFAbsoluteTime oCFTime; + FSCatalogInfo catinfo; + FSRefParam pb; + OSStatus status; + + if ( ! getmacfileinfo ( fs, &pb, &catinfo ) ) + return ( false ); - CInfoPBRec pb; - - if (!getmacfileinfo (fs, &pb)) - return (false); - - if (foldertest (&pb)) { + status = UCConvertSecondsToCFAbsoluteTime ( datecreated, &oCFTime ); - pb.dirInfo.ioDrCrDat = datecreated; + status = UCConvertCFAbsoluteTimeToUTCDateTime ( oCFTime, &pb.catInfo -> createDate ); - pb.dirInfo.ioDrMdDat = datemodified; - } - else { + status = UCConvertSecondsToCFAbsoluteTime ( datemodified, &oCFTime ); - pb.hFileInfo.ioFlCrDat = datecreated; + status = UCConvertCFAbsoluteTimeToUTCDateTime ( oCFTime, &pb.catInfo -> contentModDate ); + + return ( setmacfileinfo ( fs, &pb ) ); + + #endif - pb.hFileInfo.ioFlMdDat = datemodified; - } + #ifdef WIN95VERSION - return (setmacfileinfo (fs, &pb)); -#endif + HANDLE h; + FILETIME modtime, createtime, temp; + char fn[300]; + DWORD err; + boolean fl; -#ifdef WIN95VERSION - HANDLE h; - FILETIME modtime, createtime, temp; - char fn[300]; - DWORD err; - boolean fl; + secondstofiletime (datecreated, &temp); + LocalFileTimeToFileTime (&temp, &createtime); - secondstofiletime (datecreated, &temp); - LocalFileTimeToFileTime (&temp, &createtime); + secondstofiletime (datemodified, &temp); + LocalFileTimeToFileTime (&temp, &modtime); - secondstofiletime (datemodified, &temp); - LocalFileTimeToFileTime (&temp, &modtime); - - copystring (fsname (fs), fn); - - nullterminate (fn); - - h = CreateFile (stringbaseaddress(fn), GENERIC_READ | GENERIC_WRITE, - FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if (h == INVALID_HANDLE_VALUE) { + copystring (fsname (fs), fn); - winfileerror (fs); + nullterminate (fn); + + h = CreateFile (stringbaseaddress(fn), GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - return (false); - } + if (h == INVALID_HANDLE_VALUE) { + + winfileerror (fs); + return (false); + } - //We do not alter the accessed time. - fl = SetFileTime (h, &createtime, NULL, &modtime); - if (!fl) - err = GetLastError(); + //We do not alter the accessed time. + fl = SetFileTime (h, &createtime, NULL, &modtime); - verify (CloseHandle (h)); - - if (fl) - return (true); + if (!fl) + err = GetLastError(); - oserror(err); - return (false); -#endif - } /*setfiledates*/ + verify (CloseHandle (h)); + + if (fl) + return (true); - -#ifdef MACVERSION -boolean getfilepos (const tyfilespec *fs, Point *pt) { - - /* - mao 6/x/91: modified to work with new getmacilfeinfo/setmacfileinfo. - */ - - CInfoPBRec pb; - - if (!getmacfileinfo (fs, &pb)) + oserror(err); return (false); - - if (foldertest (&pb)) - *pt = pb.dirInfo.ioDrUsrWds.frLocation; - else - *pt = pb.hFileInfo.ioFlFndrInfo.fdLocation; - - return (true); - } /*getfilepos*/ + + #endif + } /*setfiledates*/ -boolean setfilepos (const tyfilespec *fs, Point pt) { - /* - 6/x/91 mao: modified to work with new getmacilfeinfo/setmacfileinfo. - */ +boolean setfilecreated (const ptrfilespec fs, long when) { - CInfoPBRec pb; - - if (!getmacfileinfo (fs, &pb)) - return (false); - - if (foldertest (&pb)) - pb.dirInfo.ioDrUsrWds.frLocation = pt; - else - pb.hFileInfo.ioFlFndrInfo.fdLocation = pt; - - return (setmacfileinfo (fs, &pb)); - } /*setfilepos*/ -#endif - -boolean setfilecreated (const tyfilespec *fs, long when) { - /* 7/31/91 dmb: created */ @@ -1222,129 +1492,203 @@ } /*setfilecreated*/ -boolean setfilemodified (const tyfilespec *fs, long when) { - - /* - 7/31/91 dmb: created - */ - - unsigned long datecreated, datemodified; - - if (!getfiledates (fs, &datecreated, &datemodified)) - return (false); - - return (setfiledates (fs, datecreated, when)); - } /*setfilemodified*/ +#ifdef WIN95VERSION + boolean setfilemodified (const ptrfilespec fs, long when) { + + /* + 7/31/91 dmb: created + */ + + unsigned long datecreated, datemodified; + + if (!getfiledates (fs, &datecreated, &datemodified)) + return (false); + + return (setfiledates (fs, datecreated, when)); + } /*setfilemodified*/ -#ifdef MACVERSION -boolean setfiletype (const tyfilespec *fs, OSType filetype) { +#endif // WIN95VERSION - /* - 6/x/91 mao: modified to work with new getmacilfeinfo/setmacfileinfo. - */ - - CInfoPBRec pb; - - if (!getmacfileinfo (fs, &pb)) - return (false); - - if (foldertest (&pb)) - return (false); - - pb.hFileInfo.ioFlFndrInfo.fdType = filetype; - - return (setmacfileinfo (fs, &pb)); - } /*setfiletype*/ +#ifdef MACVERSION -boolean setfilecreator (const tyfilespec *fs, OSType filecreator) { - - /* - 6/x/91 mao: modified to work with new getmacilfeinfo/setmacfileinfo. Also, makes sure - folders aren't operated on - */ - - CInfoPBRec pb; - - if (!getmacfileinfo (fs, &pb)) - return (false); + boolean getfilepos (const ptrfilespec fs, Point *pt) { - if (foldertest (&pb)) - return (false); - - pb.hFileInfo.ioFlFndrInfo.fdCreator = filecreator; - - return (setmacfileinfo (fs, &pb)); - } /*setfilecreator*/ -#endif + // + // 2006-06-25 creedon: FSRef-ized + // + // 1991-06 mao: modified to work with new getmacilfeinfo/setmacfileinfo. + // + + FSCatalogInfo catinfo; + FSRefParam pb; + + if ( ! getmacfileinfo ( fs, &pb, &catinfo ) ) + return ( false ); + + if (foldertest (&pb)) + *pt = ( ( FolderInfo * ) pb.catInfo -> finderInfo ) -> location; + else + *pt = ( ( FileInfo * ) pb.catInfo -> finderInfo ) -> location; + + return (true); + } /*getfilepos*/ -#ifdef MACVERSION -static boolean copyfork (hdlfilenum fsource, hdlfilenum fdest, Handle hbuffer) { - - /* - copy either the data fork or resource fork of the indicated file. - - return true iff the file copy was successful. - - 5/19/92 dmb: call langbackgroundtask when a script is running to make it more - likely that we'll yield the processor to another app. also, only allow - background tasks if fork is larger than a single buffer. note that if a script - is copying a bunch of files in a loop, the interpreter is already allowing - backgrounding between files. - */ - register long buffersize = GetHandleSize (hbuffer); - long ctbytes; - register OSErr errcode; + boolean setfilepos (const ptrfilespec fs, Point pt) { + + // + // 2006-06-25 creedon: FSRef-ized + // + // 1991-06 mao: modified to work with new getmacilfeinfo/setmacfileinfo. + // + + FSCatalogInfo catinfo; + FSRefParam pb; + + if ( ! getmacfileinfo ( fs, &pb, &catinfo ) ) + return ( false ); + + if (foldertest (&pb)) + ( ( FolderInfo * ) pb.catInfo -> finderInfo ) -> location = pt; + else + ( ( FileInfo * ) pb.catInfo -> finderInfo ) -> location = pt; + + return (setmacfileinfo (fs, &pb)); + } /*setfilepos*/ + - SetFPos (fsource, fsFromStart, 0L); - - SetFPos (fdest, fsFromStart, 0L); - - while (true) { + boolean setfilemodified (const ptrfilespec fs, const long when) { - ctbytes = buffersize; + /* + 7/31/91 dmb: created + */ - HLock (hbuffer); + unsigned long datecreated, datemodified; - errcode = FSRead (fsource, &ctbytes, *hbuffer); + if (!getfiledates (fs, &datecreated, &datemodified)) + return (false); - HUnlock (hbuffer); + return (setfiledates (fs, datecreated, when)); + } /*setfilemodified*/ + + + boolean setfiletype (const ptrfilespec fs, OSType filetype) { - if ((errcode != noErr) && (errcode != eofErr)) { - - oserror (errcode); - + /* + 6/x/91 mao: modified to work with new getmacilfeinfo/setmacfileinfo. + */ + + FSCatalogInfo catinfo; + FSRefParam pb; + + // clearbytes ( &pb, sizeof ( pb ) ); + // clearbytes ( &catinfo, sizeof ( catinfo ) ); + + // pb.catInfo = &catinfo; + + if ( ! getmacfileinfo ( fs, &pb, &catinfo ) ) + return ( false ); + + if (foldertest (&pb)) return (false); - } - - if (ctbytes == 0) /*last read got no bytes*/ - return (true); - HLock (hbuffer); + ( ( FileInfo * ) pb.catInfo -> finderInfo ) -> fileType = filetype; - errcode = FSWrite (fdest, &ctbytes, *hbuffer); + return (setmacfileinfo (fs, &pb)); + } /*setfiletype*/ + + + boolean setfilecreator (const ptrfilespec fs, OSType filecreator) { - HUnlock (hbuffer); + /* + 6/x/91 mao: modified to work with new getmacilfeinfo/setmacfileinfo. Also, makes sure + folders aren't operated on + */ - if (oserror (errcode)) + FSCatalogInfo catinfo; + FSRefParam pb; + + if ( ! getmacfileinfo ( fs, &pb, &catinfo ) ) + return ( false ); + + if (foldertest (&pb)) return (false); - if (ctbytes < buffersize) /*copy of fork is finished*/ - return (true); + ( ( FileInfo * ) pb.catInfo -> finderInfo ) -> fileCreator = filecreator; - if (flscriptrunning) - langbackgroundtask (false); - else - shellbackgroundtask (); /*give background processes a chance*/ + return (setmacfileinfo (fs, &pb)); + } /*setfilecreator*/ + + + /* + static boolean copyfork (hdlfilenum fsource, hdlfilenum fdest, Handle hbuffer) { - filebeachball (); /*roll the beachball cursor if there is one*/ - } /*while*/ - } /*copyfork*/ + // + copy either the data fork or resource fork of the indicated file. + + return true iff the file copy was successful. + + 5/19/92 dmb: call langbackgroundtask when a script is running to make it more + likely that we'll yield the processor to another app. also, only allow + background tasks if fork is larger than a single buffer. note that if a script + is copying a bunch of files in a loop, the interpreter is already allowing + backgrounding between files. + // + register long buffersize = GetHandleSize (hbuffer); + long ctbytes; + register OSErr errcode; + + SetFPos (fsource, fsFromStart, 0L); + + SetFPos (fdest, fsFromStart, 0L); + + while (true) { + + ctbytes = buffersize; + + HLock (hbuffer); + + errcode = FSRead (fsource, &ctbytes, *hbuffer); + + HUnlock (hbuffer); + + if ((errcode != noErr) && (errcode != eofErr)) { + + oserror (errcode); + + return (false); + } + + if (ctbytes == 0) // last read got no bytes + return (true); + + HLock (hbuffer); + + errcode = FSWrite (fdest, &ctbytes, *hbuffer); + + HUnlock (hbuffer); + + if (oserror (errcode)) + return (false); + + if (ctbytes < buffersize) // copy of fork is finished + return (true); + + if (flscriptrunning) + langbackgroundtask (false); + else + shellbackgroundtask (); // give background processes a chance + + filebeachball (); // roll the beachball cursor if there is one + } // while + } // copyfork + */ + +#endif // MACVERSION -#endif boolean largefilebuffer (Handle *hbuffer) { @@ -1412,337 +1756,144 @@ #ifdef MACVERSION -static pascal OSErr FSpCreateMinimum (const FSSpec *fs) +extern OSStatus LSIsApplication( const FSRef *inRef, Boolean *outIsApplication, + Boolean *outIsBundled ) { - HParamBlockRec pb; - - pb.fileParam.ioNamePtr = (StringPtr)(*fs).name; - - pb.fileParam.ioVRefNum = (*fs).vRefNum; - - pb.ioParam.ioVersNum = 0; - - pb.fileParam.ioDirID = (*fs).parID; - - return (PBHCreateSync (&pb)); - } /*FSpCreateMinimum*/ + LSItemInfoRecord info; + OSStatus err = LSCopyItemInfoForRef( inRef, kLSRequestBasicFlagsOnly, + &info ); + + if ( err == noErr ) + { + *outIsApplication = ( kLSItemInfoIsApplication &info.flags ) != 0; + *outIsBundled = ( kLSItemInfoIsPackage &info.flags ) != 0; + } + return( err ); +} + // + // ConvertCStringToHFSUniStr is from HelloWorldTool.c of FSCopyObject with no changes, I didn't want to include + // HelloWorldTool.c in this project because there is a whole bunch of code we don't need + // -static pascal OSErr FSpOpenAware (const tyfilespec *fs, boolean flresource, short denyModes, hdlfilenum *refNum) { - - /* - 3.0.2 dmb: customized version of HOpenAware from MoreFiles 1.1 - */ - - HParamBlockRec pb; - OSErr err; - GetVolParmsInfoBuffer volParmsInfo; - long infoSize = sizeof (GetVolParmsInfoBuffer); - - pb.ioParam.ioNamePtr = (StringPtr) (*fs).name; - pb.ioParam.ioVRefNum = (*fs).vRefNum; - pb.ioParam.ioVersNum = 0; - pb.ioParam.ioMisc = nil; - - /* - get volume attributes - this preflighting is needed because Foreign File Access based file systems don't - return the correct error result to the OpenDeny call - */ - pb.ioParam.ioBuffer = (Ptr) &volParmsInfo; - pb.ioParam.ioReqCount = infoSize; - - err = PBHGetVolParmsSync (&pb); - - pb.fileParam.ioDirID = (*fs).parID; - - /* - err = HGetVolParms ((StringPtr) (*fs).name, (*fs).vRefNum, &volParmsInfo, &infoSize); - */ - - if (err == noErr) { - - /* if volume supports OpenDeny, use it and return */ - if (hasOpenDeny (volParmsInfo)) { - - pb.accessParam.ioDenyModes = denyModes; - - if (flresource) - err = PBHOpenRFDenySync (&pb); + #define kCouldNotCreateCFString 4 + #define kCouldNotGetStringData 5 + + static OSErr ConvertCStringToHFSUniStr(const char* cStr, HFSUniStr255 *uniStr) + { + OSErr err = noErr; + CFStringRef tmpStringRef = CFStringCreateWithCString( kCFAllocatorDefault, cStr, kCFStringEncodingMacRoman ); + if( tmpStringRef != NULL ) + { + if( CFStringGetCString( tmpStringRef, (char*)uniStr->unicode, sizeof(uniStr->unicode), kCFStringEncodingUnicode ) ) + uniStr->length = CFStringGetLength( tmpStringRef ); else - err = PBHOpenDenySync (&pb); - - *refNum = pb.ioParam.ioRefNum; - - return (err); - } + err = kCouldNotGetStringData; + + CFRelease( tmpStringRef ); } - else - if (err != paramErr) /* paramErr is OK, it just means this volume doesn't support GetVolParms */ - return (err); - - /* - OpenDeny isn't supported, so try File Manager Open functions - Set File Manager permissions to closest thing possible - */ - pb.ioParam.ioPermssn = ((denyModes == dmWr) || (denyModes == dmRdWr)) ? (fsRdWrShPerm) : (denyModes % 4); - - if (flresource) - err = PBHOpenRFSync (&pb); - - else { + else + err = kCouldNotCreateCFString; - err = PBHOpenDFSync (&pb); /* Try OpenDF */ - - if (err == paramErr) - err = PBHOpenSync (&pb); /* OpenDF not supported, so try Open */ - } - - *refNum = pb.ioParam.ioRefNum; - - return (err); - } /*FSpOpenAware*/ + return err; + } +#endif -static boolean copyfileattrs (const tyfilespec *fsource, const tyfilespec *fdest, boolean flcopylockbit) { +boolean copyfile ( const ptrfilespec fsource, const ptrfilespec fdest, boolean fldata, boolean flresources ) { + + // + // create a copy of the indicated file in the destination folder or volume, with the indicated name. + // + // 2006-06-18 creedon: for Mac, FSRef-ized + // + // combined the two definitions (Mac and Win) of this function into one deleted old code, see + // revision 1329 use FSCopyObject code + // + // 5.0.1 dmb: for Windows, if the file exists, overwrite it. + // - CInfoPBRec pb; - OSErr err; - boolean flfolder; + #ifdef MACVERSION - pb.hFileInfo.ioVRefNum = (*fsource).vRefNum; - pb.hFileInfo.ioDirID = (*fsource).parID; - pb.hFileInfo.ioNamePtr = (StringPtr) (*fsource).name; - pb.hFileInfo.ioFDirIndex = 0; - - err = PBGetCatInfoSync(&pb); - - if (err == noErr) { + bigstring bs; + boolean flsourcefolder; + HFSUniStr255 name; - flfolder = (pb.hFileInfo.ioFlAttrib & 0x10); + if ( ! fileisfolder ( fsource, &flsourcefolder ) ) + return ( false ); - pb.hFileInfo.ioVRefNum = (*fdest).vRefNum; - pb.hFileInfo.ioDirID = (*fdest).parID; - pb.hFileInfo.ioNamePtr = (StringPtr) (*fdest).name; + if ( flsourcefolder ) { - /* don't copy the hasBeenInited bit */ - pb.hFileInfo.ioFlFndrInfo.fdFlags = (pb.hFileInfo.ioFlFndrInfo.fdFlags & 0xfeff); - - err = PBSetCatInfoSync(&pb); - - if ((err == noErr) && (flcopylockbit) && (pb.hFileInfo.ioFlAttrib & 0x01)) { - - err = PBHSetFLockSync ((HParmBlkPtr) &pb); - - if ((err != noErr) && (flfolder)) - err = noErr; /* ignore lock errors if destination is directory */ + setfserrorparam ( fdest ); // in case error message takes a filename parameter + + if ( ! newfolder ( fdest ) ) + return ( false ); + + return ( true ); } - } - - return (err); - } /*copyfileattrs*/ - - -boolean copyfile (const tyfilespec *fsource, const tyfilespec *fdest, boolean fldata, boolean flresources) { - - /* - create a copy of the indicated file in the destination volume, with the indicated - name. - - we allocate a good-sized buffer in the heap, then open and copy the data fork then - open and copy the resource fork of the source file. - - return true if the operation was successful, false otherwise. - - 7/27/90 DW: add fldata, flresources -- allows selective copying of the two - forks of each file. we assume one of these two booleans is true. - - 3/16/92 dmb: maintain all public Finder flags, not just creator/type & dates - - 3.0.2 dmb: use CreateMinimum and do things in special order for drop-box copies. - For details, see MoreFiles:FileCopy.c on the Reference Library CD. note that - there are more details handled by the sample code that we're ignoring here. one - is using CopyFile if src and dst are on the same server and the server supports - that function. another is to open forks with deny modes set. maybe next time... - also, we now handle folders, so file.copy can retain folder attributes. - */ - - Handle hbuffer = nil; - short sourcefnum = 0, sourcernum = 0; - short destfnum = 0, destrnum = 0; - boolean fldestcreated = false; - boolean flsourcefolder, fldestfolder; - - if (!fileisfolder (fsource, &flsourcefolder)) - return (false); - - if (flsourcefolder) - fldata = flresources = false; - - else { + + getfsfile ( fdest, bs ); - if (!largefilebuffer (&hbuffer)) - return (false); - } - - if (fldata) { + convertpstring ( bs ); - if (oserror (FSpOpenAware (fsource, false, dmRdDenyWr, &sourcefnum))) - goto error; - } - - if (flresources) { + if ( oserror ( ConvertCStringToHFSUniStr ( bs , &name ) ) ) + return ( false ); - if (oserror (FSpOpenAware (fsource, true, dmRdDenyWr, &sourcernum))) - goto error; - } - - if (fileexists (fdest, &fldestfolder)) { /*file exists, delete it*/ - - if (!deletefile (fdest)) - goto error; - } - - setfserrorparam (fdest); /*in case error message takes a filename parameter*/ - - if (flsourcefolder) { - - if (!newfolder (fdest... [truncated message content] |