| 74 | } |
| 75 | |
| 76 | std::shared_ptr<IBlob> WinResFileSystem::readFile(const fs::path& name) |
| 77 | { |
| 78 | std::string nameString = name.lexically_normal().generic_string(); |
| 79 | donut::string_utils::ltrim(nameString, '/'); |
| 80 | |
| 81 | HRSRC hResource = FindResourceA((HMODULE)m_hModule, nameString.c_str(), m_Type.c_str()); |
| 82 | |
| 83 | if (hResource == nullptr) |
| 84 | return nullptr; |
| 85 | |
| 86 | DWORD size = SizeofResource((HMODULE)m_hModule, hResource); |
| 87 | if (size == 0) |
| 88 | { |
| 89 | // empty resource (can that really happen?) |
| 90 | return std::make_shared<NonOwningBlob>(nullptr, 0); |
| 91 | } |
| 92 | |
| 93 | HGLOBAL hGlobal = LoadResource((HMODULE)m_hModule, hResource); |
| 94 | |
| 95 | if (hGlobal == nullptr) |
| 96 | return nullptr; |
| 97 | |
| 98 | void* pData = LockResource(hGlobal); |
| 99 | return std::make_shared<NonOwningBlob>(pData, size); |
| 100 | } |
| 101 | |
| 102 | bool WinResFileSystem::writeFile(const fs::path&, const void*, size_t) |
| 103 | { |