Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/Microsoft.PowerShell.Commands.Diagnostics/PdhHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;

using System.Text;
using Microsoft.PowerShell.Commands.GetCounter;
using Microsoft.Win32;

Expand Down Expand Up @@ -531,20 +531,38 @@ public uint ConnectToDataSource(string dataSourceName)
return res;
}

public uint ConnectToDataSource(StringCollection blgFileNames)
public uint ConnectToDataSource(List<string> blgFileNames)
{
if (blgFileNames.Count == 1)
{
return ConnectToDataSource(blgFileNames[0]);
}

string doubleNullTerminated = string.Empty;
foreach (string fileName in blgFileNames)
int length = blgFileNames.Count + 1;
for (int i = 0; i < blgFileNames.Count; i++)
{
doubleNullTerminated += fileName + '\0';
length += blgFileNames[i].Length;
}

doubleNullTerminated += '\0';
string doubleNullTerminated = string.Create(length, blgFileNames, (buf, fileNames) =>
{
int pos = 0;
for (int i = 0; i < fileNames.Count; i++)
{
string fileName = fileNames[i];
int fileNameLength = fileName.Length;
fileName.AsSpan().CopyTo(
buf.Slice(pos, fileNameLength));
pos += fileNameLength;
buf[pos] = '\0';
pos++;
}

buf[pos] = '\0';
pos++;

Debug.Assert(pos == length, "Error constructing double null terminated string.");
});

return ConnectToDataSource(doubleNullTerminated);
}
Expand Down