#include "Minecraft_Utils.h" CMinecraftUtils utils; CMinecraftUtils::CMinecraftUtils() {} fs::path CMinecraftUtils::GetExeDir() { wchar_t szExePath[MAX_PATH] = {}; GetModuleFileNameW(nullptr, szExePath, MAX_PATH); return fs::path(szExePath).parent_path(); } std::string CMinecraftUtils::WideToUtf8(const std::wstring &value) { if (value.empty()) return std::string(); int charCount = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), (int)value.length(), nullptr, 0, nullptr, nullptr); if (charCount <= 0) return std::string(); std::string utf8; utf8.resize(charCount); WideCharToMultiByte(CP_UTF8, 0, value.c_str(), (int)value.length(), &utf8[0], charCount, nullptr, nullptr); return utf8; } std::wstring CMinecraftUtils::Utf8ToWide(const char *value) { if (value == nullptr || value[0] == 0) return std::wstring(); int wideCount = MultiByteToWideChar(CP_UTF8, 0, value, -1, nullptr, 0); if (wideCount <= 0) { // Fall back to the current ANSI code page so legacy non-UTF-8 inputs remain readable. wideCount = MultiByteToWideChar(CP_ACP, 0, value, -1, nullptr, 0); if (wideCount <= 0) return std::wstring(); std::wstring wide; wide.resize(wideCount - 1); MultiByteToWideChar(CP_ACP, 0, value, -1, &wide[0], wideCount); return wide; } std::wstring wide; wide.resize(wideCount - 1); MultiByteToWideChar(CP_UTF8, 0, value, -1, &wide[0], wideCount); return wide; } std::wstring CMinecraftUtils::Utf8ToWide(const std::string &value) { return Utf8ToWide(value.c_str()); }