forked from kwsch/SysBot.AnimalCrossing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (42 loc) · 1.55 KB
/
Program.cs
File metadata and controls
50 lines (42 loc) · 1.55 KB
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
using System;
using System.IO;
using System.Threading.Tasks;
using System.Text.Json;
using System.Threading;
namespace SysBot.AnimalCrossing
{
internal static class Program
{
private const string ConfigPath = "config.json";
private static async Task Main(string[] args)
{
Console.WriteLine("Starting up...");
if (args.Length > 1)
Console.WriteLine("This program does not support command line arguments.");
if (!File.Exists(ConfigPath))
{
CreateConfigQuit();
return;
}
var json = File.ReadAllText(ConfigPath);
var config = JsonSerializer.Deserialize<CrossBotConfig>(json);
SaveConfig(config);
await BotRunner.RunFrom(config, CancellationToken.None).ConfigureAwait(false);
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
private static void SaveConfig(CrossBotConfig config)
{
var options = new JsonSerializerOptions {WriteIndented = true};
var json = JsonSerializer.Serialize(config, options);
File.WriteAllText(ConfigPath, json);
}
private static void CreateConfigQuit()
{
SaveConfig(new CrossBotConfig {IP = "192.168.0.1", Port = 6000});
Console.WriteLine("Created blank config file. Please configure it and restart the program.");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}