Skip to content

Commit 2608362

Browse files
committed
Add support for '*' as a wildcard on first entry
1 parent 113f9f2 commit 2608362

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

src/cli/AssemblyInfo.cs

+3-3
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.1")]
10-
[assembly: AssemblyInformationalVersion("2.1")]
11-
[assembly: AssemblyFileVersion("2.1.10.2")]
9+
[assembly: AssemblyVersion("2.2")]
10+
[assembly: AssemblyInformationalVersion("2.2")]
11+
[assembly: AssemblyFileVersion("2.2.0.0")]

src/cli/Program.cs

+32-22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Linq;
44
using System.Text;
5+
using System.Collections.Generic;
56
using System.Runtime.InteropServices;
67
using Microsoft.Win32;
78
using VDFparse;
@@ -102,20 +103,35 @@ static int Main(string[] args)
102103
case "info":
103104
return Info(vdfFile);
104105
}
105-
uint id;
106-
bool success = uint.TryParse(args[2], out id);
107-
if (!success)
106+
List<Dataset> processing;
107+
if (args[2] == "*")
108108
{
109-
Console.Error.WriteLine(ErrorInvalidNumber, args[2]);
110-
return 5;
109+
processing = vdfFile.Datasets;
110+
}
111+
else
112+
{
113+
uint id;
114+
bool success = uint.TryParse(args[2], out id);
115+
if (!success)
116+
{
117+
Console.Error.WriteLine(ErrorInvalidNumber, args[2]);
118+
return 5;
119+
}
120+
var dataset = vdfFile.FindByID(id);
121+
if (dataset == null)
122+
{
123+
Console.Error.WriteLine(ErrorNoId, id);
124+
return 6;
125+
}
126+
processing = new List<Dataset> {dataset};
111127
}
112128
switch (args[0])
113129
{
114130
case "json":
115131
int.TryParse(args.ElementAtOrDefault(4), out int indent);
116-
return Json(vdfFile, id, indent: 4);
132+
return Json(processing, indent: 4);
117133
case "query":
118-
return Query(vdfFile, id, args.Skip(3).ToArray());
134+
return Query(processing, args.Skip(3).ToArray());
119135
}
120136
}
121137
catch (Exception e)
@@ -137,29 +153,23 @@ static int Info(VDFFile source)
137153
return 0;
138154
}
139155

140-
static int Json(VDFFile source, uint id, int indent)
156+
static int Json(List<Dataset> datasets, int indent)
141157
{
142-
var dataset = source.FindByID(id);
143-
if (dataset == null)
158+
foreach (var dataset in datasets)
144159
{
145-
Console.Error.WriteLine(ErrorNoId, id);
146-
return 6;
160+
Console.WriteLine(dataset.Data.ToJSON(indent: indent));
147161
}
148-
Console.WriteLine(dataset.Data.ToJSON(indent: indent));
149162
return 0;
150163
}
151164

152-
static int Query(VDFFile source, uint id, string[] queries)
165+
static int Query(List<Dataset> datasets, string[] queries)
153166
{
154-
var dataset = source.FindByID(id);
155-
if (dataset == null)
156-
{
157-
Console.Error.WriteLine(ErrorNoId, id);
158-
return 6;
159-
}
160-
foreach (var query in queries)
167+
foreach (var dataset in datasets)
161168
{
162-
Console.WriteLine(String.Join("\n", dataset.Data.Search(query)));
169+
foreach (var query in queries)
170+
{
171+
Console.WriteLine(String.Join("\n", dataset.Data.Search(query)));
172+
}
163173
}
164174
return 0;
165175
}

0 commit comments

Comments
 (0)