Magic_Game/core/Tool/Data.cpp

48 lines
1.8 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dtool.h"
void e2d::Data::saveInt(const String& key, int value, const String& field)
{
2018-07-04 12:49:05 +08:00
::WritePrivateProfileString((LPCWSTR)field, (LPCWSTR)key, (LPCWSTR)String::parse(value), (LPCWSTR)Path::getDataPath());
}
void e2d::Data::saveDouble(const String& key, double value, const String& field)
{
2018-07-04 12:49:05 +08:00
::WritePrivateProfileString((LPCWSTR)field, (LPCWSTR)key, (LPCWSTR)String::parse(value), (LPCWSTR)Path::getDataPath());
}
void e2d::Data::saveBool(const String& key, bool value, const String& field)
{
2018-07-04 12:49:05 +08:00
::WritePrivateProfileString((LPCWSTR)field, (LPCWSTR)key, (value ? L"1" : L"0"), (LPCWSTR)Path::getDataPath());
}
void e2d::Data::saveString(const String& key, const String& value, const String& field)
{
2018-07-04 12:49:05 +08:00
::WritePrivateProfileString((LPCWSTR)field, (LPCWSTR)key, (LPCWSTR)value, (LPCWSTR)Path::getDataPath());
}
int e2d::Data::getInt(const String& key, int defaultValue, const String& field)
{
2018-07-04 12:49:05 +08:00
return ::GetPrivateProfileInt((LPCWSTR)field, (LPCWSTR)key, defaultValue, (LPCWSTR)Path::getDataPath());
}
double e2d::Data::getDouble(const String& key, double defaultValue, const String& field)
{
wchar_t temp[32] = { 0 };
2018-07-04 12:49:05 +08:00
::GetPrivateProfileString((LPCWSTR)field, (LPCWSTR)key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)Path::getDataPath());
return std::stof(temp);
}
bool e2d::Data::getBool(const String& key, bool defaultValue, const String& field)
{
int nDefaultValue = defaultValue ? 1 : 0;
2018-07-04 12:49:05 +08:00
int nValue = ::GetPrivateProfileInt((LPCWSTR)field, (LPCWSTR)key, nDefaultValue, (LPCWSTR)Path::getDataPath());
return nValue != 0;
}
e2d::String e2d::Data::getString(const String& key, const String& defaultValue, const String& field)
{
wchar_t temp[256] = { 0 };
2018-07-04 12:49:05 +08:00
::GetPrivateProfileString((LPCWSTR)field, (LPCWSTR)key, (LPCWSTR)defaultValue, temp, 255, (LPCWSTR)Path::getDataPath());
return temp;
}