Skip to content

Commit

Permalink
Some more public registry value API
Browse files Browse the repository at this point in the history
  • Loading branch information
LTRData committed Nov 12, 2023
1 parent bf4e5ed commit b626507
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Library/DiscUtils.Registry/RegistryKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public RegistryValue GetRegistryValue(string name)
return null;
}

private RegistryValue AddRegistryValue(string name)
public RegistryValue AddRegistryValue(string name)
{
var valueListMem = ArrayPool<byte>.Shared.Rent(_cell.NumValues * 4);
try
Expand Down
29 changes: 24 additions & 5 deletions Library/DiscUtils.Registry/RegistryValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,26 @@ public object Value
var buffer = ArrayPool<byte>.Shared.Rent(_cell.DataLength & int.MaxValue);
try
{
return ConvertToObject(GetData(buffer), DataType);
return ConvertToObject(GetRawData(buffer), DataType);
}
finally
{
ArrayPool<byte>.Shared.Return(buffer);
}
}
}

/// <summary>
/// Gets raw binary value without interpretation as any particular data type.
/// </summary>
public byte[] RawValue
{
get
{
var buffer = ArrayPool<byte>.Shared.Rent(_cell.DataLength & int.MaxValue);
try
{
return GetRawData(buffer).ToArray();
}
finally
{
Expand All @@ -116,7 +135,7 @@ public object Value
/// The raw value data as a byte array.
/// </summary>
/// <returns>The value as a raw byte array.</returns>
internal Span<byte> GetData(Span<byte> maxBytes)
internal Span<byte> GetRawData(Span<byte> maxBytes)
{
if (_cell.DataLength < 0)
{
Expand All @@ -140,7 +159,7 @@ internal Span<byte> GetData(Span<byte> maxBytes)
/// </summary>
/// <param name="data">The data to store.</param>
/// <param name="valueType">The type of the data.</param>
internal void SetData(ReadOnlySpan<byte> data, RegistryValueType valueType)
public void SetRawData(ReadOnlySpan<byte> 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)
Expand Down Expand Up @@ -184,7 +203,7 @@ internal void SetData(ReadOnlySpan<byte> data, RegistryValueType valueType)
public void SetValue(object value, RegistryValueType valueType)
{
var data = ConvertToData(value, valueType);
SetData(data.Span, valueType);
SetRawData(data.Span, valueType);
}

/// <summary>
Expand Down Expand Up @@ -281,7 +300,7 @@ private string DataAsString()
var buffer = ArrayPool<byte>.Shared.Rent(_cell.DataLength & int.MaxValue);
try
{
var data = GetData(buffer);
var data = GetRawData(buffer);

switch (DataType)
{
Expand Down

0 comments on commit b626507

Please sign in to comment.