-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
56 lines (47 loc) · 1.95 KB
/
Config.cs
File metadata and controls
56 lines (47 loc) · 1.95 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
51
52
53
54
55
56
using AngryMonkey.POCO;
using Newtonsoft.Json;
namespace AngryMonkey
{
internal static class Config
{
internal static AppConfig LoadConfig(string path)
{
var cfg = JsonConvert.DeserializeObject<AppConfig>(File.ReadAllText(path))
?? throw new InvalidOperationException("Invalid config JSON.");
cfg.RootFolder = Path.GetFullPath(cfg.RootFolder);
cfg.SourceRoot = MakePath(cfg.RootFolder, cfg.SourceRoot);
cfg.StagingRoot = MakePath(cfg.RootFolder, cfg.StagingRoot);
cfg.TemplatesFolder = MakePath(cfg.RootFolder, cfg.TemplatesFolder);
cfg.HtmlTemplate = MakePath(cfg.RootFolder, cfg.HtmlTemplate);
for (int i = 0; i < cfg.DataFolders.Length; i++)
{
cfg.DataFolders[i] = MakePath(cfg.SourceRoot, cfg.DataFolders[i]);
}
return cfg;
}
internal static string MakePath(string root, string p)
{
if (string.IsNullOrWhiteSpace(p)) return root;
return Path.IsPathRooted(p) ? Path.GetFullPath(p) : Path.GetFullPath(Path.Combine(root, p));
}
internal static Hive[] BuildHives(AppConfig cfg)
{
return cfg.Hives.Select(h =>
{
var folder = (h.Folder ?? "").Trim().Trim('\\', '/');
string source = string.IsNullOrEmpty(folder) ? cfg.SourceRoot : Path.Combine(cfg.SourceRoot, folder);
string dest = string.IsNullOrEmpty(folder) ? cfg.StagingRoot : Path.Combine(cfg.StagingRoot, folder);
Enum.TryParse(h.Type, out HiveType ht);
return new Hive
{
Name = h.Name,
Source = source,
Destination = dest,
ShortName = h.ShortName,
Type = ht,
URL = h.Url
};
}).ToArray();
}
}
}