Skip to content

Commit 9ae466a

Browse files
committed
Fix support for both UTF8 and UTF16
Dont cast to char and append directly, but instead use `Encoding` class to convert the data in the buffer. Also set Console output to UTF8 mode for cases where it outputs UTF8 but isnt set yet
1 parent 2608362 commit 9ae466a

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/ValveKV/KVParser.cs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,21 @@ public static KVObject Parse(BinaryReader reader)
7777
}
7878
}
7979

80-
// TODO: Correct this to produce correct wide string results
8180
private static string ReadString(BinaryReader reader, byte width=1)
8281
{
83-
StringBuilder builder = new StringBuilder();
84-
byte[] current = new byte[width];
82+
var buffer = new List<byte>();
83+
byte[] current;
8584

8685
while (true)
8786
{
88-
for (int i = 0; i < width ; ++i)
89-
{
90-
current[i] = reader.ReadByte();
91-
}
87+
current = reader.ReadBytes(width);
9288
if (current.All(val => val == 0))
93-
{
9489
break;
95-
}
9690
foreach (var c in current)
97-
{
98-
builder.Append((char)c);
99-
}
91+
buffer.Add(c);
10092
}
101-
return builder.ToString();
93+
return (width == 1 ? Encoding.UTF8 : Encoding.Unicode)
94+
.GetString(buffer.ToArray());
10295
}
10396
}
10497
}

src/cli/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
[assembly: AssemblyDescription("Parses and displays info about Steam .vdf files")]
77
[assembly: AssemblyCopyright("© Grub4K 2021")]
88

9-
[assembly: AssemblyVersion("2.2")]
10-
[assembly: AssemblyInformationalVersion("2.2")]
11-
[assembly: AssemblyFileVersion("2.2.0.0")]
9+
[assembly: AssemblyVersion("2.3")]
10+
[assembly: AssemblyInformationalVersion("2.3")]
11+
[assembly: AssemblyFileVersion("2.3.2.0")]

src/cli/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ static partial class Program
1515
{
1616
static int Main(string[] args)
1717
{
18+
Console.OutputEncoding = Encoding.UTF8;
1819
switch (args.ElementAtOrDefault(0)){
1920
case "-v":
2021
case "--version":

0 commit comments

Comments
 (0)