blob: f5e42120111380e7c13e5d3ae0c10e5ca96a45ad [file] [log] [blame]
Jack Jansen42218ce1997-01-31 16:15:11 +00001/***********************************************************
2Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
3The Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI or Corporation for National Research Initiatives or
13CNRI not be used in advertising or publicity pertaining to
14distribution of the software without specific, written prior
15permission.
16
17While CWI is the initial source for this software, a modified version
18is made available by the Corporation for National Research Initiatives
19(CNRI) at the Internet address ftp://ftp.python.org.
20
21STICHTING MATHEMATISCH CENTRUM AND CNRI DISCLAIM ALL WARRANTIES WITH
22REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
23MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH
24CENTRUM OR CNRI BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
25DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
26PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
27TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
28PERFORMANCE OF THIS SOFTWARE.
29
30******************************************************************/
31
Jack Jansen924ca851996-09-20 15:25:16 +000032/*
33** FindApplicationFromCreator uses the Desktop Database to
34** locate the creator application for the given document
35**
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)
39**
40** This code was created from FindApplicationFromDocument
41** routine, origin unknown.
42*/
43
44#include <Types.h>
45#include <Files.h>
46#include <Errors.h>
47#include "getapplbycreator.h"
48
49
50OSErr FindApplicationFromCreator(OSType creator,
51 FSSpecPtr applicationFSSpecPtr)
52{
53 enum { localPass, remotePass, donePass } volumePass;
54 DTPBRec desktopParams;
55 HParamBlockRec hfsParams;
56 short volumeIndex;
57 Boolean foundFlag;
58 GetVolParmsInfoBuffer volumeInfoBuffer;
59 OSErr retCode;
60
61/* dkj 12/94 initialize flag to false (thanks to Peter Baral for pointing out this bug) */
62 foundFlag = false;
63
64 volumePass = localPass;
65 volumeIndex = 0;
66
67 do {
68 /*
69 ** first, find the vRefNum of the volume whose Desktop Database
70 ** we're checking this time
71 */
72
73 volumeIndex++;
74
75 /* convert the volumeIndex into a vRefNum */
76
77 hfsParams.volumeParam.ioNamePtr = nil;
78 hfsParams.volumeParam.ioVRefNum = 0;
79 hfsParams.volumeParam.ioVolIndex = volumeIndex;
80 retCode = PBHGetVInfoSync(&hfsParams);
81
82 /* a nsvErr indicates that the current pass is over */
83 if (retCode == nsvErr) goto SkipThisVolume;
84 if (retCode != noErr) goto Bail;
85
86 /*
87 ** call GetVolParms to determine if this volume is a server
88 ** (a remote volume)
89 */
90
91 hfsParams.ioParam.ioBuffer = (Ptr) &volumeInfoBuffer;
92 hfsParams.ioParam.ioReqCount = sizeof(GetVolParmsInfoBuffer);
93 retCode = PBHGetVolParmsSync(&hfsParams);
94 if (retCode != noErr) goto Bail;
95
96 /*
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
100 */
101
102 if ((volumeInfoBuffer.vMServerAdr != 0) !=
103 (volumePass == remotePass)) goto SkipThisVolume;
104
105 /* okay, now we've found the vRefNum for our desktop database call */
106
107 desktopParams.ioVRefNum = hfsParams.volumeParam.ioVRefNum;
108
109 /*
110 ** find the path refNum for the desktop database for
111 ** the volume we're interested in
112 */
113
114 desktopParams.ioNamePtr = nil;
115
116 retCode = PBDTGetPath(&desktopParams);
117 if (retCode == noErr && desktopParams.ioDTRefNum != 0) {
118
119 /*
120 ** use the GetAPPL call to find the preferred application
121 ** for opening any document with this one's creator
122 */
123
124 desktopParams.ioIndex = 0;
125 desktopParams.ioFileCreator = creator;
126 desktopParams.ioNamePtr = applicationFSSpecPtr->name;
127 retCode = PBDTGetAPPLSync(&desktopParams);
128
129 if (retCode == noErr) {
130 /*
131 ** okay, found it; fill in the application file spec
132 ** and set the flag indicating we're done
133 */
134
135 applicationFSSpecPtr->parID = desktopParams.ioAPPLParID;
136 applicationFSSpecPtr->vRefNum = desktopParams.ioVRefNum;
137 foundFlag = true;
138
139 }
140 }
141
142 SkipThisVolume:
143 /*
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
146 */
147
148 if (retCode == nsvErr) {
149 volumePass++;
150 volumeIndex = 0;
151 }
152
153 } while (foundFlag == false && volumePass != donePass);
154
155Bail:
156 if (retCode == nsvErr)
157 return fnfErr; /* More logical than "No such volume" */
158 return retCode;
159}