Pogger/src/Config.cpp

84 lines
1.8 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.
*/
2020-07-03 19:13:41 -05:00
#include "Config.h"
2020-12-30 22:07:54 -06:00
#include <String.h>
#include <iostream>
Config::Config() {
verbose = false;
daemon = true;
will_save = false;
updateFeeds = false;
2020-07-03 19:13:41 -05:00
}
2020-07-07 20:17:52 -05:00
2020-12-30 22:07:54 -06:00
Config::Config(Config* cfg) {
verbose = cfg->verbose;
daemon = cfg->daemon;
will_save = cfg->will_save;
updateFeeds = cfg->updateFeeds;
minDate = cfg->minDate;
maxDate = cfg->maxDate;
}
2020-12-30 22:07:54 -06:00
2020-07-07 20:17:52 -05:00
// !! handle file status
void
2020-12-30 22:07:54 -06:00
Config::Load()
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-07-13 12:31:52 -05:00
BString filename = BString(configDir);
2020-07-07 20:17:52 -05:00
filename.Append("settings");
2020-12-30 22:07:54 -06:00
BFile* file = new BFile(filename.String(), B_READ_ONLY);
2020-07-07 20:17:52 -05:00
status_t result = file->InitCheck();
BMessage storage;
2020-12-30 22:07:54 -06:00
storage.Unflatten(file);
2020-07-07 20:17:52 -05:00
2020-12-30 22:07:54 -06:00
if (outDir == NULL)
outDir = BString(storage.GetString("outDir", "/boot/home/feeds/"));
if (cacheDir == NULL)
cacheDir = BString(storage.GetString("cacheDir",
"/boot/home/config/cache/Pogger/"));
2020-07-07 20:17:52 -05:00
delete file;
}
2020-12-30 22:07:54 -06:00
2020-07-07 20:17:52 -05:00
// !! handle file status
void
Config::Save ()
{
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();
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
}