implement first version of embedded resource loader for Windows
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "EmbeddedResourceLoaderWindows.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include "Base/Logger.hpp"
|
||||
#include "../resources/resource.h"
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique<EmbeddedResourceLoaderWindows>());
|
||||
}
|
||||
|
||||
std::string EmbeddedResourceLoaderWindows::GetResourcePath(const std::string& resourceName)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
Array<char> EmbeddedResourceLoaderWindows::GetResource(const std::string& resourceName)
|
||||
{
|
||||
return {};
|
||||
//return GetResource(resourceName, GetResourceType(resourceName));
|
||||
}
|
||||
|
||||
//LPSTR EmbeddedResourceLoaderWindows::GetResourceType(const std::string& resourceName) const
|
||||
//{
|
||||
// std::filesystem::path path(resourceName);
|
||||
// std::string ext = path.extension().string();
|
||||
// if (ext.empty() || ext == ".")
|
||||
// {
|
||||
// Logger::APP->warn("Could not load embedded resource {}. Unsupported extension", resourceName, ext);
|
||||
// return {};
|
||||
// }
|
||||
// if (ext == ".ico" || ext == ".icon")
|
||||
// {
|
||||
// return RT_ICON;
|
||||
// }
|
||||
// else if (ext == ".ttf" || ext == ".fnt" || ext == ".font")
|
||||
// {
|
||||
// return RT_FONT;
|
||||
// }
|
||||
// // custom raw data
|
||||
// return RT_RCDATA;
|
||||
//}
|
||||
|
||||
Array<char> EmbeddedResourceLoaderWindows::GetResource(LPSTR resId, LPSTR resourceType) const
|
||||
{
|
||||
HMODULE exe = GetModuleHandleA(NULL);
|
||||
LPCSTR resourceName = resId;
|
||||
HRSRC hRes = FindResourceA(exe, resourceName, resourceType);
|
||||
if (!hRes)
|
||||
{
|
||||
Logger::APP->warn("Could not find embedded resource");
|
||||
return {};
|
||||
}
|
||||
|
||||
HGLOBAL hResData = LoadResource(exe, hRes);
|
||||
if (!hResData)
|
||||
{
|
||||
Logger::APP->warn("Embedded resource found, but could not load.");
|
||||
return {};
|
||||
}
|
||||
|
||||
void* data = LockResource(hResData);
|
||||
DWORD size = SizeofResource(exe, hRes);
|
||||
Array<char> dst(size);
|
||||
std::memcpy(dst.Data(), data, size);
|
||||
return dst;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Host/ResourceLoader.hpp"
|
||||
#include <variant>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
class EmbeddedResourceLoaderWindows final : public ResourceLoader
|
||||
{
|
||||
public:
|
||||
std::string GetResourcePath(const std::string& resourceName) override;
|
||||
Array<char> GetResource(const std::string& resourceName) override;
|
||||
Array<char> GetResource(char* resId, char* resourceType) const;
|
||||
private:
|
||||
char* GetResourceType(const std::string& resourceName) const;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user