From b6265070d16961eb610cdc85f33332c476635ee0 Mon Sep 17 00:00:00 2001 From: LTRData Date: Sun, 12 Nov 2023 01:51:23 +0100 Subject: [PATCH] Some more public registry value API --- Library/DiscUtils.Registry/RegistryKey.cs | 2 +- Library/DiscUtils.Registry/RegistryValue.cs | 29 +++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Library/DiscUtils.Registry/RegistryKey.cs b/Library/DiscUtils.Registry/RegistryKey.cs index 349a49e9a..5dd0d9739 100644 --- a/Library/DiscUtils.Registry/RegistryKey.cs +++ b/Library/DiscUtils.Registry/RegistryKey.cs @@ -738,7 +738,7 @@ public RegistryValue GetRegistryValue(string name) return null; } - private RegistryValue AddRegistryValue(string name) + public RegistryValue AddRegistryValue(string name) { var valueListMem = ArrayPool.Shared.Rent(_cell.NumValues * 4); try diff --git a/Library/DiscUtils.Registry/RegistryValue.cs b/Library/DiscUtils.Registry/RegistryValue.cs index 75606915b..7acc93841 100644 --- a/Library/DiscUtils.Registry/RegistryValue.cs +++ b/Library/DiscUtils.Registry/RegistryValue.cs @@ -103,7 +103,26 @@ public object Value var buffer = ArrayPool.Shared.Rent(_cell.DataLength & int.MaxValue); try { - return ConvertToObject(GetData(buffer), DataType); + return ConvertToObject(GetRawData(buffer), DataType); + } + finally + { + ArrayPool.Shared.Return(buffer); + } + } + } + + /// + /// Gets raw binary value without interpretation as any particular data type. + /// + public byte[] RawValue + { + get + { + var buffer = ArrayPool.Shared.Rent(_cell.DataLength & int.MaxValue); + try + { + return GetRawData(buffer).ToArray(); } finally { @@ -116,7 +135,7 @@ public object Value /// The raw value data as a byte array. /// /// The value as a raw byte array. - internal Span GetData(Span maxBytes) + internal Span GetRawData(Span maxBytes) { if (_cell.DataLength < 0) { @@ -140,7 +159,7 @@ internal Span GetData(Span maxBytes) /// /// The data to store. /// The type of the data. - internal void SetData(ReadOnlySpan data, RegistryValueType valueType) + public void SetRawData(ReadOnlySpan data, RegistryValueType valueType) { // If we can place the data in the DataIndex field, do that to save space / allocation if ((valueType == RegistryValueType.Dword || valueType == RegistryValueType.DwordBigEndian) && data.Length <= 4) @@ -184,7 +203,7 @@ internal void SetData(ReadOnlySpan data, RegistryValueType valueType) public void SetValue(object value, RegistryValueType valueType) { var data = ConvertToData(value, valueType); - SetData(data.Span, valueType); + SetRawData(data.Span, valueType); } /// @@ -281,7 +300,7 @@ private string DataAsString() var buffer = ArrayPool.Shared.Rent(_cell.DataLength & int.MaxValue); try { - var data = GetData(buffer); + var data = GetRawData(buffer); switch (DataType) {