From ffb7143c2d429b356db4a516bb4db10ca4df0023 Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Tue, 21 Nov 2023 14:53:43 +0100 Subject: [PATCH] Add ResourceLoaderAppDirWindows --- .../Windows/ResourceLoaderAppDirWindows.cpp | 45 +++++++++++++++++++ .../Windows/ResourceLoaderAppDirWindows.hpp | 18 ++++++++ 2 files changed, 63 insertions(+) create mode 100644 openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.cpp create mode 100644 openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.hpp diff --git a/openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.cpp b/openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.cpp new file mode 100644 index 0000000..1d6ca35 --- /dev/null +++ b/openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.cpp @@ -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 +#include + +namespace OpenVulkano +{ + namespace + { + void* HANDLE = ResourceLoader::RegisterResourceLoader(std::make_unique()); + + 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 ResourceLoaderAppDirWindows::GetResource(const std::string& resourceName) + { + return Utils::ReadFile(GetAppDir() + resourceName); + } +} \ No newline at end of file diff --git a/openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.hpp b/openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.hpp new file mode 100644 index 0000000..fa0ac97 --- /dev/null +++ b/openVulkanoCpp/Host/Windows/ResourceLoaderAppDirWindows.hpp @@ -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 GetResource(const std::string& resourceName) override; + }; +} \ No newline at end of file