home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
PRG
/
AESample.sit
/
AESample
/
sources
/
sample.send.c
< prev
next >
Wrap
Text File
|
1996-06-22
|
25KB
|
838 lines
/*
*--------------------------------------------------------------
* sample.send.c
*--------------------------------------------------------------
*/
#include <Processes.h>
#include <PPCToolBox.h>
#include <Strings.h>
#include <AppleEvents.h>
#include <AERegistry.h>
#include "sample.h"
#include "sample.AE.h"
#include "sample.subs.h"
#include "sample.send.h"
#include "sample.dlog.h"
#include "sample.alrt.h"
/*
*--------------------------------------------------------------
* constant definitions
*--------------------------------------------------------------
*/
/* abbreviations */
#define PSN ProcessSerialNumber
#define PSNPtr ProcessSerialNumberPtr
/* resources IDs and indexes */
enum constPromptStrIDs {
strPromotID = 130,
strPPCindex = 1
};
/* Finder Types */
enum FinderTypes {
kFinderSig = 'MACS',
kAEFinder = 'FNDR',
kSystemType = 'FNDR'
};
/*
*--------------------------------------------------------------
* file filter callback procedure
*--------------------------------------------------------------
*/
pascal Boolean MyCustomFileFilter(ParmBlkPtr);
/*
*--------------------------------------------------------------
* static function prototypes
*--------------------------------------------------------------
*/
static Boolean DoGetFileDialog(FSSpecPtr);
static OSErr GetOriginalFromAlias(FSSpecPtr);
static OSErr OpenAnyFileUsingAE(const FSSpecPtr);
static OSErr JustLaunchAnApp(const FSSpecPtr);
static OSErr LaunchAppWithDoc(const FSSpecPtr app, const FSSpecPtr doc);
static OSErr LaunchAppWithAEDesc(const FSSpecPtr, AEDescList *);
static OSErr SendMyAppleEvent(AEAddressDesc *, AEDescList *, const AEEventID);
static OSErr MakeMyDocDescList(const FSSpecPtr, AEDescList *);
static OSErr FindAppFromItsSig(const OSType, FSSpecPtr);
static OSErr FindAProcess(const OSType, const OSType, ProcessSerialNumberPtr, FSSpecPtr);
static OSErr FindAProcessByFSS(ProcessSerialNumberPtr, const FSSpecPtr);
static Boolean FindSameProcess(ProcessSerialNumberPtr);
static Boolean EqualFSSpec(FSSpecPtr, FSSpecPtr);
/*
*--------------------------------------------------------------
* global FSSpec for sending document
*--------------------------------------------------------------
*/
FSSpec gDocSpec;
/*
*--------------------------------------------------------------
* DoOpenFile
*--------------------------------------------------------------
* handle file open dialog
*--------------------------------------------------------------
*/
void DoOpenFile(void)
{
FSSpec myFSpec;
/* */
if (DoGetFileDialog(&myFSpec)) {
/* send an OpenDocument AppleEvent to myself */
SendSpecToMyself(&myFSpec, kAEOpenDocuments);
}
}
/*
*--------------------------------------------------------------
* DoPrintFile
*--------------------------------------------------------------
* handle print menu; open dialog -> send print event
*--------------------------------------------------------------
*/
void DoPrintFile(void)
{
FSSpec myFSpec;
if (DoGetFileDialog(&myFSpec)) {
SendAEToFinder(&myFSpec, kAEPrintSelection);
}
}
/*
*--------------------------------------------------------------
* DoHoldFile
*--------------------------------------------------------------
* handle send menu; open dialog -> hold a document
*--------------------------------------------------------------
*/
void DoHoldFile(void)
{
FSSpec aFileSpec;
if (DoGetFileDialog(&aFileSpec)) {
OpenMyViewDialog(&aFileSpec);
}
}
/*
*--------------------------------------------------------------
* DoSendFile
*--------------------------------------------------------------
* handle send menu; open dialog -> send a document to target
* using PPCBrowser
*--------------------------------------------------------------
*/
void DoSendFile(void)
{
AEAddressDesc targetAddress = { typeNull, nil };
AEDescList myDocDescList = { typeNull, nil };
TargetID myTargetID;
PortInfoRec myPortInfo;
Str255 prompt;
OSErr result;
if (gDocSpec.name[0] != 0) {
GetIndString(prompt, strPromotID, strPPCindex);
BlockMoveData(&gDocSpec.name[1], &prompt[prompt[0] +1], gDocSpec.name[0]);
prompt[0] += gDocSpec.name[0];
result = PPCBrowser(prompt, nil, false, &myTargetID.location, &myPortInfo, nil, nil);
if (result == noErr) {
myTargetID.name = myPortInfo.name;
result = AECreateDesc(typeTargetID, &myTargetID, sizeof(TargetID), &targetAddress);
}
if (result == noErr) {
result = MakeMyDocDescList(&gDocSpec, &myDocDescList);
}
if (result == noErr) {
result = SendMyAppleEvent(&targetAddress, &myDocDescList, kAEOpenDocuments);
}
AEDisposeDesc(&targetAddress);
AEDisposeDesc(&myDocDescList);
}
}
/*
*--------------------------------------------------------------
* DoGetFileDialog
*--------------------------------------------------------------
* handle file open dialog
*--------------------------------------------------------------
*/
static Boolean DoGetFileDialog(FSSpecPtr gotSpec)
{
FileFilterUPP MyFileFilterUPP;
StandardFileReply myReply;
SFTypeList myTypes;
myReply.sfGood = false;
/* install custom file filter */
MyFileFilterUPP = NewFileFilterProc(MyCustomFileFilter);
if (MyFileFilterUPP != nil) {
/* call file select dialog */
StandardGetFile(MyFileFilterUPP, -1, myTypes, &myReply);
DisposeRoutineDescriptor(MyFileFilterUPP);
if (myReply.sfGood) {
*gotSpec = myReply.sfFile;
}
}
return (myReply.sfGood);
}
/*
*--------------------------------------------------------------
* MyCustomFileFilter
*--------------------------------------------------------------
* it hides invisible file in Select File Dialog
*--------------------------------------------------------------
*/
pascal Boolean MyCustomFileFilter(ParmBlkPtr thePB)
{
if (((FileParam *)thePB)->ioFlFndrInfo.fdFlags & fInvisible) {
return (true);
}
return (false);
}
/*
*--------------------------------------------------------------
* OpenDroppedFile
*--------------------------------------------------------------
* handle the given file
*--------------------------------------------------------------
*/
OSErr OpenDroppedFile(const FSSpecPtr theSpec)
{
FSSpec myFSpec;
OSErr result;
myFSpec = *theSpec;
result = GetOriginalFromAlias(&myFSpec);
if (result == noErr) {
result = OpenAnyFileUsingAE(&myFSpec);
}
return (result);
}
/*
*--------------------------------------------------------------
* PrintDroppedFile
*--------------------------------------------------------------
* handle the given file
*--------------------------------------------------------------
*/
OSErr PrintDroppedFile(const FSSpecPtr theSpec)
{
FSSpec myFSpec;
OSErr result;
myFSpec = *theSpec;
result = GetOriginalFromAlias(&myFSpec);
if (result == noErr) {
result = SendAEToFinder(&myFSpec, kAEPrintSelection);
}
return (result);
}
/*
*--------------------------------------------------------------
* GetOriginalFromAlias
*--------------------------------------------------------------
* check if its an alias file and get original file spec
*--------------------------------------------------------------
*/
static OSErr GetOriginalFromAlias(FSSpecPtr theSpec)
{
OSErr result;
Boolean isFolder, wasAlias;
result = ResolveAliasFile(theSpec, true, &isFolder, &wasAlias);
if (result != noErr) {
DoAliasAlert(theSpec->name, result);
}
return (result);
}
/*
*--------------------------------------------------------------
* OpenAnyFileUsingAE
*--------------------------------------------------------------
* launch document using AppleEvent
* it checks whether the FSSpec is an application
* if so, it just launches it
* if not, it attempts to find the application of the document
* and launches it using LaunchApplication() with AEDesc
*--------------------------------------------------------------
*/
static OSErr OpenAnyFileUsingAE(const FSSpecPtr theSpec)
{
ProcessSerialNumber itsPSN;
FInfo itsInfo;
FSSpec appSpec, docSpec;
OSErr result;
/* copy FSSpec */
appSpec = docSpec = *theSpec;
/* get info of the FSSpec */
result = FSpGetFInfo(&docSpec, &itsInfo);
if (result != noErr) {
DoFileAlert(docSpec.name, result);
return (result);
}
/* check if the passed file is an application */
if (itsInfo.fdType == 'APPL') {
/* launch the application */
result = JustLaunchAnApp(&appSpec);
} else {
result = FindAProcess('APPL', itsInfo.fdCreator, &itsPSN, &appSpec);
if (result == noErr) {
/* the process is already running */
result = SendAEToApp(&itsPSN, &docSpec, kAEOpenDocuments);
} else {
/* find the application of the document and launch it */
result = FindAppFromItsSig(itsInfo.fdCreator, &appSpec);
if (result == noErr) {
/* if the document belongs to an application */
result = LaunchAppWithDoc(&appSpec, &docSpec);
} else {
/* if the document may be a DA or a control panel */
result = SendAEToFinder(theSpec, kAEOpenSelection);
}
}
}
return (result);
}
/*
*--------------------------------------------------------------
* JustLaunchAnApp
*--------------------------------------------------------------
* simply launch application using LaunchApplication
*--------------------------------------------------------------
*/
static OSErr JustLaunchAnApp(const FSSpecPtr theAppSpec)
{
LaunchParamBlockRec launchPrm;
OSErr result;
launchPrm.launchBlockID = extendedBlock;
launchPrm.launchEPBLength = extendedBlockLen;
launchPrm.launchFileFlags = launchNoFileFlags;
launchPrm.launchAppSpec = theAppSpec;
launchPrm.launchControlFlags = launchContinue + launchNoFileFlags;
launchPrm.launchAppParameters = nil;
result = LaunchApplication(&launchPrm);
return (result);
}
/*
*--------------------------------------------------------------
* LaunchAppWithDoc
*--------------------------------------------------------------
* launch application with 'odoc' AppleEvent
*--------------------------------------------------------------
*/
static OSErr LaunchAppWithDoc(const FSSpecPtr theAppSpec, const FSSpecPtr theDocSpec)
{
AEDescList itsDocList = { typeNull, nil };
OSErr result;
result = MakeMyDocDescList(theDocSpec, &itsDocList);
if (result == noErr) {
result = LaunchAppWithAEDesc(theAppSpec, &itsDocList);
}
AEDisposeDesc(&itsDocList);
return (result);
}
/*
*--------------------------------------------------------------
* SendAEToApp
*--------------------------------------------------------------
* send Open Document AppleEvent to the designated application
*--------------------------------------------------------------
*/
static OSErr SendAEToApp(
ProcessSerialNumberPtr thePSN,
const FSSpecPtr theDocSpec,
const AEEventID theEventID)
{
AEAddressDesc targetAddress = { typeNull, nil };
AEDescList myDocDescList = { typeNull, nil };
OSErr result;
/* create a descriptor of the application with its ProcessSerialNumber */
result = AECreateDesc(typeProcessSerialNumber, thePSN,
sizeof(ProcessSerialNumber), &targetAddress);
/* create a descriptor list of the document */
if (result == noErr) {
result = MakeMyDocDescList(theDocSpec, &myDocDescList);
}
/* send an AppleEvent to the application along with the documet list */
if (result == noErr) {
result = SendMyAppleEvent(&targetAddress, &myDocDescList, theEventID);
}
/* cleanup */
AEDisposeDesc(&targetAddress);
AEDisposeDesc(&myDocDescList);
return (result);
}
/*
*--------------------------------------------------------------
* SendSpecToMyself
*--------------------------------------------------------------
* This is called from Drag and Drop recieve handler.
* Note that Drag Manager does not allow process switching.
* If we want to interract with user or Finder within the Receive
* Handlers, we will meet a fatal lock up.
* To avoid such trouble, we have to send the got file spec to
* myself via AppleEvent
*--------------------------------------------------------------
*/
OSErr SendSpecToMyself(const FSSpecPtr theDocSpec, const AEEventID theEventID)
{
ProcessSerialNumber myPSN;
OSErr result;
/* get my process serial number */
result = GetCurrentProcess(&myPSN);
if (result == noErr) {
result = SendAEToApp(&myPSN, theDocSpec, theEventID);
}
return (result);
}
/*
*--------------------------------------------------------------
* SendAEToFinder
*--------------------------------------------------------------
* launch designated file using AppleEvent
*--------------------------------------------------------------
*/
OSErr SendAEToFinder(const FSSpecPtr theSpec, const AEEventID sentAEKind)
{
AppleEvent myAppleEvent = { typeNull, nil };
AEAddressDesc findersAddress = { typeNull, nil };
AEDesc myDirDesc = { typeNull, nil };
AEDesc listElement = { typeNull, nil };
AEDesc fileList = { typeNull, nil };
FSSpec appSpec;
FSSpec dirSpec;
AliasHandle docAlias;
AliasHandle dirAlias;
ProcessSerialNumber findersPSN;
Size itsSize;
OSErr result;
/* check if Finder is running */
if (FindAProcess(kSystemType, kFinderSig, &findersPSN, &appSpec) != noErr)
return (procNotFound);
/* create a target address of Finder */
itsSize = sizeof(ProcessSerialNumber);
result = AECreateDesc(typeProcessSerialNumber, &findersPSN,
itsSize, &findersAddress);
/* create an AppleEvent record to be sent to Finder */
if (result == noErr) {
result = AECreateAppleEvent(kAEFinder, sentAEKind, &findersAddress,
kAutoGenerateReturnID, kAnyTransactionID, &myAppleEvent);
}
/* create alias records of the target document and its folder */
if (result == noErr) {
FSMakeFSSpec(theSpec->vRefNum, theSpec->parID, nil, &dirSpec);
NewAlias(nil, &dirSpec, &dirAlias);
NewAlias(nil, theSpec, &docAlias);
result = AECreateList(nil, 0, false, &fileList);
}
/* create a descriptor of the target folder */
if (result == noErr) {
HLock((Handle)dirAlias);
itsSize = GetHandleSize((Handle)dirAlias);
result = AECreateDesc(typeAlias, *dirAlias, itsSize, &myDirDesc);
DisposeHandle((Handle)dirAlias);
}
/* put the folder descriptor into the AppleEvent */
if (result == noErr) {
result = AEPutParamDesc(&myAppleEvent, keyDirectObject, &myDirDesc);
AEDisposeDesc(&myDirDesc);
}
/* create a descriptor of the target document */
if (result == noErr) {
HLock((Handle)docAlias);
itsSize = GetHandleSize((Handle)docAlias);
result = AECreateDesc(typeAlias, *docAlias, itsSize, &listElement);
DisposeHandle((Handle)docAlias);
}
/* put the document descriptor into the file list */
if (result == noErr) {
result = AEPutDesc(&fileList, 0, &listElement);
AEDisposeDesc(&listElement);
}
/* put the file list into the AppleEvent */
if (result == noErr) {
result = AEPutParamDesc(&myAppleEvent, keySelection, &fileList);
AEDisposeDesc(&fileList);
}
/* at last, send the AppleEvent containing the document list */
if (result == noErr) {
result = AESend(&myAppleEvent, nil,
kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
kAENormalPriority, kAEDefaultTimeout, nil, nil);
}
/* clean up memory */
AEDisposeDesc(&findersAddress);
AEDisposeDesc(&myAppleEvent);
/* if error occurred, show an alert */
if (result != noErr) DoAEError(result, sentAEKind);
return (result);
}
/*
*--------------------------------------------------------------
* LaunchAppWithAEDesc
*--------------------------------------------------------------
* Launch specified application with doc list
* FSSpec should be the application spec and
* AEDescList should be the document descriptor
*--------------------------------------------------------------
*/
static OSErr LaunchAppWithAEDesc(const FSSpecPtr theAppSpec, AEDescList *theDocDesc)
{
LaunchParamBlockRec launchPrm;
ProcessSerialNumber myPSN;
AppleEvent myAppleEvent = { typeNull, nil };
AEDesc targetDesc = { typeNull, nil };
AEDesc launchDesc = { typeNull, nil };
OSErr result;
/* get the ProcessSerialNumber of myself */
result = GetCurrentProcess(&myPSN);
/* create an address descriptor of myself */
if (result == noErr) {
result = AECreateDesc(typeProcessSerialNumber, (Ptr)&myPSN,
sizeof(ProcessSerialNumber), &targetDesc);
}
/* create an AppleEvent record to be sent */
if (result == noErr) {
result = AECreateAppleEvent(kCoreEventClass, kAEOpenDocuments, &targetDesc,
kAutoGenerateReturnID, kAnyTransactionID, &myAppleEvent);
AEDisposeDesc(&targetDesc);
}
/* put the document list into the AppleEvent */
if (result == noErr) {
result = AEPutParamDesc(&myAppleEvent, keyDirectObject, theDocDesc);
}
/* coerce (convert) the AppleEvent into launching descriptor */
if (result == noErr) {
result = AECoerceDesc(&myAppleEvent, typeAppParameters, &launchDesc);
AEDisposeDesc(&myAppleEvent);
}
/* set the launch parameters */
if (result == noErr) {
HLock(launchDesc.dataHandle);
launchPrm.launchBlockID = extendedBlock;
launchPrm.launchEPBLength = extendedBlockLen;
launchPrm.launchFileFlags = launchNoFileFlags;
launchPrm.launchAppSpec = theAppSpec;
launchPrm.launchControlFlags = launchContinue;
launchPrm.launchAppParameters = (AppParametersPtr)(*launchDesc.dataHandle);
/* now launch it! */
result = LaunchApplication(&launchPrm);
/* cleanup */
HUnlock(launchDesc.dataHandle);
AEDisposeDesc(&launchDesc);
}
return (result);
}
/*
*--------------------------------------------------------------
* SendMyAppleEvent
*--------------------------------------------------------------
* send AppleEvent with the target application's address and
* the descriptor of the file
*--------------------------------------------------------------
*/
static OSErr SendMyAppleEvent(
AEAddressDesc *theTargetAddress,
AEDescList *theDocDescList,
const AEEventID theAEKind)
{
AppleEvent myAppleEvent = { typeNull, nil };
OSErr result;
/* create an AppleEvent record to be sent */
result = AECreateAppleEvent(kCoreEventClass, theAEKind, theTargetAddress,
kAutoGenerateReturnID, kAnyTransactionID, &myAppleEvent);
/* put the document list into the AppleEvent */
if (result == noErr) {
result = AEPutParamDesc(&myAppleEvent, keyDirectObject, theDocDescList);
}
/* now send the AppleEvent */
if (result == noErr) {
AppleEvent nilReply = { typeNull, nil };
result = AESend(&myAppleEvent, &nilReply,
kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
kAENormalPriority, kAEDefaultTimeout, nil, nil);
}
/* cleanup */
AEDisposeDesc(&myAppleEvent);
if (result != noErr) {
DoAEError(result, theAEKind);
}
return (result);
}
/*
*--------------------------------------------------------------
* MakeMyDocDescList
*--------------------------------------------------------------
* make AEDescList from FSSpec; its content is just one FSSpec
*--------------------------------------------------------------
*/
static OSErr MakeMyDocDescList(const FSSpecPtr theSpec, AEDescList *theList)
{
AEDesc itsDocDesc = { typeNull, nil };
AliasHandle itsAlias;
Size itsSize;
OSErr result = noErr;
/* create a new document list */
result = AECreateList(nil, 0, false, theList); /* new description */
/* create an alias record of the document */
if (result == noErr) {
result = NewAlias(nil, theSpec, &itsAlias);
}
if (result == noErr) {
HLock((Handle)itsAlias);
itsSize = GetHandleSize((Handle)itsAlias);
/* create a descriptor of the document alias */
result = AECreateDesc(typeAlias, (Ptr)*itsAlias, itsSize, &itsDocDesc);
/* put the alias descriptor into the document list */
if (result == noErr) {
result = AEPutDesc(theList, 0, &itsDocDesc);
}
/* dispose the alias descriptor and the alias record */
AEDisposeDesc(&itsDocDesc);
DisposeHandle((Handle)itsAlias);
}
return (result);
}
/*--------------------------------------------------------------
* FindAppFromItsSig
*--------------------------------------------------------------
* find a process from the application's signature
*--------------------------------------------------------------
*/
static OSErr FindAppFromItsSig(const OSType theSig, FSSpecPtr theSpec)
{
DTPBRec aDTPBRec;
DTPBPtr aDBP;
VolumeParam *aVLP;
HFileParam *aFIP;
Str63 itsName;
short volIndex;
OSErr result;
/* substitute pointers */
aDBP = &aDTPBRec;
aVLP = (VolumeParam *)aDBP;
aFIP = (HFileParam *)aDBP;
/* search the application */
volIndex = 0;
do {
/* get a volume info */
itsName[0] = 0;
aVLP->ioCompletion = nil;
aVLP->ioVolIndex = ++volIndex;
aVLP->ioNamePtr = itsName;
result = PBGetVInfoSync((ParmBlkPtr)aVLP);
/* get a desktop file path */
if (result == noErr) {
result = PBDTGetPath(aDBP);
}
/* get an application info of the volume */
if (result == noErr) {
itsName[0] = 0;
aDBP->ioNamePtr = itsName;
aDBP->ioIndex = 0;
aDBP->ioFileCreator = theSig;
result = PBDTGetAPPLSync(aDBP);
}
/* confirm the result */
if (result == noErr) {
/* once copy answers */
theSpec->vRefNum = aDBP->ioVRefNum;
theSpec->parID = aDBP->ioAPPLParID;
BlockMoveData(itsName, theSpec->name, *itsName +1);
aFIP->ioFVersNum = 0;
aFIP->ioFDirIndex = 0;
aFIP->ioVRefNum = theSpec->vRefNum;
aFIP->ioDirID = theSpec->parID;
result = PBHGetFInfoSync((HParmBlkPtr)aFIP);
}
if (result == noErr) {
if (aFIP->ioFlFndrInfo.fdType != 'APPL') {
result = afpItemNotFound;
}
}
if (result == noErr) {
return (noErr);
}
} while (result != nsvErr); /* until no such volume */
return (result);
}
/*
*--------------------------------------------------------------
* FindAProcess
*--------------------------------------------------------------
* returns its ProcessSerialNumber and file spec of the process
*--------------------------------------------------------------
*/
static OSErr FindAProcess(
const OSType theType,
const OSType theCreator,
ProcessSerialNumberPtr thePSN,
FSSpecPtr theSpec)
{
ProcessInfoRec itsInfo;
Str31 itsName;
short found;
OSErr result;
/* initialize the ProcessSerialNumber */
thePSN->lowLongOfPSN = kNoProcess;
thePSN->highLongOfPSN = kNoProcess;
itsInfo.processInfoLength = sizeof(ProcessInfoRec);
itsInfo.processName = itsName;
itsInfo.processAppSpec = theSpec;
do {
/* search the processes */
result = GetNextProcess(thePSN);
if (result == noErr) {
result = GetProcessInformation(thePSN, &itsInfo);
}
/* compare the creators and the types */
if (result == noErr) {
found = (itsInfo.processSignature == theCreator
&& itsInfo.processType == theType);
} else {
break;
}
} while (found == false);
return (result);
}
/*
*--------------------------------------------------------------
* FindAProcessByFSS
*--------------------------------------------------------------
* Search process table by its FSSpec.
* If the process has specified FSSpec,
* fill appropriate contents in thePSN and return noErr,
* else return procNotFound
*--------------------------------------------------------------
*/
static OSErr FindAProcessByFSS(
ProcessSerialNumberPtr thePSN,
const FSSpecPtr theSpec)
{
ProcessSerialNumber thisPSN;
ProcessInfoRec thisInfo;
FSSpec thisSpec;
Str31 itsName;
/* initialize the ProcessSerialNumber */
thePSN->lowLongOfPSN = thisPSN.lowLongOfPSN = kNoProcess;
thePSN->highLongOfPSN = thisPSN.highLongOfPSN = kNoProcess;
/* search the processes */
while (GetNextProcess(&thisPSN) != procNotFound) {
thisInfo.processInfoLength = sizeof(ProcessInfoRec);
thisInfo.processName = itsName;
thisInfo.processAppSpec = &thisSpec;
GetProcessInformation(&thisPSN, &thisInfo);
/* compare the FSSpecs */
if (EqualFSSpec(thisInfo.processAppSpec, theSpec)) {
if (thePSN != nil) {
thePSN->lowLongOfPSN = thisPSN.lowLongOfPSN;
thePSN->highLongOfPSN = thisPSN.highLongOfPSN;
}
return (noErr);
}
}
return (procNotFound);
}
/*
*--------------------------------------------------------------
* FindSameProcess
*--------------------------------------------------------------
* search a process that has same ProcessSerialNumber
*--------------------------------------------------------------
*/
static Boolean FindSameProcess(ProcessSerialNumberPtr thePSNP)
{
ProcessSerialNumber queryPSN;
OSErr result;
Boolean found;
/* initialize the ProcessSerialNumber */
queryPSN.lowLongOfPSN = kNoProcess;
queryPSN.highLongOfPSN = kNoProcess;
found = false;
/* search the same ProcessSerialNumber */
while (GetNextProcess(&queryPSN) != procNotFound) {
result = SameProcess(thePSNP, &queryPSN, &found);
if (found || (result != noErr)) break;
}
return (found);
}
/*
*--------------------------------------------------------------
* EqualFSSpec
*--------------------------------------------------------------
* compare two FSSpecs
*--------------------------------------------------------------
*/
static Boolean EqualFSSpec(FSSpecPtr f1, FSSpecPtr f2)
{
return (
f1->vRefNum == f2->vRefNum
&& f1->parID == f2->parID
&& EqualString(f1->name, f2->name, false, true)
);
}