home *** CD-ROM | disk | FTP | other *** search
- /*
- resetdtdbs.c
- resets all desktop databases
- by Brian Gaeke, dec 28 1992
- */
-
- #define done(vcb) ((vcb) == (vcbQHdr->qTail)) && ((vcbQHdr->qHead) != (vcbQHdr->qTail))
- #include <Processes.h>
- #include <AppleEvents.h>
- #include <ShutDown.h>
-
- short OpenDatabase(short vRefNum);
- void DeleteDatabase(short dtRefNum);
- void PrepareDatabase(short dtRefNum);
- void InitMac(void);
- void DoDialogs(void);
- void KillFinder(void);
- void Panic(OSErr err, unsigned char *routine);
-
- pascal void main(void)
- {
- QHdrPtr vcbQHdr = GetVCBQHdr();
- VCB *aVCB = (VCB *) vcbQHdr->qHead;
- short itsVRefNum,
- itsDTRefNum;
-
- InitMac();
- DoDialogs();
- KillFinder();
-
- while (!done(aVCB))
- {
- itsVRefNum = aVCB->vcbVRefNum;
- itsDTRefNum = OpenDatabase(itsVRefNum);
- PrepareDatabase(itsDTRefNum);
- DeleteDatabase(itsVRefNum);
- aVCB = (VCB *) aVCB->qLink;
- };
-
- (void)Alert(131,NULL);
- ShutDwnStart();
- }
-
- short OpenDatabase(short vRefNum)
- {
- DTPBRec dtpb;
- short dtRefNum;
- OSErr err;
-
- dtpb.ioCompletion = NULL;
- dtpb.ioNamePtr = NULL;
- dtpb.ioVRefNum = vRefNum;
- err = PBDTGetPath(&dtpb);
- if (err) Panic(err,"\pOpenDatabase");
- return dtpb.ioDTRefNum;
- }
-
- void DeleteDatabase(short vRefNum)
- {
- DTPBRec dtpb;
- OSErr err;
-
- dtpb.ioCompletion = NULL;
- dtpb.ioVRefNum = vRefNum;
- dtpb.ioIndex = 0;
- err = PBDTDelete(&dtpb,false);
- if (err) Panic(err,"\pDeleteDatabase");
- }
-
- void PrepareDatabase(short dtRefNum)
- {
- DTPBRec dtpb;
- OSErr err;
-
- dtpb.ioCompletion = NULL;
- dtpb.ioDTRefNum = dtRefNum;
- err = PBDTFlush(&dtpb,false);
- if (err) Panic(err,"\pPrepareDatabase--Flush");
-
- err = PBDTCloseDown(&dtpb);
- if (err) Panic(err,"\pPrepareDatabase--CloseDown");
- }
-
- void InitMac(void)
- {
- short x;
-
- InitGraf(&qd.thePort);
- InitFonts();
- FlushEvents(everyEvent,0);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NULL);
- InitCursor();
- MaxApplZone();
- for(x=1;x<11;x++)
- MoreMasters();
- }
-
- void DoDialogs(void)
- {
- (void)Alert(128,NULL);
- if (Alert(129,NULL) != ok) ExitToShell();
- }
-
- void KillFinder(void)
- {
- ProcessSerialNumber psn,
- finder;
- ProcessInfoRec pir;
- OSErr err;
- AppleEvent theEvent;
- AEDesc theAddress;
- Boolean gotEvent;
- EventRecord event;
- short x;
-
- /* We have to do this because IM VI says not to call PBDTReset/PBDTDelete
- "unless you are manipulating the desktop database in the absence
- of the Finder"... and we all know that IM is the word of God... :)
- So here goes... */
-
- psn.highLongOfPSN = 0;
- psn.lowLongOfPSN = kNoProcess;
-
- pir.processInfoLength = sizeof(ProcessInfoRec);
- pir.processAppSpec = NULL;
- pir.processName = NULL;
-
- while (GetNextProcess(&psn) != procNotFound)
- {
- (void)GetProcessInformation(&psn,&pir);
- if (pir.processSignature == 'MACS')
- {
- finder = psn;
- break;
- }
- }
-
- /*** kill the app code swiped from C.K. Haun with minimal modifications ***/
- (void)AECreateDesc(typeProcessSerialNumber, (Ptr)&finder,
- sizeof(finder), &theAddress);
- (void)AECreateAppleEvent(kCoreEventClass, kAEQuitApplication,
- &theAddress, kAutoGenerateReturnID, kAnyTransactionID, &theEvent);
- AEDisposeDesc(&theAddress);
- AESend(&theEvent, NULL, kAENoReply + kAEAlwaysInteract +
- kAECanSwitchLayer, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
- AEDisposeDesc(&theEvent);
- /*** end swiped code ***/
-
- /* give it time to work */
- for(x=1; x<=5; x++)
- gotEvent = EventAvail(everyEvent, &event);
-
- }
-
- void Panic(OSErr err, unsigned char *routine)
- {
- Str255 errstr;
-
- NumToString((long) err,errstr);
- ParamText(errstr,routine,"\p","\p");
- (void)Alert(130,NULL);
- ShutDwnStart();
- }
-
-