1 /***********************************************************
2 Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
7 Permission to use, copy, modify, and distribute this software and its
8 documentation for any purpose and without fee is hereby granted,
9 provided that the above copyright notice appear in all copies and that
10 both that copyright notice and this permission notice appear in
11 supporting documentation, and that the names of Stichting Mathematisch
12 Centrum or CWI or Corporation for National Research Initiatives or
13 CNRI not be used in advertising or publicity pertaining to
14 distribution of the software without specific, written prior
17 While CWI is the initial source for this software, a modified version
18 is made available by the Corporation for National Research Initiatives
19 (CNRI) at the Internet address ftp://ftp.python.org.
21 STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22 REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23 MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24 CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28 PERFORMANCE OF THIS SOFTWARE.
30 ******************************************************************/
33 ** FindApplicationFromCreator uses the Desktop Database to
34 ** locate the creator application for the given document
36 ** this routine will check the desktop database of all local
37 ** disks, then the desktop databases of all server volumes
38 ** (so up to two passes will be made)
40 ** This code was created from FindApplicationFromDocument
41 ** routine, origin unknown.
47 #include "getapplbycreator.h"
50 OSErr
FindApplicationFromCreator(OSType creator
,
51 FSSpecPtr applicationFSSpecPtr
)
53 enum { localPass
, remotePass
, donePass
} volumePass
;
54 DTPBRec desktopParams
;
55 HParamBlockRec hfsParams
;
58 GetVolParmsInfoBuffer volumeInfoBuffer
;
61 /* dkj 12/94 initialize flag to false (thanks to Peter Baral for pointing out this bug) */
64 volumePass
= localPass
;
69 ** first, find the vRefNum of the volume whose Desktop Database
70 ** we're checking this time
75 /* convert the volumeIndex into a vRefNum */
77 hfsParams
.volumeParam
.ioNamePtr
= nil
;
78 hfsParams
.volumeParam
.ioVRefNum
= 0;
79 hfsParams
.volumeParam
.ioVolIndex
= volumeIndex
;
80 retCode
= PBHGetVInfoSync(&hfsParams
);
82 /* a nsvErr indicates that the current pass is over */
83 if (retCode
== nsvErr
) goto SkipThisVolume
;
84 if (retCode
!= noErr
) goto Bail
;
87 ** call GetVolParms to determine if this volume is a server
91 hfsParams
.ioParam
.ioBuffer
= (Ptr
) &volumeInfoBuffer
;
92 hfsParams
.ioParam
.ioReqCount
= sizeof(GetVolParmsInfoBuffer
);
93 retCode
= PBHGetVolParmsSync(&hfsParams
);
94 if (retCode
!= noErr
) goto Bail
;
97 ** if the vMServerAdr field of the volume information buffer
98 ** is zero, this is a local volume; skip this volume
99 ** if it's local on a remote pass or remote on a local pass
102 if ((volumeInfoBuffer
.vMServerAdr
!= 0) !=
103 (volumePass
== remotePass
)) goto SkipThisVolume
;
105 /* okay, now we've found the vRefNum for our desktop database call */
107 desktopParams
.ioVRefNum
= hfsParams
.volumeParam
.ioVRefNum
;
110 ** find the path refNum for the desktop database for
111 ** the volume we're interested in
114 desktopParams
.ioNamePtr
= nil
;
116 retCode
= PBDTGetPath(&desktopParams
);
117 if (retCode
== noErr
&& desktopParams
.ioDTRefNum
!= 0) {
120 ** use the GetAPPL call to find the preferred application
121 ** for opening any document with this one's creator
124 desktopParams
.ioIndex
= 0;
125 desktopParams
.ioFileCreator
= creator
;
126 desktopParams
.ioNamePtr
= applicationFSSpecPtr
->name
;
127 retCode
= PBDTGetAPPLSync(&desktopParams
);
129 if (retCode
== noErr
) {
131 ** okay, found it; fill in the application file spec
132 ** and set the flag indicating we're done
135 applicationFSSpecPtr
->parID
= desktopParams
.ioAPPLParID
;
136 applicationFSSpecPtr
->vRefNum
= desktopParams
.ioVRefNum
;
144 ** if retCode indicates a no such volume error or if this
145 ** was the first pass, it's time to move on to the next pass
148 if (retCode
== nsvErr
) {
153 } while (foundFlag
== false && volumePass
!= donePass
);
156 if (retCode
== nsvErr
)
157 return fnfErr
; /* More logical than "No such volume" */