Saving Preferences

Alex Rice alex at mindlube.com
Tue Sep 30 13:25:01 EDT 2003


On Tuesday, September 30, 2003, at 12:02  PM, Ken Norris wrote:

> Howdy,
>
> What are you favorite ways of saving Preferences?
>
> examples:
>
> external files, substacks, reading into CustomProps, hidden fields, 
> etc.

Definitely a data stack with custom properties.

Here is a function, not really tested, that decides good place to save 
preferences x-platform

--
-- prefsFolder()
--
function prefsFolder
   local tAppDataF, tPrefsF, tAppPrefsF
   get the filename of stack the mainStack of stack kSelf
   set the itemDelimiter to "/"
   get item 1 to -2 of it
   put it into tStackF
   if the platform = "Win32" then
     -- for Windows 2000/XP
     put specialFolderPath(kCSIDL_APPDATA) into tAppDataF
     if tAppDataF = empty then
       -- maybe it's Win 95/98/ME?
       -- use the the mainstack folder
       return tStackF
     end if
     -- have user's application data folder (on 2000/XP)
     -- e.g. c:\documents and settings\alex\application data
     -- make sure our subfolder exists there
     put format("%s/%s", tAppDataF, "Mindlube") into tAppPrefsF
     --
   else if the platform = "MacOS" then
     put specialFolderPath("Preferences") into tPrefsF
     put format("%s/%s", \
         tPrefsF, \
         "Mindlube") into tAppPrefsF
   else -- some Unix variant
     put format("%s/.%s", $HOME, "Mindlube") into tAppPrefsF
   end if
   -- does it exist
   if there is not a folder tAppPrefsF then
     create folder tAppPrefsF
     if the result <> empty then
       throw "failed to create prefs folder:" && the result && tAppPrefsF
     end if
   end if
   if not canWriteFileTo(tAppPrefsF) then
     throw "preferences folder is not writable:" && tAppPrefsF
   end if
   return tAppPrefsF
end prefsFolder



Alex Rice <alex at mindlube.com> | Mindlube Software | http://mindlube.com

what a waste of thumbs that are opposable
to make machines that are disposable  -Ani DiFranco




More information about the use-livecode mailing list