The way Fl_Preferences seems to work is that if there isn’t a file it creates one, and the first time you “get” a setting, you supply a default value for it. You do not need a default file. I don’t think you need to write the setting back for the file to be written. The file will be in a fixed location depending on OS settings.
Phil.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/6a4a2bc2-7685-4549-94d4-6440d09eba06n%40googlegroups.com.
>I am trying to work without knowledge of the actual prefs path, in case it changes in the future.The method Fl_Preferences::getUserdataPath can provide you with the path, so you can use that to deal with location changes.
>Also, I would like to save the runtime prefs file (different from the default prefs file) and transfer it to another install. Can fltk take a prefs file from a string and write it out ? And can it take the prefs file and read it into a string ?I don't see built-in import/export functions. Others might be able to point to others who have done this.
The preferences file is a set of "groups" containing key/value pairs. You'll want to iterate across the groups and then across the keys. Probably not hard to generate JSON or something ...
From: 'Matthias Melcher' via fltk.general
Sent: 19 March 2021 14:57
To: fltk.general
Subject: [fltk.general] Re: Fl_preferences inquiry
, there is no provision for that. Also, there is a misunderstanding between "runtime prefs" and "prefs files". Preferences files are usually only read or written in a very brief period, for example a subroutine, to gather or change aspects of the UI. For example, you would read the preferences once to find out where the user wants his window. You should not leave the preferences item allocated.
When the user closes the app, you again briefly open the preferences database, write your changes (no need to write anything else), for example, where was the window, when the user closed it, and then close the database again. This will all be stored in a file on disk in a simple Windows config file kind of format. Don't keep references to an Fl_Preferences instance around outside of a simple subroutine.
I had assumed that when you create the Fl_Preferences item at the start of the app it reads all the file into a local data structure and when the app closes it writes it back. I use the Fl_Preferences item throughout the existence of the app. It does not appear to update the file after every call to set(). I’ve had to explicitly use flush() for information I want to preserve after a crash.