Core/Win32: Add PathToWideTemp function

This commit is contained in:
SirLynix 2024-01-22 16:58:12 +01:00
parent 373309d6d9
commit 8dab084037
5 changed files with 31 additions and 12 deletions

View File

@ -3,6 +3,7 @@
// For conditions of distribution and use, see copyright notice in Config.hpp
#include <Nazara/Core/Win32/DynLibImpl.hpp>
#include <Nazara/Core/Win32/Win32Utils.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <NazaraUtils/PathUtils.hpp>
@ -28,10 +29,7 @@ namespace Nz::PlatformImpl
bool DynLibImpl::Load(const std::filesystem::path& libraryPath, std::string* errorMessage)
{
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(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;

View File

@ -5,7 +5,7 @@
#include <Nazara/Core/Win32/FileImpl.hpp>
#include <Nazara/Core/Error.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <Nazara/Core/Win32/Utils.hpp>
#include <Nazara/Core/Win32/Win32Utils.hpp>
#include <NazaraUtils/CallOnExit.hpp>
#include <NazaraUtils/PathUtils.hpp>
#include <memory>
@ -90,10 +90,7 @@ namespace Nz::PlatformImpl
if (!mode.Test(OpenMode::Lock))
shareMode |= FILE_SHARE_WRITE;
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(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;
}

View File

@ -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 <Nazara/Core/Win32/Utils.hpp>
#include <Nazara/Core/Win32/Win32Utils.hpp>
#include <Nazara/Core/StringExt.hpp>
#include <NazaraUtils/PathUtils.hpp>
#include <Nazara/Core/Debug.hpp>
namespace Nz
namespace Nz::PlatformImpl
{
time_t FileTimeToTime(FILETIME* time)
{

View File

@ -9,11 +9,19 @@
#include <NazaraUtils/Prerequisites.hpp>
#include <ctime>
#include <filesystem>
#include <Windows.h>
namespace Nz
namespace Nz::PlatformImpl
{
constexpr bool ArePathWide = std::is_same_v< std::filesystem::path::value_type, wchar_t>;
using WidePathHolder = std::conditional_t<ArePathWide, /*null-terminated*/ std::wstring_view, std::wstring>;
inline WidePathHolder PathToWideTemp(const std::filesystem::path& path);
time_t FileTimeToTime(FILETIME* time);
}
#include <Nazara/Core/Win32/Win32Utils.inl>
#endif // NAZARA_CORE_WIN32_UTILS_HPP

View File

@ -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();
}
}