Magic_Game/core/Tool/Data.cpp

90 lines
1.6 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dtool.h"
2018-07-17 23:07:51 +08:00
e2d::Data::Data(const String & key, const String & field)
2018-09-04 22:42:34 +08:00
: key_(key)
, field_(field)
, data_path_(Path::GetDataPath())
{
}
2018-09-04 22:42:34 +08:00
void e2d::Data::SaveInt(int value)
{
2018-07-17 23:07:51 +08:00
::WritePrivateProfileString(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
(LPCWSTR)String::Parse(value),
(LPCWSTR)data_path_
2018-07-17 23:07:51 +08:00
);
}
2018-09-04 22:42:34 +08:00
void e2d::Data::SaveDouble(float value)
{
2018-07-17 23:07:51 +08:00
::WritePrivateProfileString(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
(LPCWSTR)String::Parse(value),
(LPCWSTR)data_path_
2018-07-17 23:07:51 +08:00
);
}
2018-09-04 22:42:34 +08:00
void e2d::Data::SaveBool(bool value)
{
2018-07-17 23:07:51 +08:00
::WritePrivateProfileString(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
2018-07-17 23:07:51 +08:00
(value ? L"1" : L"0"),
2018-09-04 22:42:34 +08:00
(LPCWSTR)data_path_
2018-07-17 23:07:51 +08:00
);
}
2018-09-04 22:42:34 +08:00
void e2d::Data::SaveString(const String& value)
{
2018-07-17 23:07:51 +08:00
::WritePrivateProfileString(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
2018-07-17 23:07:51 +08:00
(LPCWSTR)value,
2018-09-04 22:42:34 +08:00
(LPCWSTR)data_path_
2018-07-17 23:07:51 +08:00
);
}
2018-09-04 22:42:34 +08:00
int e2d::Data::GetInt(int default_value)
2018-07-17 23:07:51 +08:00
{
return ::GetPrivateProfileInt(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
default_value,
(LPCWSTR)data_path_
2018-07-17 23:07:51 +08:00
);
}
2018-09-04 22:42:34 +08:00
float e2d::Data::GetDouble(float default_value)
{
wchar_t temp[32] = { 0 };
2018-09-04 22:42:34 +08:00
::GetPrivateProfileString((LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)String::Parse(default_value), temp, 31, (LPCWSTR)data_path_);
return std::stof(temp);
}
2018-09-04 22:42:34 +08:00
bool e2d::Data::GetBool(bool default_value)
{
2018-07-17 23:07:51 +08:00
int nValue = ::GetPrivateProfileInt(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
default_value ? 1 : 0,
(LPCWSTR)data_path_);
return nValue != 0;
}
2018-09-04 22:42:34 +08:00
e2d::String e2d::Data::GetString(const String& default_value)
{
wchar_t temp[256] = { 0 };
2018-07-17 23:07:51 +08:00
::GetPrivateProfileString(
2018-09-04 22:42:34 +08:00
(LPCWSTR)field_,
(LPCWSTR)key_,
(LPCWSTR)default_value,
2018-07-17 23:07:51 +08:00
temp,
255,
2018-09-04 22:42:34 +08:00
(LPCWSTR)data_path_
2018-07-17 23:07:51 +08:00
);
return temp;
}