blob: 8c0b00fd93a16bac41ae56a948c168ab95e02523 [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
Jack Jansen25e0c792001-05-19 12:57:22 +000044#ifdef WITHOUT_FRAMEWORKS
Jack Jansen924ca851996-09-20 15:25:16 +000045#include <Types.h>
46#include <Files.h>
47#include <Errors.h>
Jack Jansen25e0c792001-05-19 12:57:22 +000048#else
49#include <Carbon/Carbon.h>
50#endif
Jack Jansen924ca851996-09-20 15:25:16 +000051#include "getapplbycreator.h"
52
53
54OSErr FindApplicationFromCreator(OSType creator,
55 FSSpecPtr applicationFSSpecPtr)
56{
57 enum { localPass, remotePass, donePass } volumePass;
58 DTPBRec desktopParams;
59 HParamBlockRec hfsParams;
60 short volumeIndex;
61 Boolean foundFlag;
62 GetVolParmsInfoBuffer volumeInfoBuffer;
63 OSErr retCode;
64
65/* dkj 12/94 initialize flag to false (thanks to Peter Baral for pointing out this bug) */
66 foundFlag = false;
67
68 volumePass = localPass;
69 volumeIndex = 0;
70
71 do {
72 /*
73 ** first, find the vRefNum of the volume whose Desktop Database
74 ** we're checking this time
75 */
76
77 volumeIndex++;
78
79 /* convert the volumeIndex into a vRefNum */
80
81 hfsParams.volumeParam.ioNamePtr = nil;
82 hfsParams.volumeParam.ioVRefNum = 0;
83 hfsParams.volumeParam.ioVolIndex = volumeIndex;
84 retCode = PBHGetVInfoSync(&hfsParams);
85
86 /* a nsvErr indicates that the current pass is over */
87 if (retCode == nsvErr) goto SkipThisVolume;
88 if (retCode != noErr) goto Bail;
89
90 /*
91 ** call GetVolParms to determine if this volume is a server
92 ** (a remote volume)
93 */
94
95 hfsParams.ioParam.ioBuffer = (Ptr) &volumeInfoBuffer;
96 hfsParams.ioParam.ioReqCount = sizeof(GetVolParmsInfoBuffer);
97 retCode = PBHGetVolParmsSync(&hfsParams);
98 if (retCode != noErr) goto Bail;
99
100 /*
101 ** if the vMServerAdr field of the volume information buffer
102 ** is zero, this is a local volume; skip this volume
103 ** if it's local on a remote pass or remote on a local pass
104 */
105
106 if ((volumeInfoBuffer.vMServerAdr != 0) !=
107 (volumePass == remotePass)) goto SkipThisVolume;
108
109 /* okay, now we've found the vRefNum for our desktop database call */
110
111 desktopParams.ioVRefNum = hfsParams.volumeParam.ioVRefNum;
112
113 /*
114 ** find the path refNum for the desktop database for
115 ** the volume we're interested in
116 */
117
118 desktopParams.ioNamePtr = nil;
119
120 retCode = PBDTGetPath(&desktopParams);
121 if (retCode == noErr && desktopParams.ioDTRefNum != 0) {
122
123 /*
124 ** use the GetAPPL call to find the preferred application
125 ** for opening any document with this one's creator
126 */
127
128 desktopParams.ioIndex = 0;
129 desktopParams.ioFileCreator = creator;
130 desktopParams.ioNamePtr = applicationFSSpecPtr->name;
131 retCode = PBDTGetAPPLSync(&desktopParams);
132
133 if (retCode == noErr) {
134 /*
135 ** okay, found it; fill in the application file spec
136 ** and set the flag indicating we're done
137 */
138
139 applicationFSSpecPtr->parID = desktopParams.ioAPPLParID;
140 applicationFSSpecPtr->vRefNum = desktopParams.ioVRefNum;
141 foundFlag = true;
142
143 }
144 }
145
146 SkipThisVolume:
147 /*
148 ** if retCode indicates a no such volume error or if this
149 ** was the first pass, it's time to move on to the next pass
150 */
151
152 if (retCode == nsvErr) {
153 volumePass++;
154 volumeIndex = 0;
155 }
156
157 } while (foundFlag == false && volumePass != donePass);
158
159Bail:
160 if (retCode == nsvErr)
161 return fnfErr; /* More logical than "No such volume" */
162 return retCode;
163}