From 997aca7e6e959b34c195ef74f8833e6a3cebe6ff Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Tue, 4 Sep 2018 22:57:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0Data::Exists=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E5=88=A4=E6=96=AD=E6=95=B0=E6=8D=AE=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/Base/Renderer.cpp | 2 +- core/Node/Text.cpp | 8 ++--- core/Tool/Data.cpp | 74 +++++++++++++++++++++++++++++++----------- core/Tool/Path.cpp | 2 +- core/e2dtool.h | 49 ++++++++++++++-------------- 5 files changed, 85 insertions(+), 50 deletions(-) diff --git a/core/Base/Renderer.cpp b/core/Base/Renderer.cpp index c75697cf..eeaa2d56 100644 --- a/core/Base/Renderer.cpp +++ b/core/Base/Renderer.cpp @@ -106,7 +106,7 @@ void e2d::Renderer::EndDraw() ThrowIfFailed( GetWriteFactory()->CreateTextLayout( - (const WCHAR *)fpsText, + (const wchar_t *)fpsText, (UINT32)fpsText.GetLength(), fps_text_format_, 0, diff --git a/core/Node/Text.cpp b/core/Node/Text.cpp index 341fdcb1..53287a9a 100644 --- a/core/Node/Text.cpp +++ b/core/Node/Text.cpp @@ -323,7 +323,7 @@ void e2d::Text::CreateFormat() ThrowIfFailed( Renderer::GetWriteFactory()->CreateTextFormat( - (const WCHAR *)font_.family, + (const wchar_t *)font_.family, nullptr, DWRITE_FONT_WEIGHT(font_.weight), font_.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL, @@ -387,7 +387,7 @@ void e2d::Text::CreateLayout() { ThrowIfFailed( writeFactory->CreateTextLayout( - (const WCHAR *)text_, + (const wchar_t *)text_, length, text_format_, style_.wrap_width, @@ -406,7 +406,7 @@ void e2d::Text::CreateLayout() // 为防止文本对齐问题,根据先创建 layout 以获取宽度 ThrowIfFailed( writeFactory->CreateTextLayout( - (const WCHAR *)text_, + (const wchar_t *)text_, length, text_format_, 0, @@ -425,7 +425,7 @@ void e2d::Text::CreateLayout() SafeRelease(text_layout_); ThrowIfFailed( writeFactory->CreateTextLayout( - (const WCHAR *)text_, + (const wchar_t *)text_, length, text_format_, size_.width, diff --git a/core/Tool/Data.cpp b/core/Tool/Data.cpp index 4b24f7c3..08a33e95 100644 --- a/core/Tool/Data.cpp +++ b/core/Tool/Data.cpp @@ -8,80 +8,116 @@ e2d::Data::Data(const String & key, const String & field) { } -void e2d::Data::SaveInt(int value) +bool e2d::Data::Exists() const { - ::WritePrivateProfileString( + wchar_t temp[256] = { 0 }; + ::GetPrivateProfileStringW( + (LPCWSTR)field_, + (LPCWSTR)key_, + L"", + temp, + 255, + (LPCWSTR)data_path_ + ); + return temp[0] == L'\0'; +} + +bool e2d::Data::SaveInt(int value) +{ + BOOL ret = ::WritePrivateProfileStringW( (LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)String::Parse(value), (LPCWSTR)data_path_ ); + return ret != 0; } -void e2d::Data::SaveDouble(float value) +bool e2d::Data::SaveFloat(float value) { - ::WritePrivateProfileString( + BOOL ret = ::WritePrivateProfileStringW( (LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)String::Parse(value), (LPCWSTR)data_path_ ); + return ret != 0; } -void e2d::Data::SaveBool(bool value) +bool e2d::Data::SaveDouble(double value) { - ::WritePrivateProfileString( + BOOL ret = ::WritePrivateProfileStringW( + (LPCWSTR)field_, + (LPCWSTR)key_, + (LPCWSTR)String::Parse(value), + (LPCWSTR)data_path_ + ); + return ret != 0; +} + +bool e2d::Data::SaveBool(bool value) +{ + BOOL ret = ::WritePrivateProfileStringW( (LPCWSTR)field_, (LPCWSTR)key_, (value ? L"1" : L"0"), (LPCWSTR)data_path_ ); + return ret != 0; } -void e2d::Data::SaveString(const String& value) +bool e2d::Data::SaveString(const String& value) { - ::WritePrivateProfileString( + BOOL ret = ::WritePrivateProfileStringW( (LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)value, (LPCWSTR)data_path_ ); + return ret != 0; } -int e2d::Data::GetInt(int default_value) +int e2d::Data::GetInt() const { - return ::GetPrivateProfileInt( + return ::GetPrivateProfileIntW( (LPCWSTR)field_, (LPCWSTR)key_, - default_value, + 0, (LPCWSTR)data_path_ ); } -float e2d::Data::GetDouble(float default_value) +float e2d::Data::GetFloat() const { wchar_t temp[32] = { 0 }; - ::GetPrivateProfileString((LPCWSTR)field_, (LPCWSTR)key_, (LPCWSTR)String::Parse(default_value), temp, 31, (LPCWSTR)data_path_); + ::GetPrivateProfileStringW((LPCWSTR)field_, (LPCWSTR)key_, L"0.0", temp, 31, (LPCWSTR)data_path_); return std::stof(temp); } -bool e2d::Data::GetBool(bool default_value) +double e2d::Data::GetDouble() const { - int nValue = ::GetPrivateProfileInt( + wchar_t temp[32] = { 0 }; + ::GetPrivateProfileStringW((LPCWSTR)field_, (LPCWSTR)key_, L"0.0", temp, 31, (LPCWSTR)data_path_); + return std::stod(temp); +} + +bool e2d::Data::GetBool() const +{ + int nValue = ::GetPrivateProfileIntW( (LPCWSTR)field_, (LPCWSTR)key_, - default_value ? 1 : 0, + 0, (LPCWSTR)data_path_); return nValue != 0; } -e2d::String e2d::Data::GetString(const String& default_value) +e2d::String e2d::Data::GetString() { wchar_t temp[256] = { 0 }; - ::GetPrivateProfileString( + ::GetPrivateProfileStringW( (LPCWSTR)field_, (LPCWSTR)key_, - (LPCWSTR)default_value, + L"", temp, 255, (LPCWSTR)data_path_ diff --git a/core/Tool/Path.cpp b/core/Tool/Path.cpp index 5c560444..10e70ee6 100644 --- a/core/Tool/Path.cpp +++ b/core/Tool/Path.cpp @@ -56,7 +56,7 @@ const e2d::String& e2d::Path::GetLocalAppDataPath() if (local_app_data_path.IsEmpty()) { // 获取 AppData/Local 文件夹的路径 - WCHAR path[MAX_PATH] = { 0 }; + wchar_t path[MAX_PATH] = { 0 }; ::SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path); local_app_data_path = path; } diff --git a/core/e2dtool.h b/core/e2dtool.h index e8f3afdd..bb974491 100644 --- a/core/e2dtool.h +++ b/core/e2dtool.h @@ -370,49 +370,48 @@ public: const String& field = L"Defalut" /* 字段名称 */ ); + // 该数据是否存在 + bool Exists() const; + // 保存 int 类型的值 - void SaveInt( - int value /* 数据 */ + bool SaveInt( + int value ); // 保存 float 类型的值 - void SaveDouble( - float value /* 数据 */ + bool SaveFloat( + float value + ); + + // 保存 double 类型的值 + bool SaveDouble( + double value ); // 保存 bool 类型的值 - void SaveBool( - bool value /* 数据 */ + bool SaveBool( + bool value ); - // 保存 字符串 类型的值 - void SaveString( - const String& value /* 数据 */ + // 保存 String 类型的值 + bool SaveString( + const String& value ); // 获取 int 类型的值 - // (若不存在则返回 default_value 参数的值) - int GetInt( - int default_value /* 默认值 */ - ); + int GetInt() const; // 获取 float 类型的值 - // (若不存在则返回 default_value 参数的值) - float GetDouble( - float default_value /* 默认值 */ - ); + float GetFloat() const; + + // 获取 double 类型的值 + double GetDouble() const; // 获取 bool 类型的值 - // (若不存在则返回 default_value 参数的值) - bool GetBool( - bool default_value /* 默认值 */ - ); + bool GetBool() const; // 获取 字符串 类型的值 - // (若不存在则返回 default_value 参数的值) - String GetString( - const String& default_value /* 默认值 */ - ); + String GetString(); protected: String key_;