[comp.sys.mac.programmer] Vol # of Launched APPL?

gf0c+@andrew.cmu.edu (Gregory S. Fox) (01/26/89)

Greetings...

The situation:  An application, a configuration file, and a preferences
file.  The application and the configuration file are in Folder A, the
pref file in Folder B.  Double click the config file, the appl launches
without difficulty.  Double click the pref file, and the default dir is
Folder B, so although the appl is launched, it can't find the config
file.  Sort of a fox, goat, cabbage problem.

The question:  How do you determine the directory that the application
resides in, _regardless of the location of the document that launched it_???

I've pondered this one for a while.  It seems like a worthwhile thing
to know, so if I figure it out first, I'll post the answer myself.

-Greg

bob@accuvax.nwu.edu (Bob Hablutzel) (01/26/89)

> Greetings...

> The situation:  An application, a configuration file, and a preferences
> file.  The application and the configuration file are in Folder A, the
> pref file in Folder B.  Double click the config file, the appl launches
> without difficulty.  Double click the pref file, and the default dir is
> Folder B, so although the appl is launched, it can't find the config
> file.  Sort of a fox, goat, cabbage problem.

> The question:  How do you determine the directory that the application
> resides in, _regardless of the location of the document that launched it_???

> I've pondered this one for a while.  It seems like a worthwhile thing
> to know, so if I figure it out first, I'll post the answer myself.
 
I haven't tried this, but it should work:

	At program startup, get the CurResFile. This gives you a refNum to
	the current application.

	Call _GetFCBInfo (see Inside Macintosh, Page 179) with ioRefNum
	set to the CurResFile refNum, and ioFCBIndx set to zero. This
	will return in ioVRefNum a vRefNum (probably actually a WDRefNum)
	for the disk (folder) holding the application.

Good luck.

> -Greg

Bob Hablutzel	Wildwood Software	BOB@NUACC.ACNS.NWU.EDU

tim@hoptoad.uucp (Tim Maroney) (01/27/89)

In article <QXrTZSy00WB3E3pUk8@andrew.cmu.edu> gf0c+@andrew.cmu.edu (Gregory
S. Fox) writes:
>The situation:  An application, a configuration file, and a preferences
>file.  The application and the configuration file are in Folder A, the
>pref file in Folder B.  Double click the config file, the appl launches
>without difficulty.  Double click the pref file, and the default dir is
>Folder B, so although the appl is launched, it can't find the config
>file.  Sort of a fox, goat, cabbage problem.
>
>The question:  How do you determine the directory that the application
>resides in, _regardless of the location of the document that launched it_???

IMNSHO, all configuration and preferences files should be in the system
folder.  There are two main reasons.  First, everyone else does it that
way, so you're less likely to confuse the user by sticking to the de
facto convention.  Second, on file servers, many people may be using
the same copy of the application, but they are all likely to have their
own system folders, so this way you avoid conflicts.

Also, I don't think there should be two files; configuration and
preferences ought to go in the same file.

All that said, it's pretty easy to find where the application is.  Use
the low-memory global CurAppRefNum to find the reference number of the
application resource file.  You can accomplish the same thing in a more
future-compatible way using the CurResFile system function, as long as
you haven't opened any more resource files.  Then call PBGetFCBInfo
using that reference number.  The ioVRefNum and ioFCBParID in the
parameter block on return contain the information you desire.
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"The men promise to provide unconditionally for their wives.  The women in turn
serve unconditionally to provide the other household services necessary for the
men to fulfill their obligations to the women.  The women are satisfied because
they have the men working for THEM." -- Colin Jenkins, soc.women

wdh@well.UUCP (Bill Hofmann) (01/28/89)

In article <QXrTZSy00WB3E3pUk8@andrew.cmu.edu> gf0c+@andrew.cmu.edu (Gregory S. Fox) writes:
>The question:  How do you determine the directory that the application
>resides in, _regardless of the location of the document that launched it_???

Actually, not all that hard.  I had to figure it out recently.  Remember
early on in your program you called GetAppParms() (or did you...).  It
will return (among other things) the refnum of the application resource
file (gleaned from a nasty low-mem global apRefNum).  With this piece
of information, call PBGetFCBInfo() (IM IV-179) and get ioFCBVRefNum,
which is the vRefNum of the folder.  This may be a WDRefNum, getting the
dirID and the volume vRefNum are left as an exercise for the reader.

A minor gotcha can happen if you're using THINK C, which has a <Project>.rsrc
file which it opens after the "application" if you're just doing a ^R (run).
If you want the (say) name of the *resource* file and not the project file,
do a Get1Resource on the signature resource, a HomeResFile, and proceed as
above.

-Bill Hofmann
  Flashpoint