[comp.sys.mac.programmer] Probably a simplistic question, but I haven't seen the answer

elliott@itsgw.rpi.edu (Jim Elliott) (09/17/90)

After several frustrating attempts over the last year or so, I've
actually written a nifty application for my Mac, thus finally
acheiving the level of ownership I used to feel with my //e. Think C
4.0 and the TCL have been no small part of my success -- I bought them
a week ago, and written a very ambitious (and working!) program with
them. But, the important part of this posting:

When I launch my application, I want to be able to have it look in the
directory in which it resides for certain documents, and open them if
the user hasn't specified startup documents. I can't see anywhere that
tells me how to determine the location of an executing application's
file, for use in later HFS calls. How can I do this? Obviously many
programs manage to do it.

-- 
-----
Jim Elliott		      "Like a bridge he'll come between us, not a wall"
elliott@netserv2.its.rpi.edu

pepke@gw.scri.fsu.edu (Eric Pepke) (09/17/90)

The answer, at least, is simple.  Don't use HFS calls.  Use MFS calls.
The folder in which the application sits is in the Poor Man's Search Path.

Eric Pepke                                    INTERNET: pepke@gw.scri.fsu.edu
Supercomputer Computations Research Institute MFENET:   pepke@fsu
Florida State University                      SPAN:     scri::pepke
Tallahassee, FL 32306-4052                    BITNET:   pepke@fsu

Disclaimer: My employers seldom even LISTEN to my opinions.
Meta-disclaimer: Any society that needs disclaimers has too many lawyers.

kurash@chocorua.dartmouth.edu (Mark Valence) (09/17/90)

In article <701@sun13.scri.fsu.edu> pepke@gw.scri.fsu.edu (Eric Pepke) writes:
>The answer, at least, is simple.  Don't use HFS calls.  Use MFS calls.
>The folder in which the application sits is in the Poor Man's Search Path.

That's certainly one simple answer.  In case the original poster does
not know what the Poor Man's Search Path is (if you only have IM I & II,
you may not know), it is the 'list' of folders the File Manager checks
whenever you Open files (or do various other operations).

Another way to do this is to make this call immediately after your
manager Initialization (_InitGraf,...,_InitWindows, TEInit, etc):

theErr := GetVol(nil, appFolder);

(in this case theErr:OSErr and appFolder:integer)

This way you can have the VRefNum of the folder from which
your application was launched at the tip of your fingers
for the entire time your program runs.

When you do an FSOpen call:

theErr := FSOpen(fileName, appFolder, refNum);

alternately, for a PBOpen:

...
pb.ioVRefNum := appFolder;
...
theErr := PBOpen(@pb, false);

These calls are similar in C, if that's your preference.

>Eric Pepke                                    INTERNET: pepke@gw.scri.fsu.edu
>Supercomputer Computations Research Institute MFENET:   pepke@fsu
>Florida State University                      SPAN:     scri::pepke
>Tallahassee, FL 32306-4052                    BITNET:   pepke@fsu
>
>Disclaimer: My employers seldom even LISTEN to my opinions.
>Meta-disclaimer: Any society that needs disclaimers has too many lawyers.

Any society that *has* lawyers has too many lawyers.  Attorneys are
another story.

Mark.

leonardr@svc.portal.com (09/18/90)

In article <701@sun13.scri.fsu.edu> pepke@gw.scri.fsu.edu (Eric Pepke) writes:
>The answer, at least, is simple.  Don't use HFS calls.  Use MFS calls.
>The folder in which the application sits is in the Poor Man's Search Path.
>
	An even easier approach, is to simply call GetVol which will give
you the name and vRefNum of the current directory.  Since it should be the
same folder as the appl on a launch w/o documents, it will give you the info
that you want.  (NOTE: There are some INITs, such as DefaultD, which allow
the user to change the default directory for appls, but any user which does
this DESERVES what they get!)

Leonard Rosenthol
Software Ventures

eastman@csa2.lbl.gov (JACK EASTMAN) (09/18/90)

In article <1990Sep17.171658.18666@svc.portal.com>, leonardr@svc.portal.com writes...
>In article <701@sun13.scri.fsu.edu> pepke@gw.scri.fsu.edu (Eric Pepke) writes:
>>The answer, at least, is simple.  Don't use HFS calls.  Use MFS calls.
>>The folder in which the application sits is in the Poor Man's Search Path.
>>
>	An even easier approach, is to simply call GetVol which will give
>you the name and vRefNum of the current directory.  Since it should be the
>same folder as the appl on a launch w/o documents, it will give you the info
>that you want.  

I'm not sure what happens with that method if you launch your app WITH 
documents. It's probably safer to call PBGetCatInfo with a file refNum 
supplied by CurResFile.  (You probably don't want to use the PMSP anyway;
you'll get all those other directories involved, too.)

				Jack Eastman
				eastman@lbl.gov