HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
registry_win32.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "../utility/module.hpp"
8#include <string_view>
9#include <string>
10#include <vector>
11#include <cstdint>
12#include <optional>
13
14namespace hi::inline v1 {
15
16enum class registry_key { classes_root, current_config, current_user, local_machine, users };
17
26bool registry_delete(registry_key key, std::string_view path, std::string_view name);
27
35bool registry_delete(registry_key key, std::string_view path);
36
46[[nodiscard]] void registry_write(registry_key key, std::string_view path, std::string_view name, uint32_t value);
47
57[[nodiscard]] void registry_write(registry_key key, std::string_view path, std::string_view name, std::string_view value);
58
61[[nodiscard]] bool registry_exists(registry_key key, std::string_view path, std::string_view name);
62
71[[nodiscard]] std::optional<uint32_t> registry_read_dword(registry_key key, std::string_view path, std::string_view name);
72
81[[nodiscard]] std::optional<std::string> registry_read_string(registry_key key, std::string_view path, std::string_view name);
82
91[[nodiscard]] std::optional<std::vector<std::string>>
92registry_read_multi_string(registry_key key, std::string_view path, std::string_view name);
93
103template<typename T>
104[[nodiscard]] std::optional<T> registry_read(registry_key key, std::string_view path, std::string_view name) = delete;
105
106template<std::integral T>
107[[nodiscard]] inline std::optional<T> registry_read(registry_key key, std::string_view path, std::string_view name)
108{
109 if (hilet tmp = registry_read_dword(key, path, name)) {
110 return narrow_cast<T>(*tmp);
111 } else {
112 return std::nullopt;
113 }
114}
115
116template<>
117[[nodiscard]] inline std::optional<std::string> registry_read(registry_key key, std::string_view path, std::string_view name)
118{
119 return registry_read_string(key, path, name);
120}
121
122template<>
123[[nodiscard]] inline std::optional<std::vector<std::string>>
124registry_read(registry_key key, std::string_view path, std::string_view name)
125{
126 return registry_read_multi_string(key, path, name);
127}
128
129} // namespace hi::inline v1
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:13
std::optional< std::vector< std::string > > registry_read_multi_string(registry_key key, std::string_view path, std::string_view name)
Read a list of strings from the registry value.
bool registry_delete(registry_key key, std::string_view path, std::string_view name)
Delete a registry value.
bool registry_exists(registry_key key, std::string_view path, std::string_view name)
Check if a registry entry exists.
std::optional< T > registry_read(registry_key key, std::string_view path, std::string_view name)=delete
Read from the registry value.
Definition registry_win32.hpp:107
std::optional< uint32_t > registry_read_dword(registry_key key, std::string_view path, std::string_view name)
Read a DWORD registry value.
void registry_write(registry_key key, std::string_view path, std::string_view name, uint32_t value)
Write a DWORD registry value.
std::optional< std::string > registry_read_string(registry_key key, std::string_view path, std::string_view name)
Read a strings from the registry value.