Copyright (c) 1996, 1997 by John Montbriand. All Rights Reserved.
Permission hereby granted for public use.
Distribute freely in areas where the laws of copyright apply.
USE AT YOUR OWN RISK.
DO NOT DISTRIBUTE MODIFIED COPIES.
Comments/questions/postcards* to the author at the address:
John Montbriand
P.O. Box. 1133
Saskatoon Saskatchewan Canada
S7K 3N2
or by email at:
tinyjohn@sk.sympatico.ca
*if you mail a postcard, then I will provide you with technical support
regarding questions you may have about this file.
see also: <http://www3.sk.sympatico.ca/tinyjohn>
Contents
About StdPrefs...
Implementation Notes
Materials
Finding the Preferences Folder
Finding Your Preferences File
Creating Preferences Files
Files in this package
Copies for sale!
NO WARRANTY
Bug reports make this a better product!
Further Reference
Other
About StdPrefs...
Preferences files are commonly used by applications and other utilities to store various configuration parameters for their operation. This library provides a convenient set of routines you can use in any application for conveniently creating and accessing preferences files. In system 6, these files are located in the System Folder, and in system seven or later, these files are located in the Preferences folder (which is located in the System Folder).
Implementation Notes
In this implementation, preferences files are searched for by file type and creator, not by name. This is so your preferences files do not become lost if the user decides to change the name, or if your program and it's file names are translated into another language.
The routines are safe to use with any version of Mac OS that includes the hierarchical file system, which first appeared in the MacPlus era. Odds are, this isn't something you have to worry too much about, but these routines have been implemented for use with both System 6 and system 7.x.
Materials
The routines documented herein are the copyright property of John Montbriand. They're handy, easy to use, and practical. I hope all who find them will use them well.
Copyright (c) 1996, 1997 by John Montbriand. All Rights Reserved.
Permission hereby granted for public use.
Distribute freely in areas where the laws of copyright apply.
USE AT YOUR OWN RISK.
DO NOT DISTRIBUTE MODIFIED COPIES.
Finding the Preferences Folder
FindPreferencesFolder
OSErr FindPreferencesFolder(short *pvol, long *pdir);
FindPreferencesFolder finds the preferences folder returning its volume reference number and directory id. Under system 6, this will be the System Folder. Under System 7, this will be the Preferences folder inside of the System Folder.
EXAMPLE:
short vRefNum;
long parID;
OSErr err;
err = FindPreferencesFolder(&vRefNum, &parID);
if (err != noErr) goto bail;
....
Finding Your Preferences File
PrefsDirSearch
OSErr PrefsDirSearch(OSType creator, OSType type,
short *fvol, long *fdir, StringPtr fname);
PrefsDirSearch searches the preferences folder for a file with the given creator and type. If such a file exists, then fvol, fdir, and fname are set to refer to the file. Under system 6, the System Folder is searched, and, under System 7, the Preferences folder inside of the System Folder is searched. If a file with the given type and creator cannot be found, the routine returns fnfErr.
FSpPrefsDirSearch is identical to PrefsDirSearch except it returns information about the file's location in a file specification record. If a file with the given type and creator cannot be found, the routine returns fnfErr.
PrefsCreate creates a file in the prefs folder with the given creator type and defaultname. If a file already exists with the name defaultname, then a digit (1 2 3...) is appended to defaultname until a unique name is found. This routine creates a resource fork for the file too. Once the file has been successfully created, fvol, fdir, and fname are set to refer to the file.
StdPrefs.c -- source code for the StdPrefs routines' implementation
StdPrefs.h -- header file providing interfaces to the StdPrefs routines
ReadMe -- this file
:Libraries: -- precompiled libraries, ready to link.
StdPrefs.o -- 68K version of the StdPrefs library
StdPrefs.xcoff -- PowerPC version of the StdPrefs library
Copies for sale!
These libraries are provided for free and you may use them in any program you make; however, if you would like to purchase a copy of these libraries and have a legal paper trail establishing your right to use them, then send along a cheque or a money order in the amount of $10.00 for the purchase of one copy. I'll send you a receipt.
NO WARRANTY
No warranties are made regarding these files. John Montbriand disclaims all warranties regarding these files, either express or implied, including but not limited to implied warranties of merchantability and fitness for any particular purpose. These files are provided "AS IS" without any warranty of any kind. Use them at your own risk. Copies of these files are not for sale in areas where the law does not allow exclusion of implied warranties.
Bug reports make this a better product!
As in all of my products, I advertise a $10.00 finder's fee for bug reports that lead to corrections. If you find a problem here, report it! it could be worth your while....
Further Reference
Inside Macintosh: Files by Apple Computer, Inc. Addison-Wesley.
A discussion of files, file handling routines, and how to use them.
The C Programming Language 2nd edition by Brian W. Kernighan and Dennis M. Ritchie. Prentice Hall.