diff --git a/src/kiwano/core/Resource.cpp b/src/kiwano/core/Resource.cpp index 0f1da5a1..ad44a5ff 100644 --- a/src/kiwano/core/Resource.cpp +++ b/src/kiwano/core/Resource.cpp @@ -26,11 +26,11 @@ namespace kiwano { Resource::Resource() : id_(0) - , type_(nullptr) + , type_() { } -Resource::Resource(uint32_t id, const wchar_t* type) +Resource::Resource(uint32_t id, const String& type) : id_(id) , type_(type) { @@ -45,7 +45,7 @@ Resource::Data Resource::GetData() const break; } - HRSRC res_info = FindResourceW(nullptr, MAKEINTRESOURCE(id_), type_); + HRSRC res_info = FindResourceA(nullptr, MAKEINTRESOURCEA(id_), type_.data()); if (res_info == nullptr) { KGE_ERROR("FindResource failed"); diff --git a/src/kiwano/core/Resource.h b/src/kiwano/core/Resource.h index b8394d34..19c742db 100644 --- a/src/kiwano/core/Resource.h +++ b/src/kiwano/core/Resource.h @@ -49,7 +49,7 @@ public: Data(); - operator bool() const; + bool IsValid() const; }; /// \~chinese @@ -60,7 +60,7 @@ public: /// @brief 构造资源 /// @param id 资源 ID /// @param type 资源类型 - Resource(uint32_t id, const wchar_t* type); + Resource(uint32_t id, const String& type); /// \~chinese /// @brief 获取资源的二进制数据 @@ -73,11 +73,11 @@ public: /// \~chinese /// @brief 获取资源类型 - const wchar_t* GetType() const; + String GetType() const; private: - uint32_t id_; - const wchar_t* type_; + uint32_t id_; + String type_; mutable Resource::Data data_; }; @@ -88,7 +88,7 @@ inline Resource::Data::Data() { } -inline Resource::Data::operator bool() const +inline bool Resource::Data::IsValid() const { return buffer != nullptr && size; } @@ -98,7 +98,7 @@ inline uint32_t Resource::GetId() const return id_; } -inline const wchar_t* Resource::GetType() const +inline String Resource::GetType() const { return type_; } diff --git a/src/kiwano/platform/FileSystem.cpp b/src/kiwano/platform/FileSystem.cpp index 1446f59d..a8b4e0d6 100644 --- a/src/kiwano/platform/FileSystem.cpp +++ b/src/kiwano/platform/FileSystem.cpp @@ -177,7 +177,7 @@ bool FileSystem::ExtractResourceToFile(const Resource& res, const String& dest_f return false; Resource::Data data = res.GetData(); - if (data) + if (data.IsValid()) { DWORD written_bytes = 0; ::WriteFile(file_handle, data.buffer, data.size, &written_bytes, NULL); diff --git a/src/kiwano/render/DirectX/FontCollectionLoader.cpp b/src/kiwano/render/DirectX/FontCollectionLoader.cpp index f4de0f78..7dd1a870 100644 --- a/src/kiwano/render/DirectX/FontCollectionLoader.cpp +++ b/src/kiwano/render/DirectX/FontCollectionLoader.cpp @@ -824,7 +824,7 @@ ResourceFontFileStream::ResourceFontFileStream() STDMETHODIMP ResourceFontFileStream::Initialize(const Resource resource) { Resource::Data data = resource.GetData(); - HRESULT hr = data ? S_OK : E_FAIL; + HRESULT hr = data.IsValid() ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { diff --git a/src/kiwano/render/DirectX/RendererImpl.cpp b/src/kiwano/render/DirectX/RendererImpl.cpp index 1f4e8042..596f3598 100644 --- a/src/kiwano/render/DirectX/RendererImpl.cpp +++ b/src/kiwano/render/DirectX/RendererImpl.cpp @@ -220,7 +220,7 @@ void RendererImpl::CreateTexture(Texture& texture, const Resource& resource) { Resource::Data data = resource.GetData(); - hr = data ? S_OK : E_FAIL; + hr = data.IsValid() ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { @@ -308,7 +308,7 @@ void RendererImpl::CreateGifImage(GifImage& gif, const Resource& resource) { Resource::Data data = resource.GetData(); - hr = data ? S_OK : E_FAIL; + hr = data.IsValid() ? S_OK : E_FAIL; if (SUCCEEDED(hr)) {