Magic_Game/core/Tool/Path.cpp

65 lines
1.9 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
2018-03-13 23:35:00 +08:00
void e2d::Data::saveInt(const String & key, int value, const String & field)
2018-01-30 16:45:38 +08:00
{
2018-03-13 23:35:00 +08:00
::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath());
2018-01-30 16:45:38 +08:00
}
2018-03-13 23:35:00 +08:00
void e2d::Data::saveDouble(const String & key, double value, const String & field)
2018-01-30 16:45:38 +08:00
{
2018-03-13 23:35:00 +08:00
::WritePrivateProfileString(field, key, String::toString(value), Data::getDataFilePath());
2018-01-30 16:45:38 +08:00
}
2018-03-13 23:35:00 +08:00
void e2d::Data::saveBool(const String & key, bool value, const String & field)
{
2018-03-01 19:28:22 +08:00
const wchar_t* sValue = value ? L"1" : L"0";
2018-03-13 23:35:00 +08:00
::WritePrivateProfileString(field, key, sValue, Data::getDataFilePath());
}
2018-03-13 23:35:00 +08:00
void e2d::Data::saveString(const String & key, const String & value, const String & field)
2018-01-30 16:45:38 +08:00
{
2018-03-13 23:35:00 +08:00
::WritePrivateProfileString(field, key, value, Data::getDataFilePath());
2018-01-30 16:45:38 +08:00
}
2018-03-13 23:35:00 +08:00
int e2d::Data::getInt(const String & key, int defaultValue, const String & field)
2018-01-30 16:45:38 +08:00
{
2018-03-13 23:35:00 +08:00
return ::GetPrivateProfileInt(field, key, defaultValue, Data::getDataFilePath());
2018-01-30 16:45:38 +08:00
}
2018-03-13 23:35:00 +08:00
double e2d::Data::getDouble(const String & key, double defaultValue, const String & field)
2018-01-30 16:45:38 +08:00
{
wchar_t temp[32] = { 0 };
2018-03-13 23:35:00 +08:00
::GetPrivateProfileString(field, key, String::toString(defaultValue), temp, 31, Data::getDataFilePath());
2018-01-30 16:45:38 +08:00
return std::stof(temp);
}
2018-03-13 23:35:00 +08:00
bool e2d::Data::getBool(const String & key, bool defaultValue, const String & field)
{
int nDefaultValue = defaultValue ? 1 : 0;
2018-03-13 23:35:00 +08:00
int nValue = ::GetPrivateProfileInt(field, key, nDefaultValue, Data::getDataFilePath());
return nValue != 0;
}
2018-03-13 23:35:00 +08:00
e2d::String e2d::Data::getString(const String & key, const String & defaultValue, const String & field)
2018-01-30 16:45:38 +08:00
{
wchar_t temp[256] = { 0 };
2018-03-13 23:35:00 +08:00
::GetPrivateProfileString(field, key, defaultValue, temp, 255, Data::getDataFilePath());
2018-01-30 16:45:38 +08:00
return temp;
}
2018-03-13 23:35:00 +08:00
void e2d::Data::setDataFileName(const String & fileName)
{
if (!fileName.isEmpty())
{
s_sDefaultFileName.clear();
s_sDefaultFileName << fileName << L".ini";
}
}
2018-03-13 23:35:00 +08:00
e2d::String e2d::Data::getDataFilePath()
{
2018-03-13 23:35:00 +08:00
return Path::getDefaultSavePath() + s_sDefaultFileName;
}