From d7d2c0929a5d7871e913451fd542e03ae4561183 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 24 Aug 2012 20:11:04 +0000 Subject: Taf isn't really...the best backend for this now, I need some more fixes there first, so next up we need the windows registry backend. --- src/unstable/settingsdrivertaf.cpp | 81 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 4 deletions(-) (limited to 'src/unstable/settingsdrivertaf.cpp') diff --git a/src/unstable/settingsdrivertaf.cpp b/src/unstable/settingsdrivertaf.cpp index 164bf0b..8cbcbc5 100644 --- a/src/unstable/settingsdrivertaf.cpp +++ b/src/unstable/settingsdrivertaf.cpp @@ -12,18 +12,91 @@ Bu::SettingsDriverTaf::SettingsDriverTaf() : Bu::SettingsDriverTaf::~SettingsDriverTaf() { + if( !pRoot ) + return; + + Bu::File fOut( sPath, Bu::File::WriteNew ); + Bu::TafWriter tw( fOut ); + tw.writeGroup( pRoot ); + delete pRoot; } void Bu::SettingsDriverTaf::init( const Bu::UtfString &sCompany, const Bu::UtfString &sProduct ) { Bu::UtfString us( getenv("HOME") ); - us += "/"; + us += "/.config/"; us += sCompany; us += "/"; us += sProduct; - Bu::File fIn( us.get(), Bu::File::Read|Bu::File::Create ); - Bu::TafReader tr( fIn ); - pRoot = tr.readGroup(); + sPath = us.get(); + try + { + Bu::File fIn( sPath, Bu::File::Read|Bu::File::Create ); + Bu::TafReader tr( fIn ); + pRoot = tr.readGroup(); + } + catch(...) + { + } + if( !pRoot ) + { + pRoot = new Bu::TafGroup( sProduct.get() ); + } +} + +void Bu::SettingsDriverTaf::set( const Bu::UtfString &sKey, + const Bu::UtfString &sValue ) +{ + Bu::StringList lPath = sKey.get().split('/'); + Bu::StringList::iterator i = lPath.begin(); + Bu::StringList::iterator in; + Bu::TafGroup *pGrp = pRoot; + for(; i;) + { + in = i; + in++; + if( in ) + { + if( pGrp->hasChild( *i ) ) + pGrp = (Bu::TafGroup *)pGrp->getChild( *i ); + else + pGrp = pGrp->addGroup( *i ); + } + else + { + pGrp->addProperty( *i, sValue.get() ); + } + i = in; + } +} + +Bu::UtfString Bu::SettingsDriverTaf::get( const Bu::UtfString &sKey, + const Bu::UtfString &sValue ) +{ + Bu::StringList lPath = sKey.get().split('/'); + Bu::StringList::iterator i = lPath.begin(); + Bu::StringList::iterator in; + Bu::TafGroup *pGrp = pRoot; + for(; i;) + { + in = i; + in++; + if( in ) + { + if( pGrp->hasChild( *i ) ) + pGrp = (Bu::TafGroup *)pGrp->getChild( *i ); + else + return sValue; + } + else + { + if( pGrp->hasProperty( *i ) ) + return pGrp->getProperty( *i ); + else + return sValue; + } + i = in; + } } -- cgit v1.2.3