Add ResourceLoaderAppDirWindows
This commit is contained in:
45
openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.cpp
Normal file
45
openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 "ResourceLoaderAppDirWindows.hpp"
|
||||
#include "Base/Utils.hpp"
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
namespace
|
||||
{
|
||||
void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique<ResourceLoaderAppDirWindows>());
|
||||
|
||||
std::string FindAppDir()
|
||||
{
|
||||
char buffer[4096];
|
||||
size_t size;
|
||||
if ((size = GetModuleFileNameA(NULL, buffer, sizeof(buffer))) > 0)
|
||||
{
|
||||
std::string_view appDirPath(buffer, size);
|
||||
return std::string(appDirPath.substr(0, appDirPath.find_last_of('\\') + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "Failed to find real path to application!";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
const std::string& GetAppDir()
|
||||
{
|
||||
static const std::string appDirPath = FindAppDir();
|
||||
return appDirPath;
|
||||
}
|
||||
}
|
||||
|
||||
Array<char> ResourceLoaderAppDirWindows::GetResource(const std::string& resourceName)
|
||||
{
|
||||
return Utils::ReadFile(GetAppDir() + resourceName);
|
||||
}
|
||||
}
|
||||
18
openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.hpp
Normal file
18
openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
namespace OpenVulkano
|
||||
{
|
||||
class ResourceLoaderAppDirWindows final : public ResourceLoader
|
||||
{
|
||||
public:
|
||||
Array<char> GetResource(const std::string& resourceName) override;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user