-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.cs
62 lines (55 loc) · 1.79 KB
/
Configuration.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
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace Hibiki
{
internal static class Configuration
{
private static Dictionary<string, string> Core = new Dictionary<string, string>();
public static async Task LoadAsync(LoadOptions options = null)
{
await Task.Run(async () =>
{
try
{
var ConfigText = File.ReadAllText(options == null ? @"hibikiconfig.json" : options.ConfigLocation);
Core = JsonConvert.DeserializeObject<Dictionary<string, string>>(ConfigText);
}
catch (Exception e)
{
await Logger.ErrorAsync("Cannot read from configuration file. Exiting...");
await Logger.ErrorAsync(e.Message);
Console.Read();
Environment.Exit(0);
}
});
}
public static async Task<ConfigurationSearchResult> TrySearchAsync(string key)
{
return await Task.Run(() =>
{
string Result;
var CSearch = new ConfigurationSearchResult();
var Success = Core.TryGetValue(key, out Result);
CSearch.Success = Success;
CSearch.Result = Result;
return CSearch;
});
}
public static async Task<string> SearchAsync(string key)
{
return (await TrySearchAsync(key)).Result;
}
}
public class ConfigurationSearchResult
{
public bool Success;
public string Result;
}
public class LoadOptions
{
public string ConfigLocation = @"hibikiconfig.json";
}
}