diff --git a/src/Nazara/Core/Win32/DynLibImpl.cpp b/src/Nazara/Core/Win32/DynLibImpl.cpp index 9259cc64f..9d5397bf0 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.cpp +++ b/src/Nazara/Core/Win32/DynLibImpl.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -28,10 +29,7 @@ namespace Nz::PlatformImpl bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage) { - if constexpr (std::is_same_v) - m_handle = LoadLibraryExW(libraryPath.c_str(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); - else - m_handle = LoadLibraryExW(ToWideString(PathToString(libraryPath)).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); + m_handle = LoadLibraryExW(PathToWideTemp(libraryPath).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); if (m_handle) return true; diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index 682e9540a..27ea6c37e 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -90,10 +90,7 @@ namespace Nz::PlatformImpl if (!mode.Test(OpenMode::Lock)) shareMode |= FILE_SHARE_WRITE; - if constexpr (std::is_same_v) - m_handle = CreateFileW(filePath.c_str(), access, shareMode, nullptr, openMode, 0, nullptr); - else - m_handle = CreateFileW(ToWideString(PathToString(filePath)).data(), access, shareMode, nullptr, openMode, 0, nullptr); + m_handle = CreateFileW(PathToWideTemp(filePath).data(), access, shareMode, nullptr, openMode, 0, nullptr); return m_handle != INVALID_HANDLE_VALUE; } diff --git a/src/Nazara/Core/Win32/Utils.cpp b/src/Nazara/Core/Win32/Win32Utils.cpp similarity index 84% rename from src/Nazara/Core/Win32/Utils.cpp rename to src/Nazara/Core/Win32/Win32Utils.cpp index 441906b4c..d6e9eab24 100644 --- a/src/Nazara/Core/Win32/Utils.cpp +++ b/src/Nazara/Core/Win32/Win32Utils.cpp @@ -2,10 +2,12 @@ // This file is part of the "Nazara Engine - Core module" // For conditions of distribution and use, see copyright notice in Config.hpp -#include +#include +#include +#include #include -namespace Nz +namespace Nz::PlatformImpl { time_t FileTimeToTime(FILETIME* time) { diff --git a/src/Nazara/Core/Win32/Utils.hpp b/src/Nazara/Core/Win32/Win32Utils.hpp similarity index 55% rename from src/Nazara/Core/Win32/Utils.hpp rename to src/Nazara/Core/Win32/Win32Utils.hpp index 4a71441b7..94d90a7ec 100644 --- a/src/Nazara/Core/Win32/Utils.hpp +++ b/src/Nazara/Core/Win32/Win32Utils.hpp @@ -9,11 +9,19 @@ #include #include +#include #include -namespace Nz +namespace Nz::PlatformImpl { + constexpr bool ArePathWide = std::is_same_v< std::filesystem::path::value_type, wchar_t>; + + using WidePathHolder = std::conditional_t; + + inline WidePathHolder PathToWideTemp(const std::filesystem::path& path); time_t FileTimeToTime(FILETIME* time); } +#include + #endif // NAZARA_CORE_WIN32_UTILS_HPP diff --git a/src/Nazara/Core/Win32/Win32Utils.inl b/src/Nazara/Core/Win32/Win32Utils.inl new file mode 100644 index 000000000..4549dd713 --- /dev/null +++ b/src/Nazara/Core/Win32/Win32Utils.inl @@ -0,0 +1,14 @@ +// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com) +// This file is part of the "Nazara Engine - Core module" +// For conditions of distribution and use, see copyright notice in Config.hpp + +namespace Nz::PlatformImpl +{ + inline WidePathHolder PathToWideTemp(const std::filesystem::path& path) + { + if constexpr (ArePathWide) + return path.native(); + else + return path.generic_wstring(); + } +}