appletfiledesktop.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletfiledesktop.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletdefs.h"
00008 #include "appletprocess.h"
00009 #include "appletmemory.h"
00010 #include "appletfiles.h"
00011 #include "appletfilesinternal.h"
00012 #include "appletfiledesktop.h"
00013 
00014 
00015 
00016 boolean hasdesktopmanager (short vnum) {
00017     
00018     GetVolParmsInfoBuffer volparms;
00019     HParamBlockRec pb;
00020     
00021     pb.volumeParam.ioVRefNum = vnum;
00022     
00023     pb.volumeParam.ioNamePtr = nil;
00024     
00025     pb.ioParam.ioBuffer = (Ptr) &volparms;
00026     
00027     pb.ioParam.ioReqCount = sizeof (volparms);
00028     
00029     if (PBHGetVolParmsSync (&pb) != noErr)
00030         return (false);
00031     
00032     return ((volparms.vMAttrib & (1 << bHasDesktopMgr)) != 0);
00033     } /*hasdesktopmanager*/
00034 
00035 
00036 boolean findapplication (short vnum, OSType creator, boolean flappsonly, FSSpec *pfs) {
00037     
00038     /*
00039     dmb 9/21/93: keep looping until an APPL is found, or PBDTGetAPPLSync 
00040     returns an error. (it will eventually return afpItemNotFound.)
00041     
00042     dmb 9/24/93: added flappsonly parameter. a non-app, such as an extension 
00043     or desk accessory, can own a document type.
00044     */
00045     
00046     DTPBRec dt;
00047     bigstring appname;
00048     tyfileinfo info;
00049     
00050     if (!hasdesktopmanager (vnum))
00051         return (false);
00052         
00053     clearbytes (&dt, longsizeof (dt));
00054         
00055     dt.ioVRefNum = vnum;
00056     
00057     if (PBDTGetPath (&dt) != noErr)
00058         return (false);
00059         
00060     dt.ioNamePtr = (StringPtr) &appname;
00061     
00062     dt.ioFileCreator = creator;
00063     
00064     for (dt.ioIndex = 0; ; ++dt.ioIndex) {
00065         
00066         if (PBDTGetAPPLSync (&dt) != noErr) 
00067             return (false);
00068         
00069         if (!filemakespec (vnum, dt.ioAPPLParID, appname, pfs))
00070             continue;
00071         
00072         if (!fileexists (pfs))
00073             continue;
00074         
00075         if (!filegetinfo (pfs, &info))
00076             continue;
00077         
00078         if (!flappsonly) /*dmb 9/24/93: some callers don't require apps*/
00079             return (true);
00080         
00081         if (info.filetype == 'APPL') /*DW 9/16/93: desktop db can contain references to non-apps*/
00082             return (true);
00083         }
00084     } /*findapplication*/
00085 
00086 
00087 boolean findapponanydisk (OSType appid, FSSpec *fs) {
00088     
00089     /*
00090     find the app whose creator id is appid. return true if we found it, 
00091     false otherwise.
00092     */
00093     
00094     DTPBRec dt;
00095     ParamBlockRec pb;
00096     Str255 appfname;
00097     
00098     clearbytes (&pb, (long) sizeof (pb));
00099     
00100     while (true) {
00101         
00102         ++pb.volumeParam.ioVolIndex;
00103         
00104         if (PBGetVInfoSync (&pb) != noErr)
00105             return (false);
00106         
00107         if (!hasdesktopmanager (pb.volumeParam.ioVRefNum))
00108             continue;
00109         
00110         dt.ioNamePtr = NULL;
00111         
00112         dt.ioVRefNum = pb.volumeParam.ioVRefNum;
00113         
00114         if (PBDTGetPath (&dt) != noErr)
00115             return (false);
00116         
00117         dt.ioNamePtr = (StringPtr) &appfname;
00118         
00119         dt.ioIndex = 0;
00120         
00121         dt.ioFileCreator = appid;
00122         
00123         if (PBDTGetAPPLSync (&dt) == noErr) {
00124         
00125             if (FSMakeFSSpec (pb.volumeParam.ioVRefNum, dt.ioAPPLParID, appfname, fs) == noErr)
00126                 return (true);
00127             }
00128         } /*while*/
00129         
00130     return (false);
00131     } /*findapponanydisk*/
00132 
00133 
00134 boolean assureappisrunning (OSType serverid, boolean flbringtofront) {
00135     
00136     /*
00137     if the application whose creator id is serverid is running, return true.
00138     
00139     if not, we look for the application and try to launch it. we wait until it's 
00140     actually running and ready to receive Apple Events.
00141     */
00142     
00143     typrocessinfo info;
00144     FSSpec fs;
00145     
00146     if (findrunningapp (serverid, &info)) /*already running, nothing to do*/
00147         return (true);
00148         
00149     if (!findapponanydisk (serverid, &fs))
00150         return (false);
00151         
00152     if (!launchappwithdoc (&fs, nil, flbringtofront))
00153         return (false);
00154         
00155     return (true);
00156     } /*assureappisrunning*/
00157     
00158     
00159 boolean getfilecomment (FSSpec *pfs, bigstring bscomment) {
00160     
00161     DTPBRec dt;
00162     
00163     clearbytes (&dt, longsizeof (dt));
00164     
00165     setemptystring (bscomment); /*default return*/
00166     
00167     if (!hasdesktopmanager ((*pfs).vRefNum))
00168         return (false);
00169     
00170     dt.ioVRefNum = (*pfs).vRefNum;
00171     
00172     if (PBDTGetPath (&dt) != noErr)
00173         return (false);
00174     
00175     dt.ioNamePtr = (*pfs).name;
00176     
00177     dt.ioDirID = (*pfs).parID;
00178     
00179     dt.ioDTBuffer = (Ptr) bscomment + 1;
00180     
00181     dt.ioDTReqCount = lenbigstring;
00182     
00183     if (PBDTGetCommentSync (&dt) != noErr)
00184         return (false);
00185     
00186     setstringlength (bscomment, dt.ioDTActCount);
00187     
00188     return (true);
00189     } /*getfilecomment*/
00190 
00191 
00192 boolean setfilecomment (FSSpec *pfs, bigstring bscomment) {
00193     
00194     DTPBRec dt;
00195     
00196     clearbytes (&dt, longsizeof (dt));
00197     
00198     if (!hasdesktopmanager ((*pfs).vRefNum))
00199         return (false);
00200     
00201     dt.ioVRefNum = (*pfs).vRefNum;
00202     
00203     if (PBDTGetPath (&dt) != noErr)
00204         return (false);
00205     
00206     dt.ioNamePtr = (*pfs).name;
00207     
00208     dt.ioDirID = (*pfs).parID;
00209     
00210     dt.ioDTBuffer = (Ptr) bscomment + 1;
00211     
00212     dt.ioDTReqCount = stringlength (bscomment);
00213     
00214     if (PBDTSetCommentSync (&dt) != noErr)
00215         return (false);
00216     
00217     PBDTFlushSync (&dt);
00218     
00219     return (true);
00220     } /*setfilecomment*/
00221 
00222 
00223 boolean filecopycomment (FSSpec *fssource, FSSpec *fsdest) {
00224 
00225     bigstring bscomment;
00226     
00227     if (!getfilecomment (fssource, bscomment))
00228         return (false);
00229     
00230     return (setfilecomment (fsdest, bscomment));
00231     } /*filecopycomment*/
00232 
00233 

Generated on Wed May 31 18:19:41 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6