#include "StdAfx.h"
#include "SuppCmds.h"
#include "ParamStore.h"
#include "Config.h"
Config::Config(): m_sGeneralMakeOpts(""),
m_bEnableLog(false),
m_LogLevel(Logger::cError),
m_sLogPath(""),
m_bInstallTab(false),
m_pStore(&(ParamStore::GetInstance()))
{
Load();
}
Config::~Config()
{
}
void Config::Load()
{
m_sGeneralMakeOpts = LoadString("General", "GeneralMakeOpts");
m_bEnableLog = LoadBool("General", "EnableLog");
m_LogLevel = static_cast<Logger::Level>(LoadLong("General", "LogLevel"));
m_sLogPath = LoadString("General", "LogPath");
for(SupportedCommands::cmditerator_t pCmd = SupportedCommands::GetInstance().begin();
pCmd != SupportedCommands::GetInstance().end(); ++pCmd)
{
if(pCmd->second.bMake)
{
CmdOpts opts;
opts.sMakeOpts = LoadString(pCmd->second.sCmdName, "MakeOpts");
opts.bShowInContextMenu = LoadBool(pCmd->second.sCmdName, "ShowInContextMenu");
opts.bMasterToDswName = LoadBool(pCmd->second.sCmdName, "SetMasterToDswName");
opts.bRemoveDoneFlags = LoadBool(pCmd->second.sCmdName, "RemoveDoneFlags");
m_CommandOptions[pCmd->first] = opts;
}
}
m_bInstallTab = LoadBool("General", "InstallTab");
}
void Config::Save()
{
StoreString("General", "GeneralMakeOpts", m_sGeneralMakeOpts);
StoreBool("General", "EnableLog", m_bEnableLog);
StoreLong("General", "LogLevel", m_LogLevel);
StoreString("General", "LogPath", m_sLogPath);
StoreBool("General", "InstallTab", m_bInstallTab);
for(cmdoptcont_t::iterator pCmdOpts = m_CommandOptions.begin();
pCmdOpts != m_CommandOptions.end(); ++pCmdOpts)
{
CmdOpts opts = pCmdOpts->second;
_bstr_t sSection = SupportedCommands::GetInstance().GetCmdInfo(pCmdOpts->first).sCmdName;
StoreString(sSection, "MakeOpts", opts.sMakeOpts);
StoreBool(sSection, "ShowInContextMenu", opts.bShowInContextMenu);
StoreBool(sSection, "SetMasterToDswName", opts.bMasterToDswName);
StoreBool(sSection, "RemoveDoneFlags", opts.bRemoveDoneFlags);
}
}
Config::CmdOpts Config::GetCmdMakeOpts(SupportedCommands::CmdId id) const
{
return const_cast<Config*>(this)->m_CommandOptions[id];
}
void Config::SetCmdMakeOpts(SupportedCommands::CmdId id, const CmdOpts &opts)
{
m_CommandOptions[id] = opts;
}
bool Config::LoadBool(const _bstr_t &sSection, const _bstr_t &sKey)
{
_bstr_t dummy;
m_pStore->GetValue(sSection, sKey, dummy);
return dummy.length() > 0;
}
void Config::StoreBool(const _bstr_t &sSection, const _bstr_t &sKey, bool bValue)
{
m_pStore->PutValue(sSection, sKey, bValue ? "1" : "");
}
long Config::LoadLong(const _bstr_t &sSection, const _bstr_t &sKey)
{
_bstr_t dummy;
long ret = 0;
if(m_pStore->GetValue(sSection, sKey, dummy))
{
swscanf(dummy, L"%d", &ret);
}
return ret;
}
void Config::StoreLong(const _bstr_t &sSection, const _bstr_t &sKey, long lValue)
{
WCHAR buf[32] = {L'\0'};
swprintf(buf, L"%d", lValue);
m_pStore->PutValue(sSection, sKey, buf);
}
_bstr_t Config::LoadString(const _bstr_t &sSection, const _bstr_t &sKey)
{
_bstr_t ret;
m_pStore->GetValue(sSection, sKey, ret);
return ret;
}
void Config::StoreString(const _bstr_t &sSection, const _bstr_t &sKey, const _bstr_t &sValue)
{
m_pStore->PutValue(sSection, sKey, sValue);
}