2021-09-22 15:16:20 -04:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <SHLWAPI.H>
|
2021-10-18 13:15:56 -04:00
|
|
|
#include <SSTREAM>
|
|
|
|
#include <STRING>
|
2021-09-22 15:16:20 -04:00
|
|
|
|
|
|
|
#include "../cmn/path.h"
|
|
|
|
|
|
|
|
Config config;
|
|
|
|
|
|
|
|
Config::Config()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL Config::Load()
|
|
|
|
{
|
|
|
|
// Get config file
|
|
|
|
m_configFile.resize(MAX_PATH);
|
|
|
|
return GetConfigFilename(&m_configFile[0]) && PathFileExists(m_configFile.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT Config::GetInt(LPCTSTR name, UINT defaultValue)
|
|
|
|
{
|
|
|
|
return GetPrivateProfileInt(appName, name, defaultValue, m_configFile.c_str());
|
|
|
|
}
|
2021-10-18 13:15:56 -04:00
|
|
|
|
|
|
|
float Config::GetFloat(LPCTSTR name, float defaultValue)
|
|
|
|
{
|
|
|
|
// Convert float to string
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << defaultValue;
|
|
|
|
std::string defaultStr = oss.str();
|
|
|
|
|
|
|
|
std::string currentStr = GetString(name, defaultStr);
|
|
|
|
|
|
|
|
// Convert to float
|
|
|
|
return atof(currentStr.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Config::GetString(LPCTSTR name, const std::string &defaultValue)
|
|
|
|
{
|
|
|
|
const int max_string_sz = 100;
|
|
|
|
std::string s;
|
|
|
|
s.resize(max_string_sz);
|
|
|
|
|
2021-10-21 02:35:37 -04:00
|
|
|
DWORD count = GetPrivateProfileString(appName, name, defaultValue.c_str(), &s[0], max_string_sz, m_configFile.c_str());
|
|
|
|
|
|
|
|
s.resize(count);
|
2021-10-18 13:15:56 -04:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|