#include "pch.h" #include "RcResource.h" #include std::optional RcResource::create(int resource_id, const std::wstring_view resource_class) { const HRSRC resHandle = FindResourceW(nullptr, MAKEINTRESOURCEW(resource_id), resource_class.data()); if (!resHandle) { return std::nullopt; } const HGLOBAL memHandle = LoadResource(nullptr, resHandle); if (!memHandle) { return std::nullopt; } const size_t resSize = SizeofResource(nullptr, resHandle); if (!resSize) { return std::nullopt; } auto res = static_cast(LockResource(memHandle)); if (!res) { return std::nullopt; } return RcResource{ res, resSize }; } bool RcResource::saveAsFile(const std::filesystem::path destination) { std::fstream installerFile{ destination, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc }; if (!installerFile.is_open()) { return false; } installerFile.write(reinterpret_cast(_memory), _size); return true; }