Pogger/src/Config.cpp

71 lines
1.7 KiB
C++
Raw Normal View History

2020-07-07 20:17:52 -05:00
#include <iostream>
2020-07-03 19:13:41 -05:00
#include <String.h>
#include "Config.h"
Config::Config () {
2020-07-13 12:31:52 -05:00
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
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-07-07 20:17:52 -05:00
// !! handle file status
void
Config::Load ()
{
2020-07-13 12:31:52 -05: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");
BFile* file = new BFile( filename.String(), B_READ_ONLY );
status_t result = file->InitCheck();
BMessage storage;
storage.Unflatten( file );
if ( outDir == NULL)
outDir = BString( storage.GetString("outDir", "/boot/home/feeds/") );
2020-07-13 12:31:52 -05:00
if ( cacheDir == NULL)
cacheDir = BString( storage.GetString("cacheDir", "/boot/home/config/cache/Pogger/") );
2020-07-07 20:17:52 -05:00
delete file;
}
// !! handle file status
void
Config::Save ()
{
2020-07-13 12:31:52 -05: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
BPath* cfgPath = new BPath( configDir.String(), NULL, true );
2020-07-07 20:17:52 -05:00
BEntry* cfgEntry = new BEntry( cfgPath->Path() );
BDirectory* cfgDir = new BDirectory;
cfgDir->CreateDirectory(cfgPath->Path(), NULL);
if ( cfgEntry->Exists() == false )
cfgDir->CreateDirectory( cfgPath->Path(), NULL );
BMessage storage;
2020-07-13 12:31:52 -05:00
BString filename = BString( configDir ).Append("/settings");
2020-07-07 20:17:52 -05:00
BFile* file = new BFile( filename.String(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE );
status_t result = file->InitCheck();
storage.AddString( "outDir", outDir.String() );
2020-07-13 12:31:52 -05:00
storage.AddString( "cacheDir", cacheDir.String() );
2020-07-07 20:17:52 -05:00
storage.Flatten( file );
}