From f2bc00d2ea0574104f302cdce35cbb6d7a53bd1c Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 3 Apr 2023 12:51:26 +0200 Subject: [PATCH] Core: Skip conversion to UTF-16 if filesystem::path is based on it --- src/Nazara/Core/Win32/DynLibImpl.cpp | 6 +++++- src/Nazara/Core/Win32/FileImpl.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Nazara/Core/Win32/DynLibImpl.cpp b/src/Nazara/Core/Win32/DynLibImpl.cpp index 5677921ba..e2e40a5c3 100644 --- a/src/Nazara/Core/Win32/DynLibImpl.cpp +++ b/src/Nazara/Core/Win32/DynLibImpl.cpp @@ -33,7 +33,11 @@ namespace Nz bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage) { - m_handle = LoadLibraryExW(ToWideString(libraryPath.generic_u8string()).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); + 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(libraryPath.generic_u8string()).data(), nullptr, (libraryPath.is_absolute()) ? LOAD_WITH_ALTERED_SEARCH_PATH : 0); + if (m_handle) return true; else diff --git a/src/Nazara/Core/Win32/FileImpl.cpp b/src/Nazara/Core/Win32/FileImpl.cpp index cc9dd2aa5..35b7efc12 100644 --- a/src/Nazara/Core/Win32/FileImpl.cpp +++ b/src/Nazara/Core/Win32/FileImpl.cpp @@ -89,7 +89,11 @@ namespace Nz if ((mode & OpenMode::Lock) == 0) shareMode |= FILE_SHARE_WRITE; - m_handle = CreateFileW(ToWideString(filePath.generic_u8string()).data(), access, shareMode, nullptr, openMode, 0, nullptr); + if constexpr (std::is_same_v) + m_handle = CreateFileW(filePath.c_str(), access, shareMode, nullptr, openMode, 0, nullptr); + else + m_handle = CreateFileW(ToWideString(filePath.generic_u8string()).data(), access, shareMode, nullptr, openMode, 0, nullptr); + return m_handle != INVALID_HANDLE_VALUE; }