-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
98 lines (84 loc) · 2.91 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.IO;
using System.Text;
using CommandLine;
using GameFinder.StoreHandlers.BethNet;
using GameFinder.StoreHandlers.EGS;
using GameFinder.StoreHandlers.GOG;
using GameFinder.StoreHandlers.Steam;
using GameFinder.StoreHandlers.Xbox;
namespace GameFinder.Example
{
public static class Program
{
private const string LogFile = "log.log";
private static FileStream? _logFileStream;
private static StreamWriter? _streamWriter;
public static void Main(string[] args)
{
_logFileStream = File.Open(LogFile, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);
_streamWriter = new StreamWriter(_logFileStream, Encoding.UTF8);
Parser.Default.ParseArguments<Options>(args)
.WithParsed(Run);
_streamWriter.Dispose();
_logFileStream.Dispose();
}
private static void Log(string s)
{
Console.WriteLine(s);
_streamWriter?.WriteLine(s);
}
private static void RunHandler<THandler, TGame>(string handlerName, Action<TGame> logGame) where THandler : AStoreHandler<TGame>, new() where TGame : AStoreGame
{
Log($"Finding {handlerName} games...");
try
{
var handler = new THandler();
var res = handler.FindAllGames();
if (res.HasErrors)
{
Log($"{handlerName} has errors:\n{res.ErrorsToString()}");
}
if (!res.Value)
{
Log($"Unable to find {handlerName} games");
return;
}
Log($"Found {handler.Games.Count} {handlerName} games");
handler.Games.ForEach(logGame);
}
catch (Exception e)
{
Log($"Exception trying to find {handlerName} games:\n{e}");
}
}
private static void Run(Options options)
{
if (options.BethNet)
{
RunHandler<BethNetHandler, BethNetGame>("BethNet",
x => Log($"{x}: {x.Path}"));
}
if (options.EGS)
{
RunHandler<EGSHandler, EGSGame>("EGS",
x => Log($"{x}: {x.Path}"));
}
if (options.GOG)
{
RunHandler<GOGHandler, GOGGame>("GOG",
x => Log($"{x}: {x.Path}"));
}
if (options.Steam)
{
RunHandler<SteamHandler, SteamGame>("Steam",
x => Log($"{x}: {x.Path}"));
}
if (options.Xbox)
{
RunHandler<XboxHandler, XboxGame>("Xbox",
x => Log($"{x}: {x.Path}"));
}
}
}
}