17#if defined(__BORLANDC__)
129 : Key{}, Name{
move(
keyName)}, SubkeyCount{}, ValueCount{}, ShouldClose{
true}
135 const auto init = [&]()
noexcept ->
long
163 const auto r = init();
184 : Key{}, Name{}, SubkeyCount{}, ValueCount{}, ShouldClose{
true}
190 const auto init = [&]()
noexcept ->
long
212 const auto r = init();
238 const auto init = [&]()
noexcept ->
long
254 const auto r = init();
274 : Key{}, Name{}, SubkeyCount{}, ValueCount{}, ShouldClose{}
279 swap(SubkeyCount,
v.SubkeyCount);
280 swap(ValueCount,
v.ValueCount);
281 swap(ShouldClose,
v.ShouldClose);
282 WARN(!Key,
_T(
"TRegKey::TRegKey: Moved from invalid key"));
307 return ::RegQueryInfoKey(
Key,
331 const auto p =
const_cast<LPTSTR>(
i.Class.data());
336 &
i.MaxSubkeyNameSize,
337 &
i.MaxSubkeyClassSize,
341 &
i.SecurityDescriptorSize,
345 i.Class.shrink_to_fit();
424 const auto r = key->NukeKey(s);
454 : Data(key.QueryInfo().SecurityDescriptorSize)
456 auto n =
static_cast<DWORD>(Data.size());
489 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetControl: GetSecurityDescriptorControl failed"),
tstring{},
static_cast<long>(::GetLastError())};
505 if (!IsValid())
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetLength failed"),
tstring{}};
532 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetDacl: GetSecurityDescriptorDacl failed"),
tstring{},
static_cast<long>(::GetLastError())};
554 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetGroup: GetSecurityDescriptorGroup failed"),
tstring{},
static_cast<long>(::GetLastError())};
576 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetOwner: GetSecurityDescriptorOwner failed"),
tstring{},
static_cast<long>(::GetLastError())};
596 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetRevision: GetSecurityDescriptorControl failed"),
tstring{},
static_cast<long>(::GetLastError())};
645 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::GetSacl: GetSecurityDescriptorSacl failed"),
tstring{},
static_cast<long>(::GetLastError())};
665 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::Initialize: InitializeSecurityDescriptor failed"),
tstring{},
static_cast<long>(::GetLastError())};
681 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::RemoveDacl: SetSecurityDescriptorDacl failed"),
tstring{},
static_cast<long>(::GetLastError())};
698 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::RemoveGroup: SetSecurityDescriptorGroup failed"),
tstring{},
static_cast<long>(::GetLastError())};
714 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::RemoveOwner: SetSecurityDescriptorOwner failed"),
tstring{},
static_cast<long>(::GetLastError())};
729 if (
r !=
ERROR_SUCCESS)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::RemoveRmControl: SetSecurityDescriptorRMControl failed"),
tstring{},
static_cast<long>(
r)};
745 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::RemoveSacl: SetSecurityDescriptorSacl failed"),
tstring{},
static_cast<long>(::GetLastError())};
773 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::SetDacl: SetSecurityDescriptorDacl failed"),
tstring{},
static_cast<long>(::GetLastError())};
800 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::SetGroup: SetSecurityDescriptorGroup failed"),
tstring{},
static_cast<long>(::GetLastError())};
827 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::SetOwner: SetSecurityDescriptorOwner failed"),
tstring{},
static_cast<long>(::GetLastError())};
872 if (!
ok)
throw TXRegistry{
_T(
"TRegKey::TSecurityDescriptor::SetSacl: SetSecurityDescriptorSacl failed"),
tstring{},
static_cast<long>(::GetLastError())};
892 Key(key), Name(
name), DataType(
REG_NONE), Data(0), DataSize(0)
897#if defined(BI_COMP_BORLANDC)
911long TRegValue::QueryTypeAndSize()
913 long r = Key.
QueryValue(Name, &DataType,
nullptr, &DataSize);
923 Key(
iter.BaseKey()), Name(), DataType(
REG_NONE), Data(0), DataSize(0)
941 throw TXRegistry{
_T(
"TRegValue::operator uint32: Incompatible data type"), Key};
944 return *
reinterpret_cast<uint32*
>(&Data[0]);
955 throw TXRegistry{
_T(
"TRegValue::operator uint64: Incompatible data type"), Key};
958 return *
reinterpret_cast<uint64*
>(&Data[0]);
973 throw TXRegistry{
_T(
"TRegValue::operator LPCTSTR: Incompatible data type"), Key};
979 CHECK(!Data.empty());
981 const size_t n = Data.size() /
sizeof(
tchar);
982 if (
n == 0)
throw TXRegistry{
_T(
"TRegValue::operator LPCTSTR: Data size is zero"), Key};
983 WARN((Data.size() %
sizeof(
tchar)) != 0,
_T(
"TRegValue::operator LPCTSTR: Oddly sized string"));
984 WARN(s[
n - 1] !=
_T(
'\0'),
_T(
"TRegValue::operator LPCTSTR: String lacks null-termination"));
988 WARN(s[
n - 2] !=
_T(
'\0'),
_T(
"TRegValue::operator LPCTSTR: Multi-string lacks double null-termination"));
1001 return Data.empty() ?
nullptr : &Data[0];
1018 if (
dataSize == Data.size() && !Data.empty())
1138 try {std::vector<uint8>().swap(Data);}
1139 catch (...) {Data.clear();}
1150TRegValue::RetrieveOnDemand()
const
1152 if (!Data.empty())
return;
1153 if (DataType ==
REG_NONE || DataSize == 0)
throw TXRegistry{
_T(
"TRegValue::RetrieveOnDemand: Value is void"), Key};
1156 Data.resize(DataSize);
1159 if (
r !=
ERROR_SUCCESS)
throw TXRegistry{
_T(
"TRegValue::RetrieveOnDemand: QueryValue failed"), Key,
r};
1160 if (
dataType != DataType)
throw TXRegistry{
_T(
"TRegValue::RetrieveOnDemand: Type changed"), Key};
1161 if (
dataSize != DataSize)
throw TXRegistry{
_T(
"TRegValue::RetrieveOnDemand: Size changed"), Key};
1177 for (Count = 0; List[Count]; Count++)
1179 EnabledFlags =
new int8[Count];
1187 delete[] EnabledFlags;
1197 EnabledFlags[*
pc - 1] = 0;
1207 EnabledFlags[*
pc - 1]++;
1222 for (Count = 0; List[Count].
Param; Count++)
1225 Values =
new cpchar[Count];
1242 for (
int i = Count; --
i >= 0; )
1243 Values[
i] = List[
i].Default;
1304 for (; item && item->
Key; item++) {
1307 if (*item->
Key ==
' ') {
1315 if (
i < 0)
throw TXRegistry{
_T(
"TRegSymbolTable::UpdateParams failed"),
k};
1335# define _A2WB_(val) _A2WB(val,(tchar*)conv_buf)
1337# define _A2WB_(val) val
1387 if (*
pc == 0 && *
pt ==
_T(
' '))
1397 while (*(
pb-1) ==
_T(
' '))
1401 while (*
pt ==
_T(
' '))
1450 if (
in.peek() ==
_T(
'\\'))
1459 while (*(
pc-1) ==
_T(
' '))
1462 while (*(++
data) ==
_T(
' '))
1471 const uint8* buf =
reinterpret_cast<const uint8*
>(s);
1496 if (
in.peek() ==
_T(
'\\'))
1505 while (*(
pc-1) ==
_T(
' '))
1508 while (*(++
data) ==
_T(
' '))
1541# define _A2WB_(val) _A2WB(val,(tchar*)conv_buf)
1542# define _W2AB_(val) _W2AB(val,(tchar*)conv_buf)
1546# define _A2WB_(val) val
1547# define _W2AB_(val) val
#define WARN(condition, message)
#define PRECONDITION(condition)
auto GetLength() const -> DWORD
Returns the length, in bytes, of the security descriptor.
void RemoveGroup()
Removes the primary group information from the security descriptor.
void SetSacl(PACL sacl, bool saclDefaulted=false)
Sets the system access control list (SACL) of the security descriptor.
auto GetDacl() const -> std::optional< PACL >
Retrieves the discretionary access control list (DACL) from the security descriptor.
auto GetOwner() const -> PSID
Retrieves the owner information from the security descriptor.
void RemoveOwner()
Removes the owner information from the security descriptor.
auto IsValid() const noexcept -> bool
Determines whether the components of the security descriptor are valid.
TSecurityDescriptor(const TRegKey &key, SECURITY_INFORMATION infoRequested)
Retrieves a copy of the security descriptor protecting the specified open registry key.
void SetRmControl(UCHAR rmControl)
Sets the resource manager control bits of the security descriptor.
void Initialize(DWORD revision=SECURITY_DESCRIPTOR_REVISION)
Initializes a new security descriptor.
void SetOwner(PSID owner, bool ownerDefaulted=false)
Sets the owner information of the security descriptor.
void SetGroup(PSID group, bool groupDefaulted=false)
Sets the primary group information of the security descriptor.
auto GetControl() const -> SECURITY_DESCRIPTOR_CONTROL
Retrieves the control information from the security descriptor.
auto GetRevision() const -> DWORD
Retrieves the revision number of the security descriptor structure.
void RemoveDacl()
Removes the discretionary access control list (DACL) from the security descriptor.
void SetDacl(PACL dacl, bool daclDefaulted=false)
Sets the discretionary access control list (DACL) of the security descriptor.
auto GetRmControl() const -> std::optional< UCHAR >
Retrieves the resource manager control bits from the security descriptor.
auto GetGroup() const -> PSID
Retrieves the primary group information from the security descriptor.
void RemoveSacl()
Removes the system access control list (SACL) from the security descriptor.
auto GetSacl() const -> std::optional< PACL >
Retrieves the system access control list (SACL) from the security descriptor.
void RemoveRmControl()
Removes the resource manager control bits from the security descriptor.
Encapsulates a registration key in the Windows Registry.
long EnumValue(int index, TCHAR *valueName, uint32 &valueNameSize, uint32 *type=nullptr, uint8 *data=nullptr, uint32 *dataSize=nullptr) const
Enumerates the values associated with this key.
static auto GetClassesRoot() -> TRegKey &
Special predefined root key used by shell and OLE applications (HKEY_CLASSES_ROOT).
long NukeKey(LPCTSTR subKeyName)
Completely eliminates a child key, including any of its subkeys.
static auto GetUsers() -> TRegKey &
Special predefined root key defining the default user configuration (HKEY_USERS).
LPCTSTR GetName() const
Returns a string identifying this key.
static auto GetCurrentConfig() -> TRegKey &
Special predefined root key containing information about the current hardware profile of the local co...
auto HasSubkey(const tstring &keyName) const -> bool
Returns true if this key has a subkey with the given name.
DWORD SubkeyCount
Number of subkeys.
long DeleteKey(LPCTSTR subKeyName)
Deletes the specified subkey of this registry key.
tstring Name
This Key's Name.
THandle Key
This Key's Handle.
auto GetSubkey(const tstring &keyName, REGSAM samDesired=KEY_READ) const -> std::optional< TRegKey >
Returns the subkey with the given name, if it exists.
long SetValue(LPCTSTR valName, uint32 type, const uint8 *data, uint32 dataSize) const
Associates a value with this key.
long DeleteValue(LPCTSTR valName) const
Removes a named value from this registry key.
auto GetSecurity(SECURITY_INFORMATION infoRequested, PSECURITY_DESCRIPTOR secDesc, DWORD *secDescSize) const -> long
Retrieves a copy of the security descriptor protecting this registry key.
~TRegKey()
Closes the underlying key handle, if owned.
auto GetValue(const tstring &valueName) const -> std::optional< TRegValue >
Returns the value with the given name, if it exists within this key.
bool ShouldClose
Should this key be closed on destruction.
long QueryValue(LPCTSTR valName, uint32 *type, uint8 *data, uint32 *dataSize) const
Retrieves the value associated with the unnamed value for this key in the registry.
auto QueryInfo() const -> TInfo
Functional-style overload.
static auto GetCurrentUser() -> TRegKey &
Special predefined root key defining the preferences of the current user (HKEY_CURRENT_USER).
static auto GetClassesRootClsid() -> TRegKey &
Commonly used subkey by shell and OLE applications (HKEY_CLASSES_ROOT\CLSID).
static auto GetPerformanceData() -> TRegKey &
Special predefined root key used to obtain performance data (HKEY_PERFORMANCE_DATA).
auto HasValue(const tstring &valueName) const -> bool
Return true if this key has a value with the given name.
TRegKey(THandle baseKey, tstring keyName, REGSAM samDesired=KEY_ALL_ACCESS, TCreateOK createOK=CreateOK)
Creates or opens a key given a base key and a subkey name.
DWORD ValueCount
Number of value entries.
static auto GetLocalMachine() -> TRegKey &
Special predefined root key defining the physical state of the computer (HKEY_LOCAL_MACHINE).
TCreateOK
Enumeration used to specify whether a key should be created (or simply opened).
@ CreateOK
Create key if it does not exist.
Iterator for walking thru the subkeys of a key.
A registration parameter table, composed of a list of TRegItems.
const tchar *& Value(int i)
Return the value of the param entry at the passed index.
void ResetDefaultValues()
TRegParamList(const TEntry *)
int Find(LPCTSTR param)
Looks for a given param in this param list.
void StreamOut(TRegItem *item, tostream &out)
void Init(LPCTSTR filter)
TRegTemplateList Templates
void UpdateParams(TLangId lang, TRegItem *item)
TRegSymbolTable(TRegKey &basekey, LPCTSTR tplList[], const TRegParamList::TEntry *paramList)
void DisableAll()
Disables all templates in this list.
bool IsActive(int i) const
Returns true if the template at the passed index is active, false otherwise.
void Activate(int i)
Activates the template at the passed index.
TRegTemplateList(TRegKey &basekey, LPCTSTR _list[])
int GetCount() const
Returns the number of templates in this list.
TRegKey & GetBaseKey()
Returns the registry key upon which these templates are based.
void Enable(int i)
Enables the template at the passed index.
void EnableAll()
Enables all templates in this list.
Encapsulates a value-data entry within one registration key.
const uint8 * GetData() const
Returns the data associated with this value.
TRegValue(const TRegKey &key, LPCTSTR name)
Creates a registry value object from the specified registry key and name.
long Delete()
Removes the value from its associated key, and clears the state of this object.
TRegValue & operator=(uint32 value)
Forwards to Set (uint32).
long Set(uint32 type, const uint8 *data, uint32 dataSize)
Sets the data associated with this value.
Iterator for walking through the values of a key.
static void Update(TRegKey &baseKey, tistream &in)
Writes lines to registry.
static int Unregister(TRegList ®Info, const TUnregParams *params, const TRegItem *overrides=nullptr)
Unregisters entries given a reglist.
static int Validate(TRegKey &baseKey, tistream &in)
Returns number of mismatched entries.
Thrown for errors within the Registry classes.
Object Windows Library (OWLNext Core)
owl::uint16 TLangId
Holds a language ID, a predefined number that represents a base language and dialect.
auto to_tstring(const T &v) -> tstring
#define COUNTOF(s)
Array element count Important: Only use this with an argument of array type.
Various types of smart pointer templatized classes.
General Registry access & registration implementation TRegKey, TRegValue, TRegKeyIterator,...
const tchar * Translate(TLangId lang)
translate string
A single registration list entry.
TLocaleString Value
Localizable value for parameter or subkey.
const char * Key
Non-localized parameter or registry subkey.
Data structure returned by QueryInfo.
LPCTSTR Param
Substituted parameter name.
Definition of TSystem, a system information provider class.
#define GetExceptionCode()