Magic_Game/core/Tool/Data.cpp

69 lines
2.2 KiB
C++
Raw Normal View History

2018-01-30 16:45:38 +08:00
#include "..\etools.h"
static e2d::String s_sDefaultFileName = L"DefaultData.ini";
2018-01-30 16:45:38 +08:00
void e2d::Data::saveInt(const String & key, int value, const String & fileName)
2018-01-30 16:45:38 +08:00
{
::WritePrivateProfileString(L"Default", key, String::toString(value), Data::getDataFilePath(fileName));
2018-01-30 16:45:38 +08:00
}
void e2d::Data::saveDouble(const String & key, double value, const String & fileName)
2018-01-30 16:45:38 +08:00
{
::WritePrivateProfileString(L"Default", key, String::toString(value), Data::getDataFilePath(fileName));
2018-01-30 16:45:38 +08:00
}
void e2d::Data::saveBool(const String & key, bool value, const String & fileName)
{
2018-03-01 19:28:22 +08:00
const wchar_t* sValue = value ? L"1" : L"0";
::WritePrivateProfileString(L"Default", key, sValue, Data::getDataFilePath(fileName));
}
void e2d::Data::saveString(const String & key, const String & value, const String & fileName)
2018-01-30 16:45:38 +08:00
{
::WritePrivateProfileString(L"Default", key, value, Data::getDataFilePath(fileName));
2018-01-30 16:45:38 +08:00
}
int e2d::Data::getInt(const String & key, int defaultValue, const String & fileName)
2018-01-30 16:45:38 +08:00
{
return ::GetPrivateProfileInt(L"Default", key, defaultValue, Data::getDataFilePath(fileName));
2018-01-30 16:45:38 +08:00
}
double e2d::Data::getDouble(const String & key, double defaultValue, const String & fileName)
2018-01-30 16:45:38 +08:00
{
wchar_t temp[32] = { 0 };
::GetPrivateProfileString(L"Default", key, String::toString(defaultValue), temp, 31, Data::getDataFilePath(fileName));
2018-01-30 16:45:38 +08:00
return std::stof(temp);
}
bool e2d::Data::getBool(const String & key, bool defaultValue, const String & fileName)
{
int nDefaultValue = defaultValue ? 1 : 0;
int nValue = ::GetPrivateProfileInt(L"Default", key, nDefaultValue, Data::getDataFilePath(fileName));
return nValue != 0;
}
e2d::String e2d::Data::getString(const String & key, const String & defaultValue, const String & fileName)
2018-01-30 16:45:38 +08:00
{
wchar_t temp[256] = { 0 };
::GetPrivateProfileString(L"Default", key, defaultValue, temp, 255, Data::getDataFilePath(fileName));
2018-01-30 16:45:38 +08:00
return temp;
}
void e2d::Data::setDefaultFileName(const String & fileName)
{
if (!fileName.isEmpty())
{
s_sDefaultFileName.clear();
s_sDefaultFileName << fileName << L".ini";
}
}
e2d::String e2d::Data::getDataFilePath(const String & fileName)
{
if (fileName.isEmpty())
{
return Path::getDefaultSavePath() + s_sDefaultFileName;
}
return Path::getDefaultSavePath() + fileName + L".ini";
}