Core: Skip conversion to UTF-16 if filesystem::path is based on it

This commit is contained in:
Lynix 2023-04-03 12:51:26 +02:00
parent 36643f173b
commit f2bc00d2ea
2 changed files with 10 additions and 2 deletions

View File

@ -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<std::filesystem::path::value_type, wchar_t>)
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

View File

@ -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<std::filesystem::path::value_type, wchar_t>)
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;
}