#include "re/config.h" #include #include #include namespace re { namespace { std::wstring g_path; std::wstring Widen(const char* s) { return std::wstring(s, s + strlen(s)); } } // namespace void SetConfigPath(const std::wstring& path) { g_path = path; } const std::wstring& ConfigPath() { return g_path; } std::wstring ModuleDirectory() { return g_path.substr(0, g_path.find_last_of(L"\\/") + 1); } int ConfigInt(const char* section, const char* key, int fallback) { if (g_path.empty()) { return fallback; } return static_cast(GetPrivateProfileIntW(Widen(section).c_str(), Widen(key).c_str(), fallback, g_path.c_str())); } std::string ConfigString(const char* section, const char* key, const char* fallback) { if (g_path.empty()) { return fallback; } wchar_t value[256]; GetPrivateProfileStringW(Widen(section).c_str(), Widen(key).c_str(), Widen(fallback).c_str(), value, static_cast(std::size(value)), g_path.c_str()); char narrow[256]; WideCharToMultiByte(CP_UTF8, 0, value, -1, narrow, sizeof(narrow), nullptr, nullptr); return narrow; } void SetConfigString(const char* section, const char* key, const char* value) { if (g_path.empty()) { return; } wchar_t wide[256]; MultiByteToWideChar(CP_UTF8, 0, value, -1, wide, static_cast(std::size(wide))); WritePrivateProfileStringW(Widen(section).c_str(), Widen(key).c_str(), wide, g_path.c_str()); } } // namespace re