-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
75 lines (65 loc) · 2.02 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using KVSurfaceUpdater;
using System.Diagnostics;
using System.Reflection;
using ValveKeyValue;
Console.WriteLine("KV Updater by rob5300");
Converter? converter = null;
var type = typeof(Converter);
var converterTypes = type.Assembly.GetTypes().Where(x => !x.IsAbstract && x.IsSubclassOf(type)).ToList();
string allConverters = string.Join(", ", converterTypes.Select(x => $"{converterTypes.IndexOf(x)}: {x.Name.Replace("Converter", "")}"));
while(converter == null)
{
Console.WriteLine("Enter name/num of converter to use:");
Console.WriteLine(allConverters);
string input = Console.ReadLine();
try
{
int index = int.Parse(input);
converter = (Converter?)Activator.CreateInstance(converterTypes[index]);
}
catch (Exception)
{
foreach(var converterType in converterTypes)
{
if(converterType.Name.ToLower().Contains(input.ToLower()))
{
converter = (Converter?)Activator.CreateInstance(converterType);
}
}
}
}
string targetFolder = null;
while(string.IsNullOrEmpty(targetFolder))
{
Console.WriteLine("-= Input target folder:");
targetFolder = Console.ReadLine();
string relativePath = Path.Combine(Directory.GetCurrentDirectory(), targetFolder);
if (Directory.Exists(relativePath))
{
targetFolder = relativePath;
}
else if(!Directory.Exists(targetFolder))
{
Console.WriteLine("Folder does not exist!");
targetFolder = null;
}
}
Console.WriteLine("Input prefix for converted files (leave empty for no prefix):");
KV3Object.Prefix = Console.ReadLine();
if(KV3Object.Prefix != "")
{
Console.WriteLine($"Will use prefix '{KV3Object.Prefix}'.");
}
if (Directory.Exists(targetFolder))
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
await converter.ConvertAsync(targetFolder);
stopwatch.Stop();
Console.WriteLine($"Done! Took {stopwatch.Elapsed}.");
}
else
{
Console.WriteLine("-= Directory doesnt exist, exiting...");
}
Console.ReadKey();