[comp.sys.mac.programmer] What's the right way to create a user preferences file?

minow@thundr.dec.com (Fortran for Precedent) (09/07/88)

As my first attempt to write a Macintosh application, I wrote a terminal
emulator.  This has been a not altogether pleasant process as the Mac
lacks decent programming documentation.   The program is working reasonably
well, and I'm stuck now trying too add a "Save Parameters" capability.
What I want to save are the Baud Rate (and similar options) and a set
of STR resources defining host names and telephone numbers.  My design
is roughly as follows:

-- At startup, read the default values from the application resource file.
-- If the user selects "Load Parameters", load them from a selected file
   and make it the current parameter file.
-- If the user selects "Save As", store the entire parameter database
   in the selected file and make that the current parameter file.
-- If the user selects "Save", update the current parameter file.

Some of the things that go wrong include

-- The application resource file changes: how do I prevent this?
-- If I do multiple saves to the same file, I get multiple copies
   of a particular resource.  I want only one copy.
-- If I have a parameter file open and try to create a new file
   ("Save As"), things get written to the wrong file, or don't get
   written to the correct file.
-- Sometimes the telephone number resources disappear!

Does anyone have a "cookbook" for this problem (I'm hardly the first
person to have faced it)?  Mail to me will be summarized (with code)
to the net.

Thanks.

Martin Minow
minow%thundr.dec@decwrl.dec.com
...!decwrl!dec-rhea!dec-thundr!minow