-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
registry.h
146 lines (132 loc) · 6.18 KB
/
registry.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//
// registry.h - registry interface
//
// leccore library, part of the liblec library
// Copyright (c) 2019 Alec Musasa (alecmus at live dot com)
//
// Released under the MIT license. For full details see the
// file LICENSE.txt
//
#pragma once
#if defined(LECCORE_EXPORTS)
#include "leccore.h"
#else
#include <liblec/leccore.h>
#endif
#include <string>
namespace liblec {
namespace leccore {
/// <summary>Class for reading and writing to the Windows registry.</summary>
class leccore_api registry {
public:
/// <summary>The registry scope.</summary>
enum class scope {
/// <summary>Settings for the currently logged in user only.</summary>
current_user,
/// <summary>Settings for everyone that uses this computer.</summary>
/// <remarks>The application must be executed with administrator rights
/// to use this scope otherwise access will be denied.</remarks>
local_machine
};
/// <summary>The constructor.</summary>
/// <param name="registry_scope">The registry scope as defined in the
/// <see cref="scope"></see> enumeration.</param>
registry(scope registry_scope);
~registry();
/// <summary>Read from the registry.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="value_name">The value name, e.g. "Color"</param>
/// <param name="value">The value read from the registry.</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
[[nodiscard]]
bool do_read(const std::string& path,
const std::string& value_name,
std::string& value,
std::string& error);
/// <summary>Read binary data from the registry.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="value_name">The value name, e.g. "Installation ID"</param>
/// <param name="data">The raw binary data read from the registry.</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
[[nodiscard]]
bool do_read_binary(const std::string& path,
const std::string& value_name,
std::string& data,
std::string& error);
/// <summary>Write data to the registry.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="value_name">The value name, e.g. "Color"</param>
/// <param name="value">The value to be written to the registry
/// under <see cref="value_name"></see>, e.g. "#ffff00"</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
[[nodiscard]]
bool do_write(const std::string& path,
const std::string& value_name,
const std::string& value,
std::string& error);
/// <summary>Write binary data to the registry.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="value_name">The value name, e.g. "Installation ID"</param>
/// <param name="data">The raw binary data to be written to the registry
/// under <see cref="value_name"></see>.</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
[[nodiscard]]
bool do_write_binary(const std::string& path,
const std::string& value_name,
const std::string& data,
std::string& error);
/// <summary>Delete a <see cref="value_name"></see> from the registry.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="value_name">The value name, e.g. "Installation ID"</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
[[nodiscard]]
bool do_delete(const std::string& path,
const std::string& value_name,
std::string& error);
/// <summary>Delete a sub-key if it's empty.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
/// <remarks>Only deletes the sub-key if it's empty. If the sub-key is not empty
/// an access is denied error is returned. This is a useful method to call on the
/// Software\company-name sub-key after deleting a specific application's sub-key, e.g.
/// after deleting the sub-key Software\com.github.alecmus\PC Info using the
/// <see cref="do_recursive_delete"></see> it's a great idea to then call this method. If
/// no settings for other applications are stored under the Software\com.github.alecmus
/// subkey then it is deleted as well, leaving a clean registry. This is highly
/// recommended as it leaves a clean registry after all apps for a given company
/// are uninstalled.</remarks>
[[nodiscard]]
bool do_delete(const std::string& path,
std::string& error);
/// <summary>Delete a sub-key and everything contained within it,
/// including other sub-keys.</summary>
/// <param name="path">The path, relative to the scope as defined in the
/// <see cref="scope"></see> enumeration, e.g. Software\com.github.alecmus\PC Info</param>
/// <param name="error">Error information.</param>
/// <returns>True if successful, else false.</returns>
/// <remarks>Use with care as the changes are irreversible.</remarks>
[[nodiscard]]
bool do_recursive_delete(const std::string& path,
std::string& error);
private:
class impl;
impl& _d;
// Default constructor and copying an object of this class are not allowed
registry() = delete;
registry(const registry&) = delete;
registry& operator=(const registry&) = delete;
};
}
}