AmendHub

Download:

nulleric

/

Fix-a-Fork

/

amendments

/

26

Fixes to allow app to run in system 6.


eric made amendment 26 about 1 year ago
--- main.c Sat Nov 11 10:22:16 2023 +++ main.c Sat Nov 11 16:38:45 2023 @@ -9,12 +9,12 @@ pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent * { FSSpec fss; AEDescList docList; - OSErr err; + OSErr err = noErr; long index, itemsInList; Size actualSize; AEKeyword keywd; DescType returnedType; - short fRefNum; + short fRefNum = 0; err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docList); if(err != noErr) return err; @@ -26,8 +26,10 @@ pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent * err = AEGetNthPtr(&docList, index, typeFSS, &keywd, &returnedType, (Ptr)&fss, sizeof(fss), &actualSize); if(err) return err; - // Handled file by drag and drop - err = openFile(fss.name, 0, 0); + err = FSpOpenDF(&fss, fsRdPerm, &fRefNum); + if(err) return err; + + err = openFile(fss.name, fRefNum, fss.vRefNum, fss.parID); if(err) return err; else @@ -41,7 +43,7 @@ void InstallEventHandlers() { EventRecord event; long hasAppleEvents; - OSErr err; + OSErr err = 0; short i = 0; if(Gestalt(gestaltAppleEventsAttr, &hasAppleEvents) == noErr) @@ -58,38 +60,53 @@ void InstallEventHandlers() AEProcessAppleEvent(&event); } +OSErr MyGetWDInfo(short wdRefNum, short *vRefNum, long *dirID, long *procID) +{ + OSErr result; + WDPBRec wdPB; + wdPB.ioVRefNum = wdRefNum; + wdPB.ioWDIndex = 0; + wdPB.ioNamePtr = nil; + result = PBGetWDInfoSync(&wdPB); + *vRefNum = wdPB.ioWDVRefNum; + *dirID = wdPB.ioWDDirID; + *procID = wdPB.ioWDProcID; + return result; +} + void OpenFileDialog() { + long dirID = 0, procID = 0; + short volRefNum = 0; SFReply tr = {0}; - //StandardFileReply reply; + short fRefNum = 0; + Point where; where.h = 100; where.v = 50; - + do { SFGetFile(where, nil, nil, -1, nil, nil, &tr); - //StandardGetFile(nil, -1, nil, &reply); if(tr.good) { - openFile(tr.fName, 0, tr.vRefNum); + MyGetWDInfo(tr.vRefNum, &volRefNum, &dirID, &procID); + HOpen(tr.vRefNum, dirID, tr.fName, fsRdPerm, &fRefNum); + openFile(tr.fName, fRefNum, volRefNum, dirID); } } while(tr.good); } -OSErr openFile(unsigned char *fName, short fRefNum, short vRefNum) +OSErr openFile(unsigned char *fName, short fRefNum, short vRefNum, long dirID) { - short err; + OSErr err = noErr; long count = BUF_SIZE; FInfo fi = {0}; Boolean found = false; char ext[5] = {0}; short i = 0, j = 0; - err = FSOpen(fName, vRefNum, &fRefNum); + err = FSRead(fRefNum, &count, gBuf); if(err) return err; - - FSRead(fRefNum, &count, gBuf); - // Check for magic in first 1024 bytes if(isBinHex4()) found = true; @@ -138,18 +155,19 @@ OSErr openFile(unsigned char *fName, short fRefNum, sh { if(gCreator != 0 && gType != 0) { - err = GetFInfo(fName, vRefNum, &fi); + err = HGetFInfo(vRefNum, dirID, fName, &fi); if(err) return err; fi.fdType = gType; fi.fdCreator = gCreator; - err = SetFInfo(fName, vRefNum, &fi); + err = HSetFInfo(vRefNum, dirID, fName, &fi); } // else unkown type/creator } else { - ParamText("\pUnknown file type for ", fName, "\p", "\p"); + ParamText("\pCould't determine type/creator for ", fName, "\p", "\p"); StopAlert(128, nil); } + return FSClose(fRefNum); } --- main.h Sat Nov 11 10:23:15 2023 +++ main.h Sat Nov 11 16:31:00 2023 @@ -20,7 +20,7 @@ OSType gType = 0; OSType gCreator = 0; Boolean gHandledByDnD = false; -OSErr openFile(unsigned char *fName, short fRefNum, short vRefNum); +OSErr openFile(unsigned char *fName, short fRefNum, short vRefNum, long dirID); pascal OSErr DoOpenDoc(AppleEvent *event, AppleEvent *reply, long handlerRefcon); // checks