[GD-General] A portable preferences library
Brought to you by:
vexxed72
From: Brian H. <ho...@py...> - 2003-12-02 06:59:30
|
Everyone seems like they have to write their own portable preferences/registry wrapper. I've got one that I hacked up, and I'm currently in the process of refactoring it and will make it open source. It is designed to be minimal, and will wrap around the Windows registry; CFPreferences on MacOS/OS X; and the standard file system on Linux. The features will be: - open/close/delete a preferences object - read/write 16-bit, 32-bit, 64-bit, float, double, string, and byte-bucket objects safely (e.g. endianess) - delete keys Preference objects can be opened either system-wide (corresponding to HKEY_LOCAL_MACHINE on Windows, "/Library" on OS X, "/usr/local/share" on Linux) or locally (corresponding to HKEY_CURRENT_USER on Windows, "~/Library" on OS X, and "~" on Linux). If you do not have privilege for the operation, tough cookies -- it's the app's responsibility to ensure that appropriate privilege exists. Key enumeration is not planned at this time. As an example, using an ad hoc API, it would look something like: prefs p; PrefsLib_OpenPrefs( &p, "~/MyCompany/ThisGame" ); //local to user PrefsLib_WriteFloat( p, "joystickX", fJoystick ); PrefsLib_WriteString( p, "username", getUserName() ); PrefsLib_ClosePrefs( p ); You get the gist. If anyone has comments/suggestions, I'd love to hear them. Brian |