From de7cc1f12273ae80f4d972b0dbfc48066f851684 Mon Sep 17 00:00:00 2001 From: Stephen Enders <84310577289916ceefd4132143fb36b63a5f0c71> Date: Fri, 24 Jun 2022 21:35:03 -0400 Subject: Fix compilation for Windows I left a few changes undone in the Windows API. This should be cross platform now --- src/resources/windows/WindowsResources.cpp | 52 ++++++++++++++++-------------- 1 file changed, 28 insertions(+), 24 deletions(-) (limited to 'src/resources/windows/WindowsResources.cpp') diff --git a/src/resources/windows/WindowsResources.cpp b/src/resources/windows/WindowsResources.cpp index cfe264f..4ef0e2e 100644 --- a/src/resources/windows/WindowsResources.cpp +++ b/src/resources/windows/WindowsResources.cpp @@ -23,32 +23,36 @@ // distribution. // //======================================================================== -#include "../Resources.h" +#include "WindowsResources.h" #include #define MAX_BUF_SIZE 1024 -class WindowsResources : public Resources { +std::filesystem::path exeDir; +std::filesystem::path workingDir; -protected: - std::filesystem::path exeDir; - std::filesystem::path workingDir; +std::vector WindowsResources::levelSearchDirs() { + return {workingDir / "maps", exeDir / "maps"}; +} +std::vector WindowsResources::defaultsSearchDirs() { + return {workingDir / "dnglib", exeDir / "dnglib"}; +} +std::vector WindowsResources::fontSearchDirs() { + return {workingDir / "res", exeDir / "res"}; +} +WindowsResources::WindowsResources() : Resources() { + this->workingDir = std::filesystem::current_path(); + this->font = std::make_shared(workingDir / "res" / + DEFAULT_FONT); - std::vector levelSearchDirs() override { - return {workingDir / "maps", exeDir / "maps"}; - } - std::vector defaultsSearchDirs() override { - return {workingDir / "dnglib", exeDir / "dnglib"}; - } - std::vector fontSearchDirs() override { - return {workingDir / "res", exeDir / "res"}; - } + char exe_dir_str[255]; + GetModuleFileNameA(nullptr, exe_dir_str, 255); + this->exeDir = std::filesystem::path{exe_dir_str}.remove_filename(); +} -public: - const char *convert_to_str(std::filesystem::path &path) override { - std::setlocale(LC_ALL, "en_US.utf8"); // TODO more support? - const wchar_t *wstr = path.c_str(); - size_t len = std::wcslen(wstr) + 1; // gotta get that \0 - char *ret = static_cast(malloc(sizeof(char) * len)); // buffered - std::wcstombs(ret, path.c_str(), len); - return ret; - } -}; \ No newline at end of file +const char *WindowsResources::convert_to_str(std::filesystem::path &path) { + std::setlocale(LC_ALL, "en_US.utf8"); // TODO more support? + const wchar_t *wstr = path.c_str(); + size_t len = std::wcslen(wstr) + 1; // gotta get that \0 + char *ret = static_cast(malloc(sizeof(char) * len)); // buffered + std::wcstombs(ret, path.c_str(), len); + return ret; +} -- cgit v1.2.3-54-g00ecf