HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
user_settings_win32_impl.hpp
1
2#pragma once
3
4#include "user_settings_intf.hpp"
5#include "../win32/win32.hpp"
6#include "../path/path.hpp"
7#include "../macros.hpp"
8#include <format>
9#include <string>
10#include <expected>
11#include <system_error>
12
13hi_export_module(hikogui.settings.user_settings : impl);
14
15namespace hi { inline namespace v1 {
16
17[[nodiscard]] inline std::string user_setting_registry_path()
18{
19 return std::format("Software\\{}\\{}", get_application_vendor(), get_application_name());
20}
21
26[[nodiscard]] inline std::expected<std::string, std::error_code> get_user_setting_string(std::string_view name) noexcept
27{
28 // First check the registry of the current-user.
29 if (hilet value = win32_RegGetValue<std::string>(HKEY_CURRENT_USER, user_setting_registry_path(), name)) {
30 return *value;
31 } else if (value.error() != win32_error::file_not_found) {
32 return std::unexpected{std::error_code{value.error()}};
33 }
34
35 // Now check the registry for the local-machine.
36 // These are settings that where made by the Administrator of the machine.
37 if (hilet value = win32_RegGetValue<std::string>(HKEY_LOCAL_MACHINE, user_setting_registry_path(), name)) {
38 return *value;
39 } else {
40 return std::unexpected{std::error_code{value.error()}};
41 }
42}
43
44[[nodiscard]] inline std::expected<long long, std::error_code> get_user_setting_integral(std::string_view name) noexcept
45{
46 // First check the registry of the current-user.
47 if (hilet value = win32_RegGetValue<long long>(HKEY_CURRENT_USER, user_setting_registry_path(), name)) {
48 return *value;
49 } else if (value.error() != win32_error::file_not_found) {
50 return std::unexpected{std::error_code{value.error()}};
51 }
52
53 // Now check the registry for the local-machine.
54 // These are settings that where made by the Administrator of the machine.
55 if (hilet value = win32_RegGetValue<long long>(HKEY_LOCAL_MACHINE, user_setting_registry_path(), name)) {
56 return *value;
57 } else {
58 return std::unexpected{std::error_code{value.error()}};
59 }
60}
61
62inline std::error_code set_user_setting(std::string_view name, std::string_view value) noexcept
63{
64 return win32_RegSetKeyValue(HKEY_CURRENT_USER, user_setting_registry_path(), name, value);
65}
66
67inline std::error_code set_user_setting(std::string_view name, long long value) noexcept
68{
69 return win32_RegSetKeyValue(HKEY_CURRENT_USER, user_setting_registry_path(), name, narrow_cast<uint32_t>(value));
70}
71
72inline std::error_code delete_user_setting(std::string_view name) noexcept
73{
74 return win32_RegDeleteKeyValue(HKEY_CURRENT_USER, user_setting_registry_path(), name);
75}
76
78{
79 return win32_RegDeleteKey(HKEY_CURRENT_USER, user_setting_registry_path());
80}
81
82}}
83
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
std::error_code delete_user_settings() noexcept
Delete all user-setting for the application.
Definition user_settings_win32_impl.hpp:77
std::expected< std::string, std::error_code > get_user_setting_string(std::string_view key) noexcept
Definition user_settings_win32_impl.hpp:26
std::error_code delete_user_setting(std::string_view key) noexcept
Delete a user-setting for the application.
Definition user_settings_win32_impl.hpp:72
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
std::error_code set_user_setting(std::string_view key, std::string_view value) noexcept
Set a user-setting for the application.
Definition user_settings_win32_impl.hpp:62
T unexpected(T... args)