AmendHub

Download:

nulleric

/

Fix-a-Fork

/

amendments

/

35

Add TouchFolder to update the modification time so folders show new icons right away.

Added an error message if could not set type/creator.
 
Moved hasAppleEvents to a global so can be checked in other methods that may need to send apple events.
 
Put an attempt in scratch for sending a Finder update event. Did not work on system 7.1 and below.

eric made amendment 35 3 months ago
--- main.c Fri Apr 5 08:36:15 2024 +++ main.c Fri Apr 5 22:47:39 2024 @@ -9,7 +9,36 @@ // Globals OSType gType; OSType gCreator; +long gHasAppleEvents; +// Change the modification date on the parent folder so the +// Finder notices a change. +OSErr TouchFolder(short vRefNum, long parID) +{ + CInfoPBRec rec; + Str63 name; + short err; + + rec.hFileInfo.ioNamePtr = name; + name[0]=0; + rec.hFileInfo.ioVRefNum = vRefNum; + rec.hFileInfo.ioDirID = parID; + rec.hFileInfo.ioFDirIndex = -1; + rec.hFileInfo.ioFVersNum = 0; + PBGetCatInfoSync(&rec); + err = GetDateTime(&rec.dirInfo.ioDrMdDat); + if(err) + return err; + + rec.hFileInfo.ioVRefNum = vRefNum; + rec.hFileInfo.ioDirID = parID; + rec.hFileInfo.ioFDirIndex = -1; + rec.hFileInfo.ioFVersNum = 0; + rec.hFileInfo.ioNamePtr[0] = 0; + err = PBSetCatInfoSync(&rec); + return err; +} + pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon) { FSSpec fss; @@ -47,11 +76,10 @@ pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent * void InstallEventHandlers() { EventRecord event; - long hasAppleEvents; OSErr err = 0; short i = 0; - if(Gestalt(gestaltAppleEventsAttr, &hasAppleEvents) == noErr) + if(Gestalt(gestaltAppleEventsAttr, &gHasAppleEvents) == noErr) { AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, &DoOpenDoc, 0L, false); } else { @@ -104,6 +132,7 @@ void OpenFileDialog() OSErr openFile(unsigned char *fName, short fRefNum, short vRefNum, long dirID) { OSErr err = noErr; + Str255 errString = "\p"; long count = BUF_SIZE; FInfo fi = {0}; Boolean found = false; @@ -165,8 +194,14 @@ OSErr openFile(unsigned char *fName, short fRefNum, sh if(err) return err; fi.fdType = gType; fi.fdCreator = gCreator; - err = HSetFInfo(vRefNum, dirID, fName, &fi); + + if(err) + { + NumToString(err, errString); + ParamText("\pCould't set type/creator for ", fName, "\p err: ", errString); + StopAlert(128, nil); + } } // else unkown type/creator } else { @@ -174,6 +209,7 @@ OSErr openFile(unsigned char *fName, short fRefNum, sh StopAlert(128, nil); } + TouchFolder(vRefNum, dirID); return FSClose(fRefNum); } --- scratch.c Sat Mar 30 20:46:53 2024 +++ scratch.c Fri Apr 5 22:43:40 2024 @@ -139,4 +139,25 @@ pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent * AEDisposeDesc(&docList); return noErr; } + + +// This does not work on 7.1 and below. +// An attempt to send the finder update apple event to refresh the folder. +void SendFinderSyncEvent(FSSpec spec) +{ + const OSType sig = 'MACS'; + OSErr err = 0; + Str255 errString; + AppleEvent event, reply; + AEAddressDesc addr; + + if(!gHasAppleEvents) + return; + + AECreateDesc( typeApplSignature, &sig, sizeof sig, &addr); + AECreateAppleEvent('fndr', 'fupd', &addr, kAutoGenerateReturnID, kAnyTransactionID, &event); + AEPutParamPtr(&event, keyDirectObject, typeFSS, &spec, sizeof(spec)); + AESend(&event, &reply, kAENoReply, kAENormalPriority, kNoTimeOut, NULL, NULL); + AEDisposeDesc(&event); +} */