home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-04-20 | 5.0 KB | 204 lines | [TEXT/PJMM] |
- unit MySystem7;
-
- { This program was written by Peter N Lewis, Mar 1992 in THINK Pascal 4.0.1 }
-
- interface
-
- {Note: InitUtilities must be called prior to using functions marked * in this file }
- { (It is normally called by InitMainLoop in MyMainLoop.unit) }
-
- uses
- AppleTalk, Aliases, PPCToolBox, Processes, EPPC, Notification, AppleEvents;
-
- function MyResolveAliasFile (var vrn: integer; var dirID: longInt; var fname: str63): OSErr; { * }
- function MyFindFolder (vrn: INTEGER; folder: OSType; var ovrn: INTEGER; var oDirID: LONGINT): OSErr; { * }
- function MyInteractWithUser (idleproc: Ptr): OSErr; { * }
- function MyGetAPPL (sig: OSType; var vrn: integer; var dirID: longInt; var fname: str63): OSErr; { * }
- function GetPSN (signature: OSType; var process: ProcessSerialNumber): boolean;
- procedure QuitApplication (creator: OSType);
- procedure SegmentSystem7;
-
- implementation
-
- uses
- MyUtils, MyUtilities, MyNotifier, Folders;
-
- const
- pref_folder = 'Preferences';
-
- {$S System7}
- procedure SegmentSystem7;
- begin
- end;
-
- {$S System7}
- function MyResolveAliasFile (var vrn: integer; var dirID: longInt; var fname: str63): OSErr;
- var
- fs: FSSpec;
- isfolder, wasalias: boolean;
- oe: OSErr;
- begin
- if system7 then begin
- with fs do begin
- vRefNum := vrn;
- parID := dirID;
- name := fname;
- oe := ResolveAliasFile(fs, true, isfolder, wasalias);
- if oe = noErr then begin
- vrn := vRefNum;
- dirID := parID;
- fname := name;
- end;
- end;
- end
- else
- oe := noErr;
- MyResolveAliasFile := oe;
- end;
-
- {$S Init}
- function MyFindFolder (vrn: INTEGER; folder: OSType; var ovrn: INTEGER; var oDirID: LONGINT): OSErr;
- var
- oe: OSErr;
- name: str255;
- prefDirID: longInt;
- pb: HParamBlockRec;
- begin
- if system7 then begin
- oe := FindFolder(vrn, folder, true, ovrn, oDirID);
- end
- else begin
- oe := GetDirID(sysenv.sysVRefNum, ovrn, oDirID);
- if (oe = noErr) and (folder = kPreferencesFolderType) then begin
- name := pref_folder;
- oe := DirCreate(ovrn, oDirID, name, prefDirID);
- if oe = noErr then
- oDirID := prefDirID
- else begin
- with pb do begin
- ioNamePtr := @name;
- ioVRefNum := ovrn;
- ioDirID := oDirID;
- ioFDirIndex := 0;
- end;
- oe := PBGetCatInfo(@pb, false);
- if oe = noErr then
- oDirID := pb.ioDirID;
- end;
- oe := noErr;
- end;
- end;
- MyFindFolder := oe;
- end;
-
- {$S System7}
- function MyInteractWithUser (idleproc: Ptr): OSErr;
- var
- oe: OSErr;
- begin
- if system7 then
- oe := AEInteractWithUser(maxLongInt, nil, idleproc)
- else begin
- if in_foreground then
- MyInteractWithUser := noErr
- else begin
- Notify(true, true, 128, 0, 0, 0, 0);
- { Should wait til we are in the foreground, but its too messy }
- end;
- end;
- end;
-
- {$S System7}
- function MyGetAPPL (sig: OSType; var vrn: integer; var dirID: longInt; var fname: str63): OSErr;
- var
- i: integer;
- pbdt: DTPBRec;
- crdate: longInt;
- oe: OSErr;
- found: boolean;
- begin
- found := false;
- if system7 then begin
- i := 1;
- repeat
- vrn := 0;
- oe := GetVolInfo(fname, vrn, i, crdate);
- i := i + 1;
- if oe = noErr then begin
- with pbdt do begin
- fname := '';
- ioNamePtr := @fname;
- ioVRefNum := vrn;
- oe := PBDTGetPath(@pbdt);
- if oe = noErr then begin
- ioIndex := 0;
- ioFileCreator := sig;
- oe := PBDTGetAPPLSync(@pbdt);
- if oe = noErr then
- found := true;
- end;
- end;
- oe := noErr;
- end;
- until found or (oe <> noErr);
- end;
- if found then begin
- oe := noErr;
- dirID := pbdt.ioAPPLParID;
- end
- else begin
- oe := afpItemNotFound;
- vrn := 0;
- dirID := 2;
- fname := '';
- end;
- MyGetAPPL := oe;
- end;
-
- {$S System7}
- function GetPSN (signature: OSType; var process: ProcessSerialNumber): boolean;
- var
- info: ProcessInfoRec;
- s: str63;
- fs: FSSpec;
- oe: OSErr;
- gv: longInt;
- begin
- GetPSN := false;
- if (Gestalt(gestaltOSAttr, gv) = noErr) & (BTST(gv, gestaltLaunchControl)) then begin
- process.highLongOfPSN := 0;
- process.lowLongOfPSN := kNoProcess;
- info.processInfoLength := sizeof(ProcessInfoRec);
- info.processName := @s;
- info.processAppSpec := @fs;
- while GetNextProcess(process) = noErr do begin
- if GetProcessInformation(process, info) = noErr then
- if (info.processType = longInt('APPL')) and (info.processSignature = signature) then begin
- GetPSN := true;
- leave;
- end;
- end;
- end;
- end;
-
- {$S System7}
- procedure QuitApplication (creator: OSType);
- var
- process: processSerialNumber;
- infoRec: processInfoRec;
- targetAddress: AEAddressDesc;
- AEvent, AReply: AppleEvent;
- fs: FSSpec;
- oe: OSErr;
- begin
- if GetPSN(creator, process) then begin
- oe := AECreateDesc(typeProcessSerialNumber, @process, SizeOf(process), targetAddress);
- oe := AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, targetAddress, kAutoGenerateReturnID, kAnyTransactionID, AEvent);
- oe := AEDisposeDesc(targetAddress);
- oe := AESend(AEvent, AReply, kAENoReply, kAEHighPriority, 5 * 60, nil, nil);
- oe := AEDisposeDesc(AEvent);
- oe := AEDisposeDesc(AReply);
- end;
- end;
-
- end.