From c5802ae0cbce8d4c5ea84589a04363a1ed1989f9 Mon Sep 17 00:00:00 2001 From: Sajid Date: Tue, 28 Jan 2025 16:01:12 +0600 Subject: [PATCH] Use string_view value names for registry --- UnleashedRecomp/CMakeLists.txt | 1 + UnleashedRecomp/os/linux/registry_linux.inl | 4 ++-- UnleashedRecomp/os/registry.h | 4 ++-- UnleashedRecomp/os/win32/registry_win32.inl | 10 +++++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/UnleashedRecomp/CMakeLists.txt b/UnleashedRecomp/CMakeLists.txt index 4aa448d1..0adeb8a4 100644 --- a/UnleashedRecomp/CMakeLists.txt +++ b/UnleashedRecomp/CMakeLists.txt @@ -298,6 +298,7 @@ endif() if (UNLEASHED_RECOMP_FLATPAK) target_compile_definitions(UnleashedRecomp PRIVATE "GAME_INSTALL_DIRECTORY=\"/var/data\"") + target_compile_definitions(UnleashedRecomp PRIVATE "UNLEASHED_RECOMP_FLATPAK") endif() if (UNLEASHED_RECOMP_D3D12) diff --git a/UnleashedRecomp/os/linux/registry_linux.inl b/UnleashedRecomp/os/linux/registry_linux.inl index 459db772..d3717776 100644 --- a/UnleashedRecomp/os/linux/registry_linux.inl +++ b/UnleashedRecomp/os/linux/registry_linux.inl @@ -8,14 +8,14 @@ inline bool os::registry::Init() // TODO: read from file? template -bool os::registry::ReadValue(const std::filesystem::path& path, const std::string& name, T& data) +bool os::registry::ReadValue(const std::string_view& name, T& data) { return false; } // TODO: write to file? template -bool os::registry::WriteValue(const std::filesystem::path& path, const std::string& name, const T& data) +bool os::registry::WriteValue(const std::string_view& name, const T& data) { return false; } diff --git a/UnleashedRecomp/os/registry.h b/UnleashedRecomp/os/registry.h index 28cd7993..760512eb 100644 --- a/UnleashedRecomp/os/registry.h +++ b/UnleashedRecomp/os/registry.h @@ -5,10 +5,10 @@ namespace os::registry bool Init(); template - bool ReadValue(const std::string& name, T& data); + bool ReadValue(const std::string_view& name, T& data); template - bool WriteValue(const std::string& name, const T& data); + bool WriteValue(const std::string_view& name, const T& data); } #if _WIN32 diff --git a/UnleashedRecomp/os/win32/registry_win32.inl b/UnleashedRecomp/os/win32/registry_win32.inl index df0284f2..e5c2b1db 100644 --- a/UnleashedRecomp/os/win32/registry_win32.inl +++ b/UnleashedRecomp/os/win32/registry_win32.inl @@ -9,7 +9,7 @@ inline bool os::registry::Init() } template -bool os::registry::ReadValue(const std::string& name, T& data) +bool os::registry::ReadValue(const std::string_view& name, T& data) { HKEY hKey; @@ -17,7 +17,7 @@ bool os::registry::ReadValue(const std::string& name, T& data) return false; wchar_t wideName[128]; - int wideNameSize = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), name.size(), wideName, sizeof(wideName)); + int wideNameSize = MultiByteToWideChar(CP_UTF8, 0, name.data(), name.size(), wideName, sizeof(wideName)); if (wideNameSize == 0) { return false; @@ -90,7 +90,7 @@ bool os::registry::ReadValue(const std::string& name, T& data) } template -bool os::registry::WriteValue(const std::string& name, const T& data) +bool os::registry::WriteValue(const std::string_view& name, const T& data) { HKEY hKey; @@ -136,7 +136,7 @@ bool os::registry::WriteValue(const std::string& name, const T& data) if (wideString) { wchar_t wideName[128]; - int wideNameSize = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), name.size(), wideName, sizeof(wideName)); + int wideNameSize = MultiByteToWideChar(CP_UTF8, 0, name.data(), name.size(), wideName, sizeof(wideName)); if (wideNameSize == 0) { return false; @@ -147,7 +147,7 @@ bool os::registry::WriteValue(const std::string& name, const T& data) } else { - result = RegSetValueExA(hKey, name.c_str(), 0, dataType, pData, dataSize); + result = RegSetValueExA(hKey, name.data(), 0, dataType, pData, dataSize); } RegCloseKey(hKey);