mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-23 21:22:07 +00:00
feat: add dialog handler for ModMan
This commit is contained in:
40
src/ModMan/Web/Platform/Windows/PlatformUtilsWindows.cpp
Normal file
40
src/ModMan/Web/Platform/Windows/PlatformUtilsWindows.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "PlatformUtilsWindows.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <exception>
|
||||
#include <format>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace PLATFORM_NAMESPACE_WINDOWS
|
||||
{
|
||||
std::string WideStringToString(const std::wstring& wideString)
|
||||
{
|
||||
if (wideString.empty())
|
||||
return "";
|
||||
|
||||
const auto sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, wideString.data(), static_cast<int>(wideString.size()), nullptr, 0, nullptr, nullptr);
|
||||
if (sizeNeeded <= 0)
|
||||
throw std::runtime_error(std::format("WideCharToMultiByte() failed: {}", sizeNeeded));
|
||||
|
||||
std::string result(sizeNeeded, 0);
|
||||
WideCharToMultiByte(CP_UTF8, 0, wideString.data(), static_cast<int>(wideString.size()), result.data(), sizeNeeded, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
std::wstring StringToWideString(const std::string& string)
|
||||
{
|
||||
if (string.empty())
|
||||
return L"";
|
||||
|
||||
const auto sizeNeeded = MultiByteToWideChar(CP_UTF8, 0, string.data(), static_cast<int>(string.size()), nullptr, 0);
|
||||
if (sizeNeeded <= 0)
|
||||
throw std::runtime_error(std::format("MultiByteToWideChar() failed: {}", sizeNeeded));
|
||||
|
||||
std::wstring result(sizeNeeded, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, string.data(), static_cast<int>(string.size()), result.data(), sizeNeeded);
|
||||
return result;
|
||||
}
|
||||
} // namespace PLATFORM_NAMESPACE_WINDOWS
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user