Pogger/src/Preferences.cpp

72 lines
1.6 KiB
C++
Raw Normal View History

2020-12-30 22:07:54 -06:00
/*
* Copyright 2020, Jaidyn Levesque <jadedctrl@teknik.io>
* All rights reserved. Distributed under the terms of the MIT license.
*/
2021-01-24 23:20:11 -06:00
#include "Preferences.h"
2020-07-03 19:13:41 -05:00
2020-12-30 22:07:54 -06:00
#include <String.h>
#include <iostream>
2021-01-24 23:20:11 -06:00
Preferences::Preferences() {
2020-07-03 19:13:41 -05:00
}
2020-07-07 20:17:52 -05:00
2020-12-30 22:07:54 -06:00
2021-01-24 23:20:11 -06:00
Preferences::Preferences(Preferences* pref) {
}
2020-12-30 22:07:54 -06:00
2020-07-07 20:17:52 -05:00
// !! handle file status
void
2021-01-24 23:20:11 -06:00
Preferences::Load()
2020-07-07 20:17:52 -05:00
{
2021-01-12 19:08:42 -06:00
configDir = BString("/boot/home/config/settings/Pogger/");
2020-07-07 20:17:52 -05:00
2020-07-13 12:31:52 -05:00
BString filename = BString(configDir);
2020-07-07 20:17:52 -05:00
filename.Append("settings");
2021-01-12 19:08:42 -06:00
BFile file(filename.String(), B_READ_ONLY);
status_t result = file.InitCheck();
2020-07-07 20:17:52 -05:00
BMessage storage;
2021-01-12 19:08:42 -06:00
storage.Unflatten(&file);
2021-01-13 14:52:09 -06:00
updateInterval = storage.GetInt64("updateInterval", 3600000000);
2021-01-12 19:08:42 -06:00
outDir = BString(storage.GetString("outDir", "/boot/home/feeds/"));
cacheDir = BString(storage.GetString("cacheDir",
"/boot/home/config/cache/Pogger/"));
2020-07-07 20:17:52 -05:00
}
2020-12-30 22:07:54 -06:00
2020-07-07 20:17:52 -05:00
// !! handle file status
void
2021-01-24 23:20:11 -06:00
Preferences::Save ()
2020-07-07 20:17:52 -05:00
{
2020-12-30 22:07:54 -06:00
if (configDir == NULL)
configDir = BString("/boot/home/config/settings/Pogger/");
2020-07-07 20:17:52 -05:00
2020-12-30 22:07:54 -06:00
BPath* cfgPath = new BPath(configDir.String(), NULL, true);
BEntry* cfgEntry = new BEntry(cfgPath->Path());
BDirectory* cfgDir = new BDirectory;
2020-07-07 20:17:52 -05:00
cfgDir->CreateDirectory(cfgPath->Path(), NULL);
2020-12-30 22:07:54 -06:00
if (cfgEntry->Exists() == false)
cfgDir->CreateDirectory(cfgPath->Path(), NULL);
2020-07-07 20:17:52 -05:00
BMessage storage;
2020-12-30 22:07:54 -06:00
BString filename = BString(configDir).Append("/settings");
2020-07-07 20:17:52 -05:00
2020-12-30 22:07:54 -06:00
BFile* file = new BFile(filename.String(), B_WRITE_ONLY | B_CREATE_FILE
| B_ERASE_FILE);
2020-07-07 20:17:52 -05:00
status_t result = file->InitCheck();
2021-01-12 19:08:42 -06:00
storage.AddFloat("updateInterval", updateInterval);
2020-12-30 22:07:54 -06:00
storage.AddString("outDir", outDir.String());
storage.AddString("cacheDir", cacheDir.String());
2020-07-07 20:17:52 -05:00
2020-12-30 22:07:54 -06:00
storage.Flatten(file);
2020-07-07 20:17:52 -05:00
}