Magic_Game/Easy2D/base/Resource.h

89 lines
2.3 KiB
C
Raw Normal View History

// Copyright (c) 2016-2018 Easy2D - Nomango
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#pragma once
#include "../macros.h"
#include "../common/helper.h"
namespace easy2d
{
// <20><>Դ
//
// <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͣ<EFBFBD>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD>DZ<EFBFBD><C7B1><EFBFBD><EFBFBD><EFBFBD> exe <20>еĶ<D0B5><C4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ
// <20><><EFBFBD><EFBFBD>, һ<><D2BB><EFBFBD><EFBFBD>Ƶ<EFBFBD><C6B5>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ L"WAVE", <20><><EFBFBD>Ʊ<EFBFBD>ʶ<EFBFBD><CAB6>Ϊ IDR_WAVE_1,
// <20><>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ: Resource res(MAKEINTRESOURCE(IDR_WAVE_1), L"WAVE");
//
// <20>˽<EFBFBD><CBBD><EFBFBD>Դ<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>Ϣ: https://docs.microsoft.com/en-us/windows/desktop/menurc/resources
//
class E2D_API Resource
{
enum class Type { File, Binary };
public:
Resource(
LPCWSTR file_name /* <20>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
Resource(
String const& file_name /* <20>ļ<EFBFBD>·<EFBFBD><C2B7> */
);
Resource(
LPCWSTR name, /* <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
LPCWSTR type /* <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD> */
);
Resource(
Resource const& rhs
);
virtual ~Resource();
inline bool IsFileType() const { return type_ == Type::File; }
inline String GetFileName() const { if (file_name_) return *file_name_; return String(); }
bool Load(
LPVOID& buffer,
DWORD& buffer_size
) const;
size_t GetHashCode() const;
Resource& operator= (Resource const& rhs);
private:
Type type_;
union
{
struct
{
String* file_name_;
};
struct
{
LPCWSTR bin_name_;
LPCWSTR bin_type_;
};
};
};
}