libsaria: Better prefs::init() function
The preference may be set to zero by the user but default to a non-zero value. This can cause frustration on both the user and developer ends. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
83e3763083
commit
a9d875e05e
|
@ -49,6 +49,13 @@ static void set_preference(string key, int p)
|
|||
libsaria::app::save("prefs", save, &state, NULL);
|
||||
}
|
||||
|
||||
static bool key_exists(string key)
|
||||
{
|
||||
map<string, int>::iterator it;
|
||||
it = preferences.find(key);
|
||||
return it != preferences.end();
|
||||
}
|
||||
|
||||
namespace libsaria
|
||||
{
|
||||
void prefs::init()
|
||||
|
@ -74,12 +81,11 @@ namespace libsaria
|
|||
|
||||
int prefs::init(string key, int value)
|
||||
{
|
||||
int cur = get(key);
|
||||
if (cur == 0){
|
||||
if (!key_exists(key)) {
|
||||
set_preference(key, value);
|
||||
return value;
|
||||
}
|
||||
return cur;
|
||||
return get(key);
|
||||
}
|
||||
|
||||
}; /* Namespace: libsaria */
|
||||
|
|
Loading…
Reference in New Issue