Jack Jansen | 42218ce | 1997-01-31 16:15:11 +0000 | [diff] [blame] | 1 | /*********************************************************** |
| 2 | Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
| 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 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 |
| 15 | permission. |
| 16 | |
| 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. |
| 20 | |
| 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. |
| 29 | |
| 30 | ******************************************************************/ |
| 31 | |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 32 | /* |
| 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 Jansen | 25e0c79 | 2001-05-19 12:57:22 +0000 | [diff] [blame^] | 44 | #ifdef WITHOUT_FRAMEWORKS |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 45 | #include <Types.h> |
| 46 | #include <Files.h> |
| 47 | #include <Errors.h> |
Jack Jansen | 25e0c79 | 2001-05-19 12:57:22 +0000 | [diff] [blame^] | 48 | #else |
| 49 | #include <Carbon/Carbon.h> |
| 50 | #endif |
Jack Jansen | 924ca85 | 1996-09-20 15:25:16 +0000 | [diff] [blame] | 51 | #include "getapplbycreator.h" |
| 52 | |
| 53 | |
| 54 | OSErr 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 | |
| 159 | Bail: |
| 160 | if (retCode == nsvErr) |
| 161 | return fnfErr; /* More logical than "No such volume" */ |
| 162 | return retCode; |
| 163 | } |